# Camera rotation around a point causes flickering

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

## Recommended Posts

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)
{
//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 on other sites
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 on other sites
I tried that already, it still flickers.

##### Share on other sites
is this flicker occurring only when you look straight up or straight down?

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 12
• 13
• 10
• 11
• 13
• ### Forum Statistics

• Total Topics
634096
• Total Posts
3015482
×