Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

Camera Question.

Started by X5-Programmer Nov 19, 2004 at 6:42 AM 0 replies 350+ views
Original Post
X5-Programmer
X5-Programmer
Hi, I have been trying to get my camera work a long time now, And I have some questions about it. The camera will have to follow the character and have the ability to rotate around the character. I have get the rotation around a point to work, but the problem is how to add the pos vector with the rotate vector if you know what I mean. Like this: first i lock the cameraPos to the character pos like this. SetCamera(m_player.x + 20.0f, m_player.z + 20.0f); Now I have the character in fron of the camera. But the problem is my rotate function mPos is the camera pos, and when I lock the camera to the character the mPos cant be change, and I need to change to get the ability to rotate around it.. here is the code to rotate:

void CCamera::Rotate_Position(float rot, float x, float y, float z)
{
	Vector3 vNewPosition;		

	Vector3 vPos = mPos - mView;

	float cosTheta = (float)cos(rot);
	float sinTheta = (float)sin(rot);

	vNewPosition.x  = (cosTheta + (1 - cosTheta) * x * x)		* vPos.x;
	vNewPosition.x += ((1 - cosTheta) * x * y - z * sinTheta)	* vPos.y;
	vNewPosition.x += ((1 - cosTheta) * x * z + y * sinTheta)	* vPos.z;

	vNewPosition.y  = ((1 - cosTheta) * x * y + z * sinTheta)	* vPos.x;
	vNewPosition.y += (cosTheta + (1 - cosTheta) * y * y)		* vPos.y;
	vNewPosition.y += ((1 - cosTheta) * y * z - x * sinTheta)	* vPos.z;

	vNewPosition.z  = ((1 - cosTheta) * x * z - y * sinTheta)	* vPos.x;
	vNewPosition.z += ((1 - cosTheta) * y * z + x * sinTheta)	* vPos.y;
	vNewPosition.z += (cosTheta + (1 - cosTheta) * z * z)		* vPos.z;

	mPos.x = mView.x + vNewPosition.x;
	mPos.z = mView.z + vNewPosition.z;
}

so my question is how can I add the rotate pos with the mPos? Hope anyone can help me with this, Im not good at explain things so I hope you understand what I mean. The camera will be created for an single-player rpg game. thanks.
-[ thx ]-
X5-Programmer
X5-Programmer
EDIT:

Some info about the camera:

mouse controlled camera system. Players will be able to zoom far out to get more of the tactical view but will also be able to zoom all the way in to first person view for a more personal feel to the game. also camera is on the other mouse button, which is our mouse move or mouse look, which will allow you to cruise around the world while moving the camera around your character. The camera also sticks so that whatever angle you leave it at, it'll stay there.

Were can I find some info to get this done?.
-[ thx ]-

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.