Esempio n. 1
0
        public void SetViewMatrix(MatrixD value)
        {
            ViewMatrix = value;

            MatrixD.Invert(ref ViewMatrix, out WorldMatrix);
            Position = WorldMatrix.Translation;
            InversePositionTranslationMatrix = MatrixD.CreateTranslation(-Position);

            PreviousPosition = Position;

            ForwardVector = (Vector3)WorldMatrix.Forward;
            UpVector      = (Vector3)WorldMatrix.Up;
            LeftVector    = (Vector3)WorldMatrix.Left;

            //  Projection matrix according to zoom level
            ProjectionMatrix = MatrixD.CreatePerspectiveFieldOfView(FovWithZoom, ForwardAspectRatio,
                                                                    GetSafeNear(),
                                                                    FarPlaneDistance);

            ProjectionMatrixFar = MatrixD.CreatePerspectiveFieldOfView(FovWithZoom, ForwardAspectRatio,
                                                                       GetSafeNear(),
                                                                       1000000);

            ViewProjectionMatrix    = ViewMatrix * ProjectionMatrix;
            ViewProjectionMatrixFar = ViewMatrix * ProjectionMatrixFar;

            //  Projection matrix according to zoom level
            float near = System.Math.Min(NearPlaneDistance, NearForNearObjects); //minimum cockpit distance

            ProjectionMatrixForNearObjects = MatrixD.CreatePerspectiveFieldOfView(FovWithZoomForNearObjects, ForwardAspectRatio,
                                                                                  near,
                                                                                  FarForNearObjects);

            float safenear = System.Math.Min(4, NearPlaneDistance); //minimum cockpit distance

            ViewMatrixAtZero     = value;
            ViewMatrixAtZero.M14 = 0;
            ViewMatrixAtZero.M24 = 0;
            ViewMatrixAtZero.M34 = 0;
            ViewMatrixAtZero.M41 = 0;
            ViewMatrixAtZero.M42 = 0;
            ViewMatrixAtZero.M43 = 0;
            ViewMatrixAtZero.M44 = 1;

            UpdateBoundingFrustum();

            VRageRender.MyRenderProxy.SetCameraViewMatrix(
                value,
                ProjectionMatrix,
                ProjectionMatrixForNearObjects,
                safenear,
                Zoom.GetFOVForNearObjects(),
                Zoom.GetFOV(),
                NearPlaneDistance,
                FarPlaneDistance,
                NearForNearObjects,
                FarForNearObjects,
                Position);
        }