1

I'm making a little game in which I want to throw an object in direction I am facing. The problem is that my (camera) orientation is determined by model/view matrix. And this matrix is supplied by system (on android device).

How can I compute vector which will serve as velocity vector for my thrown object?
I tried multiplying some vectors with the matrix, but results doesn't give me a clue how to accomplish this.

Matrix contains only rotational part (no scale, skew or translate).
I am working with OpenGL ES 1.1, but it probably doesn't matter.

Following this answer I was able to get rotation angles around each axis, but I still don't know how to build my velocity vector from it.

EDIT: What I am trying to accomplish is to rotate model/view matrix in whatever ways, and throwing object the way I am facing. I need the object to eventually accelerate to the ground. I have no problem computing this trajectory, if I know exact vector I'm (camera is) facing.

Thanks for any help.

Community
  • 1
  • 1
sidon
  • 1,434
  • 1
  • 17
  • 30

1 Answers1

2

The first 3 columns of the modelview matrix are the bases of the view coordinate system. So all you need is the 3rd column (or row, depending if you're going from camera to world, or from world to camera).

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • Thanks for your answer. However I'm not able to make it work the way you describe it. If I rotate matrix (after glLoadIndenity) only around X axis, it works fine. But if I rotate around Z and then around X (in GL in reverse order), the vector is still pointing same way as without Z rotation. It is understandable, because rotating around Z axis as I see it doesn't change the third column in matrix. – sidon Apr 24 '12 at 16:14
  • Are you actually extracting the column? OpenGL orders matrices in column major order. So try exchanging "rows" and "columns" in your code. – datenwolf Apr 24 '12 at 16:51
  • Yes I'm extracting column. I.e. M[8], M[9], M[10], where M is 4x4 matrix (float[16]) supplied by OpenGL. – sidon Apr 24 '12 at 21:19
  • I was extracting column, but should have been extracting row. And thank you for clarifying what cols/rows of the matrix really are. – sidon May 22 '12 at 12:05