public override void UpdateViewport(int Width, int Height) { Screen.Width = Width; Screen.Height = Height; GL.Viewport(0, 0, Screen.Width, Screen.Height); Screen.AspectRatio = Screen.Width / (double)Screen.Height; Camera.HorizontalViewingAngle = 2.0 * Math.Atan(Math.Tan(0.5 * Camera.VerticalViewingAngle) * Screen.AspectRatio); switch (CurrentViewportMode) { case ViewportMode.Scenery: BackgroundObject b = Program.CurrentRoute.CurrentBackground as BackgroundObject; double cd = b != null?Math.Max(Program.CurrentRoute.CurrentBackground.BackgroundImageDistance, b.ClipDistance) : Program.CurrentRoute.CurrentBackground.BackgroundImageDistance; CurrentProjectionMatrix = Matrix4D.CreatePerspectiveFieldOfView(Camera.VerticalViewingAngle, Screen.AspectRatio, 0.5, cd); break; case ViewportMode.Cab: CurrentProjectionMatrix = Matrix4D.CreatePerspectiveFieldOfView(Camera.VerticalViewingAngle, Screen.AspectRatio, 0.025, 50.0); break; } Touch.UpdateViewport(); }
public virtual void UpdateViewport(int Width, int Height) { Screen.Width = Width; Screen.Height = Height; GL.Viewport(0, 0, Screen.Width, Screen.Height); Screen.AspectRatio = Screen.Width / (double)Screen.Height; Camera.HorizontalViewingAngle = 2.0 * Math.Atan(Math.Tan(0.5 * Camera.VerticalViewingAngle) * Screen.AspectRatio); CurrentProjectionMatrix = Matrix4D.CreatePerspectiveFieldOfView(Camera.VerticalViewingAngle, Screen.AspectRatio, 0.2, 1000.0); }
private void UpdateRightEyeSceneState() { Matrix4D perspectiveMatrix = Matrix4D.CreatePerspectiveFieldOfView(_rightEyeSceneState.Camera.FieldOfViewY, _rightEyeSceneState.Camera.AspectRatio, _rightEyeSceneState.Camera.PerspectiveNearPlaneDistance, _rightEyeSceneState.Camera.PerspectiveFarPlaneDistance); Matrix4D viewMatrix = Matrix4D.LookAt(_rightEyeSceneState.Camera.Eye, _rightEyeSceneState.Camera.Target, _rightEyeSceneState.Camera.Up); // 外部更新SceneState的内部变换矩阵以方便VR设备变换矩阵更新 _rightEyeSceneState.PerspectiveMatrix = perspectiveMatrix; _rightEyeSceneState.ViewMatrix = viewMatrix; _rightEyeSceneState.HmdPoseMatrix = Matrix4D.Identity; }
private void SetupVR(Ellipsoid globeShape) { // 创建一个默认相机以方便计算SceneState对象在VR模式下创建时需要外部提供的变换矩阵 Camera camera = new Camera(); Matrix4D perspectiveMatrix = Matrix4D.CreatePerspectiveFieldOfView(camera.FieldOfViewY, camera.AspectRatio, camera.PerspectiveNearPlaneDistance, camera.PerspectiveFarPlaneDistance); Matrix4D viewMatrix = Matrix4D.LookAt(camera.Eye, camera.Target, camera.Up); _leftEyeSceneState = new SceneState(VREye.LeftEye, perspectiveMatrix, viewMatrix); _leftEyeCamera = new CameraLookAtPoint(_leftEyeSceneState.Camera, _window, globeShape); _leftEyeSceneState.HmdPoseMatrix = Matrix4D.Identity; _rightEyeSceneState = new SceneState(VREye.RightEye, perspectiveMatrix, viewMatrix); _rightEyeCamera = new CameraLookAtPoint(_rightEyeSceneState.Camera, _window, globeShape); _rightEyeSceneState.HmdPoseMatrix = Matrix4D.Identity; }