3D Orientation & Movement
Well, I''ve been fiddling with different ways to store and manipulate the players ''looking direction''
I was curious how any of you working on 3D first person perspective games handle the keyboard or mouse input and how you alter the players view & make the up arrow work correcly.
Also, if someone knows how to, or where to read about how to, get a direction vector for a quaternion I''d appreciate the info. I want a vector that points in the direction that the person is looking, D3DMath_RotationFromQuaternion doesn''t do it.
It seem that Q''s are overkill for keyboard input, but I want to learn how to use them.
Magmai Kai Holmlor
- The disgruntled & disillusioned
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
This is regarding how to use mouse input for fps games. I am assuming your using the look at, up, and right technique. What I do is rotate all the vectors about the world''s y axis first. The rotation amount is equal to the mouse''s x delta. Then I rotate the look_at and up vectors by the right vector. That is of course using the mouse''s y delta. You must be sure to check if you are rotating to far up or down, in which case you should stop rotating. Hope that helps.
*** Triality ***
*** Triality ***
*** Triality ***
How do I generate the LookAt vector and Up vector from a quaternion?
The eye should be the players position, right? (the camera's position)
Edited by - Magmai Kai Holmlor on January 7, 2001 12:59:41 AM
Hey!? There was another post here earlier... was it wrong?
Wait a minute, my edit is gone! Oh man, did gamedev web servers blow a fuse?
So which function am I abusing the wrong way?
Edited by - Magmai Kai Holmlor on January 9, 2001 7:47:57 PM
The eye should be the players position, right? (the camera's position)
Edited by - Magmai Kai Holmlor on January 7, 2001 12:59:41 AM
Hey!? There was another post here earlier... was it wrong?
Wait a minute, my edit is gone! Oh man, did gamedev web servers blow a fuse?
So which function am I abusing the wrong way?
D3DXMATRIX matRot; D3DXVECTOR3 v3Looking_At(1.0f, 0.0f, 0.0f); D3DXVECTOR3 temp; D3DXMatrixRotationQuaternion(&matRot, fac); D3DXVec3TransformCoord(&temp, &v3Looking_At, &matRot); v3Looking_At = temp;
Edited by - Magmai Kai Holmlor on January 9, 2001 7:47:57 PM
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
dag nabbit!
i posted a big reply before the server''s crashed and now it''s not here...
oh well...
ok, here''s a nifty trick i''m not sure if you know
given a view matrix, the first column is the left vector, 2nd is the up, and the 3rd is the direction or at vector.
what you can do is find your quaternion, convert it to a rotation matrix, and extract the vectors you need, like this:
( the extra // are cuz the source tag removes all emtpy lines.. uggh )
so, to extract just the "looking direction" is an optimization of this:
hope it helps
(actually, i''m glad that the 1st post didnt make it, cuz i optimized w/ the wrong matrix elements... )
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I have no name that you may call me. I am merely Succinct.
~Succinct Demos Online~
-(Drop me a line here)-
i posted a big reply before the server''s crashed and now it''s not here...
oh well...
ok, here''s a nifty trick i''m not sure if you know
given a view matrix, the first column is the left vector, 2nd is the up, and the 3rd is the direction or at vector.
what you can do is find your quaternion, convert it to a rotation matrix, and extract the vectors you need, like this:
//-----------------------------------------------------------------------------------------------------------------------------inline Matrix Quaternion::ToRotationMatrix( void ) const{ // cache double angles double tx = 2.0*x; double ty = 2.0*y; double tz = 2.0*z; // cache permutations of double angles double twx = tx*w; double twy = ty*w; double twz = tz*w; double txx = tx*x; double txy = ty*x; double txz = tz*x; double tyy = ty*y; double tyz = tz*y; double tzz = tz*z; // Matrix RotationMatrix; // RotationMatrix[0][0] = 1.0 - (tyy + tzz); RotationMatrix[0][1] = txy - twz; RotationMatrix[0][2] = txz + twy; RotationMatrix[1][0] = txy + twz; RotationMatrix[1][1] = 1.0 - (txx + tzz); RotationMatrix[1][2] = tyz - twx; RotationMatrix[2][0] = txz - twy; RotationMatrix[2][1] = tyz + twx; RotationMatrix[2][2] = 1.0 - (txx + tyy); RotationMatrix[3][3] = 1.0; // return RotationMatrix;}//-----------------------------------------------------------------------------------------------------------------------------void TCamera::ExtractOrientation( void )// derives the orthogonal axes from the View matrix{ // extract the coordinate system from the View matrix mLeft = Vector3d( float( mViewMatrix[0][0] ),float( mViewMatrix[1][0] ),float( mViewMatrix[2][0] ) ).Unit( ); mUp = Vector3d( float( mViewMatrix[0][1] ),float( mViewMatrix[1][1] ),float( mViewMatrix[2][1] ) ).Unit( ); mDir = Vector3d( float( mViewMatrix[0][2] ),float( mViewMatrix[1][2] ),float( mViewMatrix[2][2] ) ).Unit( );}
( the extra // are cuz the source tag removes all emtpy lines.. uggh )
so, to extract just the "looking direction" is an optimization of this:
// cache double anglesdouble tx = 2.0*OrientationQuaternion.x;double ty = 2.0*OrientationQuaternion.y;double tz = 2.0*OrientationQuaternion.z;//DirectionVector.x = tx*z + tw*yDirectionVector.y = ty*z - tw*xDirectionVector.z = 1.0 - (tx*x + ty*y)
hope it helps
(actually, i''m glad that the 1st post didnt make it, cuz i optimized w/ the wrong matrix elements... )
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I have no name that you may call me. I am merely Succinct.
~Succinct Demos Online~
-(Drop me a line here)-
-- Succinct(Don't listen to me)
I seem to remember seeing that before
I couldn't find it in any of my CG books though! I need to get a decent affine math book.
...
Oh man, do I feel like a yam. My motion wasn't working right becuase I swapped my x&y when I called the other guys 'setcamera' function. Eariler it was backwards from what I wanted, but I corrected for it with a world rotation and never put the x/y in the correct order.
Incidental, the code I was using produces that exact same results as yours, thought it's a <holds nose> mathematians method. Your's is more optimized, thanks again.
Ah well, on to strafing.
Edited by - Magmai Kai Holmlor on January 12, 2001 12:50:12 AM
I couldn't find it in any of my CG books though! I need to get a decent affine math book.
...
Oh man, do I feel like a yam. My motion wasn't working right becuase I swapped my x&y when I called the other guys 'setcamera' function. Eariler it was backwards from what I wanted, but I corrected for it with a world rotation and never put the x/y in the correct order.
Incidental, the code I was using produces that exact same results as yours, thought it's a <holds nose> mathematians method. Your's is more optimized, thanks again.
Ah well, on to strafing.
Edited by - Magmai Kai Holmlor on January 12, 2001 12:50:12 AM
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement