Sign in to follow this  
X5-Programmer

Rotation.

Recommended Posts

X5-Programmer    100
Hi there, I have an question about rotate around a point(character). Here is what I have. Vector3 m_vPlayerPos; //Players pos (x,y,z) Vector3 m_vPosition; //Camera pos (x,y,z) Vector3 m_vView; //Camera View (x,y,z) And here is the RotateAroundPoint function.
void CCamera::RotateAroundPoint(Vector3 vCenter, float angle, float x, float y, float z)
{
	Vector3 vNewPosition;			

	Vector3 vPos = m_vPosition - vCenter;

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

	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;

	m_vPosition = vCenter + vNewPosition;
}

To rotate the camera using this I only do this: RotateAroundPoint(m_vView, -(0.001f * kSpeed) * m_timer.elapsed, 0, 1, 0); How can I lock the camera to the Character point(m_vPlayer) and let it rotate around him? and always point at him. Hope you know what I whant I mean, and can help me. thanks.

Share this post


Link to post
Share on other sites
X5-Programmer    100
Hi there, to lock the camera you need to like this.

m_vPosition.x = m_vPlayer.x;
m_vPosition.y = m_vPlayer.y;
m_vPosition.z = m_vPlayer.z;

but if you whant to rotate around a point you need to use matrix rotation...

take a look at: http://www.newtondynamics.com
and the tutorial4 you will find the camera you look for.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this