Hey everyone... I'm working on a camera class and I'm having some troubles
what I did was draw a triangle and then position my camera to look at it. Now, when I move my camera forward the triangle should get bigger, however it doesn't.. what happens is the triangle stays the same size, and then will completely go away after the camera has past z=1.0000... this holds true for when you move back away from the triangle.. except it goes away at z=-1.00
Also.... when I rotate the view, something seems fishy with that too
You can try it out to see what I mean.. here is the link
http://users.eastlink.ca/~mrhodes/camera.exe
here is my rotate function
void TE3DCamera::RotateCamera(float angle, float x, float y, float z)
{
VECTOR vNewView, vView;
// Get the view vector
vView.x = m_vLookat.x - m_vPosition.x;
vView.y = m_vLookat.y - m_vPosition.y;
vView.z = m_vLookat.z - m_vPosition.z;
// Calculate the sine and cosine of the angle once
float cosTheta = (float)cos(angle);
float sinTheta = (float)sin(angle);
// Find the new x position for the new rotated point
vNewView.x = (cosTheta + (1 - cosTheta) * x * x) * vView.x;
vNewView.x += ((1 - cosTheta) * x * y - z * sinTheta) * vView.y;
vNewView.x += ((1 - cosTheta) * x * z + y * sinTheta) * vView.z;
// Find the new y position for the new rotated point
vNewView.y = ((1 - cosTheta) * x * y + z * sinTheta) * vView.x;
vNewView.y += (cosTheta + (1 - cosTheta) * y * y) * vView.y;
vNewView.y += ((1 - cosTheta) * y * z - x * sinTheta) * vView.z;
// Find the new z position for the new rotated point
vNewView.z = ((1 - cosTheta) * x * z - y * sinTheta) * vView.x;
vNewView.z += ((1 - cosTheta) * y * z + x * sinTheta) * vView.y;
vNewView.z += (cosTheta + (1 - cosTheta) * z * z) * vView.z;
// Now we just add the newly rotated vector to our position to set
// our new rotated view of our camera.
m_vLookat.x = m_vPosition.x + vNewView.x;
m_vLookat.y = m_vPosition.y + vNewView.y;
m_vLookat.z = m_vPosition.z + vNewView.z;
} // void TE3DCamera::RotateCamera(float angle, float x, float y, float z)
And here is the code to move the camera
void TE3DCamera::MoveCamera(float speed)
{
VECTOR vView;
// Get the view vector (direction camera is facing)
vView.x = m_vLookat.x - m_vPosition.x;
vView.y = m_vLookat.y - m_vPosition.y;
vView.z = m_vLookat.z - m_vPosition.z;
m_vPosition.x += vView.x * speed;
m_vPosition.z += vView.z * speed;
m_vLookat.x += vView.x * speed;
m_vLookat.z += vView.z * speed;
} // void TE3DCamera::MoveCamera(float speed)
Please download the program to see what I mean,
Thanks...
Michael Rhodes
[edited by - mrhodes on April 23, 2004 8:45:20 AM]
[edited by - mrhodes on April 23, 2004 8:45:38 AM]
[edited by - mrhodes on April 23, 2004 8:45:54 AM]
Michael RhodesTiger Studios Web Designhttp://tigerstudios.net