Archived

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

triangle normal vector

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

i build a small landscape with direct3d triangles. now i need the normal vectors for the triangles d3dvertex-objects. how can i calculate them ? sorry if this is in the tutorials,but i didnt find it.

Share this post


Link to post
Share on other sites
I don''t really know how D3D defines vectors and such, but assuming they look something like:

struct vector3 {
float x;
float y;
float z;
}

And assuming a triangle is defined by 3 vector3''s (and texture-coords and stuff, of course) named v1, v2, and v3 you can do this:
    
vector3 normal;
normal = crossProduct (v2 - v1, v2 - v3);


In effect you take the cross product of the vector (v2-v1) and the vector (v2-v3).

-Neophyte


- Death awaits you all with nasty, big, pointy teeth. -

Share this post


Link to post
Share on other sites
YOu get the right one by multiplying anticlockwise, ie:
(vertex 2 - vertex 1) x (vertex 2 - vertex 3)

I think that is correct. I could be wrong about that though, and it might be the other way round. If it goes wrong try it the other way.

------------------------------
#pragma twice


sharewaregames.20m.com

Share this post


Link to post
Share on other sites
double post, hmmm....

-------------------------------
I'll screw up whoever screws around with the gamedev forum!

..-=gLaDiAtOr=-..

Edited by - furby100 on October 10, 2000 3:11:24 AM

Share this post


Link to post
Share on other sites
I''m glad you''re the new moderator but I hope that your ego doesn''t grow and do stupid things like you just did a minute ago. Thanks. You can''t just edit my post and say whatever you feel like in there because I don''t want you to. Why did you have to offend me because I pointed out that you double posted? You''re the moderator, you should watch what you say if you want to stay there to be one.

-------------------------------
I'll screw up whoever screws around with the gamedev forum!

..-=gLaDiAtOr=-..

Share this post


Link to post
Share on other sites
I misread you. If you were just trying to help, thankyou. I think you misread me as well, as just someone messing around. Look, you won't find anyone's posts edited. I was quite upset at the time anyway. I thought you were finding fault. Shall I delete these posts? They don't really help the thread much. I apologise Gladiator.

------------------------------
#pragma twice


sharewaregames.20m.com

Edited by - furby100 on October 10, 2000 3:34:54 AM

Share this post


Link to post
Share on other sites
The usual way of computing the triangle normal is like this:

n = (v1 - v2) x (v1 - v3)

This is why counter-clockwise triangles are culled in D3D and clockwise triangles are culled in OGL. This plus the fact that D3D uses a lefthanded system whereas OGL uses a righthanded one.



- WitchLord

Share this post


Link to post
Share on other sites
Witchy... I mean A.Jey

Double post?

something''s wrong here...

-------------------------------
I'll screw up whoever screws around with the gamedev forum!

..-=gLaDiAtOr=-..

Share this post


Link to post
Share on other sites
quote:

This is why counter-clockwise triangles are culled in D3D and clockwise triangles are culled in OGL.



FYI - You can change the direction of culling with this function in OpenGL: glFrontFace(GL_CCW); or glFrontFace(GL_CW);

In my game I use GL_CCW. It seems to work with all the 3d file formats that I have written code for.

Share this post


Link to post
Share on other sites