Advertisement

3d movement

Started by May 11, 2002 10:19 AM
4 comments, last by Maverick the divider 22 years, 9 months ago
maybe anyone knows of a good tutorial or sample of implementing free movement in 3d (with quaternions). not the source, but the particular algorithm is what bothers me. (use D3DX for gods sake
---Quite soon...ICQ: 163187735
well.. if you want completely free movement just generate for example from the mousemovement eulerangles, generate a quat from this and multiply it by the current quat. to draw the scene, rotate it by that current quat.

"take a look around" - limp bizkit
www.google.com
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

Advertisement
Well I do generate a quat from euler angles and then make a matrix from it - it stills show the gimbal lock effect ((
---Quite soon...ICQ: 163187735
logically you get the same problems if you just use your eulerangles directly, wich is what you do.

euler->quat->matrix->transform is essencially the same as
euler->transform
just some conversions before..
what you have to do is STORING the current orientation

quat myorientation;

then in the update func you have something like this:

update() {
quat rotation = get_rotation_change_from_eulers();
//THIS LINE!!!!
myorientation *= rotation;
}

and where you set up your camera you do this:

setupcamera() {
matrix rotation = myorientation.getmatrix();
loadmatrix(rotation);
}

you have to STORE your current rotation, and apply the change on it. THEN quaternions solve your gimbal lock, not if you use eulers the way you did before..

"take a look around" - limp bizkit
www.google.com
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

Well i do create the orientation quaternion, get matrix from it and multiply it with translation matrix, then update the position, but somehow after a coulpe of turns my object starts flying backwards .... and in other directions :/

here''s the code:
****************

// Ship position & orientation
static D3DXVECTOR3 vPosition(0.0f, -15.0f, -30.0f);
static D3DXQUATERNION qOrientation(0.0f, 0.0f, -1.0f, 0.0f);

// Direction quats
D3DXQUATERNION qRight;
D3DXQUATERNION qLeft;
D3DXQUATERNION qUp;
D3DXQUATERNION qDown;
D3DXQUATERNION qQ1;
D3DXQUATERNION qQ2;
D3DXQuaternionRotationAxis(&qRight, &D3DXVECTOR3(0, 1, 0), 0.02f);
D3DXQuaternionRotationAxis(&qLeft, &D3DXVECTOR3(0, 1, 0), -0.02f);
D3DXQuaternionRotationAxis(&qUp, &D3DXVECTOR3(1, 0, 0), 0.02f);
D3DXQuaternionRotationAxis(&qDown, &D3DXVECTOR3(1, 0, 0), -0.02f);
D3DXQuaternionRotationAxis(&qQ1, &D3DXVECTOR3(0, 0, 1), 0.02f);
D3DXQuaternionRotationAxis(&qQ2, &D3DXVECTOR3(0, 0, 1), -0.02f);

// Input
Input.UpdateKeyboard();
if (Input.KeyPressed(DIK_D)) qOrientation = qRight* qOrientation;
if (Input.KeyPressed(DIK_A)) qOrientation = qLeft* qOrientation;
if (Input.KeyPressed(DIK_W)) qOrientation = qUp* qOrientation;
if (Input.KeyPressed(DIK_S)) qOrientation = qDown* qOrientation;
if (Input.KeyPressed(DIK_Q)) qOrientation = qQ1 * qOrientation;
if (Input.KeyPressed(DIK_E)) qOrientation = qQ2 * qOrientation;
D3DXQuaternionNormalize(&qOrientation, &qOrientation);

// Generate matrices
D3DXMATRIX mFinal;
D3DXMatrixRotationQuaternion(&mFinal, &qOrientation);

// Update position
vPosition.x += mFinal._13 / 50;
vPosition.y += mFinal._23 / 50;
vPosition.z += mFinal._33 / 50;

mFinal._41 = vPosition.x;
mFinal._42 = vPosition.y;
mFinal._43 = vPosition.z;


---Quite soon...ICQ: 163187735
my fault, forgot that matrrices have lines, not columns in dx

vPosition.x += mFinal._31 / 50;
vPosition.y += mFinal._32 / 50;
vPosition.z += mFinal._33 / 50;

is the right way

---
Keep it simple, stupid
---Quite soon...ICQ: 163187735

This topic is closed to new replies.

Advertisement