# vertex normals

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

## Recommended Posts

When calculating the face normal, can I get the value by drawing a line anywhere on the surface, and finding the perpendicular line? IN other words, the normal is just the perpendicular slope, and not actually holding values relative to the face?

##### Share on other sites
Correct. But there's no reason the face normal has to be perpendicular to the face if you're wanting different lighting effects.

##### Share on other sites
Thanks Steve, I really appreciate your help. Could you recommend any particular book or article on DX or perhaps a good math book?

##### Share on other sites
If you just want to get the normal for a triangle, you'll need three points, since there's an infinite number of lines perpendicular to a line.

Usually, if you have three vertices A, B and C, you can get the normal as:
normalize(vAB x vAC)
Where vAB is the vector from A to B (or B-A if you have A and B as points), vAC is the vector from A to C, and x is the cross product.
Also note that the order you do the cross product in depends on the winding order of the triangle (I.e. vAB x vAC may give you the opposite of the normal if your points are in counter-clockwise order, in which case you'd do vAC x vAB instead).

##### Share on other sites
wow this sheds some light on things, I actually thought vectors were directions. I thought wrong. Thanks again.

##### Share on other sites
Quote:
 Original post by VprMatrix89wow this sheds some light on things, I actually thought vectors were directions.
Bare in mind that Direct3D confuses this issue by using a "vector" datatype (D3DXVECTORn for example) but in code it can be used to store points (amongst other things)... so be careful with your definitions between "proper" maths and Direct3D coding [smile]

Quote:
 Could you recommend any particular book or article on DX or perhaps a good math book?
Yes, I personally recommend
Mathematics For 3D Game Programming And Computer Graphics, Second Edition. It's pretty comprehensive but also quite easy to read - both editions have served me well!

Also, remember this site has a Maths & Physics forum that you can ask more general maths questions in. They're a nice enough bunch over there [grin]

hth
Jack

##### Share on other sites
Quote:
 Original post by VprMatrix89wow this sheds some light on things, I actually thought vectors were directions. I thought wrong. Thanks again.
A vector has both magnitude (length) and direction. The vector (0, 0, 1) has a length of 1, and a direction of +Z. The vector (0, 0, 2) has the same direction, but twice the length.

If you have two points, and you want to get a vector that describes point B from point A (The direction from point A to point B), you just subtract B from A. Example:
D3DXVECTOR3 ptA(10, 15, 7);D3DXVECTOR3 ptB(20, 20, 5);D3DXVECTOR3 vAB = ptB - ptA; // vAB = (10, 5, -2)

That way, vAB is the direction you need to go in from point A (or the coordinates you need to add to point A) to get to point B.

Since a 3D vector has 3 components, and a 3D point has 3 components, they're usually used interchangeably.

I'd highly recommend having a look on Google for some 3D geometry tutorials; this stuff is fairly fundamental to 3D graphics and D3D and you'll probably have difficulty with other areas of D3D if you're not completely clear on the basics first.