Jump to content
  • Advertisement


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


coupla questions..

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

answer to any would be great. 1) how to get the normal in the correct direction of, say, a counter-cw triangle? Cross product, unfortunately, is somewhat unpredictable and will give a correct normal, but one that may be facing the opposite direction. DOES it matter in d3d.. i think it does, but to save me the trouble...? 2) that takes me to second q, how to quickly figure out if a set of points is ccw or cw? i suppose i just compare x,y,z values? thanks in advance!

Share this post

Link to post
Share on other sites
For the CCW order use the ''right hand rule'' : close your right hand in the direction you describe vertices...raise your thumb and you''ll get normal direction.
For example describe a triangle on a paper in CCW order...your thumb will be directed against you (visible triangle). If you see the triangle from the other side of the paper you''ll get a normal with opposite direction.

You cannot say if a triangle is described in CW or CCW order : it depends on which side you''re seeing it !

For example if you''re rendering a cube you should describe every face with the normal pointing out of the cube.

Share this post

Link to post
Share on other sites
In Direct3D it does matter the order of the vertices. If there not in CW or CCW order (depends on what you set it to), then the back side (the side you don''t see) won''t render, even if you rotate it towards you.

Share this post

Link to post
Share on other sites
In OpenGL if you rotate a triangle (or move the viewer on the other side), the triangle becomes visible and viceversa!

I''m not sure but I think that every renderer that performs a ''back face culling'' has the same behaviour.

Are D3D so strange ?

Share this post

Link to post
Share on other sites
no, d3d isn''t so strange..
but i''m afraid my question remains... assuming i go with right hand side rule, or whatever you call it, how can i calculate the triangle normal, and be sure that it is pointing in the correct direction? the cross product will calculate a correct normal, but depending on how you pass the parameters, it might end up pointing in the opposite direction...

Share this post

Link to post
Share on other sites
If you dont see the triangle it's facing in the opposite direction...and it's facing in your direction when you are able to see it Are you hating me, he ?

When do D3D, OpenGL, Glide and every API decide if a triangle is facing in the right direction?

Suppose you have a triangle with vertices P0,P1 and P2
They apply model transforming to P0,P1,P2.
After this, you are viewing the (world) transformed triangle
from (0,0,0) along z axis.
These API compute the polygon (or triangle) normal (you should not confuse it with vertex normal used for lightning!)

>>>>>We're using CCW

normal = v1 x v2 (cross product)

where v1 = P1-P0
and v2 = P2-P0

What is the plane on which the triangle lies ?

plane : ax + by + cz + d = 0

where (a,b,c) is the normal
and d = - normal * P0 (dot product)

d is the distance from the origin to the plane (if normal is 'normalized')

if(d>0) you see the triangle but if(d<0) you dont see the triangle because you're behind its plane!

In practice we cannot read the transformed vertices (it's slow reading info from hardware) so we suppose that the viewer is not in the origin...
Of course if you have transformed the polygon you must know where it is (if you have a static environment you can compute vertices one time).

the algorithm:
- get polygon vertices

- compute the plane (normal and 'd' coefficient)

- compute the distance from the plane to the viewer

distance = ( normal*viewer_pos + d ) / L

where L = lenght(normal) = sqrt(a*a+b*b+c*c)

if(distance<0) you're behind the plane and you cannot see the polygon (if you use CW order invert the sign!)

I continue to not understand why you want to compute the exact normal (D3D will take care of this).
If you use the 'right hand rule' to describe your objects there is no problem and if you dont see the polygon invert the order!

Edited by - Andrea on 3/11/00 2:01:36 PM

Share this post

Link to post
Share on other sites
well, the reason i compute the normal is i don''t want to switch the shading mode in d3d every poly, so i assign normals like in flat mode to the three verts... and do gouraud all the way..
BUT, if it is less expensive to switch the shading mode than do gouraud for even flat polys, please fill me in.


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!