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;
}
Rotation.
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.
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement