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

Rendering a quad, facing a normal

Started by Bruno Oct 10, 2004 at 5:30 AM 1 replies 450+ views
Original Post
Bruno
Bruno
Hi, This is to be used in bullet decals. So, lets imagine i have the point of impact, and the normal of the face at where the impact was made. With this two values, is there a way to render a quad that faces that normal ? thanks
Sharlin
Sharlin
Yes. You need two vectors perpendicular to the normal, let's call them Up and Right. These can be obtained for example using cross product. Given a unit-length normal vector N:
// epsilon is something like 1e-3// we do this to prevent floating-point inaccuracies// also, cross(v,v) is a null vector which we don't wantif(N.y < 1-epsilon)  Right = cross(N, (0,1,0))else  Right = cross(N, (1,0,0))Up = cross(Right, N)

Now, the vertices for the quad are (if you want the quad centered around the point of impact):
V1 = Point - Up/2 - Right/2V2 = Point - Up/2 + Right/2V3 = Point + Up/2 + Right/2V4 = Point + Up/2 - Right/2
Bruno
Bruno
Thanks :)

Topic Locked

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

Sign in to reply to this topic.