Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Decal Verts

This topic is 5419 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I''m trying to create decals on my walls from them being shot. So far my code''s working on most surfaces but some odd surfaces. It specifically appears to dislike non-axial planes (as in not XY, YZ, or XZ planes). Also, it often seems to dislike changes in the y-coordinate between the decal''s position and the player''s position. Anyway, here''s some psuedocode:
Vector HitPos //Center of the decal

Vector PlayerPos //The position of the player

Vector PlayerOrientation //Orientation is offsetted by a random amount to emulate inaccuracy

Vector Normal //Normal to the plane

Vector DecalVerts[4] //Four vertices of the decal

Plane  plane //Plane of the tri that the decal is to be placed on

Real  size //size of the decal

if(Dot(Plane, PlayerPos))
normal = -normal

Vector tempvec = Cross( PlayerPos - HitPos, (0, 1,0) )
Vector PlaneY = Cross( tempvec, Normal)
Vector PlaneX = Cross( Normal, PlaneY )

DecalVerts[0] = HitPos - PlaneX*size + PlaneY*size + normal*0.001f; //Offset by the normal a little to avoid Z-Fighting

DecalVerts[1] = HitPos + PlaneX*size + PlaneY*size + normal*0.001f;
DecalVerts[2] = HitPos - PlaneX*size - PlaneY*size + normal*0.001f;
DecalVerts[3] = HitPos + PlaneX*size - PlaneY*size + normal*0.001f;
Is this the proper method for doing this? Thanks, ms

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!