Scaling in D3D problem...

Started by
1 comment, last by Taulin 23 years, 5 months ago
Hello, While rotations and translations work fine, I seem to be having some trouble with scaling and was hoping someone here might know what the problem is. I have a simple cube, rendering is not a problem. I also have a directional light pointing < 0, 0, 1 > Camera is at origin, and the cube is translated to z = +8. No problems. If I apply any scale to the matrix that is set in the d3ddevice using SetTransform, weird things happen. First, by increasig the z scale ( _33 ), the side facing the camera gets darker as it gets closer. Also, if I increase the x scal ( _11 ) it increases the size of the cube along x and z. I have looked at the matrix I am passing into my device right before and it is set and it looks ok. ex: 1.000000, 0.000000, 0.000000, 0.000000 0.000000, 1.000000, 0.000000, 0.000000 0.000000, 0.000000, 4.826808, 0.000000 0.000000, 0.000000, 8.000000, 1.000000 If anyone knows what I am missing I would really appreciate because my brain is frying. Did I forget to set something on the device? Thansk in advance!
Advertisement
Well, let''s see what happens when you multiply your x,y,z by that matrix of yours. Two matrices are mul''d as follows: you mul each element of each row of the first matrix by corresponding element of each column of the second matrix, and you sum up the results to get the corresponding element of resulting matrix.

Since [x,y,z] is a single row matrix (vector), we get:

xr,yr,zr=[x,y,z]*[your_matrix]=[x,y,z*4.8268+8] which means you effectively stretch the object along z axis with no change along axes x and y.

A proper scaling matrix should look like this:

Scale_factor 0.0000000000 0.0000000000 0.0
0.0000000000 Scale_factor 0.0000000000 0.0
0.0000000000 0.0000000000 Scale_factor 0.0
x__translate y__translate z__translate 1.0
The example matrix was intended to show that
I was translating it along the z-axix 8 units and
scaling along z axis also 4.82.. units.
The strange thing is, the more I scale on the z
axis, the less light the polygon facing my
directionall light ( <0, 0, 1> ) gets. Adding
any rotations to the matrix work fine, and all lighting
is perfect, except the face that originaly faced toward the camera, which is at ( 0, 0, -10 ) is scaled darker.

Why would scaling on the z-axis ( which is facing
a directional light perfectly ) effect how much
light shines on it?

This topic is closed to new replies.

Advertisement