PDA

View Full Version : Transformation matrix problem!



matsurambo
07-30-2008, 05:18 AM
hi... i need help about transformation, i mean rotation object.
i want to rotate object without glRotatef, so i multiple the points and matrix
ex.
rotate x
1 0 0 | | x | | x
0 cos -sin |X | y |=| cos * y + (-sin)*z
0 sin cos | | z | | sin * y + cos * z

my line program
double RadTheta=theta*3.14159265358979323846/180.0;

double CosRadTheta=cos(RadTheta);
double SinRadTheta=sin(RadTheta);

for (unsigned int i=1;i<=o->nPoints;i++){
o->points[i].x=o->points[i].x;
o->points[i].y=(o->points[i].y*CosRadTheta)+((-SinRadTheta)*o->points[i].z);
o->points[i].z=(SinRadTheta*o->points[i].y)+(o->points[i].z*CosRadTheta);

}

the problem is, the result is not corect. my object not rotate corectly. please help me... what i must do?
i have change degree to radian (angle*3,14.../180).

Zengar
07-30-2008, 05:24 AM
You fall prey for a very basic algorithmic mistake mathematicians usually make: you change the y coordinate but then use it again to compute the z coordinate, where you should have used the old value. You should use a temporary variable that will store the old y value, like



old_y = y
// compute new y
// compute new z, with old_y

matsurambo
07-30-2008, 05:53 AM
oh... i see...
my point y is change!
wow thank you!