protected override void OnUpdateFrame(FrameEventArgs e) { base.OnUpdateFrame(e); var keyState = Keyboard.GetState(); var mouseState = Mouse.GetState(); if (keyState.IsKeyDown(Key.Escape)) { Exit(); } _player.HandleKeyboard(keyState); _player.HandleMouse(mouseState); _player.Update((float)e.Time); _world.Update((float)e.Time); if (Focused) { var centerPoint = new Point(_width / 2, _height / 2); centerPoint = PointToScreen(centerPoint); OpenTK.Input.Mouse.SetPosition(centerPoint.X, centerPoint.Y); } DebugDrawManager.Update(); }
public void Update(float frameTime) { // ApplyGravity(frameTime); ApplyMovement(frameTime); var ray = new Ray(Position + new Vector3(0, CameraHeight, 0), _viewDirection); if (_collisionController.CollidesWithWorld(ray, 5.0f, out var hit)) { var worldPos = new WorldPosition(hit); DebugDrawManager.AddElement(new DebugDrawCube(worldPos.BBox(Vector3.One)), 100); if (_playerState.Attack1) { if (!_blockDestoryCooldown.IsRunning) { _blockController.DestroyBlock(worldPos); _blockDestoryCooldown.Start(); } else { if (_blockDestoryCooldown.ElapsedMilliseconds > 200) { _blockDestoryCooldown.Reset(); } } } } UpdateCamera(); }
// ---------------------------------------------------------------------------- protected override void OnCreate() { base.OnCreate(); m_grid = new UniformGrid( new int2(-100, -100), new int2(100, 100), 7); Debug.LogFormat("[GridTestSystem::OnCreate] Created Grid: {0}\n", m_grid.ToStringCompact()); //TestGrid(); DebugDrawManager.Register(this); }
public Color4 GetLightAt(Vector3 position) { // Cast a ray from each light to the position foreach (var light in _lights) { var maxDistance = (position - light.Position).Length; var ray = new Ray(position, light.Position - position); DebugDrawManager.AddElement(new DebugDrawLine(ray, maxDistance), 10000); if (!_collisionController.CollidesWithWorld(ray, maxDistance, out var hit)) { return(light.Color); } } return(new Color4(100, 100, 100, 255)); }
protected override void OnRenderFrame(FrameEventArgs e) { base.OnRenderFrame(e); string oglVersion = GL.GetString(StringName.Version); Title = $"FPS: {1 / e.Time:F0}, Version: {oglVersion}"; GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _skyboxProgram.Use(); _skyboxProgram.setMat4("view", _player.Camera.ViewMatrix.ClearTranslation()); _skyboxProgram.setMat4("projection", _player.Camera.ProjectionMatrix); GL.DepthMask(false); GL.Disable(EnableCap.DepthTest); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); _skybox.Render(); _program.Use(); _program.setMat4("view", _player.Camera.ViewMatrix); _program.setMat4("projection", _player.Camera.ProjectionMatrix); _program.setMat4("model", Matrix4.Identity); _program.setVec3("light_color", Vector3.One); _program.setVec3("light_position", new Vector3(0, 10, 50)); _program.setVec3("camera_position", _player.Position); GL.DepthMask(true); GL.Enable(EnableCap.DepthTest); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); _world.Render(); _debugProgram.Use(); _debugProgram.setMat4("view", _player.Camera.ViewMatrix); _debugProgram.setMat4("projection", _player.Camera.ProjectionMatrix); _debugProgram.setMat4("model", Matrix4.Identity); GL.Disable(EnableCap.DepthTest); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); DebugDrawManager.Render(); SwapBuffers(); }