Hi!
How do you do this? Up to now all formulas I've seen will cause the x y and z parts to collapse by sin(theta/2) if theta is 0. So how do you express say an orientation straight down the x-axis with no rotation about that axis? Thanks ;)
Printable View
Hi!
How do you do this? Up to now all formulas I've seen will cause the x y and z parts to collapse by sin(theta/2) if theta is 0. So how do you express say an orientation straight down the x-axis with no rotation about that axis? Thanks ;)
A zero rotation quaternion would be the unit quaternion.
Thanks mate. Out of curiousity what would its values be for an orientation down the x-axis? I did some research on unit quats but got more confused :)
What do you mean an orientation down the x - axis?
I think the question is, how can you produce a quaternion which points down the x-axis but expresses a rotation of 0? The answer is there's no such thing -- a rotation of 0 about the x-axis is a rotation of 0 about any axis. It's like asking which way the zero vector is pointing. It doesn't point anywhere at all.
O_o
Left-handed devils or right-handed devils?
*shrug*
Either way, I'd say a rotation of 90 degrees should suit you.
Soma
Wow. If that's his question, he wasn't kidding about being confused.Quote:
how can you produce a quaternion which points down the x-axis but expresses a rotation of 0?
Soma
You'd better believe it!!!! I got it figured in the end, thanks guys ;)
Some code from my quaternion camera. Most of it taken from various tutorials on the internet and then plugged in to my existing system. Don't ask me how quaternions work b/c the math behind them is complex. I just know properties of them and various operations that can be performed on them. So this is one of those things in my book that 'just works'.
Code:void X3DCamera::Pitch(float angle)
{
D3DXQUATERNION quat = m_qRot;
D3DXQuaternionRotationAxis(&quat,TransformVector(&m_qRot,
&D3DXVECTOR3(1.0f, 0.0f, 0.0f)),
angle);
m_qRot *= quat;
D3DXQuaternionNormalize(&m_qRot,&m_qRot);
m_inTransition = true;
}
void X3DCamera::Yaw(float angle)
{
m_yaw += angle;
D3DXMATRIX matRot;
D3DXQUATERNION quat;
D3DXMatrixRotationY(&matRot,m_yaw);
D3DXQuaternionRotationMatrix(&quat,&matRot);
D3DXQuaternionRotationAxis(&quat,TransformVector(&quat,
&D3DXVECTOR3(0.0f, 1.0f, 0.0f)),
angle);
m_qRot *= quat;
D3DXQuaternionNormalize(&m_qRot,&m_qRot);
m_inTransition = true;
}
void X3DCamera::Roll(float angle)
{
D3DXQUATERNION quat = m_qRot;
D3DXQuaternionRotationAxis(&quat,TransformVector(&m_qRot,
&D3DXVECTOR3(0.0f, 0.0f, 1.0f)),
angle);
m_qRot *= quat;
D3DXQuaternionNormalize(&m_qRot , &m_qRot);
m_inTransition = true;
}
D3DXVECTOR3* X3DCamera::TransformVector(D3DXQUATERNION *pOrientation, D3DXVECTOR3 *pAxis)
{
D3DVECTOR vNewAxis;
D3DXMATRIX matRotation;
// Build a matrix from the quaternion.
D3DXMatrixRotationQuaternion(&matRotation, pOrientation);
// Transform the queried axis vector by the matrix.
vNewAxis.x = pAxis->x * matRotation._11 + pAxis->y * matRotation._21 + pAxis->z *
matRotation._31 + matRotation._41;
vNewAxis.y = pAxis->x * matRotation._12 + pAxis->y * matRotation._22 + pAxis->z *
matRotation._32 + matRotation._42;
vNewAxis.z = pAxis->x * matRotation._13 + pAxis->y * matRotation._23 + pAxis->z *
matRotation._33 + matRotation._43;
memcpy(pAxis, &vNewAxis, sizeof(vNewAxis)); // Copy axis.
return(pAxis);
}
void X3DCamera::GetViewMatrix(D3DXMATRIX *outMatrix)
{
D3DXMATRIX matRot;
D3DXQuaternionNormalize(&m_qRot,&m_qRot);
D3DXMatrixRotationQuaternion(&matRot,&D3DXQUATERNION(-m_qRot.x,-m_qRot.y,-m_qRot.z,m_qRot.w));
D3DXVECTOR3 vecLook(matRot._13,matRot._23,matRot._33);
D3DXVECTOR3 vecOrbitPos = m_vecTargetPos + vecLook * -m_fCamDist;
D3DXMATRIX matOrbit;
D3DXMatrixTranslation(&matOrbit,-vecOrbitPos.x,-vecOrbitPos.y,-vecOrbitPos.z);
D3DXMATRIX matTrans;
D3DXMatrixTranslation(&matTrans,-Pos.x,-Pos.y,-Pos.z);
m_matView = matOrbit * matRot * matTrans;
*outMatrix = m_matView;
}
That's really nice! Can i copy that please?
O_o
I don't imagine that he would've posted the example if he didn't intend for you to make use of it.
Soma
Hehe. :) One would think that such a conclusion was obvious but perhaps not. :DQuote:
I don't imagine that he would've posted the example if he didn't intend for you to make use of it.
Or it could even be described as being polite......
And i don't see why something you sweated over to make should just be acquired by someone without asking your permission first ;)