Jump to content
  • Advertisement
Sign in to follow this  
havythoai

OpenGL How to draw normal vectors like this

This topic is 3947 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 everybody, I'm new to OpenGL. I'm doing the machining simulation software, I got the problem that how to draw normal vectors like this. http://upload.tinhco.net/thoai/normal.jpg Thank you :)

Share this post


Link to post
Share on other sites
Advertisement
Render a line from position to position + scale * normal where scale is some value that controls the length of the line. Assuming your normals are indeed unit length, a scale of 1 will result in a line 1 unit long.

Share this post


Link to post
Share on other sites
The normals in the image have 1D texture mapped, which is a gradient 1D image from blue to white. The centroid (the centre of a triangle) point can be easily computed by averaging the sum of 3 points. And Kalidor mentioned how to find the other end point.

Here is a code snippet to draw normals
glBindTexture(GL_TEXTURE_1D, texId);

// draw lines with 1D texture
glBegin(GL_LINES);
glTexCoord1f(0); glVertex3fv(point1);
glTexCoord1f(1); glVertex3fv(point2);
...
glEnd();

glBindTexture(GL_TEXTURE_1D, 0);


Share this post


Link to post
Share on other sites
Actually, to get the gradient you don't need to use a texture. You can just set the color of the first point on the line to blue and the color of the second point to white, turn off texturing and lighting, and OGL will do the rest.

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.

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!