Exemple #1
0
        public override void Collision()
        {
            if (node == null)
                return;

            if (Render.Scene.ActiveCamera == null)
                return;

            Vector3D intersection = new Vector3D();
            Triangle3D triangle = new Triangle3D();

            Position2D mouse = new Position2D((int)Ox.DataStore.Input.Position[0], (int)Ox.DataStore.Input.Position[1]);
            Line3D line = Render.Scene.CollisionManager.GetRayFromScreenCoordinates(mouse, Render.Scene.ActiveCamera);

            bool hit = Render.Scene.CollisionManager.GetCollisionPoint(
                        line,
                        node.TriangleSelector,
                        out intersection,
                        out triangle
                        );

            if (hit)
            {
                float[] point = Util.ToPositionArrayFromIrrlicht(ref intersection);
                float length = (float)intersection.DistanceFrom(line.Start);
                PointData.HitData data = new PointData.HitData(point[0], point[1], point[2], PointData.ObjectType.Ground, ClickActionType.None, length, string.Empty);
                Ox.DataStore.World.Point.Add(ref data);
            }
        }
Exemple #2
0
        public override void Collision()
        {
            if (Render.Scene.ActiveCamera == null)
                return;

            Position2D mouse = new Position2D((int)Ox.DataStore.Input.Position[0], (int)Ox.DataStore.Input.Position[1]);
            Line3D line = Render.Scene.CollisionManager.GetRayFromScreenCoordinates(mouse, Render.Scene.ActiveCamera);

            foreach (string key in list.Keys)
            {
                if (list[key].Node == null)
                    continue;

                AnimatedMeshSceneNode node = list[key].Node;

                Box3D box;
                Util.CreateBox3DFromNode(node, out box);

                // Check inside bounding box
                if (box.IntersectsWithLimitedLine(line))
                {
                    Vector3D intersection = new Vector3D();
                    Triangle3D triangle = new Triangle3D();

                    Mesh mesh = node.AnimatedMesh.GetMesh(node.CurrentFrame);
                    TriangleSelector ts = Render.Scene.CreateTriangleSelector(mesh, node);

                    bool hit = Render.Scene.CollisionManager.GetCollisionPoint(
                                line,
                                ts,
                                out intersection,
                                out triangle
                                );

                    if (!hit)
                        continue;

                    ObjectData data;
                    if (!Ox.DataStore.World.SimCollection.TryGetObject(key, out data))
                        continue;

                    if (!(data is AvatarData))
                        continue;

                    AvatarData avatarData = data as AvatarData;
                    float[] point = Util.ToPositionArrayFromIrrlicht(ref intersection);
                    float length = (float)intersection.DistanceFrom(line.Start);
                    PointData.HitData hitData = new PointData.HitData(
                        point[0], point[1], point[2],
                        (avatarData.Myself ? PointData.ObjectType.AvatarSelf  : PointData.ObjectType.Avatar),
                        ClickActionType.None,
                        length,
                        key
                        );
                    Ox.DataStore.World.Point.Add(ref hitData);
                }
            }
        }
 public Vector3D GetCollisionResultPoint(TriangleSelector selector, Vector3D ellipsoidPosition, Vector3D ellipsoidRadius, Vector3D ellipsoidDirectionAndSpeed, out Triangle3D outTriangle, out bool outFalling, float slidingSpeed, Vector3D gravityDirectionAndSpeed)
 {
     float[] outtri = new float[9];
     float[] outpos = new float[3];
     outFalling = false;
     SceneCollisionManager_GetCollisionResultPoint(_raw, selector.Raw, ellipsoidPosition.ToUnmanaged(), ellipsoidRadius.ToUnmanaged(), ellipsoidDirectionAndSpeed.ToUnmanaged(), outtri, ref outFalling, slidingSpeed, gravityDirectionAndSpeed.ToUnmanaged(), outpos);
     outTriangle = Triangle3D.FromUnmanaged(outtri);
     return Vector3D.FromUnmanaged(outpos);
 }
 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;
 }
Exemple #5
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;
        }
Exemple #6
0
 public void Draw3DTriangle(Triangle3D tri, Color col)
 {
     VideoDriver_Draw3DTriangle(_raw, tri.ToUnmanaged(), col.ToUnmanaged());
 }
        private void UserAvatarMoveMouse(Position2D _position)
        {
            if (Reference.Viewer.GuiManager.Focused)
            {
                Reference.Viewer.ProtocolManager.AvatarConnection.Forward = false;
                return;
            }

            // Get target position from mouse cursor position.
            Vector3D targetPosition = new Vector3D();
            Triangle3D triangle = new Triangle3D();
            bool find = FindPositionFromMousePosition(_position, out targetPosition, out triangle);
            if (find == false)
            {
                return;
            }

            targetPosition.Y = 0;

            // Get user avatar position.
            Vector3D userPosition = m_userPosition; //userObject.Node.Position;
            userPosition.Y = 0;

            bool isRunLenght = false;

            // Create target vector.
            Vector3D targetVec = targetPosition - userPosition;
            if (targetVec.LengthSQ < (ignoreMoveArea * ignoreMoveArea))
            {
                return;
            }
            else
            {
                if (targetVec.LengthSQ > (runLength * runLength))
                    isRunLenght = true;

                targetVec.Normalize();
            }

            Vector3D baseVector = new Vector3D(0, 0, -1);
            Vector3D verticalVector = baseVector.CrossProduct(targetVec);

            bool flipVector = verticalVector.Y > 0;
            if (flipVector == false)
            {
                baseVector = new Vector3D(0, 0, 1);
            }

            radHeading = baseVector.DotProduct(targetVec) * div2pi;
            radHeadingSmoothReset = true;

            if (flipVector)
            {
                radHeading += pi;
            }

            UserAvatarRotation(0);

            Reference.Viewer.ProtocolManager.AvatarConnection.Forward = true;
            Reference.Viewer.ProtocolManager.AvatarConnection.Run = isRunLenght;
        }
        private bool FindPositionFromMousePosition(Position2D _mousePosition, out Vector3D _targetPosition, out Triangle3D _triangle)
        {
            Vector3D intersection = new Vector3D();
            Triangle3D triangle = new Triangle3D();
            bool find = false;

            Line3D line = Reference.SceneManager.CollisionManager.GetRayFromScreenCoordinates(_mousePosition, Reference.SceneManager.ActiveCamera);

            if (pickSceneNode != null)
            {
                find = Reference.SceneManager.CollisionManager.GetCollisionPoint(
                            line,
                            pickSceneNode.TriangleSelector,
                            out intersection,
                            out triangle
                            );
            }

            _targetPosition = intersection;
            _triangle = triangle;

            return find;
        }
 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;
 }
        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;
        }