Advertisement

Camrea Class Problems

Started by August 29, 2001 07:52 AM
1 comment, last by spider111 23 years, 5 months ago
I am currently writing a camera class which is causeing me a single large problem The idea was a fully functional class that can be used to either set the camera usng a look at style, and then be able to move the camera around using slide and rotate functions The problem is that the up vector stays locked at (0.0f, 1.0f, 0.0f) even though i expect the cross products to correct it!! The set location code is here void CCamera::SetLocation(const CVector &pos, const CVector &look, const CVector &up) { //set the camera position m_vPos = pos; //set the camera to look at the target specified m_vLook = look - pos; //ensure all vectors are at right angles m_vRight = up.Cross(m_vLook); m_vUp = m_vLook.Cross(m_vRight); //ensure all vectors are unit vectors m_vLook.Normalise(); m_vUp.Normalise(); m_vRight.Normalise(); } I think the cross product code is where the problem is, but i cannot solve it!! the cross product code from the CVector class is here CVector CVector::Cross(const CVector &vector) const { CVector result; result.m_fX = ((m_fY * vector.m_fZ) - (m_fZ * vector.m_fY)); result.m_fY = ((m_fX * vector.m_fZ) - (m_fZ * vector.m_fX)); result.m_fZ = ((m_fX * vector.m_fY) - (m_fY * vector.m_fX)); return result; } Any ideas, and thanks to all those that try!!
Thanks for the helpPaul
New function:



CVector CVector::Cross(const CVector &vector) const
{
CVector result;
result.m_fX = ((m_fY * vector.m_fZ) - (m_fZ * vector.m_fY));

//result.m_fY = ((m_fX * vector.m_fZ) - (m_fZ * vector.m_fX));
result.m_fY = ((m_fZ * vector.m_fX) - (m_fX * vector.m_fZ));

result.m_fZ = ((m_fX * vector.m_fY) - (m_fY * vector.m_fX));
return result;
}


Enjoy!

-JT
Advertisement
Your the best, that sorted it a treat, Thats the kind of mistake that makes me wish id been an oil painter instead!!
Thanks for the helpPaul

This topic is closed to new replies.

Advertisement