•      Sign In
• Create Account

### #ActualHornsj3

Posted 02 July 2012 - 06:01 PM

So, as you suspected, you really messed up everything there

If you are going to make a quaternion based camera, use some quaternions. hehe

XNAMath (or, if using win8 DirectXMath) has some helper functions for you.

See below for an example from my own quaternion based camera.

I don't profess to be a quaternion expert but this one has been tested and does work.

void D3D11CameraFlight::setRoll( float angle )
{

XMVECTOR rotationQuaternion = XMQuaternionRotationAxis(m_camTarget, angle);

m_tempQuaternion = XMQuaternionMultiply(m_camUp, rotationQuaternion);
rotationQuaternion = XMQuaternionConjugate(rotationQuaternion);
m_camUp = XMQuaternionMultiply(rotationQuaternion, m_camUp);
m_camRight = XMVector3Cross(m_camUp, m_camTarget);
}


Edit- This code is obviously not polished, m_tempQuaternion doesn't really need to be there. It's calculating a rotation quaternion, multiplying the up vector by it, then multiplying that result by the conjugate of the rotation quaternion. That will give you the new up vector post roll. Then take the cross product of that and the target vector to get the right vector and you have a full 3D orthogonal basis.

You can then use the target and up vectors, along with your position, to calculate your view matrix. XMMatrixLookToLH( m_camPosition, m_camTarget, m_camUp);

Same deal for pitch and yaw, really.

### #2Hornsj3

Posted 02 July 2012 - 05:59 PM

So, as you suspected, you really messed up everything there

If you are going to make a quaternion based camera, use some quaternions. hehe

XNAMath (or, if using win8 DirectXMath) has some helper functions for you.

See below for an example from my own quaternion based camera.

I don't profess to be a quaternion expert but this one has been tested and does work.

void D3D11CameraFlight::setRoll( float angle )
{

XMVECTOR rotationQuaternion = XMQuaternionRotationAxis(m_camTarget, angle);

m_tempQuaternion = XMQuaternionMultiply(m_camUp, rotationQuaternion);
rotationQuaternion = XMQuaternionConjugate(rotationQuaternion);
m_camUp = XMQuaternionMultiply(rotationQuaternion, m_camUp);
m_camRight = XMVector3Cross(m_camUp, m_camTarget);
}


Edit- This code is obviously not polished, m_tempQuaternion doesn't really need to be there. It's calculating a rotation quaternion, multiplying the up vector by it, then multiplying that result by the conjugate of the rotation quaternion. That will give you the new up vector post roll. Then take the cross product of that and the target vector to get the right vector and you have a full 3D orthogonal basis.

### #1Hornsj3

Posted 02 July 2012 - 05:53 PM

So, as you suspected, you really messed up everything there

If you are going to make a quaternion based camera, use some quaternions. hehe

XNAMath (or, if using win8 DirectXMath) has some helper functions for you.

See below for an example from my own quaternion based camera.

I don't profess to be a quaternion expert but this one has been tested and does work.

void D3D11CameraFlight::setRoll( float angle )
{

XMVECTOR rotationQuaternion = XMQuaternionRotationAxis(m_camTarget, angle);

m_tempQuaternion = XMQuaternionMultiply(m_camUp, rotationQuaternion);
rotationQuaternion = XMQuaternionConjugate(rotationQuaternion);
m_camUp = XMQuaternionMultiply(rotationQuaternion, m_camUp);
m_camRight = XMVector3Cross(m_camUp, m_camTarget);
}


PARTNERS