Jump to content
  • Advertisement
Sign in to follow this  

Rendering a quad, facing a normal

This topic is 5400 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))
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
Sign in to follow this  

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!