Camera rotation around a point causes flickering

Started by
2 comments, last by moeron 18 years, 10 months ago
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
The more applications I write, more I find out how less I know
Advertisement
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.
I tried that already, it still flickers.
The more applications I write, more I find out how less I know
is this flicker occurring only when you look straight up or straight down?
moe.ron

This topic is closed to new replies.

Advertisement