Limit the amount a camera can pitch

Posted by ChocoMan on Game Development See other posts from Game Development or by ChocoMan
Published on 2012-10-12T04:45:31Z Indexed on 2012/10/12 9:51 UTC
Read the original article Hit count: 395

Filed under:
|

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
        axisPitch.Normalize();
        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.

© Game Development or respective owner

Related posts about XNA

Related posts about camera