// RenderAFrame is called once a frame public override void RenderAFrame() { // _guiSubText.Text = $"dt: {DeltaTime} ms, W: {Width}, H: {Height}, PS: {_maxPinchSpeed}"; // Clear the backbuffer RC.Clear(ClearFlags.Color | ClearFlags.Depth); // Mouse and keyboard movement if (Keyboard.LeftRightAxis != 0 || Keyboard.UpDownAxis != 0) { _keys = true; } var curDamp = (float)System.Math.Exp(-Damping * DeltaTime); // Zoom & Roll if (Touch.TwoPoint) { if (!_twoTouchRepeated) { _twoTouchRepeated = true; _angleRollInit = Touch.TwoPointAngle - _angleRoll; _offsetInit = Touch.TwoPointMidPoint - _offset; _maxPinchSpeed = 0; } _zoomVel = Touch.TwoPointDistanceVel * -0.01f; _angleRoll = Touch.TwoPointAngle - _angleRollInit; _offset = Touch.TwoPointMidPoint - _offsetInit; float pinchSpeed = Touch.TwoPointDistanceVel; if (pinchSpeed > _maxPinchSpeed) { _maxPinchSpeed = pinchSpeed; // _maxPinchSpeed is used for debugging only. } } else { _twoTouchRepeated = false; _zoomVel = Mouse.WheelVel * -0.5f; _angleRoll *= curDamp * 0.8f; _offset *= curDamp * 0.8f; } // UpDown / LeftRight rotation if (Mouse.LeftButton) { _keys = false; _angleVelHorz = -RotationSpeed * Mouse.XVel * 0.000002f; _angleVelVert = -RotationSpeed * Mouse.YVel * 0.000002f; } else if (Touch.GetTouchActive(TouchPoints.Touchpoint_0) && !Touch.TwoPoint) { _keys = false; float2 touchVel; touchVel = Touch.GetVelocity(TouchPoints.Touchpoint_0); _angleVelHorz = -RotationSpeed * touchVel.x * 0.000002f; _angleVelVert = -RotationSpeed * touchVel.y * 0.000002f; } else { if (_keys) { _angleVelHorz = -RotationSpeed * Keyboard.LeftRightAxis * 0.002f; _angleVelVert = -RotationSpeed * Keyboard.UpDownAxis * 0.002f; } else { _angleVelHorz *= curDamp; _angleVelVert *= curDamp; } } _zoom += _zoomVel; // Limit zoom if (_zoom < 80) { _zoom = 80; } if (_zoom > 2000) { _zoom = 2000; } _angleHorz += _angleVelHorz; // Wrap-around to keep _angleHorz between -PI and + PI _angleHorz = M.MinAngle(_angleHorz); _angleVert += _angleVelVert; // Limit pitch to the range between [-PI/2, + PI/2] _angleVert = M.Clamp(_angleVert, -M.PiOver2, M.PiOver2); // Wrap-around to keep _angleRoll between -PI and + PI _angleRoll = M.MinAngle(_angleRoll); // Create the camera matrix and set it as the current ModelView transformation var mtxRot = float4x4.CreateRotationZ(_angleRoll) * float4x4.CreateRotationX(_angleVert) * float4x4.CreateRotationY(_angleHorz); var mtxCam = float4x4.LookAt(0, 20, -_zoom, 0, 0, 0, 0, 1, 0); RC.ModelView = mtxCam * mtxRot * _sceneScale * _sceneCenter; var mtxOffset = float4x4.CreateTranslation(2 * _offset.x / Width, -2 * _offset.y / Height, 0); RC.Projection = mtxOffset * _projection; // Tick any animations and Render the scene loaded in Init() _sceneRenderer.Animate(); _sceneRenderer.Render(RC); _sinceLastTick += DeltaTime; if (_sinceLastTick >= 0.1f) { _sinceLastTick = 0; Ticker.Tick(); StringBuilder sb = new StringBuilder(Ticker.Size); foreach (char c in Ticker.CurrentText) { if (_guiLatoBlack.Alphabet.Contains(new string(c, 1))) { sb.Append(c); } else { sb.Append(' '); } } _guiSubText.Text = sb.ToString(); _subtextWidth = GUIText.GetTextWidth(_guiSubText.Text, _guiLatoBlack); _subtextHeight = GUIText.GetTextHeight(_guiSubText.Text, _guiLatoBlack); _guiSubText.PosX = (int)((Width - _subtextWidth) / 2); _guiSubText.PosY = (int)((Height - _subtextHeight) * 4.0f / 5.0f); _guiHandler.Refresh(); } _guiHandler.RenderGUI(); // Swap buffers: Show the contents of the backbuffer (containing the currently rerndered frame) on the front buffer. Present(); }
// is called once a frame public override void RenderAFrame() { RC.Clear(ClearFlags.Color | ClearFlags.Depth); // move per mouse if (Input.Instance.IsButton(MouseButtons.Left)) { _angleVelHorz = RotationSpeed * 30 * (float)Time.Instance.DeltaTime * Input.Instance.GetAxis(InputAxis.MouseX); _angleVelVert = RotationSpeed * 30 * (float)Time.Instance.DeltaTime * Input.Instance.GetAxis(InputAxis.MouseY); } else { var curDamp = (float)Math.Exp(-Damping * Time.Instance.DeltaTime); _angleVelHorz *= curDamp; _angleVelVert *= curDamp; } if (Input.Instance.GetAxis(InputAxis.MouseWheel) == 0) { var curDamp = (float)Math.Exp(-Damping * Time.Instance.DeltaTime); _zVel *= (curDamp * curDamp * curDamp); } else { _zVel = -100000 * Input.Instance.GetAxis(InputAxis.MouseWheel) * (float)Time.Instance.DeltaTime; } _angleHorz -= _angleVelHorz; _angleVert -= _angleVelVert; _zVal = Math.Max(100, Math.Min(_zVal + _zVel, 1000)); // move per keyboard if (Input.Instance.IsKey(KeyCodes.Left)) { _angleHorz -= RotationSpeed * (float)Time.Instance.DeltaTime; } if (Input.Instance.IsKey(KeyCodes.Right)) { _angleHorz += RotationSpeed * (float)Time.Instance.DeltaTime; } if (Input.Instance.IsKey(KeyCodes.Up)) { _angleVert -= RotationSpeed * (float)Time.Instance.DeltaTime; } if (Input.Instance.IsKey(KeyCodes.Down)) { _angleVert += RotationSpeed * (float)Time.Instance.DeltaTime; } var mtxRot = float4x4.CreateRotationX(_angleVert) * float4x4.CreateRotationY(_angleHorz); var mtxCam = float4x4.LookAt(0, 200, -_zVal, 0, 0, 0, 0, 1, 0); // first mesh //RC.Model = mtxCam * mtxRot /* float4x4.CreateScale(100) * */; //RC.SetShader(_spColor); //RC.SetShaderParam(_colorParam, new float4(0.5f, 0.8f, 0, 1)); //RC.Render(_meshTea); RC.ModelView = mtxCam * mtxRot * _modelScaleOffset; _sr.Render(RC); _sr.Animate(); _guiHandler.RenderGUI(); // swap buffers Present(); }
// RenderAFrame is called once a frame public override void RenderAFrame() { // _guiSubText.Text = $"dt: {DeltaTime} ms, W: {Width}, H: {Height}, PS: {_maxPinchSpeed}"; // Clear the backbuffer RC.Clear(ClearFlags.Color | ClearFlags.Depth); // Mouse and keyboard movement if (Input.Keyboard.LeftRightAxis != 0 || Input.Keyboard.UpDownAxis != 0) { _keys = true; } var curDamp = (float)System.Math.Exp(-Damping * Time.DeltaTime); // Zoom & Roll if (Input.Touch.TwoPoint) { if (!_twoTouchRepeated) { _twoTouchRepeated = true; _angleRollInit = Input.Touch.TwoPointAngle - _angleRoll; _offsetInit = Input.Touch.TwoPointMidPoint - _offset; _maxPinchSpeed = 0; } _zoomVel = Input.Touch.TwoPointDistanceVel * -0.01f; _angleRoll = Input.Touch.TwoPointAngle - _angleRollInit; _offset = Input.Touch.TwoPointMidPoint - _offsetInit; float pinchSpeed = Input.Touch.TwoPointDistanceVel; if (pinchSpeed > _maxPinchSpeed) { _maxPinchSpeed = pinchSpeed; // _maxPinchSpeed is used for debugging only. } } else { _twoTouchRepeated = false; _zoomVel = Input.Mouse.WheelVel * -0.5f; _angleRoll *= curDamp * 0.8f; _offset *= curDamp * 0.8f; } // UpDown / LeftRight rotation if (Input.Mouse.LeftButton) { _keys = false; _angleVelHorz = -RotationSpeed * Input.Mouse.XVel * 0.000002f; _angleVelVert = -RotationSpeed * Input.Mouse.YVel * 0.000002f; } else if (Input.Touch.GetTouchActive(TouchPoints.Touchpoint_0) && !Input.Touch.TwoPoint) { _keys = false; float2 touchVel; touchVel = Input.Touch.GetVelocity(TouchPoints.Touchpoint_0); _angleVelHorz = -RotationSpeed * touchVel.x * 0.000002f; _angleVelVert = -RotationSpeed * touchVel.y * 0.000002f; } else { if (_keys) { _angleVelHorz = -RotationSpeed * Input.Keyboard.LeftRightAxis * 0.002f; _angleVelVert = -RotationSpeed * Input.Keyboard.UpDownAxis * 0.002f; } else { _angleVelHorz *= curDamp; _angleVelVert *= curDamp; } } _zoom += _zoomVel; // Limit zoom if (_zoom < 80) { _zoom = 80; } if (_zoom > 2000) { _zoom = 2000; } _angleHorz += _angleVelHorz; // Wrap-around to keep _angleHorz between -PI and + PI _angleHorz = M.MinAngle(_angleHorz); _angleVert += _angleVelVert; // Limit pitch to the range between [-PI/2, + PI/2] _angleVert = M.Clamp(_angleVert, -M.PiOver2, M.PiOver2); // Wrap-around to keep _angleRoll between -PI and + PI _angleRoll = M.MinAngle(_angleRoll); // Create the camera matrix and set it as the current ModelView transformation var mtxRot = float4x4.CreateRotationZ(_angleRoll) * float4x4.CreateRotationX(_angleVert) * float4x4.CreateRotationY(_angleHorz); var mtxCam = float4x4.LookAt(0, 20, -_zoom, 0, 0, 0, 0, 1, 0); RC.View = mtxCam * mtxRot * _sceneScale * _sceneCenter; var mtxOffset = float4x4.CreateTranslation(2 * _offset.x / Width, -2 * _offset.y / Height, 0); RC.Projection = mtxOffset * _projection; // Tick any animations and Render the scene loaded in Init() _sceneRenderer.Animate(); _sceneRenderer.Render(RC); // Swap buffers: Show the contents of the backbuffer (containing the currently rerndered farame) on the front buffer. Present(); }
// RenderAFrame is called once a frame public override void RenderAFrame() { if (_gamePad != null) { Diagnostics.Log(_gamePad.LSX); } // Clear the backbuffer RC.Clear(ClearFlags.Color | ClearFlags.Depth); // Mouse and keyboard movement if (Keyboard.LeftRightAxis != 0 || Keyboard.UpDownAxis != 0) { _keys = true; } var curDamp = (float)System.Math.Exp(-Damping * DeltaTime); // Zoom & Roll if (Touch.TwoPoint) { if (!_twoTouchRepeated) { _twoTouchRepeated = true; _angleRollInit = Touch.TwoPointAngle - _angleRoll; _offsetInit = Touch.TwoPointMidPoint - _offset; _maxPinchSpeed = 0; } _zoomVel = Touch.TwoPointDistanceVel * -0.01f; _angleRoll = Touch.TwoPointAngle - _angleRollInit; _offset = Touch.TwoPointMidPoint - _offsetInit; float pinchSpeed = Touch.TwoPointDistanceVel; if (pinchSpeed > _maxPinchSpeed) { _maxPinchSpeed = pinchSpeed; // _maxPinchSpeed is used for debugging only. } } else { _twoTouchRepeated = false; _zoomVel = Mouse.WheelVel * -0.5f; _angleRoll *= curDamp * 0.8f; _offset *= curDamp * 0.8f; } // UpDown / LeftRight rotation if (Mouse.LeftButton) { _keys = false; _angleVelHorz += -RotationSpeed * Mouse.XVel * DeltaTime * 0.00005f; _angleVelVert += -RotationSpeed * Mouse.YVel * DeltaTime * 0.00005f; } else if (_spaceMouse != null) { _angleVelHorz += _spaceMouse.Rotation.y * -0.00005f * DeltaTime; _angleVelVert += _spaceMouse.Rotation.x * -0.00005f * DeltaTime; } else if (_gamePad != null) { _angleVelHorz -= -RotationSpeed * _gamePad.LSX * DeltaTime; _angleVelVert -= -RotationSpeed * _gamePad.LSY * DeltaTime; } else if (Touch.GetTouchActive(TouchPoints.Touchpoint_0) && !Touch.TwoPoint) { _keys = false; float2 touchVel; touchVel = Touch.GetVelocity(TouchPoints.Touchpoint_0); _angleVelHorz = -RotationSpeed * touchVel.x * DeltaTime * 0.0005f; _angleVelVert = -RotationSpeed * touchVel.y * DeltaTime * 0.0005f; } else { if (_keys) { _angleVelHorz = -RotationSpeed * Keyboard.LeftRightAxis * DeltaTime; _angleVelVert = -RotationSpeed * Keyboard.UpDownAxis * DeltaTime; } else { _angleVelHorz *= curDamp; _angleVelVert *= curDamp; } } _zoom += _zoomVel; // Limit zoom if (_zoom < 80) { _zoom = 80; } if (_zoom > 2000) { _zoom = 2000; } _angleHorz += _angleVelHorz; // Wrap-around to keep _angleHorz between -PI and + PI _angleHorz = M.MinAngle(_angleHorz); _angleVert += _angleVelVert; // Limit pitch to the range between [-PI/2, + PI/2] _angleVert = M.Clamp(_angleVert, -M.PiOver2, M.PiOver2); // Wrap-around to keep _angleRoll between -PI and + PI _angleRoll = M.MinAngle(_angleRoll); // Create the camera matrix and set it as the current View transformation var mtxRot = /*float4x4.CreateRotationZ(_angleRoll) **/ float4x4.CreateRotationX(_angleVert) * float4x4.CreateRotationY(_angleHorz); var mtxCam = float4x4.LookAt(0, 20, -_zoom, 0, 0, 0, 0, 1, 0); RC.View = mtxCam * mtxRot * _sceneScale * _sceneCenter; var mtxOffset = float4x4.CreateTranslation(2f * _offset.x / Width, -2f * _offset.y / Height, 0); RC.Projection *= mtxOffset; // Constantly check for interactive objects. _sih.CheckForInteractiveObjects(Input.Mouse.Position, Width, Height); if (Touch.GetTouchActive(TouchPoints.Touchpoint_0) && !Touch.TwoPoint) { _sih.CheckForInteractiveObjects(Touch.GetPosition(TouchPoints.Touchpoint_0), Width, Height); } // Tick any animations and Render the scene loaded in Init() _sceneRenderer.Animate(); _sceneRenderer.Render(RC); var projection = float4x4.CreateOrthographic(Width, Height, ZNear, ZFar); RC.Projection = projection; _sih.View = RC.View; _guiRenderer.Render(RC); projection = float4x4.CreatePerspectiveFieldOfView(_fovy, _aspectRatio, ZNear, ZFar); RC.Projection = projection; // Swap buffers: Show the contents of the backbuffer (containing the currently rendered frame) on the front buffer. Present(); }