Public Group

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

Recommended Posts

Hello, I have little problem with normals. I don't know how to compute them

Here is my vertex-struct
struct D3DVERTEX { float fX, fY, fZ; DWORD dwColor; D3DVECTOR Normal; };

And here are my vertices(?)
D3DVERTEX aQuad[] = {{1.0f,-1.0f,1.0f, 0xffffff00}, {3.0f,-1.0f,1.0f,0xffffff00}, {1.0f, 1.0f,1.0f,0xffffff00}, {3.0f, 1.0f,1.0f,0xffffff00}, {3.0f, -1.0f, 1.0f, 0xffffff00}, {3.0f, 1.0f, 1.0f, 0xffffff00}, {3.0f, -1.0f, 3.0f, 0xffffff00}, {3.0f, 1.0f, 3.0f, 0xffffff00}, {1.0f, -1.0f, 1.0f, 0xffffff00}, {1.0f, 1.0f, 1.0f, 0xffffff00}, {1.0f, -1.0f, 3.0f, 0xffffff00}, {1.0f, 1.0f, 3.0f, 0xffffff00}, {1.0f, -1.0f, 1.0f, 0xffffff00}, {3.0f, -1.0f, 1.0f, 0xffffff00}, {1.0f, -1.0f, 3.0f, 0xffffff00}, {3.0f, -1.0f, 3.0f, 0xffffff00}, {1.0f, 1.0f, 1.0f, 0xffffff00}, {3.0f, 1.0f, 1.0f, 0xffffff00}, {1.0f, 1.0f, 3.0f, 0xffffff00}, {3.0f, 1.0f, 3.0f, 0xffffff00}, {1.0f,-1.0f,3.0f,0xffffff00}, {3.0f,-1.0f,3.0f,0xffffff00}, {1.0f, 1.0f,3.0f,0xffffff00}, {3.0f, 1.0f,3.0f,0xffffff00}, };

Share on other sites
Just write the normals behind the position and the color.

The first four vertices in aQuad are the front of the cube and the normal has to stand vertical on the quad.
This means that the normal must be parallel with the z-axis (if the up-vector is the y-axis).
So the first four points would be:

 {1.0f, -1.0f, 1.0f, 0xffffff00, D3DXVECTOR3(0, 0, -1) }, {3.0f, -1.0f, 1.0f, 0xffffff00, D3DXVECTOR3(0, 0, -1) }, {1.0f, 1.0f, 1.0f, 0xffffff00, D3DXVECTOR3(0, 0, -1) }, {3.0f, 1.0f, 1.0f, 0xffffff00, D3DXVECTOR3(0, 0, -1) }, 
The next four are the right side of the quad, thus the normal would be D3DXVECTOR3(1, 0, 0);

I am not really good in explaining this, but I hope it helped.

Share on other sites
I don't understand

Share on other sites
In case of a single quad, find two independent vectors that lie within the plane and compute their cross-product. If your quad is made up from the points A,B,C and D, you can use the two vectors (A-B) and (A-C) for example.

If your normal seems to come out wrong remember that you might want to normalize it (hence the name, I guess) and that the cross-product is non-commutative: cross(x,y) = -cross(y,x)

If you don't know the cross-product just check Wikipedia. Its implementation is pretty straight-forward.

- Michael

Share on other sites

...
If your normal seems to come out wrong remember that you might want to normalize it (hence the name, I guess) ...

The length of a vector computed by the cross-product is
| a x b | == | a | * | b | * sin( <a,b> )
and hence direct proportional to the length of the both argument vectors and the sine of the angle between the both vectors. Because one often only needs the unscaled direction for e.g. lighting, setting a normal vector to its unit length is usual.

I'm not a mathematician, but I'd explain it so: The term "normal" here means a direction w.r.t. a reference, namely that it is orthogonal e.g. to a plane or curve. It falls into the same category as tangent, bi-tangent (for a plane) or bi-normal (for a curve) do. The term "normalization" means to apply a norm to a vector (in this case). The norm we usually apply is the Euclidean Norm.

1. 1
Rutin
26
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 10
• 9
• 9
• 9
• 46
• Forum Statistics

• Total Topics
631751
• Total Posts
3002077
×