Trouble with camera class

Started by
1 comment, last by mrhodes 19 years, 12 months ago
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
Advertisement
Well, I think I figured it out!

I store the near and far planes in a structure that is part of my videomanager class. I''m using these values in the call to gluPerspective... however, when I replace the varibles for actual values it works... even if the values are the same, it only works when I hardcode the near and far values...

Anyone know why it would be this way?

Thanks,

Mike
Michael RhodesTiger Studios Web Designhttp://tigerstudios.net
Doh!! I found the problem in this case!!
It''s between the chair and keyboard! lol

I''m setting my fov, near, and far planes AFTER I initialize the video.. so it''s using whatever values are already in memory

Anyway.... works now

Mike
Michael RhodesTiger Studios Web Designhttp://tigerstudios.net

This topic is closed to new replies.

Advertisement