private static void PollSelection(GameWindow window, MouseState mouseState, KeyboardState keyboardState) // TODO: raycast is performed wrong on shapes' edges; check! { var startWorld = RaycastResult.StartWorld.ToBullet3(); var endWorld = RaycastResult.EndWorld.ToBullet3(); using (var raycastCallback = new ClosestRayResultCallback(ref startWorld, ref endWorld)) { PhysicsHandler.RayTestRef(ref startWorld, ref endWorld, raycastCallback); if (/*window.IsMouseButtonPressed(MouseButton.Right)*/ mouseState.IsButtonDown(MouseButton.Right) && _lastState.IsButtonUp(MouseButton.Right)) // TODO: perhaps use Window built-in method? { if (raycastCallback.HasHit) { if (!keyboardState.IsKeyDown(Key.ControlLeft) && SelectedObjects.Find(x => x != raycastCallback.CollisionObject) != null) { // Control is not pressed and other objects are already selected ---> clear selection and add the new object to the selection ClearAndAddSelection(raycastCallback.CollisionObject); } else { // add the object to the selection if it's not there yet if (!SelectedObjects.Contains(raycastCallback.CollisionObject)) { AddSelection(raycastCallback.CollisionObject); } else { RemoveSelection(raycastCallback.CollisionObject); } } } else { // no object is selected ---> clear selection ClearSelection(); } } } }