Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Floru

Normal vector

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

Is there a function to calculate the normal vector for given points (for example 3 points). I''m using Direct3D and I have problems with lightning because I can''t calculate the normal vector. Thanks

Share this post


Link to post
Share on other sites
Advertisement
You''ll want to use the crossproduct, like so:

VECTOR V1,V2,V3, N;

N = Normalize(CrossProduct(V2-V1,V3-V1));

Remember that the direction of the normal depends on the order of its arguments so you must be consistent in the ordering.

Share this post


Link to post
Share on other sites
If you don''t want to calculate normals yourself and want dx to calculate lighting and your app is not realtime, then you can use d3ddev.setrenderstate D3DRENDERSTATE_NORMALIZENORMALS, TRUE.

Share this post


Link to post
Share on other sites
Doesn''t it do it for lighting only though? Isn''t that the solution to Floru''s problem? It is of course a horrible way to do it.

Share this post


Link to post
Share on other sites
D3DRENDERSTATE_NORMALIZENORMALS should be set to true as your Direct3D drivers are usually much faster at normalizing than anything you can do yourself (unless you do some insane optimizations ). However, for the lighting to work you have to calculate the direction of the surface normal, and that is computed with the crossproduct as in my above answer.

The D3DRENDERSTATE_NORMALIZENORMALS state is usually used to be able to keep the right magnitude of the normals after transformations, for example scaling.

Share this post


Link to post
Share on other sites

  • 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!