#174679 - iainprice - Thu Jul 08, 2010 8:44 pm
I have a problem, it keeps saying that matrix is used un-initiated....
[code]t contains floats
void DrawCubes(void)
{
m4x4 *matrix;
for (int i = 0; i < CUBECOUNT; i++)
{
matrix->m[0] = t.rot[0][0];
matrix->m[4] = t.rot[0][1];
matrix->m[8] = t.rot[0][2];
matrix->m[1] = t.rot[1][0];
matrix->m[5] = t.rot[1][1];
matrix->m[9] = t.rot[1][2];
matrix->m[2] = t.rot[2][0];
matrix->m[6] = t.rot[2][1];
matrix->m[10] = t.rot[2][2];
matrix->m[12] = t.pos[0];
matrix->m[13] = t.pos[1];
matrix->m[14] = t.pos[2];
matrix->m[3] = 0.0f;
matrix->m[7] = 0.0f;
matrix->m[11] = 0.0f;
matrix->m[15] = 1.0f;
glPushMatrix();
glMultMatrix4x4(matrix);
drawcube(0.1, 0.1, 0.1);
glPopMatrix(1);
}
}
[/code]
#174680 - headspin - Thu Jul 08, 2010 9:10 pm
You're using a pointer without creating an object. Just use
And change
Code: |
matrix->m[0] = t.rot[0][0];
... |
to
Code: |
matrix.m[0] = t.rot[0][0];
... |
If you used a pointer you would have to "new" it then "delete" it later.
Eg.
Code: |
m4x4* matrix = new m4x4();
...
delee matrix; |
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game
#174681 - iainprice - Thu Jul 08, 2010 9:33 pm
glMultMatrix4x4(matrix);
needs a pointer
so I'll try new and delete.....
thanks
#174684 - headspin - Thu Jul 08, 2010 9:49 pm
iainprice wrote: |
glMultMatrix4x4(matrix);
needs a pointer
so I'll try new and delete.....
thanks |
You don't need to use new and delete just send it the address
Code: |
m4x4 matrix;
...
glMultMatrix4x4(&matrix); |
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game
#174686 - iainprice - Thu Jul 08, 2010 10:33 pm
m4x4* matrix = new m4x4();
void DrawCubes(void)
{
matrix->m[0] = t.rot[0][0];
matrix->m[4] = t.rot[0][1];
matrix->m[8] = t.rot[0][2];
matrix->m[1] = t.rot[1][0];
matrix->m[5] = t.rot[1][1];
matrix->m[9] = t.rot[1][2];
matrix->m[2] = t.rot[2][0];
matrix->m[6] = t.rot[2][1];
matrix->m[10] = t.rot[2][2];
matrix->m[12] = t.pos[0];
matrix->m[13] = t.pos[1];
matrix->m[14] = t.pos[2];
matrix->m[3] = 0.0f;
matrix->m[7] = 0.0f;
matrix->m[11] = 0.0f;
matrix->m[15] = 1.0f;
glPushMatrix();
glMultMatrix4x4(matrix);
drawcube(0.1, 0.1, 0.1);
glPopMatrix(1);
printf("y=%f ",t.pos[1]);
}
or
m4x4 matrix;
void DrawCubes(void)
{
matrix.m[0] = t.rot[0][0];
matrix.m[4] = t.rot[0][1];
matrix.m[8] = t.rot[0][2];
matrix.m[1] = t.rot[1][0];
matrix.m[5] = t.rot[1][1];
matrix.m[9] = t.rot[1][2];
matrix.m[2] = t.rot[2][0];
matrix.m[6] = t.rot[2][1];
matrix.m[10] = t.rot[2][2];
matrix.m[12] = t.pos[0];
matrix.m[13] = t.pos[1];
matrix.m[14] = t.pos[2];
matrix.m[3] = 0.0f;
matrix.m[7] = 0.0f;
matrix.m[11] = 0.0f;
matrix.m[15] = 1.0f;
glPushMatrix();
glMultMatrix4x4(&matrix);
drawcube(0.1, 0.1, 0.1);
glPopMatrix(1);
printf("y=%f ",t.pos[1]);
}
Both ways are happy and compile but neither translates the cube.
i hate pointers, I always seem to get things mixed up with passing the pointer or the address or a pointer to a pointer......
#174692 - elhobbs - Thu Jul 08, 2010 11:22 pm
It is hard to say why it does not work as you do not show enough code to tell. What is the current matrix, what values did you put in your matrix. Why not just use gltranslate and glrotate?
#174693 - iainprice - Thu Jul 08, 2010 11:41 pm
How can i change a 4x4 to xyz rotation and xyz tranform?
On my example:
matrix.m[12] = t.pos[0];
matrix.m[13] = t.pos[1];
matrix.m[14] = t.pos[2];
is the transform I do after the rotation......
Thanks, nearly sorted now :)