private static void SetupCameraMatrices(MyRenderMessageSetCameraViewMatrix message) { var viewMatrixAt0 = message.ViewMatrix; viewMatrixAt0.M14 = 0; viewMatrixAt0.M24 = 0; viewMatrixAt0.M34 = 0; viewMatrixAt0.M41 = 0; viewMatrixAt0.M42 = 0; viewMatrixAt0.M43 = 0; viewMatrixAt0.M44 = 1; var originalProjection = message.ProjectionMatrix; var invOriginalProjection = Matrix.CreatePerspectiveFovInv(message.FOV, MyRender11.ResolutionF.X / MyRender11.ResolutionF.Y, message.NearPlane, message.FarPlane); var complementaryProjection = Matrix.CreatePerspectiveFieldOfView(message.FOV, MyRender11.ResolutionF.X / MyRender11.ResolutionF.Y, message.FarPlane, message.NearPlane); var invProj = Matrix.CreatePerspectiveFovInv(message.FOV, MyRender11.ResolutionF.X / MyRender11.ResolutionF.Y, message.FarPlane, message.NearPlane); var invView = Matrix.Transpose(viewMatrixAt0); invView.M41 = (float)message.CameraPosition.X; invView.M42 = (float)message.CameraPosition.Y; invView.M43 = (float)message.CameraPosition.Z; MyEnvironment.ViewAt0 = viewMatrixAt0; MyEnvironment.InvViewAt0 = Matrix.Transpose(viewMatrixAt0); MyEnvironment.ViewProjectionAt0 = viewMatrixAt0 * complementaryProjection; MyEnvironment.InvViewProjectionAt0 = invProj * Matrix.Transpose(viewMatrixAt0); message.CameraPosition.AssertIsValid(); MyEnvironment.CameraPosition = message.CameraPosition; MyEnvironment.View = message.ViewMatrix; MyEnvironment.InvView = invView; MyEnvironment.ViewProjection = message.ViewMatrix * complementaryProjection; MyEnvironment.InvViewProjection = invProj * invView; MyEnvironment.Projection = complementaryProjection; MyEnvironment.InvProjection = invProj; MyEnvironment.NearClipping = message.NearPlane; MyEnvironment.FarClipping = message.FarPlane; MyEnvironment.FovY = message.FOV; MyEnvironment.ViewFrustum = new BoundingFrustum(MyEnvironment.ViewProjection); }