PDA

View Full Version : Manual matrices



onorinbejasus
02-28-2010, 07: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! :)

Dark Photon
03-01-2010, 05:40 AM
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: ... Any help would be greatly appreciated! :)
These forums are not for "please debug my homework for me", requests. You can do better than that. Break down what you're doing, trace it through, push an example or two through it by hand, and if necessary ask "specific" questions here. You'll figure it out.

A few tips though: this stuff is all over the net (try this (http://www.lmgtfy.com/?q=matrix+tutorial+site%3Agamedev.net)). Further, this is covered in virtually every 3D graphics book out there. Pick one up!