Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having problems trying to limit the range my camera can pitch. Currently my camera can pitch around a model without restriction, but having a hard time trying to find the value of the degree/radian the camera is currently at after pitching. Here is what I got so far:

    // Moves camera with thumbstick
    Pitch = pController.ThumbSticks.Right.Y * MathHelper.ToRadians(speedAngleMAX);

    // Pitch Camera around model
    public void cameraPitch(float pitch)
        pitchAngle = ModelLoad.camTarget - ModelLoad.CameraPos;
        axisPitch = Vector3.Cross(Vector3.Up, pitchAngle);

        // pitch constrained to model's orientation
        ModelLoad.CameraPos = Vector3.Transform(ModelLoad.CameraPos - ModelLoad.camTarget,
            Matrix.CreateFromAxisAngle(axisPitch, pitch)) + ModelLoad.camTarget;

I've tried restraining the Y-camera position of ModelLoad.CameraPos.Y, but doing so gave me some unwanted results.

share|improve this question

I'm assuming here that you want to restrict the pitch to a range of angles above and below the horizontal.

The horizontal vector (vector parallel to ground) for the camera direction is;

 cameraDir = ModelLoad.camTarget - ModelLoad.CameraPos;
 horzDir.Y=0; //assume y-axis is up

Now to find the angle between the horizontal vector and the camera direction vector. To do this we normalize both vectors and get their dot product. This give us Cos(angleBetweenVectors). To recover the angle use Acos (cos inverse). Once you know the angle of pitch, you can restrict it.

 float angle=Math.Acos(dot);
share|improve this answer
Thanks for the input. I applied your method and it did give me an angle I could restrain, but it also gave me an undesired effect. What happened was it moved the camera within the model, creating a FPS style camera. Also when I pitched or rotated the model, the model flickers. – ChocoMan Oct 12 '12 at 19:00
What kind of camera are you trying ot create? I'm not sure what "moved the camera within the model" means. – Ken Oct 12 '12 at 19:15
its a 3rd-Person camera like GoW following the player around. – ChocoMan Oct 13 '12 at 3:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.