# Rotation.

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

## 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 on other sites
Try making the the Player pos the center of rotation

##### Share on other sites
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.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633736
• Total Posts
3013600
×