Exemple #1
0
        /// <summary>
        /// Initializes the position of the camera.
        /// </summary>
        public static void initialize( Viewport viewport, Vector3 initialLookAt, float rotation )
        {
            if (camera == null) camera = new MSCamera();
            camera.upCamera = Vector3.UnitZ;
            camera.cameraPosition = new Vector3(282f, 4.5f, 150);
            camera.cameraTarget = new Vector3(0, 0, 0);
            camera.viewVector = camera.cameraPosition - camera.cameraTarget;
            camera.normalizedViewVector = Vector3.Normalize(camera.viewVector);
            camera.shiftVector = initialLookAt;
            camera.startingLookAt = initialLookAt;
            camera.AdjustPitchAxis();
            camera.currPitchAngle = (float)Math.PI / 2 - (float)Math.Acos((float)(Vector3.Dot(camera.viewVector, camera.upCamera) / (float)(Vector3.Distance(camera.cameraPosition, camera.cameraTarget))));
            camera.minPitchAngle = (float)Math.PI / 9;
            camera.maxPitchAngle = (float)Math.PI / 2;
            camera.projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), viewport.AspectRatio, 5, 5000);
            camera.frustum = new BoundingFrustum(camera.GetView() * camera.ProjectionMatrix);

            Matrix yawRotationMatrix = Matrix.CreateFromAxisAngle(Vector3.UnitZ, rotation);
            Vector3 transformedReference = Vector3.Transform(camera.cameraPosition, yawRotationMatrix);
            camera.upCamera = Vector3.Transform(camera.upCamera, yawRotationMatrix);
            camera.cameraPosition = transformedReference;
            camera.currYawRotation = rotation / 0.005f;
        }
Exemple #2
0
 public static MSCamera GetInstance()
 {
     if (camera == null)
         camera = new MSCamera();
     return camera;
 }