private Ray3 getCameraRay(int x, int y) { SceneViewWindow activeWindow = sceneViewController.ActiveWindow; if (activeWindow != null) { return(activeWindow.getCameraToViewportRayScreen(x, y)); } return(new Ray3()); }
void pickAnatomy_FirstFrameUpEvent(EventLayer eventLayer) { IntVector3 absMouse = eventLayer.Mouse.AbsolutePosition; if (eventLayer.EventProcessingAllowed && !travelTracker.TraveledOverLimit) { SceneViewWindow activeWindow = sceneViewController.ActiveWindow; DisplayHintLocation = new IntVector2(absMouse.x + MouseClickWindowOffset, absMouse.y + MouseClickWindowOffset); TriggeredSelection = false; Ray3 cameraRay = activeWindow.getCameraToViewportRayScreen(absMouse.x, absMouse.y); AnatomyIdentifier firstMatch; IEnumerable <Anatomy> matches = anatomyController.findAnatomy(cameraRay, out firstMatch); if (!clickedAnatomy.clickedSameAnatomy(firstMatch)) { if (matches != null) { clickedAnatomy.setNewResults(matches, firstMatch); anatomyController.processSelection(clickedAnatomy.CurrentMatch, clickedAnatomy.PreviousMatch); clickedAnatomy.moveNext(); searchBox.Caption = "Picked"; clearButton.Visible = true; } else { clickedAnatomy.clear(); anatomyController.processSelection(null, null); clearButton.Visible = false; searchBox.Caption = ""; } } else { anatomyController.processSelection(clickedAnatomy.CurrentMatch, clickedAnatomy.PreviousMatch); clickedAnatomy.moveNext(); } } }
void events_OnUpdate(EventLayer eventLayer) { Ray3 spaceRay = new Ray3(); Vector3 cameraPos = Vector3.Zero; SceneViewWindow activeWindow = sceneViewController.ActiveWindow; if (activeWindow != null) { IntVector3 mouseLoc = events.Mouse.AbsolutePosition; spaceRay = activeWindow.getCameraToViewportRayScreen(mouseLoc.x, mouseLoc.y); cameraPos = activeWindow.Translation; } //Check collisions and draw shapes if (!PickEvent.HeldDown) { float closestDistance = float.MaxValue; MovableObjectTools closestTools = null; foreach (MovableObjectTools tools in movableObjects) { if (tools.checkBoundingBoxCollision(ref spaceRay)) { if (tools.processAxes(ref spaceRay)) { float distance = (tools.Movable.ToolTranslation - cameraPos).length2(); if (distance < closestDistance) { //If we had a previous closer tool clear its selection. if (closestTools != null) { closestTools.clearSelection(); } closestTools = tools; closestDistance = distance; } //If this tool was not closer clear its selection. else { tools.clearSelection(); } } else { tools.clearSelection(); } } else { tools.clearSelection(); } } if (PickEvent.FirstFrameDown) { currentTools = closestTools; if (closestTools != null) { closestTools.pickStarted(events, ref cameraPos, ref spaceRay); events.alertEventsHandled(); } } else if (PickEvent.FirstFrameUp) { if (currentTools != null) { events.alertEventsHandled(); } currentTools = null; } } else { if (currentTools != null) { currentTools.pickHeld(events, ref cameraPos, ref spaceRay); events.alertEventsHandled(); } } foreach (MovableObjectTools tools in movableObjects) { tools.drawTools(drawingSurface); } }