// RenderAFrame() public override void RenderAFrame() { RC.Clear(ClearFlags.Color | ClearFlags.Depth); // keyboard if (Input.Instance.IsKeyDown(KeyCodes.V)) { _angleVelHorz = 0.0f; _angleVelVert = 0.0f; if (_topView) { _angleHorz = 0.4f; _angleVert = -1.0f; _topView = false; } else { _angleHorz = 0.0f; _angleVert = 0.0f; _topView = true; } } if (Input.Instance.IsKeyDown(KeyCodes.S)) { Audio.Instance.SetVolume(Audio.Instance.GetVolume() > 0 ? 0 : 100); } if (Input.Instance.IsKeyDown(KeyCodes.C)) { _exampleLevel.UseStereo3D = !_exampleLevel.UseStereo3D; } if (Input.Instance.IsKey(KeyCodes.Left)) { _exampleLevel.MoveCube(Level.Directions.Left); } if (Input.Instance.IsKey(KeyCodes.Right)) { _exampleLevel.MoveCube(Level.Directions.Right); } if (Input.Instance.IsKey(KeyCodes.Up)) { _exampleLevel.MoveCube(Level.Directions.Forward); } if (Input.Instance.IsKey(KeyCodes.Down)) { _exampleLevel.MoveCube(Level.Directions.Backward); } // mouse if (Input.Instance.GetAxis(InputAxis.MouseWheel) > 0) { _exampleLevel.ZoomCamera(50); } if (Input.Instance.GetAxis(InputAxis.MouseWheel) < 0) { _exampleLevel.ZoomCamera(-50); } if (Input.Instance.IsButton(MouseButtons.Left)) { _angleVelHorz = RotationSpeed * Input.Instance.GetAxis(InputAxis.MouseX); _angleVelVert = RotationSpeed * Input.Instance.GetAxis(InputAxis.MouseY); } else { var curDamp = (float)Math.Exp(-Damping * Time.Instance.DeltaTime); _angleVelHorz *= curDamp; _angleVelVert *= curDamp; } _angleHorz += _angleVelHorz; _angleVert += _angleVelVert; // colh var mtxRot = float4x4.CreateRotationZ(_angleHorz)*float4x4.CreateRotationX(_angleVert); var mtxRot = float4x4.CreateRotationX(-_angleVert) * float4x4.CreateRotationZ(-_angleHorz); _exampleLevel.Render(mtxRot); if (_exampleLevel.UseStereo3D) { _stereo3D.Display(); } Present(); }
// RenderAFrame is called once a frame public override void RenderAFrame() { // Clear the backbuffer RC.Clear(ClearFlags.Color | ClearFlags.Depth); // Mouse and keyboard movement if (Keyboard.LeftRightAxis != 0 || Keyboard.UpDownAxis != 0) { _keys = true; } if (Mouse.LeftButton) { _keys = false; _angleVelHorz = -RotationSpeed * Mouse.XVel * DeltaTime * 0.0005f; _angleVelVert = -RotationSpeed * Mouse.YVel * DeltaTime * 0.0005f; } else if (Touch.GetTouchActive(TouchPoints.Touchpoint_0)) { //Reset view on touch ResetView(); } else { if (_keys) { _angleVelHorz = -RotationSpeed * Keyboard.LeftRightAxis * DeltaTime; _angleVelVert = -RotationSpeed * Keyboard.UpDownAxis * DeltaTime; } else { var curDamp = (float)System.Math.Exp(-Damping * DeltaTime); _angleVelHorz *= curDamp; _angleVelVert *= curDamp; } } //Rotate Scene with Mouse _angleHorz -= _angleVelHorz / 3; _angleVert -= _angleVelVert / 3; //Calculate view (DeviceTracking) float4x4 headsetRotationX = float4x4.CreateRotationX(-gameRotationVector[2] + _angleVert); float4x4 headsetRotationY = float4x4.CreateRotationY(-gameRotationVector[0] + _angleHorz); float4x4 headsetRotationZ = float4x4.CreateRotationZ(-gameRotationVector[1] + _angleRoll); //StereoRendering if (_renderStereo) { //Render Left Eye var camTrans = float4x4.CreateTranslation(_eyeDistance / 2, -200, 0); var mtxCam = float4x4.LookAt(_eyeDistance / 2, 0, 0, 0, 0, 400, 0, 1, 0); RC.ModelView = headsetRotationZ * headsetRotationX * headsetRotationY * mtxCam * camTrans; _stereo3d.Prepare(Stereo3DEye.Left); _sceneRenderer.Render(RC); _stereo3d.Save(); //Render Right Eye camTrans = float4x4.CreateTranslation(-_eyeDistance / 2, -200, 0); mtxCam = float4x4.LookAt(-_eyeDistance / 2, 0, 0, 0, 0, 400, 0, 1, 0); RC.ModelView = headsetRotationZ * headsetRotationX * headsetRotationY * mtxCam * camTrans; _stereo3d.Prepare(Stereo3DEye.Right); _sceneRenderer.Render(RC); _stereo3d.Save(); //We do nothing here in Cardboard-Mode. Used in Oculus and Anaglyph _stereo3d.Display(); } //no StereoRendering else { // Render the scene loaded in Init() var camTrans = float4x4.CreateTranslation(0, -200, 0); RC.ModelView = headsetRotationZ * headsetRotationX * headsetRotationY * camTrans; _sceneRenderer.Render(RC); } #if GUI_SIMPLE _guiHandler.RenderGUI(); //GUI is overlayed, but can also be rendered for each eye #endif // Swap buffers: Show the contents of the backbuffer (containing the currently rerndered farame) on the front buffer. Present(); }