PDA

View Full Version : translation using my own matrices



Bino
09-11-2000, 05:34 PM
I have an object located at the origin and I'm trying to translate it using my own matrix(instead of glTranslate). My matrix looks like this:
float translate[16] = { 1.0, 0.0, 0.0, 5.0,
0.0, 1.0, 0.0,-3.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0 };
Simple right? Well the problem is that I don't what to do to make it translate my object. I tried using glLoadMatrix and then glMultMatrix, but my object doesn't move. Am I doing something wrong?

Thanks, Bino

[This message has been edited by Bino (edited 09-12-2000).]

Relic
09-11-2000, 11:19 PM
Almost correct.
The order in which the matrices are stored in the array is colunm-wise. Yours is row-wise.

See the image in the glLoadMatrix help here: http://msdn.microsoft.com/library/default.asp?URL=/library/psdk/opengl/legalgl_62pa.htm

So
GLfloat translate[16] =
{
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
5.0, -3.0, 0.0, 1.0
};

should do the trick.
Also look at the glMultMatrix command if you want to integrate your matrix in between some other tansformation calls.

Bino
09-12-2000, 02:42 PM
Forget that first question. I have a new one http://www.opengl.org/discussion_boards/ubb/smile.gif How do I rotate an object using matrices? I how to set up the matrix, but what do I do after that?(Since glMultMatrix doesn't work anymore) I heard you have to use loops or something like that, is that right?

Thanks, Bino

[This message has been edited by Bino (edited 09-12-2000).]

Gabriel
09-12-2000, 03:43 PM
The opengl call glRotate work this way:

typedef float Matrixf[16];
void CreateRotateMatrixf (Matrixf mat, float a, float x, float y, float z)
{
float InvSqrt = isqrt (x * x + y * y + z * z);
float Ux = x * InvSqrt,
Uy = y * InvSqrt,
Uz = z * InvSqrt;

float sinA = (float) sin (a * PI / 180.0f), cosA = (float) cos (a * PI / 180.0f);
Matrixf SsinA, UUt, ImUUt;

SsinA[4] = -Uz * sinA;
SsinA[8] = Uy * sinA;
SsinA[1] = Uz * sinA;
SsinA[9] = -Ux * sinA;
SsinA[2] = -Uy * sinA;
SsinA[6] = Ux * sinA;

UUt[0] = Ux * Ux;
UUt[4] = Uy * Ux;
UUt[8] = Uz * Ux;
UUt[1] = UUt[4];
UUt[5] = Uy * Uy;
UUt[9] = Uz * Uy;
UUt[2] = UUt[8];
UUt[6] = UUt[9];
UUt[10]= Uz * Uz;

ImUUt[0] = (1 - UUt[0]) * cosA;
ImUUt[4] = -UUt[4] * cosA;
ImUUt[8] = -UUt[8] * cosA;
ImUUt[1] = -UUt[1] * cosA;
ImUUt[5] = (1 - UUt[5]) * cosA;
ImUUt[9] = -UUt[9] * cosA;
ImUUt[2] = -UUt[2] * cosA;
ImUUt[6] = -UUt[6] * cosA;
ImUUt[10]= (1 - UUt[10]) * cosA;

mat[0] = UUt[0] + ImUUt[0];
mat[4] = UUt[4] + ImUUt[4] + SsinA[4];
mat[8] = UUt[8] + ImUUt[8] + SsinA[8];
mat[12] = 0.0f;
mat[1] = UUt[1] + ImUUt[1] + SsinA[1];
mat[5] = UUt[5] + ImUUt[5];
mat[9] = UUt[9] + ImUUt[9] + SsinA[9];
mat[13] = 0.0f;
mat[2] = UUt[2] + ImUUt[2] + SsinA[2];
mat[6] = UUt[6] + ImUUt[6] + SsinA[6];
mat[10] = UUt[10] + ImUUt[10];
mat[14] = 0.0f;
mat[3] = 0.0f;
mat[7] = 0.0f;
mat[11] = 0.0f;
mat[15] = 1.0f;
}

Use that... it works...