Home » Community » Forums » OpenGL » OpenGL transform matrix
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 OpenGL transform matrix
Post New Topic  Post Reply 
I'm making a space-shooter-demo for fun and I have built a matrix that stores rotation and position of the ship. I've tried it and it rotates correctly and everything but when I change the position nothing happens, the ship is still at the origin. I'm using glMultMatrix() for this and I would like to know what format OpenGL uses for the transformation matrix and why I can't move the ship.

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Since unfortunately we're not psychic, we can't know what is wrong with your matrix without seeing it (ie. the code that generates it).

OpenGL uses column major order (by default). A 4x4 matrix looks like this in memory:
[0  4  8 12]
[1  5  9 13]
[2  6 10 14]
[3  7 11 15]

The upper left 3x3 part represents rotations and scaling (and shearing), the top right 3 element column (12, 13, 14) the translation:

[R0 R3 R6 Tx]
[R1 R4 R7 Ty]
[R2 R5 R8 Tz]
[ 0  0  0  1]


Now show us the code that generates your matrix, and we can see further.

 User Rating: 1996   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

It is what you described.

double mat[16];
mat[0] = Cell(0,0); mat[4] = Cell(1,0); mat[8] = Cell(2,0); mat[12] = Cell(3,0);
mat[1] = Cell(0,1); mat[5] = Cell(1,1); mat[9] = Cell(2,1); mat[13] = Cell(3,1);
mat[2] = Cell(0,2); mat[6] = Cell(1,2); mat[10] = Cell(2,2); mat[14] = Cell(3,2);
mat[3] = Cell(0,3); mat[7] = Cell(1,3); mat[11] = Cell(2,3); mat[15] = Cell(3,3);
glMultMatrixd(mat);



Cell(x,y) is a function that multiplies the rotation matrix and the translation matrix so that I get the transformation matrix.

double TRMATRIX::Cell(int x, int y) {
    return rot[0][y] * pos[x][0] +
           rot[1][y] * pos[x][1] +
           rot[2][y] * pos[x][2] +
           rot[3][y] * pos[x][3];
}



The rotation matrix looks like this:

[R1 R2 R3 0]
[R4 R5 R6 0]
[R7 R8 R9 0]
[0  0  0  1]


and the translation matrix looks like this:

[1 0 0 X]
[0 1 0 Y]
[0 0 1 Z]
[0 0 0 1]


 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Solved.

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: