// This is normally called when it is time to set up the next frame. The game // logic, therefore, would normally be placed here. Originally, I thought that // this would be a good place to calculate the dt and update the positions, // velocities, and accelerations of the critters, etc. However, after some // reflection, I realized that the OnRenderFrame (below) should be called as // often as possible, and the dt and updates should be done there. I use the // OnUpdateFrame to just get input from the user, and have it set to get it // about 30 times per second. This gives me really decent keyboard and mouse // sensitivity. Meanwhile, all the time that it takes to calculate the updates, // etc., is included in the dt, since I do this in the OnRenderFrame. -- JC public override void OnUpdateFrame(UpdateFrameEventArgs e) { for (int i = 0; i < vk.KeyList.Length; i++) { if (Keyboard[vk.KeyList[i]]) { Keydev.setkey(i); } else { Keydev.resetkey(i); } } if (Mouse[MouseButton.Left]) { leftclick = true; } else { leftclick = false; } if (Mouse.XDelta != 0 || Mouse.YDelta != 0) { view.OnMouseMove(new Point(Mouse.X, Mouse.Y)); } }
/// <summary> /// Called when it is time to setup the next frame. Add you game logic here. /// </summary> /// <param name="e">Contains timing information for framerate independent logic.</param> public override void OnUpdateFrame(UpdateFrameEventArgs e) { base.OnUpdateFrame(e); // Hopefully will be fixed in OpenTK 0.9.1 //// Set default mouse cursor //System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default; // Keyboard-Handling if (Keyboard[Key.Escape]) { Exit(); } // Handle mouse move for obbs Mouse_Move(); Mouse_WheelMove(); // Solve collisions only for obbs (not particles) m_collisionSolver.Solve(); // Pause if (m_pause) { return; } // Update particle system this.m_particleSystem.Update(Constants.DELTA_TIME_SEC); // Interaction handling AddInteractionForces(); // Solve collisions only for particles m_collisionSolver.Solve(this.m_particleSystem.Particles); // Do simulation this.m_fluidSim.Calculate(this.m_particleSystem.Particles, this.m_gravity, Constants.DELTA_TIME_SEC); }
public override void OnUpdateFrame(UpdateFrameEventArgs e) { if (Keyboard[Key.Escape]) { Exit(); } if (Keyboard[Key.W]) { camera.Position += camera.Attitude.Direction; } if (Keyboard[Key.S]) { camera.Position -= camera.Attitude.Direction; } if (Keyboard[Key.D]) { camera.Position += camera.Attitude.Side; } if (Keyboard[Key.A]) { camera.Position -= camera.Attitude.Side; } if (Keyboard[Key.U]) { camera.Position += camera.Attitude.Up; } if (Keyboard[Key.J]) { camera.Position -= camera.Attitude.Up; } Point center = new Point(Width / 2, Height / 2); PointF diff = new PointF((Mouse.X - center.X) / 100.0f, (Mouse.Y - center.Y) / 100.0f); if (Mouse[MouseButton.Right]) { camera.Position = camera.Position + camera.Attitude.Side * diff.X + camera.Attitude.Up * diff.Y; } if (Mouse[MouseButton.Left]) { Matrix4 pitch = Matrix4.Rotate(camera.Attitude.Side, -(float)Math.PI * diff.Y / Height); Matrix4 yaw = Matrix4.Rotate(camera.Attitude.Up, -(float)Math.PI * diff.X / Width); Matrix4 rotate = yaw * pitch; camera.Attitude = new Attitude(Vector3.TransformVector(camera.Attitude.Direction, rotate), Vector3.TransformVector(camera.Attitude.Up, rotate)); } }
private void OnFrameUpdate(object sender, UpdateFrameEventArgs args) { _stateHandler.Update(); }