onorinbejasus

02-28-2010, 06:59 PM

For an assignment, we had to implements transformations on shapes without using GL calls. I created my own matrices to do this, one for translation, scaling, and 3 for rotation. My scaling and translation work without a hitch. My rotation, though, does not. The object is rotating, but it is shrinking as it does so. Here is how I do it:

my rotation matrix:

T.xRotation[0][0] = 1;

T.xRotation[0][1] = 0;

T.xRotation[0][2] = 0;

T.xRotation[0][3] = 0;

T.xRotation[1][0] = 0;

T.xRotation[1][1] = cos(T.xDeg);

T.xRotation[1][2] = -sin(T.xDeg);

T.xRotation[1][3] = 0;

T.xRotation[2][0] = 0;

T.xRotation[2][1] = sin(T.xDeg);

T.xRotation[2][2] = cos(T.xDeg);

T.xRotation[2][3] = 0;

T.xRotation[3][0] = 0;

T.xRotation[3][1] = 0;

T.xRotation[3][2] = 0;

T.xRotation[3][3] = 1;

where I set the angle:

case REAL_ROTATION_MODE: // rotates around x-axis clockwise

{

T.xDeg = (10*M_PI/180);

};break;

and where I update my shape:

void my_display() {

makeTransformations();

// clear all pixels, reset depth

glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT );

// init to identity

glMatrixMode(GL_MODELVIEW);

glLoadIdentity() ;

gluLookAt(x_camera, y_camera, z_camera, // x,y,z coord of the camera

lookAtX, lookAtY, lookAtZ,

0,1,0); // the direction of Up (default is y-axis)

draw_axes();

int i,j;

for(i = 0; i <= theShape.vs; i++)

for(j = 0; j <= theShape.rs; j++)

{

multiply(theShape.verts[i][j], T.Translation, theShape.verts[i][j]);

multiply(theShape.verts[i][j], T.Scaling, theShape.verts[i][j]);

multiply(theShape.verts[i][j], T.xRotation, theShape.verts[i][j]);

multiply(theShape.verts[i][j], T.yRotation, theShape.verts[i][j]);

multiply(theShape.verts[i][j], T.zRotation, theShape.verts[i][j]);

multiply(theShape.verts[i][j], T.ArbitraryAxis, theShape.verts[i][j]);

}

draw_object(theShape.type);

// this buffer is ready

glutSwapBuffers();

T.tX = 0; T.tY = 0; T.tZ = 0; // resets translation values

T.sX = 1; T.sY = 1; T.sZ = 1; // resets scaling values

T.xDeg = 0; T.yDeg = 0; T.zDeg = 0; // resets rotation values

}

I am sure my multiple method works, for it is working on my translation and scaling. Any help would be greatly appreciated! :)

my rotation matrix:

T.xRotation[0][0] = 1;

T.xRotation[0][1] = 0;

T.xRotation[0][2] = 0;

T.xRotation[0][3] = 0;

T.xRotation[1][0] = 0;

T.xRotation[1][1] = cos(T.xDeg);

T.xRotation[1][2] = -sin(T.xDeg);

T.xRotation[1][3] = 0;

T.xRotation[2][0] = 0;

T.xRotation[2][1] = sin(T.xDeg);

T.xRotation[2][2] = cos(T.xDeg);

T.xRotation[2][3] = 0;

T.xRotation[3][0] = 0;

T.xRotation[3][1] = 0;

T.xRotation[3][2] = 0;

T.xRotation[3][3] = 1;

where I set the angle:

case REAL_ROTATION_MODE: // rotates around x-axis clockwise

{

T.xDeg = (10*M_PI/180);

};break;

and where I update my shape:

void my_display() {

makeTransformations();

// clear all pixels, reset depth

glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT );

// init to identity

glMatrixMode(GL_MODELVIEW);

glLoadIdentity() ;

gluLookAt(x_camera, y_camera, z_camera, // x,y,z coord of the camera

lookAtX, lookAtY, lookAtZ,

0,1,0); // the direction of Up (default is y-axis)

draw_axes();

int i,j;

for(i = 0; i <= theShape.vs; i++)

for(j = 0; j <= theShape.rs; j++)

{

multiply(theShape.verts[i][j], T.Translation, theShape.verts[i][j]);

multiply(theShape.verts[i][j], T.Scaling, theShape.verts[i][j]);

multiply(theShape.verts[i][j], T.xRotation, theShape.verts[i][j]);

multiply(theShape.verts[i][j], T.yRotation, theShape.verts[i][j]);

multiply(theShape.verts[i][j], T.zRotation, theShape.verts[i][j]);

multiply(theShape.verts[i][j], T.ArbitraryAxis, theShape.verts[i][j]);

}

draw_object(theShape.type);

// this buffer is ready

glutSwapBuffers();

T.tX = 0; T.tY = 0; T.tZ = 0; // resets translation values

T.sX = 1; T.sY = 1; T.sZ = 1; // resets scaling values

T.xDeg = 0; T.yDeg = 0; T.zDeg = 0; // resets rotation values

}

I am sure my multiple method works, for it is working on my translation and scaling. Any help would be greatly appreciated! :)