Esempio n. 1
0
        public static void PollEvents(GameWindow window, Camera camera, MouseState mouseState, KeyboardState keyboardState, FrameEventArgs e)
        {
            // update cursor position in NDC space
            CursorPositionNDC = MouseToNDC(window, mouseState);  // TODO: consider creating an extension method CursorPositionNDC() for MouseState

            // perform a raycast and store the result for later use
            RaycastResult = Ray.Cast(ref camera.ViewMatrix, ref camera.ProjectionMatrix);

            // attach widgets to or detach from the selected objects
            AttachWidgets(camera);

            // scale all axes so that their size on screen remains fixed
            TranslationalWidget.Scale(camera);

            if (MainWindow.Mode == InteractionMode.Design && !ImGui.IsWindowHovered(
                    ImGuiHoveredFlags.AnyWindow |
                    ImGuiHoveredFlags.AllowWhenBlockedByPopup)) // TODO: perhaps use some other way of obtaining current mode?
            {
                // check whether any physical object is being selected
                PollSelection(window, mouseState, keyboardState);

                // poll widget for interaction
                TranslationalWidget.Poll(camera, RaycastResult, mouseState, _lastState);
            }

            // poll the mouse for events
            PollMouse(window, camera, mouseState);

            // poll the keyboard for events
            PollKeyboard(window, camera, keyboardState, e);

            // poll the screen for events
            PollScreen(window, keyboardState);
        }
Esempio n. 2
0
        public static void AttachWidgets(Camera camera)
        {
            if (SelectedObjects.Count == 1)
            {
                var selected = SelectedObjects[0].UserObject as ISelectable;
                if (selected != CurrentSelectedObject)
                {
                    CurrentSelectedObject = selected;

                    // fire an event of selected object being changed
                    SelectedObjectChanged?.Invoke(selected, EventArgs.Empty);
                }

                // attach the widget
                TranslationalWidget.Attach(CurrentSelectedObject as ITranslatable, camera);
            }
            else
            {
                if (SelectedObjects.Count == 0 || !(CurrentSelectedObject is Manipulator))
                {
                    CurrentSelectedObject = null;
                }

                // detach the widget
                TranslationalWidget.Detach();
            }
        }
Esempio n. 3
0
 public static void Dispose()
 {
     // dispose of the widgets
     TranslationalWidget.Dispose();
 }