示例#1
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            physics.Update((float)e.Time);

            if (Keyboard[OpenTK.Input.Key.Escape] || Keyboard[OpenTK.Input.Key.Q])
            {
                Exit();
            }
        }
示例#2
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            physics.Update((float)e.Time);

            KeyboardState state = OpenTK.Input.Keyboard.GetState();

            if (state.IsKeyDown(Key.Escape) || state.IsKeyDown(Key.Q))
            {
                Exit();
            }
        }
示例#3
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            _physics.Update((float)e.Time);

            var keyboard = Keyboard.GetState();

            if (keyboard[Key.Escape] || keyboard[Key.Q])
            {
                Exit();
            }
        }
示例#4
0
        protected override void Update(GameTime gameTime)
        {
            KeyboardState ns = Keyboard.GetState();

            if (ns.IsKeyDown(Keys.Escape) || ns.IsKeyDown(Keys.Q))
            {
                Exit();
            }

            // Toggle debug
            if (ns.IsKeyDown(Keys.F3))
            {
                if (f3KeyPressed == false)
                {
                    f3KeyPressed = true;
                    if (IsDebugDrawEnabled == false)
                    {
                        DebugDrawer.DebugMode = DebugDrawModes.DrawAabb;
                        IsDebugDrawEnabled    = true;
                    }
                    else
                    {
                        DebugDrawer.DebugMode = DebugDrawModes.None;
                        IsDebugDrawEnabled    = false;
                    }
                }
            }
            if (f3KeyPressed == true)
            {
                if (ns.IsKeyUp(Keys.F3))
                {
                    f3KeyPressed = false;
                }
            }

            viewMatrix = Matrix.CreateLookAt(eye, target, Vector3.UnitY);

            physics.Update((float)gameTime.ElapsedGameTime.TotalSeconds);

            base.Update(gameTime);
        }
示例#5
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            _physics.Update((float)e.Time);

            var keyboard = Keyboard.GetState();

            if (keyboard[Key.Escape] || keyboard[Key.Q])
            {
                Exit();
            }

            var input = Keyboard.GetState();

            // camera parameters
            const float cameraSpeed = 3f;

            // panning
            if (input.IsKeyDown(Key.W))
            {
                position += Vector3.UnitY * cameraSpeed * (float)e.Time; // Up
            }
            if (input.IsKeyDown(Key.S))
            {
                position -= Vector3.UnitY * cameraSpeed * (float)e.Time; // Down
            }
            if (input.IsKeyDown(Key.A))
            {
                position -= Vector3.UnitX * cameraSpeed * (float)e.Time; // Left
            }
            if (input.IsKeyDown(Key.D))
            {
                position += Vector3.UnitX * cameraSpeed * (float)e.Time; // Right
            }
            var mouse  = Mouse.GetCursorState();
            var window = Location;
            var cursor = new Point(mouse.X - window.X - 8, mouse.Y - window.Y - 38);

            if (cursor.X >= 0 && cursor.X < Width && cursor.Y >= 0 && cursor.Y < Height)
            {
                OpenTK.Vector4 ndcStart = new OpenTK.Vector4(
                    ((float)cursor.X / Width - 0.5f) * 2,
                    ((float)(Height - cursor.Y) / Height - 0.5f) * 2,
                    -1, 1);
                OpenTK.Vector4 ndcEnd = new OpenTK.Vector4(
                    ((float)cursor.X / Width - 0.5f) * 2,
                    ((float)(Height - cursor.Y) / Height - 0.5f) * 2,
                    0, 1);

                var projInv = Matrix4.Invert(Matrix4.Transpose(perspective));
                var viewInv = Matrix4.Invert(Matrix4.Transpose(lookAt));

                var rayStartCamera = projInv * ndcStart;
                rayStartCamera /= rayStartCamera.W;
                var rayStartWorld = viewInv * rayStartCamera;
                rayStartWorld /= rayStartWorld.W;

                var rayEndCamera = projInv * ndcEnd;
                rayEndCamera /= rayEndCamera.W;
                var rayEndWorld = viewInv * rayEndCamera;
                rayEndWorld /= rayEndWorld.W;

                var rayDir = OpenTK.Vector4.Normalize(rayEndWorld - rayStartWorld);
                rayEndWorld = rayDir * 1000;

                var source = new BulletSharp.Math.Vector3(rayStartWorld.X, rayStartWorld.Y, rayStartWorld.Z);
                var dest   = new BulletSharp.Math.Vector3(rayEndWorld.X, rayEndWorld.Y, rayEndWorld.Z);
                using (var cb = new ClosestRayResultCallback(ref source, ref dest))
                {
                    _physics.World.RayTestRef(ref source, ref dest, cb);
                    if (cb.HasHit)
                    {
                        isHit = true;
                    }
                    else
                    {
                        isHit = false;
                    }
                }
            }

            Title = $"BulletSharp OpenTK Demo, MousePos = ({cursor.X}, {cursor.Y})";
        }
示例#6
0
 bool root_FrameStarted(FrameEvent evt)
 {
     physics.Update(evt.timeSinceLastFrame);
     return(true);
 }