protected override void OnRenderFrame(FrameEventArgs e) { base.OnRenderFrame(e); var currBoidModel = ResourceManager.GetModel("fish_0000" + ((((int)currentFishModelIndex) % 39) + 10)); Boids.ForEach(boid => boid.Model = currBoidModel); LeaderBoid.Model = currBoidModel; Renderer3D.RenderShadows(EngineObjects, ResourceManager.GetShader("shadow"), Width, Height, directionalLight); GL.ClearColor(60 / 255f, 100 / 255f, 120 / 255f, 1); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); ResourceManager.GetShader("textured").SetFloat("inputTime", cumulativeTime, true); Renderer3D.DrawModels(EngineObjects, ResourceManager.GetShader("textured"), Width, Height, directionalLight, fogEnabled); //Renderer3D.DrawSun(ResourceManager.GetShader("light"), (float)Width / Height); SwapBuffers(); }
protected override void OnUpdateFrame(FrameEventArgs e) { base.OnUpdateFrame(e); if (State == GameState.Active) { deltaTime = (float)e.Time; cumulativeTime += deltaTime; currentFishModelIndex += 24 * deltaTime; if (autoPilot) { if (leaderTarget == Vector3.Zero || Vector3.Distance(LeaderBoid.Position, leaderTarget) < 2 * Boid.MAX_SPEED) { leaderTarget = GetRandomPosition(); } LeaderBoid.MoveToPoint(leaderTarget, deltaTime); } else { LeaderBoid.CheckBoundaries(); LeaderBoid.Velocity = Vector3.Clamp(LeaderBoid.Velocity, -Vector3.One * Boid.MAX_SPEED, Vector3.One * Boid.MAX_SPEED); LeaderBoid.CalculatePositionAndRotation(deltaTime); } Boids.ForEach(boid => ((Boid)boid).Move(Boids.Where(b => b != boid).ToList(), deltaTime)); UpdateFlockMiddle(); Camera.Update(); if (shouldPause) { shouldPause = false; State = GameState.Paused; LogDebugInfo(); } } ProcessEvents(); }
private void UpdateFlockMiddle() { FlockMiddlePos = Vector3.Zero; Boids.ForEach(boid => FlockMiddlePos += boid.Position); FlockMiddlePos /= Boids.Count; }