/// <summary> /// Gets the scene object below the cursor. /// </summary> public async Task <SceneObject> GetObjectBelowCursorAsync() { if (!m_isMouseInside) { return(null); } List <SceneObject> objects = await m_renderLoop.PickObjectAsync( Point.FromGdiPoint(this.PointToClient(Cursor.Position)), new PickingOptions() { OnlyCheckBoundingBoxes = false }); if (objects == null) { return(null); } return(objects.FirstOrDefault()); }
private async void OnRefeshTimer_Tick(object sender, EventArgs e) { if (sender != m_refreshTimer) { return; } if (this.AssociatedObject == null) { return; } if (m_onRefresh) { return; } m_onRefresh = true; try { // Check for empty position if (m_mouseLocation == new Point()) { return; } // Pick objects List <SceneObject> pickedObjects = await m_renderLoop.PickObjectAsync( new SeeingSharp.Point((int)m_mouseLocation.X, (int)m_mouseLocation.Y), new PickingOptions()); GenericObject topUnderCursor = pickedObjects .Where((actPicked) => actPicked is GenericObject) .FirstOrDefault() as GenericObject; // Check current state after async action if (sender != m_refreshTimer) { return; } if (this.AssociatedObject == null) { return; } // Sync GenericObject newHovered = null; if (topUnderCursor != null) { newHovered = topUnderCursor; } // Apply changes to the scene if (m_hoveredObject != newHovered) { await m_scene.ManipulateSceneAsync(manipulator => { if (m_hoveredObject != null) { manipulator.ClearLayer(Constants.LAYER_HOVER); } m_hoveredObject = newHovered; if (m_hoveredObject != null) { GenericObject newHovering = new GenericObject(m_hoveredObject.GeometryResourceKey); newHovering.TransformationType = SpacialTransformationType.TakeFromOtherObject; newHovering.TransformSourceObject = newHovered; newHovering.Color = SeeingSharp.Color.Blue; manipulator.Add(newHovering, Constants.LAYER_HOVER); } }); } } finally { m_onRefresh = false; } }