• Advertisement
Sign in to follow this  

Camera flips

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, I have a problem with my new camera class... as soon as the camera's forward vector is too near to the world`s up vector, the camera starts to flip. I guess it's a problem with the viewmatrix, could also be that it's a gimbal lock. I don't really know how to solve this. (I don't really want to limit the rotation, though) Can anyone give me a clue how to do this? Thanks, Martin

Share this post


Link to post
Share on other sites
Advertisement
The behavior you are seeing is the expected behavior. It is a result of trying to extract a direction from a zero-length vector. In general, you will have this problem anytime you try to look in the direction of the up vector.

If you want the camera to point straight up (or nearly straight up), you can't use the world's up vector as the up vector. Try using the camera's current up vector instead.

Share this post


Link to post
Share on other sites
Ok, that's what I do:

// part of my code for rotations
Vector3 RotateAroundArbitrary(float angle, Vector3 axis, Vector3 vector)
{
Vector3 ret = new Vector3();

float cosine = (float)Math.Cos(angle);
float sinus = (float)Math.Sin(angle);

ret.X = vector.X*(axis.X*axis.X + cosine*(1 - axis.X*axis.X))
+ vector.Y*(axis.X*axis.Y*(1 - cosine) - axis.Z*sinus)
+ vector.Z*(axis.X*axis.Z*(1 - cosine) + axis.Y*sinus);
ret.Y = vector.X*(axis.X*axis.Y*(1 - cosine) + axis.Z*sinus)
+ vector.Y*(axis.Y*axis.Y + cosine*(1 - axis.Y*axis.Y))
+ vector.Z*(axis.Y*axis.Z*(1 - cosine) - axis.X*sinus);
ret.Z = vector.X*(axis.X*axis.Z*(1 - cosine) - axis.Y*sinus)
+ vector.Y*(axis.Y*axis.Z*(1 - cosine) + axis.X*sinus)
+ vector.Z*(axis.Z*axis.Z + cosine*(1 - axis.Z*axis.Z));

this.m_bFrustumUpToDate = this.m_bViewMatrixUpToDate = this.m_bVolumesUpToDate =false;
return ret;
}

public void PitchEP(float angle)
{
this.m_Forward = this.RotateAroundArbitrary(angle, this.m_Right, this.m_Forward);
this.m_Up = this.RotateAroundArbitrary(angle, this.m_Right, this.m_Up);

this.m_LookAtPoint = this.m_LookAtPoint - this.m_Eye;
this.m_LookAtPoint = this.m_Eye + this.RotateAroundArbitrary(angle, this.m_Right, this.m_LookAtPoint);
this.UpdateCoordinateSystem();

this.m_bFrustumUpToDate = this.m_bViewMatrixUpToDate = this.m_bVolumesUpToDate = false;
}





// part of my code for the viewmatrix and coordinate stuff
void UpdateViewMatrix()
{
this.m_ViewMatrix = Matrix.LookAtRH(this.m_Eye, this.m_LookAtPoint, this.m_Up);
this.m_bViewMatrixUpToDate = true;
}


Well, it seems to me, that I already do what you suggested.
Maybe I just misunderstand what's wrong...

[Edited by - gammaGT on July 8, 2006 1:44:09 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement