I have a problem in my 3d engine that I was wondering if someone could help me with. I can create the normal to a polygon and store it with the rest of the points. This way I can transform it along with the points. The problem is when I rotate and translate the polygons, the normal is not a unit mormal anymore with respect to the origin. I''m not sure how everyone else can get this lighting thing to work and I can''t. I would be grateful for some help. Thanks.
Mmmm, I'm no expert, but I think you'll have to store it as two points and subtract them to get the normal(If you scale the objects, you'll have to normalize the normal ). The way you're doing it, any transforming except rotation you do will distort it (I think)(therefore I am.)
When transforming normals the first thing you should do is to crop the fourth column and fourth row of the transformation matrix, yielding a 3 by 3 matrix. This matrix must then be inverted and then transposed before transforming the normal.
However with rotation the inversion and transposing is not necessary as they cancel each other (This has to do with the fact that the rotation matrix is orthogonal and the inversion is the same as the transposing).
With uniform scaling you don''t have to perform the inversion and transposing either, instead only a division by the scalefactor is needed.
For other non orthogonal transformations you must compute the transposed inversion of the transformation matrix, otherwise the normal will be wrong.
I''m not using either API, because I always program my own system before using an API so that I understand the theory behind it. Otherwise it is worthless.
Anyway, what does everyone think is the best way to do transformations on polygons (i.e. Rotate object and translate according to world axes, or to rotate and then translate the object according to the new transformed axes as in how an airplane can pitch up and then travel in the new path). I''m trying to do it the second way, but as you''ve seen from my previous post, I can''t get the lighting to work correctly that way.
I think it is good that you''re making your own routines instead of using DX or OpenGL I learned that way myself.
If you''re only using rotation and translation it is really simple to transform the normals. Just omit the translation part of the transformmatrix (the forth row or column depending on how you are multiplying the vectors with the matrices).
The way I transform my objects, and most other people too I suspect, is to first rotate the objects and then translate according to world axes. That way the translation is just the addition of the objects positions in world coordinates.