Quaternions

Started by
4 comments, last by Ataru 20 years, 10 months ago
I''m pretty experienced with OpenGL, but I decided to brush up on my DirectX. I''m porting my Quake 3 loader, but I''m having one problem, that''s my quaternion camera code. I''m using the D3DXQUATERNION structure, and have figured everything out, except how to convert the quaternion back to yaw,pitch and roll. I need this for strafing. I could just write a function that takes the quaternion and converts it, but I''d rather do it the proper way. I looked through D3DXVECTOR3, and there exists no such method. Am I missing something? Thanks
Advertisement
Why not using position and direction mode.

like this

///////////////////////////

float xth,zth;
D3DXVECTOR3 pos,trg;

xth=......
zth=......
pos=......

trg.x=pos.x+cosf(zth)*sinf(xth);
trg.y=pos.y+sinf(zth)*sinf(xth);
trg.z=pos.z+cosf(xth);

///////////////////////


this way you do have the position and the target also the zth and xth

you dont need more than that

i hope this is enough
Tmm
Calculating the Yaw, Pitch and Roll is possible I believe
(not implemented in DirectX no)

I wrote a Quat class and I added functions to get these values,
but I have never tested the functions, maybe you could?

anyway. depending on how D3DXQUATERNIONS are constructed
these formulas may work.

to get the Yaw,pitch,roll...

  fYaw = atan( ( 2.0 * ( quat.x * quat.y + quat.w * quat.z ) ) /	( quat.w * quat.w + quat.x * quat.x -	  quat.y * quat.y - quat.z * quat.z ) );fPitch = -asin( 2.0 * ( quat * quat.z - quat.w * quat.y ) );fRoll = atan( ( 2.0 * ( quat.w * quat.x + quat.y * quat.z ) ) /	( quat.w * quat.w - quat.x * quat.x -	  quat.y * quat.y + quat.z * quat.z ) );  


Not pretty. Also there''s lots of x*x type multiplication which could be swapped for a squared routine.

Give this a try, i''d be interested to know if it is accurate.
Some of you are not real.
If you really whant to know i dont anderstand any thing about the QUATERNION i tried to read many times but never understood the meaning and the using.............

so please tell me first about them
Tmm
Yeah, that''s what I am doing now. I just wanted to know if it was implemented in DX. It''s strange that you can create a quaternion with Yaw Pitch and Roll, but can''t extract that data back.

It''s actually easier than you have it there (I stole this from someone, but it works perfectly)


It''s
dx = 2.0 * ( x * z - w * y );
dy = 2.0 * ( y * z + w * x );
dz = 1.0 - 2.0 * ( x * x + y * y );
Ahh, excellent thanks.
Some of you are not real.

This topic is closed to new replies.

Advertisement