Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
0
Archivo: Prim.cs Proyecto: yooyke/work
        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)
            {
                SceneNode node = list[key];

                if (node.TriangleSelector == null) // <-- 3dimesh
                    continue;

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

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

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

                    if (!hit)
                        continue;

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

                    if (!(data is PrimData))
                        continue;

                    PrimData primData = data as PrimData;
                    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], PointData.ObjectType.Prim, primData.ClickActionType, length, key);
                    Ox.DataStore.World.Point.Add(ref hitData);
                }
            }
        }
Ejemplo n.º 3
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;
        }