Jump to content
  • Advertisement
Sign in to follow this  
X5-Programmer

Rotation.

This topic is 5036 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!