• ### Popular Now

• 14
• 12
• 9
• 10
• 13

#### Archived

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

# triangle normal vector

This topic is 6369 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 on other sites
thx,that formula was what i was looking for

##### Share on other sites
Remember, if you multiply them backwards then your normal''s facing the opposite way.

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

##### Share on other sites
another question: which normal vector do i get ? one pointing up or down ? does it make any difference ? i need the normal vectors for lighting.

##### 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

##### Share on other sites
double post, hmmm....

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

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

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

##### 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 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