Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

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=cameraDir;
 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.

 horzDir.Normalize();
 cameraDir.Normalize();
 float dot=Vector3.dot(horzDir,cameraDir);
 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
add comment

Your Answer

 
discard

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.