Sign in to follow this  

Rendering a quad, facing a normal

This topic is 4811 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

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

Share this post


Link to post
Share on other sites
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 want
if(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/2
V2 = Point - Up/2 + Right/2
V3 = Point + Up/2 + Right/2
V4 = Point + Up/2 - Right/2

Share this post


Link to post
Share on other sites

This topic is 4811 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this