Ejemplo n.º 1
0
 public bool GetCollisionPoint(Line3D ray, TriangleSelector selector, out Vector3D collisionPoint, out Triangle3D collisionTriangle)
 {
     float[] colp = new float[3];
     float[] coltri = new float[9];
     bool toR = SceneCollisionManager_GetCollisionPoint(_raw, ray.ToUnmanaged(), selector.Raw, colp, coltri);
     collisionPoint = Vector3D.FromUnmanaged(colp);
     collisionTriangle = Triangle3D.FromUnmanaged(coltri);
     return toR;
 }
Ejemplo n.º 2
0
        public override bool OnMouseEvent(Event p_event)
        {
            if (p_event.MouseInputEvent == MouseInputEvent.MouseWheel)
            {
                CameraController.MouseWheelAction(p_event.MouseWheelDelta);
            }
            if (p_event.MouseInputEvent == MouseInputEvent.LMouseLeftUp)
            {
                if (m_ctrlPressed)
                {
                    CameraController.ApplyMouseOffsets();
                }
                m_leftMousePressed = false;
            }
            if (p_event.MouseInputEvent == MouseInputEvent.LMousePressedDown)
            {

                m_leftMousePressed = true;
                if (m_ctrlPressed)
                {
                    CameraController.SwitchMode(ECameraMode.Build);
                    // Pick!

                    CameraController.ResetMouseOffsets();
                    Vector3D[] projection = CameraController.ProjectRayPoints(p_event.MousePosition, WindowWidth/2, WindowHeight/2, WindowAspect);
                    Line3D projectedray = new Line3D(projection[0], projection[1]);

                    Vector3D collisionpoint = new Vector3D(0, 0, 0);
                    Triangle3D tri = new Triangle3D(0, 0, 0, 0, 0, 0, 0, 0, 0);

                    // Check if we have a node under the mouse
                    SceneNode node = SceneGraph.TrianglePicker.GetSceneNodeFromRay(projectedray, 0x0128, true, CameraController.CameraNode.Position); //smgr.CollisionManager.GetSceneNodeFromScreenCoordinates(new Position2D(p_event.MousePosition.X, p_event.MousePosition.Y), 0, false);
                    if (node == null)
                    {
                        if (SceneGraph.TriangleSelector != null)
                        {
                            // Collide test against the terrain
                            if (Renderer.SceneManager.CollisionManager.GetCollisionPoint(projectedray, SceneGraph.TriangleSelector, out collisionpoint, out tri))
                            {
                                if (CameraController.CameraMode == ECameraMode.Build)
                                {
                                    CameraController.SetTarget(collisionpoint);
                                    CameraController.TargetNode = null;
                                }
                            }
                        }
                    }
                    else
                    {
                        // Sometimes the terrain picker returns weird values.
                        // If it's weird try the general 'everything' triangle picker.
                        m_log.WarnFormat("[PICK]: Picked <{0},{1},{2}>", node.Position.X, node.Position.Y, node.Position.Z);
                        if (node.Position.X == 0 && node.Position.Z == 0)
                        {
                            if (SceneGraph.TriangleSelector != null)
                            {
                                if (Renderer.SceneManager.CollisionManager.GetCollisionPoint(projectedray, SceneGraph.TriangleSelector, out collisionpoint, out tri))
                                {
                                    if (CameraController.CameraMode == ECameraMode.Build)
                                    {
                                        CameraController.SetTarget(collisionpoint);
                                        CameraController.TargetNode = null;
                                    }
                                }
                            }
                        }
                        else
                        {
                            // Target the node
                            if (CameraController.CameraMode == ECameraMode.Build)
                            {
                                CameraController.SetTarget(node.Position);
                                CameraController.TargetNode = node;
                            }
                        }
                    }
                }
            }
            if (p_event.MouseInputEvent == MouseInputEvent.RMouseLeftUp)
            {
                m_rightMousePressed = false;
            }
            if (p_event.MouseInputEvent == MouseInputEvent.RMousePressedDown)
            {
                m_rightMousePressed = true;
            }

            if (p_event.MouseInputEvent == MouseInputEvent.MouseMoved)
            {
                if (m_leftMousePressed && m_ctrlPressed)
                {
                    int deltaX = p_event.MousePosition.X - m_oldMouseX;
                    int deltaY = p_event.MousePosition.Y - m_oldMouseY;

                    CameraController.SetDeltaFromMouse(deltaX, deltaY);
                }

                if (m_rightMousePressed)
                {

                    int deltaX = p_event.MousePosition.X - m_oldMouseX;
                    int deltaY = p_event.MousePosition.Y - m_oldMouseY;

                    CameraController.SetRotationDelta(deltaX, deltaY);
                }

                m_oldMouseX = p_event.MousePosition.X;
                m_oldMouseY = p_event.MousePosition.Y;
            }
            return false;
        }
Ejemplo n.º 3
0
 public void Draw3DLine(Line3D line, Color color)
 {
     Draw3DLine(line.Start, line.End, color);
 }
Ejemplo n.º 4
0
        // Picker
        private void DetectObjectUnderMouse()
        {
            if (Reference.SceneManager != null
                && Reference.Device != null
                && Reference.SceneManager.CollisionManager != null)
            {
                SceneNode irrNodeUnderMouse =
                    Reference.SceneManager.CollisionManager.GetSceneNodeFromScreenCoordinates
                        (Reference.Device.CursorControl.Position,
                        0,
                        false);
                if (irrNodeUnderMouse == null)
                {
                    objectUnderMouse = null;
                }
                else
                {
                    Reference.Viewer.Camera.ResetMouseOffsets();
                    projectedray = Reference.SceneManager.CollisionManager.GetRayFromScreenCoordinates
                         (Reference.Device.CursorControl.Position + Reference.Viewer.CursolOffset,
                         Reference.Viewer.Camera.SNCamera);
                    irrNodeUnderMouse =
                        trianglePickerMapper.GetSceneNodeFromRay(projectedray, 0x0128, true, Reference.Viewer.Camera.SNCamera.Position);

                    bool foundRegionPrimCorrespondingToIrrNodeId = false;
                    VObject vobj = null;
                    if (irrNodeUnderMouse != null
                        && irrNodeUnderMouse.ID != -1)
                    {
                        lock (entities)
                        {
                            foreach (string vobjkey in entities.Keys)
                            {
                                vobj = entities[vobjkey];
                                if (vobj != null
                                    && vobj.Node != null
                                    && vobj.Node.ID == irrNodeUnderMouse.ID)
                                {
                                    objectUnderMouse = vobj;

                                    if (vobj.Prim != null)
                                    {
                                        string firstName = string.Empty;;
                                        string lastName = string.Empty;
                                        if (vobj.Prim.NameValues.Length > 1)
                                        {
                                            firstName = (string)vobj.Prim.NameValues[0].Value;
                                            lastName = (string)vobj.Prim.NameValues[1].Value;
                                        }

                                        StringBuilder sb = new StringBuilder();
                                        sb.Append("{");
                                        sb.Append("\"UUID\":" + "\"" + vobj.Prim.ID.ToString() + "\"");
                                        sb.Append(",");
                                        sb.Append("\"NAME\":");
                                        sb.Append("{");
                                        sb.Append("\"FIRST\":" + "\"" + firstName + "\"");
                                        sb.Append(",");
                                        sb.Append("\"LAST\":" + "\"" + lastName + "\"");
                                        sb.Append("}");
                                        sb.Append("}");
                                        Reference.Viewer.Adapter.CallAvatarPicked(sb.ToString());
                                    }

                                    string text = "AVATAR pick target found!: " + vobj.Prim.ID.ToString() + " " + this.ToString() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name;
                                    Reference.Log.Debug(text);

                                    foundRegionPrimCorrespondingToIrrNodeId = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (!foundRegionPrimCorrespondingToIrrNodeId)
                    {
                        objectUnderMouse = null;
                    }
                }
            }
        }
Ejemplo n.º 5
0
		/// <summary>
		/// Checks an intersection with some line
		/// </summary>
		/// <param name="LineToCol">
		/// A line to be checked <see cref="Line3D"/>
		/// </param>
		/// <returns>
		/// A result of the collision <see cref="System.Boolean"/>
		/// </returns>
		public bool IntersectsWithLimitedLine (Line3D lineToCol)
		{
			
			Vector3D lineVector = lineToCol.Vector.Normalize();
			float halfLength = (float)(lineToCol.Length * 0.5);
			Vector3D t = Center - lineToCol.Middle;
			Vector3D e = (MaxEdge - MinEdge); e = e * (float)(0.5);

			if ((Math.Abs(t.X)> e.X+halfLength*Math.Abs(lineVector.X)) ||
			    (Math.Abs(t.Y)> e.Y+halfLength*Math.Abs(lineVector.Y)) ||
			    (Math.Abs(t.Z)> e.Z+halfLength*Math.Abs(lineVector.Z)))
				return false;

			float r = e.Y * (float)Math.Abs(lineVector.Z) + e.Z * Math.Abs(lineVector.Y);
			if (Math.Abs(t.Y * lineVector.Z - t.Z * lineVector.Y) > r)
				return false;

			r = e.X * (float)Math.Abs(lineVector.Z) + e.Z * Math.Abs(lineVector.X);
			if (Math.Abs(t.Z * lineVector.X - t.X * lineVector.Z) > r)
				return false;

			r = e.X * (float)Math.Abs(lineVector.Y) + e.Y * Math.Abs(lineVector.X);
			if (Math.Abs(t.X * lineVector.Y - t.Y * lineVector.X) > r)
				return false;

			return true; 
			
		}
Ejemplo n.º 6
0
 /// <summary>
 /// Returns an intersection with a 3d line.
 /// </summary>
 /// <param name="line">Line to intersect with.</param>
 /// <param name="outIntersection">Place to store the intersection point, if there is one.</param>
 /// <returns>Returns true if there was an intersection, false if there was not.</returns>
 public bool GetIntersectionWithLimitedLine(Line3D line, out Vector3D outIntersection)
 {
     return GetIntersectionWithLine(line.Start,line.Vector, out outIntersection) &&
            outIntersection.IsBetweenPoints(line.Start, line.End);
 }
Ejemplo n.º 7
0
 public bool nlinTestSel(Line3D line, SceneManager smgr, ref Triangle3D tri)
 {
     lock (trilist)
     {
         foreach (TriangleSelector selector in trilist)
         {
             Vector3D intersection;
             if (smgr.CollisionManager.GetCollisionPoint(
                 line, selector, out intersection, out tri))
             {
                 return true;
             }
         }
     }
     return false;
 }
Ejemplo n.º 8
0
        public SceneNode GetSceneNodeFromRay(Line3D ray, int bitMask, bool noDebug, Vector3D campos)
        {
            SceneNode returnobj = null;
            Vector3D collisionpoint = new Vector3D(0, 0, 0);
            Triangle3D tri = new Triangle3D(0, 0, 0, 0, 0, 0, 0, 0, 0);
            Vector3D closestpoint = new Vector3D(999, 999, 9999);
            List<TriangleSelector> removeList = new List<TriangleSelector>();
            lock (trilist)
            {
                foreach (TriangleSelector trisel in trilist)
                {
                    if (trisel == null)
                    {
                        removeList.Add(trisel);
                        continue;
                    }
                    if (trisel.Raw == IntPtr.Zero)
                    {
                        removeList.Add(trisel);
                        continue;
                    }
                    try
                    {
                        if (scm.GetCollisionPoint(ray, trisel, out collisionpoint, out tri))
                        {
                            if (campos.DistanceFrom(collisionpoint) < campos.DistanceFrom(closestpoint))
                            {
                                closestpoint = collisionpoint;

                                if (triLookup.ContainsKey(trisel.Raw))
                                {
                                    SceneNode sreturnobj = triLookup[trisel.Raw];
                                    if (!(sreturnobj is TerrainSceneNode))
                                        returnobj = sreturnobj;
                                }

                            }

                        }
                    }
                    catch (AccessViolationException)
                    {
                        VUtil.LogConsole(this.ToString() + "[ACCESSVIOLATION]", "TrianglePickerMapper::GetSceneNodeFromRay");
                        removeList.Add(trisel);
                        continue;
                    }
                    catch (System.Runtime.InteropServices.SEHException)
                    {
                        removeList.Add(trisel);
                        continue;
                    }
                }
                foreach (TriangleSelector trisel2 in removeList)
                {
                    trilist.Remove(trisel2);
                }

            }
            return returnobj;
        }
Ejemplo n.º 9
0
 public static Line3D From(float xMin, float yMin, float zMin, float xMax, float yMax, float zMax)
 {
     Line3D line = new Line3D();
     line.Start = new Vector3D();
     line.End = new Vector3D();
     line.Start.Set(xMin, yMin, zMin);
     line.End.Set(xMax, yMax, zMax);
     return line;
 }
Ejemplo n.º 10
0
 public SceneNode GetSceneNodeFromRay(Line3D ray)
 {
     return GetSceneNodeFromRay(ray, 0, false);
 }
Ejemplo n.º 11
0
 public SceneNode GetSceneNodeFromRay(Line3D ray, int bitMask, bool noDebug)
 {
     return  (SceneNode)
         NativeElement.GetObject(SceneCollisionManager_GetSceneNodeFromRayBB(_raw, ray.ToUnmanaged(), bitMask, noDebug),
                                 typeof(SceneNode));
 }