Skip to main content
GameDev.net gamedev.net
🔒 Locked

Decal Verts

Started by ms291052 Jan 12, 2004 at 4:47 PM 0 replies 400+ views
Original Post
ms291052
ms291052
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.