triangle normal vector
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.
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:
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. -
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. -
Remember, if you multiply them backwards then your normal''s facing the opposite way.
------------------------------
#pragma twice
------------------------------
#pragma twice
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.
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
(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
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
-------------------------------
I'll screw up whoever screws around with the gamedev forum!
..-=gLaDiAtOr=-..
Edited by - furby100 on October 10, 2000 3:11:24 AM
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=-..
-------------------------------
I'll screw up whoever screws around with the gamedev forum!
..-=gLaDiAtOr=-..
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
------------------------------
#pragma twice
sharewaregames.20m.com
Edited by - furby100 on October 10, 2000 3:34:54 AM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement