Sign in to follow this  
CRACK123

Camera rotation around a point causes flickering

Recommended Posts

CRACK123    235
Hi, If I rotate the camera about a point I get flickering and jittery motion. No itsn ot lag, its flickering like monitoring flickering. However if I rotate about a fixed axis like y axis it works fine. This is the code I have for rotating about an arbitrary point
void Camera::RotateOnAxis(vector3 axis, float degrees)
{
	//matrix44 mat = RotateRadMatrix44(axis, DegToRad(degrees));
	//this->m_LookAtMatrix *= mat;
	
	float angle = degrees;
	float x = axis.x;
	float y = axis.y;
	float z = axis.z;

	vector3 vNewPosition;            

    // To rotate our position around a point, what we need to do is find
    // a vector from our position to the center point we will be rotating around.
    // Once we get this vector, then we rotate it along the specified axis with
    // the specified degree.  Finally the new vector is added center point that we
    // rotated around (vCenter) to become our new position.  That's all it takes.

    // Get the vVector from our position to the center we are rotating around
    vector3 vPos = m_Eye - m_Centre;

    // Calculate the sine and cosine of the angle once
    float cosTheta = (float)cos(angle);
    float sinTheta = (float)sin(angle);

    // Find the new x position for the new rotated point
    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;

    // Find the new y position for the new rotated point
    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;

    // Find the new z position for the new rotated point
    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;

    // Now we just add the newly rotated vector to our position to set
    // our new rotated position of our camera.
    m_Eye = this->m_Centre + vNewPosition;
}


Any one have any ideas why this could be happening. Thanks

Share this post


Link to post
Share on other sites
jyk    2094
Not sure, but it looks like your arguments to sin() and cos() are in degrees rather than radians. C++ trig functions work with radians, so you will need to convert from degrees to radians to get correct results.

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