private void _panel_MouseClick(object sender, MouseEventArgs e) { Point point = new Point(e.X, e.Y); Engine.QueueForRenderDispatcher(() => { if (e.Button == MouseButtons.Left) { Ray ray; RaySceneQueryResult.Enumerator itr = GetRaySceneQuery(point.X, point.Y, out ray); if (itr != null) { while (itr.MoveNext()) { RaySceneQueryResultEntry entry = itr.Current; SceneNode parentNode = entry.movable.ParentSceneNode; PositionedInstance instance = Engine.SceneNodeStore.GetInstance(parentNode); if (instance != null) { Engine.RunOnUIThread(() => { IoC.Get <IExplorer>().SelectInstance(instance); }); ActiveScene.SelectedInstance = instance; SetActiveSelectedNode(parentNode); return; } } SceneNode node; if (ExistsSelectedNode(out node)) { PositionedInstance oldInstance = Engine.SceneNodeStore.GetInstance(node); if (oldInstance != null) { SizedInstance oldSized = oldInstance as SizedInstance; if (oldSized != null) { oldSized.IsSelected = false; oldSized.IsBoundingBoxEnabled = false; } } ActiveScene.SelectedInstance = null; oldInstance.RemoveGizmoVisual(); ClearSelectedNode(); } } } }); }
private void _panel_MouseDown(object sender, MouseEventArgs e) { Point point = new Point(e.X, e.Y); Engine.QueueForRenderDispatcher(() => { if (e.Button == MouseButtons.Left) { Ray ray; RaySceneQueryResult.Enumerator itr = GetRaySceneQuery(point.X, point.Y, out ray); if (itr != null) { if (itr.MoveNext()) { RaySceneQueryResultEntry entry = itr.Current; SceneNode parentNode = entry.movable.ParentSceneNode; TransformDragging dragging; DirectionalTransformDragging directionalDragging; if (IsTranslateClick(parentNode, out dragging)) { _translateDragging = dragging; IEnumerable <SceneNode> selected = GetSelectedNode(); if (selected != null) { SceneNode node = selected.FirstOrDefault(); if (node != null) { _translateDragDifference = ray.GetPoint(entry.distance) - node.Position; } } return; } else if (IsScaleClick(parentNode, out directionalDragging)) { _scaleDragging = directionalDragging; IEnumerable <SceneNode> selected = GetSelectedNode(); if (selected != null) { SceneNode node = selected.FirstOrDefault(); if (node != null) { _scaleDragDifference = ray.GetPoint(entry.distance) - node.Position; } } return; } else { _translateDragging = TransformDragging.NONE; } } } } }); }
public string selectObject(Point mousePoint, float width, float height) { RestoreBoxnodes(); Ray ray = camera.GetCameraToViewportRay(mousePoint.X / width, mousePoint.Y / height); raySceneQuery.Ray = ray; // Execute query raySceneQuery.SetSortByDistance(true, 1); RaySceneQueryResult result = raySceneQuery.Execute(); if (result.Count > 0) { isTubeRool = true; RaySceneQueryResultEntry entry = result[0]; string entryName = entry.movable.Name; if (entryName.Substring(0, 3).Equals("box")) { Node node = entry.movable.ParentNode; Vector3 nodePosition = node.Position; if (nodePosition.x == 0) { nodePosition.x += 20; node.Position = nodePosition; } } else if (entryName.Substring(0, 4).Equals("tube")) { isTubeRool = false; Node nodeParent = entry.movable.ParentNode.Parent; for (int i = 1; i < 4; i++) { Node nodeChild = nodeParent.GetChild("tube" + i.ToString() + "Node"); nodeChild.ResetOrientation(); } } return(entryName); } return(""); }
public static Vector3 GetBestLocationFromYDown(Vector3 vector, float fallbackY, float sizeY) { Ray ray = new Ray(vector + new Vector3(0, (float.MaxValue), 0), Vector3.NEGATIVE_UNIT_Y); RaySceneQuery mRaySceneQuery = Engine.Renderer.Scene.CreateRayQuery(ray); mRaySceneQuery.SetSortByDistance(true, 64); mRaySceneQuery.QueryMask = (uint)QueryFlags.INSTANCE_ENTITY; mRaySceneQuery.QueryTypeMask = SceneManager.ENTITY_TYPE_MASK | SceneManager.STATICGEOMETRY_TYPE_MASK | SceneManager.USER_TYPE_MASK_LIMIT | SceneManager.FRUSTUM_TYPE_MASK | SceneManager.FX_TYPE_MASK | SceneManager.LIGHT_TYPE_MASK | SceneManager.WORLD_GEOMETRY_TYPE_MASK; RaySceneQueryResult result = mRaySceneQuery.Execute(); RaySceneQueryResult.Enumerator itr = (RaySceneQueryResult.Enumerator)(result.GetEnumerator()); Vector3 max = new Vector3(vector.x, fallbackY, vector.z); if (itr != null) { while (itr.MoveNext()) { RaySceneQueryResultEntry entry = itr.Current; SceneNode parentNode = entry.movable.ParentSceneNode; Vector3 current = new Vector3(vector.x, parentNode.Position.y + sizeY, vector.z); if (current.y > max.y) { max = current; } } } return(max); }
protected override bool ExampleApp_FrameStarted(FrameEvent evt) { if (base.ExampleApp_FrameStarted(evt) == false) { return(false); } // clamp to terrain Ray updateRay = new Ray(this.camera.Position, Vector3.NEGATIVE_UNIT_Y); raySceneQuery.Ray = updateRay; RaySceneQueryResult qryResult = raySceneQuery.Execute(); RaySceneQueryResultEntry rs = qryResult[0]; if (rs != null && rs.worldFragment != null) { camera.SetPosition(camera.Position.x, rs.worldFragment.singleIntersection.y + 10, camera.Position.z); } return(true); }
private void renderBox_MouseClick(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Left) { return; } foreach (MovableObject selectedNode in selectedNodes) { try { selectedNode.ParentSceneNode.ShowBoundingBox = false; } catch (Exception ex) { //log(ex.ToString()); } } selectedNodes = new ArrayList(); float scrx = (float)e.X / OgreWindow.Instance.mViewport.ActualWidth; float scry = (float)e.Y / OgreWindow.Instance.mViewport.ActualHeight; Ray ray = OgreWindow.Instance.mCamera.GetCameraToViewportRay(scrx, scry); RaySceneQuery query = OgreWindow.Instance.mSceneMgr.CreateRayQuery(ray); RaySceneQueryResult results = query.Execute(); float nearest = 100000000f; //100 mill int nearestIndex = -1; for (int i = 0; i < results.Count; i++) { RaySceneQueryResultEntry entry = results[i]; if (entry.movable.Name == "MainCamera") { continue; } if (entry.movable.Name.IndexOf("SphereEntity") > -1) { continue; } if (entry.movable.Name.IndexOf("SkyXMeshEnt") > -1) { continue; } if (entry.movable.Name.IndexOf("_Hydrax_GodRays_ManualObject") > -1) { continue; } if (entry.movable.Name.IndexOf("_Hydrax_GodRays_Projector_Camera") > -1) { continue; } if (entry.movable.Name.IndexOf("_Hydrax_Projector_Camera") > -1) { continue; } if (entry.movable.Name.IndexOf("HydraxMeshEnt") > -1) { continue; } bool cancel = false; foreach (string s in preventSelect) { if (entry.movable.Name.IndexOf(s) > -1) { cancel = true; break; } } if (cancel) { continue; } if (entry.distance < nearest) { nearest = entry.distance; nearestIndex = i; } } if (nearestIndex > -1) { RaySceneQueryResultEntry entry = results[nearestIndex]; selectSceneNode(entry.movable); } }
protected override void OnFrameStarted(object source, FrameEventArgs e) { frameCount++; int tick = Environment.TickCount; time += e.TimeSinceLastFrame; float moveTime = e.TimeSinceLastFrame; if (moveTime > 1) { moveTime = 1; } Axiom.SceneManagers.Multiverse.WorldManager.Instance.Time = time; if ((tick - lastTick) > 100) { Console.WriteLine("long frame: {0}", tick - lastTick); LogManager.Instance.Write("long frame: {0}", tick - lastTick); } lastTick = tick; // int hpg = gen.HeightPointsGenerated; // if ( lastHeightPointsGenerated != hpg ) // { // Console.WriteLine("HeightPointsGenerated: {0}", hpg - lastHeightPointsGenerated); // lastHeightPointsGenerated = hpg; // } float scaleMove = 20 * oneMeter * moveTime; // reset acceleration zero camAccel = Vector3.Zero; // set the scaling of camera motion cameraScale = 100 * moveTime; bool retry = true; //System.Threading.Thread.Sleep(3000); //while (retry) //{ // // TODO: Move this into an event queueing mechanism that is processed every frame // try // { // input.Capture(); // retry = false; // } // catch (Exception ex) // { // System.Threading.Thread.Sleep(1000); // } //} // TODO: Move this into an event queueing mechanism that is processed every frame bool realIsActive = window.IsActive; try { // force a reset of axiom's internal input state so that it will call Acquire() on the // input device again. if (captureFailed) { window.IsActive = false; input.Capture(); window.IsActive = realIsActive; } input.Capture(); captureFailed = false; } catch (Exception ex) { Console.WriteLine(ex.Message); captureFailed = true; System.Threading.Thread.Sleep(1000); } finally { window.IsActive = realIsActive; } if (input.IsKeyPressed(KeyCodes.Escape)) { Root.Instance.QueueEndRendering(); return; } if (input.IsKeyPressed(KeyCodes.A)) { camAccel.x = -0.5f; } if (input.IsKeyPressed(KeyCodes.D)) { camAccel.x = 0.5f; } if (input.IsKeyPressed(KeyCodes.W)) { camAccel.z = -1.0f; } if (input.IsKeyPressed(KeyCodes.S)) { camAccel.z = 1.0f; } if (!captureFailed) { camAccel.y += (float)(input.RelativeMouseZ * 0.1f); } if (input.IsKeyPressed(KeyCodes.Left)) { camera.Yaw(cameraScale); } if (input.IsKeyPressed(KeyCodes.Right)) { camera.Yaw(-cameraScale); } if (input.IsKeyPressed(KeyCodes.Up)) { camera.Pitch(cameraScale); } if (input.IsKeyPressed(KeyCodes.Down)) { camera.Pitch(-cameraScale); } // subtract the time since last frame to delay specific key presses toggleDelay -= e.TimeSinceLastFrame; // toggle rendering mode if (input.IsKeyPressed(KeyCodes.R) && toggleDelay < 0) { if (camera.SceneDetail == SceneDetailLevel.Points) { camera.SceneDetail = SceneDetailLevel.Solid; } else if (camera.SceneDetail == SceneDetailLevel.Solid) { camera.SceneDetail = SceneDetailLevel.Wireframe; } else { camera.SceneDetail = SceneDetailLevel.Points; } Console.WriteLine("Rendering mode changed to '{0}'.", camera.SceneDetail); toggleDelay = 1; } if (input.IsKeyPressed(KeyCodes.F) && toggleDelay < 0) { followTerrain = !followTerrain; toggleDelay = 1; } if (input.IsKeyPressed(KeyCodes.H) && toggleDelay < 0) { humanSpeed = !humanSpeed; toggleDelay = 1; } if (input.IsKeyPressed(KeyCodes.T) && toggleDelay < 0) { // toggle the texture settings switch (filtering) { case TextureFiltering.Bilinear: filtering = TextureFiltering.Trilinear; aniso = 1; break; case TextureFiltering.Trilinear: filtering = TextureFiltering.Anisotropic; aniso = 8; break; case TextureFiltering.Anisotropic: filtering = TextureFiltering.Bilinear; aniso = 1; break; } Console.WriteLine("Texture Filtering changed to '{0}'.", filtering); // set the new default MaterialManager.Instance.SetDefaultTextureFiltering(filtering); MaterialManager.Instance.DefaultAnisotropy = aniso; toggleDelay = 1; } if (input.IsKeyPressed(KeyCodes.P)) { string[] temp = Directory.GetFiles(Environment.CurrentDirectory, "screenshot*.jpg"); string fileName = string.Format("screenshot{0}.jpg", temp.Length + 1); // show briefly on the screen window.DebugText = string.Format("Wrote screenshot '{0}'.", fileName); TakeScreenshot(fileName); // show for 2 seconds debugTextDelay = 2.0f; } if (input.IsKeyPressed(KeyCodes.B)) { scene.ShowBoundingBoxes = !scene.ShowBoundingBoxes; } if (input.IsKeyPressed(KeyCodes.O)) { // hide all overlays, includes ones besides the debug overlay viewport.OverlaysEnabled = !viewport.OverlaysEnabled; } if (input.IsKeyPressed(KeyCodes.F1) && toggleDelay < 0) { Axiom.SceneManagers.Multiverse.WorldManager.Instance.DrawStitches = !Axiom.SceneManagers.Multiverse.WorldManager.Instance.DrawStitches; toggleDelay = 1; } if (input.IsKeyPressed(KeyCodes.F2) && toggleDelay < 0) { Axiom.SceneManagers.Multiverse.WorldManager.Instance.DrawTiles = !Axiom.SceneManagers.Multiverse.WorldManager.Instance.DrawTiles; toggleDelay = 1; } if (input.IsKeyPressed(KeyCodes.F3) && toggleDelay < 0) { Console.WriteLine("Camera Location: {0}, {1}, {2}", camera.Position.x.ToString("F3"), camera.Position.y.ToString("F3"), camera.Position.z.ToString("F3")); toggleDelay = 1; } if (input.IsKeyPressed(KeyCodes.F4) && toggleDelay < 0) { preview = !preview; if (preview) { // when in preview mode, move the camera up high and look at the ground camera.MoveRelative(new Vector3(0, 1000 * oneMeter, 0)); camera.LookAt(new Vector3(0, 0, 0)); followTerrain = false; } else { // when not in preview mode, hug the ground followTerrain = true; } SetupScene(); toggleDelay = 1; } if (input.IsKeyPressed(KeyCodes.F5) && toggleDelay < 0) { if (WorldManager.Instance.OceanWaveHeight >= 500) { WorldManager.Instance.OceanWaveHeight -= 500; } toggleDelay = 1; } if (input.IsKeyPressed(KeyCodes.F6) && toggleDelay < 0) { WorldManager.Instance.OceanWaveHeight += 500; toggleDelay = 1; } if (input.IsKeyPressed(KeyCodes.F7) && toggleDelay < 0) { NewRoad(); toggleDelay = 1; } if (input.IsKeyPressed(KeyCodes.F8) && toggleDelay < 0) { WorldManager.Instance.SeaLevel += 500; toggleDelay = 1; } if (input.IsKeyPressed(KeyCodes.F9) && toggleDelay < 0) { StreamWriter s = new StreamWriter("boundaries.xml"); XmlTextWriter w = new XmlTextWriter(s); //w.Formatting = Formatting.Indented; //w.Indentation = 2; //w.IndentChar = ' '; mvScene.ExportBoundaries(w); w.Close(); s.Close(); toggleDelay = 1; } if (input.IsKeyPressed(KeyCodes.F10) && toggleDelay < 0) { StreamReader s = new StreamReader("boundaries.xml"); XmlTextReader r = new XmlTextReader(s); mvScene.ImportBoundaries(r); r.Close(); s.Close(); toggleDelay = 1; } if (input.IsKeyPressed(KeyCodes.F11) && toggleDelay < 0) { StreamWriter s = new StreamWriter("terrain.xml"); gen.ToXML(s); s.Close(); toggleDelay = 1; } if (input.IsKeyPressed(KeyCodes.F12) && toggleDelay < 0) { StreamReader s = new StreamReader("terrain.xml"); gen.FromXML(s); s.Close(); SetupScene(); toggleDelay = 1; } if (input.IsKeyPressed(KeyCodes.I)) { //point camera north camera.Direction = Vector3.NegativeUnitZ; } if (input.IsKeyPressed(KeyCodes.K)) { //point camera south camera.Direction = Vector3.UnitZ; } if (input.IsKeyPressed(KeyCodes.J)) { //point camera west camera.Direction = Vector3.NegativeUnitX; } if (input.IsKeyPressed(KeyCodes.L)) { //point camera east camera.Direction = Vector3.UnitX; } if (!captureFailed) { if (!input.IsMousePressed(MouseButtons.Left)) { float cameraYaw = -input.RelativeMouseX * .13f; float cameraPitch = -input.RelativeMouseY * .13f; camera.Yaw(cameraYaw); camera.Pitch(cameraPitch); } else { cameraVector.x += input.RelativeMouseX * 0.13f; } } if (humanSpeed) { // in game running speed is 7m/sec //camVelocity = camAccel * 7 * oneMeter; camVelocity = camAccel * 32 * oneMeter; } else { camVelocity += (camAccel * scaleMove * camSpeed); } // Console.WriteLine("ScameMove: {0}", scaleMove.ToString("F3")); // Console.WriteLine("Camera Accel: {0}, {1}, {2}", camAccel.x.ToString("F3"), //camAccel.y.ToString("F3"), camAccel.z.ToString("F3")); // Console.WriteLine("Camera Velocity: {0}, {1}, {2}", camVelocity.x.ToString("F3"), //camVelocity.y.ToString("F3"), camVelocity.z.ToString("F3")); // move the camera based on the accumulated movement vector camera.MoveRelative(camVelocity * moveTime); // Now dampen the Velocity - only if user is not accelerating if (camAccel == Vector3.Zero) { float slowDown = 6 * moveTime; if (slowDown > 1) { slowDown = 1; } camVelocity *= (1 - slowDown); } if (followTerrain) { // adjust new camera position to be a fixed distance above the ground Axiom.Core.RaySceneQuery raySceneQuery = scene.CreateRayQuery(new Ray(camera.Position, Vector3.NegativeUnitY)); raySceneQuery.QueryMask = (ulong)Axiom.SceneManagers.Multiverse.RaySceneQueryType.Height; ArrayList results = raySceneQuery.Execute(); RaySceneQueryResultEntry result = (RaySceneQueryResultEntry)results[0]; camera.Position = new Vector3(camera.Position.x, result.worldFragment.SingleIntersection.y + (2f * oneMeter), camera.Position.z); } // update performance stats once per second if (statDelay < 0.0f && showDebugOverlay) { UpdateStats(); statDelay = 1.0f; } else { statDelay -= e.TimeSinceLastFrame; } // turn off debug text when delay ends if (debugTextDelay < 0.0f) { debugTextDelay = 0.0f; window.DebugText = ""; } else if (debugTextDelay > 0.0f) { debugTextDelay -= e.TimeSinceLastFrame; } }
private void _panel_MouseMove(object sender, MouseEventArgs e) { if (_oldMousePosition == null) { _oldMousePosition = new Point(e.X, e.Y); return; } Point point = new Point(e.X, e.Y); Engine.QueueForRenderDispatcher(() => { double deltaDirectionX = point.X - _oldMousePosition.X; double deltaDirectionY = point.Y - _oldMousePosition.Y; if (e.Button.HasFlag(MouseButtons.Right)) { ActiveScene.Context.ActiveWorld.Camera.pitch(new Radian((float)-deltaDirectionY / 200f).ValueDegrees); ActiveScene.Context.ActiveWorld.Camera.yaw(new Radian((float)-deltaDirectionX / 200f).ValueDegrees); } IEnumerable <SceneNode> selected = GetSelectedNode(); SceneNode selectedNode = null; if (selected != null) { selectedNode = selected.FirstOrDefault(); } if (_translateDragging != TransformDragging.NONE && ActiveScene.ActiveGizmoType == Misc.Runtime.GizmoType.TRANSLATE) { if (selectedNode != null) { Plane plane = new Plane(); if (_translateDragging == TransformDragging.X) { Vector3 normal = Vector3.UNIT_Y; plane = new Plane(normal, selectedNode.Position); } else if (_translateDragging == TransformDragging.Y) { Vector3 normal = (Engine.Renderer.Camera.Position - selectedNode.Position).NormalisedCopy; normal.y = 0; plane = new Plane(normal, selectedNode.Position); } else if (_translateDragging == TransformDragging.Z) { Vector3 normal = Vector3.UNIT_Y; plane = new Plane(normal, selectedNode.Position); } Vector3 translateVector; if (GetRaySceneLocationWithPlane(point.X, point.Y, plane, out translateVector, selectedNode)) { PositionedInstance instance = Engine.SceneNodeStore.GetInstance(selectedNode); SizedInstance sized = instance as SizedInstance; if (sized != null) { translateVector -= _translateDragDifference; if (_translateDragging == TransformDragging.X) { instance.position.x = (float)System.Math.Round(translateVector.x - (sized.size.x / 2)); //PhysicsEngine.GetCollisionVectorResolvement(instance as PhysicsInstance); } else if (_translateDragging == TransformDragging.Y) { instance.position.y = (float)System.Math.Round(translateVector.y - (sized.size.y / 2)); //PhysicsEngine.GetCollisionVectorResolvement(instance as PhysicsInstance); } else if (_translateDragging == TransformDragging.Z) { instance.position.z = (float)System.Math.Round(translateVector.z - (sized.size.z / 2)); //PhysicsEngine.GetCollisionVectorResolvement(instance as PhysicsInstance); } } } } } else if (_scaleDragging != DirectionalTransformDragging.NONE && ActiveScene.ActiveGizmoType == Misc.Runtime.GizmoType.SCALE) { if (selectedNode != null) { Plane plane = new Plane(); if (_scaleDragging == DirectionalTransformDragging.XA || _scaleDragging == DirectionalTransformDragging.XB) { Vector3 normal = Vector3.UNIT_Y; plane = new Plane(normal, selectedNode.Position); } else if (_scaleDragging == DirectionalTransformDragging.YA || _scaleDragging == DirectionalTransformDragging.YB) { Vector3 normal = (Engine.Renderer.Camera.Position - selectedNode.Position).NormalisedCopy; normal.y = 0; plane = new Plane(normal, selectedNode.Position); } else if (_scaleDragging == DirectionalTransformDragging.ZA || _scaleDragging == DirectionalTransformDragging.ZB) { Vector3 normal = Vector3.UNIT_Y; plane = new Plane(normal, selectedNode.Position); } Vector3 scaleVector; if (GetRaySceneLocationWithPlane(point.X, point.Y, plane, out scaleVector, selectedNode)) { PositionedInstance instance = Engine.SceneNodeStore.GetInstance(selectedNode); SizedInstance sized = instance as SizedInstance; if (sized != null) { int magicOffsetA = 2; if (_scaleDragging == DirectionalTransformDragging.XA) { sized.size.x = System.Math.Max(1, (float)System.Math.Round(scaleVector.x - (sized.position.x) - magicOffsetA)); } else if (_scaleDragging == DirectionalTransformDragging.YA) { sized.size.y = System.Math.Max(1, (float)System.Math.Round(scaleVector.y - (sized.position.y) - magicOffsetA)); } else if (_scaleDragging == DirectionalTransformDragging.ZA) { sized.size.z = System.Math.Max(1, (float)System.Math.Round(scaleVector.z - (sized.position.z) - magicOffsetA)); } else if (_scaleDragging == DirectionalTransformDragging.XB) { //TODO: fix float newX = scaleVector.x + (sized.size.x / 2) + _scaleDragDifference.x; //wtf? float delta = (sized.position.x - newX); float rounded = (float)System.Math.Round(delta); sized.position.x -= rounded; sized.size.x += rounded; } else if (_scaleDragging == DirectionalTransformDragging.YB) { } else if (_scaleDragging == DirectionalTransformDragging.ZB) { } } } } } Cursor cursor = null; if (_translateFreeDragging && _scaleDragging == DirectionalTransformDragging.NONE && _translateDragging == TransformDragging.NONE) { if (selectedNode != null) { Plane plane = new Plane(Vector3.UNIT_Y, Engine.Renderer.Camera.Position.y - 16); Vector3 vector; if (GetRaySceneLocationWithPlane(point.X, point.Y, plane, out vector, selectedNode)) { PositionedInstance instance = Engine.SceneNodeStore.GetInstance(selectedNode); SizedInstance sized = instance as SizedInstance; if (sized != null) { instance.position.x = (float)System.Math.Round(vector.x - (sized.size.x / 2)); instance.position.y = (float)System.Math.Round(vector.y - (sized.size.y / 2)); instance.position.z = (float)System.Math.Round(vector.z - (sized.size.z / 2)); } } cursor = Cursors.NoMove2D; } else { _translateFreeDragging = false; } } Ray ray; RaySceneQueryResult.Enumerator itr = GetRaySceneQuery(point.X, point.Y, out ray); if (itr != null) { bool nothing = true; while (itr.MoveNext()) { RaySceneQueryResultEntry entry = itr.Current; if (entry.movable.QueryFlags != (uint)QueryFlags.IGNORE_ALL) { nothing = false; } if (entry.movable.QueryFlags == (uint)QueryFlags.INSTANCE_ENTITY) { SceneNode parentNode = entry.movable.ParentSceneNode; if (selectedNode != null && selectedNode.Equals(parentNode) && e.Button.HasFlag(MouseButtons.Left) && _translateDragging == TransformDragging.NONE) { if (System.Math.Abs(deltaDirectionX) >= TRANSLATE_DRAG_THRESHOLD || System.Math.Abs(deltaDirectionY) >= TRANSLATE_DRAG_THRESHOLD) { _translateFreeDragging = true; } } if (!IsAlreadyHovered(parentNode)) { IEnumerable <SceneNode> hovered = GetHoveredNodes(); if (hovered != null) { foreach (SceneNode node in hovered) { if (!IsSelectedNode(node)) { PositionedInstance oldInstance = Engine.SceneNodeStore.GetInstance(node); if (oldInstance != null) { SizedInstance oldSized = oldInstance as SizedInstance; if (oldSized != null) { oldSized.IsBoundingBoxEnabled = false; } } } } ClearHovered(); } AddToHoverNode(parentNode); } break; } } if (nothing) { if (cursor == null) { cursor = Cursors.Default; } IEnumerable <SceneNode> hovered = GetHoveredNodes(); if (hovered != null) { foreach (SceneNode node in hovered) { if (!IsSelectedNode(node)) { PositionedInstance oldInstance = Engine.SceneNodeStore.GetInstance(node); if (oldInstance != null) { SizedInstance oldSized = oldInstance as SizedInstance; if (oldSized != null) { oldSized.IsBoundingBoxEnabled = false; } } } } ClearHovered(); } } else { if (cursor == null) { cursor = Cursors.Hand; } } } if (cursor != null) { System.Windows.Application.Current.Dispatcher.InvokeAsync(() => _panel.Cursor = cursor, DispatcherPriority.Background); } _oldMousePosition = point; }); }
private static bool GetRaySceneLocationWithPlane(double x, double y, Plane plane, out Vector3 vector, SceneNode ignore) { float width = Engine.Renderer.Camera.Viewport.ActualWidth; float height = Engine.Renderer.Camera.Viewport.ActualHeight; Ray mouseRay = Engine.Renderer.Camera.GetCameraToViewportRay((float)((x - 1) / width), (float)((y - 1) / height)); Plane inverse = new Plane(-plane.normal, -plane.d); Pair <bool, float> d0 = mouseRay.Intersects(plane); Pair <bool, float> d1 = mouseRay.Intersects(inverse); RaySceneQuery mRaySceneQuery = Engine.Renderer.Scene.CreateRayQuery(mouseRay); mRaySceneQuery.SetSortByDistance(true, 16); mRaySceneQuery.QueryMask = (uint)QueryFlags.INSTANCE_ENTITY; mRaySceneQuery.QueryTypeMask = SceneManager.ENTITY_TYPE_MASK | SceneManager.STATICGEOMETRY_TYPE_MASK | SceneManager.USER_TYPE_MASK_LIMIT | SceneManager.FRUSTUM_TYPE_MASK | SceneManager.FX_TYPE_MASK | SceneManager.LIGHT_TYPE_MASK | SceneManager.WORLD_GEOMETRY_TYPE_MASK; RaySceneQueryResult result = mRaySceneQuery.Execute(); RaySceneQueryResult.Enumerator itr = (RaySceneQueryResult.Enumerator)(result.GetEnumerator()); if (itr != null) { RaySceneQueryResultEntry entry = null; while (itr.MoveNext()) { entry = itr.Current; if (entry != null && !entry.movable.ParentSceneNode.Equals(ignore)) { vector = mouseRay.GetPoint(entry.distance); return(true); } } if (d0.first) { Vector3 planePoint = mouseRay.GetPoint(d0.second); if ((Engine.Renderer.Camera.Position - planePoint).Length < MAX_TRANSLATE_DRAG_DISTANCE) { vector = planePoint; return(true); } } if (d1.first) { Vector3 planePoint = mouseRay.GetPoint(d1.second); if ((Engine.Renderer.Camera.Position - planePoint).Length < MAX_TRANSLATE_DRAG_DISTANCE) { vector = planePoint; return(true); } else { vector = Vector3.ZERO; return(false); } } else { vector = Vector3.ZERO; return(false); } } else { vector = Vector3.ZERO; return(false); } }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(RaySceneQueryResultEntry obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }