// RenderAFrame is called once a frame public override void RenderAFrame() { RC.ClearColor = new float4(0.75f, 0.75f, 0.75f, 1); // Clear the back buffer RC.Clear(ClearFlags.Color | ClearFlags.Depth); RC.Viewport(0, 0, Width, Height); var speed = Mouse.Velocity + Touch.GetVelocity(TouchPoints.Touchpoint_0); if (Mouse.LeftButton || Touch.GetTouchActive(TouchPoints.Touchpoint_0)) { _alpha -= speed.x * 0.00001f; _beta -= speed.y * 0.00001f; } // damping var curDamp = (float)System.Math.Exp(-0.8 * Time.DeltaTime); _alpha *= curDamp; _beta *= curDamp; _zoom += Mouse.WheelVel * 0.05f; _scene.Children[0].GetComponentsInChildren <Transform>().ToList().ForEach(t => { if (t.Name != "TextTransform") { t.Rotate(new float3(_beta, _alpha, 0)); } }); // Create the camera matrix and set it as the current ModelView transformation _offsetX += Keyboard.ADAxis * -0.4f; _offsetY += Keyboard.WSAxis * -0.3f; var mtxCam = float4x4.LookAt(0, 0, _zoom, 0, 0, 0, 0, 1, 0); var offset = float4x4.CreateTranslation(new float3(_offsetX, _offsetY, 0)); RC.View = mtxCam * offset; _renderer.Render(RC); _guiDescRenderer.Render(RC); // Swap buffers: Show the contents of the backbuffer (containing the currently rendered frame) on the front buffer. Present(); }
// RenderAFrame is called once a frame public override void RenderAFrame() { // Clear the backbuffer RC.Clear(ClearFlags.Color | ClearFlags.Depth); RC.Viewport(0, 0, Width, Height); //if (!rotate) //{ // _sunTransform.RotateAround(new float3(0, 0, 0), float3.UnitX, M.DegreesToRadians(20)); // rotate = true; //} //_sunTransform.RotateAround(new float3(0, 0, 0), float3.UnitX, M.DegreesToRadians(0.5f) * Time.DeltaTime * 50); var deg = (M.RadiansToDegrees(_sunTransform.Rotation.x)) - 90; if (deg < 0) { deg = (360 + deg); } var normalizedDeg = (deg) / 360; float localLerp; if (normalizedDeg <= 0.5) { _backgroundColor = _backgroundColorDay; localLerp = normalizedDeg / 0.5f; _backgroundColor.xyz = float3.Lerp(_backgroundColorDay.xyz, _backgroundColorNight.xyz, localLerp); } else { _backgroundColor = _backgroundColorNight; localLerp = (normalizedDeg - 0.5f) / (0.5f); _backgroundColor.xyz = float3.Lerp(_backgroundColorNight.xyz, _backgroundColorDay.xyz, localLerp); } _campComp.BackgroundColor = _backgroundColor; // Mouse and keyboard movement if (Keyboard.LeftRightAxis != 0 || Keyboard.UpDownAxis != 0) { _keys = true; } if (Keyboard.IsKeyDown(KeyCodes.F)) { _sceneRenderer.FxaaOn = !_sceneRenderer.FxaaOn; } if (Keyboard.IsKeyDown(KeyCodes.G)) { _sceneRenderer.SsaoOn = !_sceneRenderer.SsaoOn; } 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)) { _keys = false; var 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; } } _angleHorz -= _angleVelHorz; _angleVert -= _angleVelVert; _angleVelHorz = 0; _angleVelVert = 0; _camTransform.FpsView(_angleHorz, _angleVert, Keyboard.WSAxis, Keyboard.ADAxis, Time.DeltaTime * 1000); _sceneRenderer.Render(RC); _guiRenderer.Render(RC); if (!Mouse.Desc.Contains("Android")) { _sih.CheckForInteractiveObjects(RC, Mouse.Position, Width, Height); } if (Touch.GetTouchActive(TouchPoints.Touchpoint_0) && !Touch.TwoPoint) { _sih.CheckForInteractiveObjects(RC, Touch.GetPosition(TouchPoints.Touchpoint_0), Width, Height); } // Swap buffers: Show the contents of the backbuffer (containing the currently rendered frame) on the front buffer. Present(); }