Esempio n. 1
0
        public static float GetDistanceTo(PhysicsVector a, PhysicsVector b)
        {
            float dx = a.X - b.X;
            float dy = a.Y - b.Y;
            float dz = a.Z - b.Z;

            return((float)Math.Sqrt(dx * dx + dy * dy + dz * dz));
        }
Esempio n. 2
0
        public virtual bool IsIdentical(PhysicsVector v, float tolerance)
        {
            PhysicsVector diff = this - v;
            float         d    = diff.length();

            if (d <= tolerance)
            {
                return(true);
            }

            return(false);
        }
Esempio n. 3
0
        public static bool isFinite(PhysicsVector v)
        {
            if (v == null)
            {
                return(false);
            }
            if (Single.IsInfinity(v.X) || Single.IsNaN(v.X))
            {
                return(false);
            }
            if (Single.IsInfinity(v.Y) || Single.IsNaN(v.Y))
            {
                return(false);
            }
            if (Single.IsInfinity(v.Z) || Single.IsNaN(v.Z))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 4
0
 public void AddPos(PhysicsVector Position)
 {
     foreach (Vertex t in vertices)
     {
         t.AddPos(Position);
     }
 }
Esempio n. 5
0
        public virtual bool IsIdentical(PhysicsVector v, float tolerance)
        {
            PhysicsVector diff = this - v;
            float d = diff.length();
            if (d <= tolerance)
                return true;

            return false;
        }
Esempio n. 6
0
        public static bool isFinite(PhysicsVector v)
        {
            if (v == null)
                return false;
            if (Single.IsInfinity(v.X) || Single.IsNaN(v.X))
                return false;
            if (Single.IsInfinity(v.Y) || Single.IsNaN(v.Y))
                return false;
            if (Single.IsInfinity(v.Z) || Single.IsNaN(v.Z))
                return false;

            return true;
        }
Esempio n. 7
0
 public static float GetDistanceTo(PhysicsVector a, PhysicsVector b)
 {
     float dx = a.X - b.X;
     float dy = a.Y - b.Y;
     float dz = a.Z - b.Z;
     return (float) Math.Sqrt(dx * dx + dy * dy + dz * dz);
 }
Esempio n. 8
0
 public static PhysicsVector cross(PhysicsVector a, PhysicsVector b)
 {
     return new PhysicsVector(a.Y*b.Z - a.Z*b.Y, a.Z*b.X - a.X*b.Z, a.X*b.Y - a.Y*b.X);
 }
Esempio n. 9
0
        public override sealed bool Update(SimPosition simObject)
        {
            //if (!WorldObjects.MaintainCollisions) return false;
            if (!simObject.IsRegionAttached) return false;
            if (MeshOnlySolids && !((MeshableObject) simObject).IsSolid) return false;
            Quaternion Rotation = simObject.SimRotation;
            Vector3 Scale = Prim.Scale; //.GetSimScale();
            Vector3 Position = simObject.SimPosition;

#if COLLIDER_ODE  
            LastSize = new PhysicsVector(1, 1, 1); // we scaled the PrimMesh already!
            LastRotation = Quaternion.Identity;  // we rotated the PrimMesh already!
            LastPosition = ToPhysicsVector(Position); // we hadn't done position though
#endif
            //pbs.

            //List<Mesh> MeshList = new List<Mesh>();

            //PrimMesh primMesh;

            //if (false)
            //{

            //    // Add Low PrimMesh (IdealistViewer code)
            //    primMesh = PrimitiveToPrimMesh(simObject.thePrim, LevelOfDetail.Low, Scale, Rotation);
            //    AddMesh(primMesh);

            //}

            // Add High PrimMesh (IdealistViewer code)

            Mesh mesh = PrimitiveToMesh(Prim, Scale, Rotation);

#if COLLIDER_ODE  
            this.mesh = mesh;
            if (!RootObject.IsPhantom)
                physicsActor = GetPhysicsActor();
#endif
            //MeshList.Add(mesh);


            //if (false)
            //{
            //    // Add based on PrimitiveBaseShape (OpenSim Meshmerizer code)
            //    PrimitiveBaseShape primShape = PrimToBaseShape(simObject.thePrim);
            //    Mesh mesh = CreateMesh(simObject.ToString(), primShape,
            //        new PhysicsVector(Scale.X, Scale.Y, Scale.Z), 32f, Object.IsPhysical, QuaternionToQuat(Rotation)); // why 32?
            //    AddMesh(mesh);

            //    // i am going to see if i can make simple bounding mox meshes for unhollow cubes
            //    if (primShape.ProfileShape == ProfileShape.Square && primShape.HollowShape == HollowShape.Same)
            //    {
            //        Mesh extramesh = Meshmerizer.CreateBoundingBoxMesh(mesh);
            //        AddMesh(extramesh);
            //    }
            //}
            if (InnerBoxes == null) InnerBoxes = new List<Box3Fill>();
            else
            InnerBoxes.Clear();
            OuterBox.Reset();
            CalcBoxesFromMeshes(mesh, InnerBoxes);
            bool verySmall = OuterBox.EdgeSize < WorldPathSystem.MinEdgeSizeOfSimplify;
            if (verySmall)
            {
                int b = InnerBoxes.Count;
                InnerBoxes.Clear();
                AddPos(Position);
                InnerBoxes.Add(OuterBox);
                DLRConsole.DebugWriteLine("Simplfy EdgeSize {0} -> 1 ", b,
                          InnerBoxes.Count + " " + OuterBox.EdgeSize + " " + this.GetObjectName());
            }
            else
            {
                if (SimplifyBoxes)
                {
                    int b = InnerBoxes.Count;
                    InnerBoxes = Box3Fill.Simplify((List<Box3Fill>)InnerBoxes);
                    if (DebugMesh) if (b > 2000 || InnerBoxes.Count * 4 < b)
                        DLRConsole.DebugWriteLine("Simplfy mesh {0} -> {1} ", b,
                                                  InnerBoxes.Count + " " + OuterBox.Mass + " " + this.GetObjectName());
                }
                AddPos(Position);
            }
#if COLLIDER_TRIANGLE
            triangles = mesh.triangles;
#endif
            return true;
        }
Esempio n. 10
0
 public static PhysicsVector cross(PhysicsVector a, PhysicsVector b)
 {
     return(new PhysicsVector(a.Y * b.Z - a.Z * b.Y, a.Z * b.X - a.X * b.Z, a.X * b.Y - a.Y * b.X));
 }
Esempio n. 11
0
        //public class FallingPrim
        //{
             //public bool DoneMoving = false;
             //public uint localId;

            public void FallingPrim(OdeScene ps, CollisionPlane Plane, PhysicsVector position, int x, int y, float offsetZ)
            {
                uint localId = Plane.fallingPrims;
                PrimitiveBaseShape newcube = PrimitiveBaseShape.CreateBox();
                OdePrim oprim = (OdePrim)ps.AddPrimShape("FallingPrim_" + localId, newcube, position, new PhysicsVector(0.1f, 0.1f, 2f), Quaternion.Identity, true);
                oprim.LocalID = localId + 100000;
                oprim.OnCollisionUpdate += delegate(EventArgs args)
                {
                    if (!oprim.m_taintremove)
                    {
                       // CollisionEventUpdate arg = (CollisionEventUpdate)args;
                        //simhinfo 58 58 30
                       // DoneMoving = true;
                        LandingHieghts[x, y] = oprim.Position.Z + offsetZ;
                        fallingPrims--;
                        ps.remCollisionEventReporting(oprim);
                        ps.RemovePrim(oprim);
                    }
                };
                oprim.SubscribeEvents(30000);
            }
Esempio n. 12
0
        void ComputeLandingHeights()
        {
            float fromZ = MaxZ + 10;
            float StepSize = PathStore.StepSize; //0.2f
            int MAPSPACE = PathStore.MAPSPACE;
            int MAPSPACE1 = MAPSPACE - 1; // 1279
            bool needsInit = false;
            float[,] _HeightMap = HeightMap;

            if (LandingHieghts == null)
            {
                if (_HeightMap != null)
                {
                    LandingHieghts = (float[,])_HeightMap.Clone();
                }
                else
                {
                    LandingHieghts = new float[MAPSPACE, MAPSPACE];
                    needsInit = true;
                }
            }

            CollisionIndex[,] MeshIndex = PathStore.MeshIndex;
            // FallingPrims = new FallingPrim[MAPSPACE, MAPSPACE];
            float fy = 256.1f;
            OdeScene ps = PathStore.odeScene;
            PrimitiveBaseShape newcube = PrimitiveBaseShape.CreateBox();
            uint localId = 6666666;
            PhysicsVector position = new PhysicsVector(1,1,30);
            OdePrim oprim = (OdePrim)ps.AddPrimShape("FallingPrim_" + localId, newcube, position, new PhysicsVector(0.1f, 0.1f, 2f), Quaternion.Identity, true);
            oprim.LocalID = localId + 100000;
            oprim.SubscribeEvents(30000);

            for (int y = MAPSPACE1; y >= 0; y--)
            {
                fy = fy - StepSize;
                position.Y = fy;
                float fx = 256.1f;
                for (int x = MAPSPACE1; x >= 0; x--)
                {
                    fx = fx - StepSize;
                    position.X = fx;
                    if (needsInit) LandingHieghts[x, y] = float.MinValue;
                    if (MeshIndex[x, y] == null) continue;
                    float z = MinZ;
                    bool FoundClearZ = false;
                    while (z < MaxZ && !FoundClearZ)
                    {
                        float ClearZ = z;
                        position.Z = z;
                        if (!ps.IsSomethingAt(oprim))
                        {
                            FoundClearZ = true;
                            float CapZ = 2f + z;
                            while (z < CapZ && FoundClearZ)
                            {
                                if (ps.IsSomethingAt(oprim))
                                 {
                                     FoundClearZ = false;
                                     break;
                                 } 
                            }
                            FoundClearZ = true;
                            break;
                        }
                        z += 0.1f;
                    }
                    if (FoundClearZ)
                    {
                        LandingHieghts[x, y] = z;
                    }
                    //FallingPrims[x, y] = new
                }
            }
            _HeightMap = LandingHieghts;
        }
Esempio n. 13
0
        public Vector3 CreateAndDropPhysicalCube(Vector3 from)
        {
            OdeScene ps = odeScene;
            PrimitiveBaseShape newcube = PrimitiveBaseShape.CreateBox();
            PhysicsVector position = new PhysicsVector(from.X, from.Y, from.Z);
            PhysicsVector size = new PhysicsVector(0.2f, 0.2f, 1f);
            Quaternion rot = Quaternion.Identity;
            PhysicsActor prim = ps.AddPrimShape("CoolShape", newcube, position, size, rot, true);
            OdePrim oprim = (OdePrim)prim;
            OdeScene pscene = (OdeScene)ps;
            //   prim.OnCollisionUpdate;
            Assert.That(oprim.m_taintadd);
            bool falling = true;
            prim.LocalID = 5;
            //oprim.OnVelocityUpdate += delegate(PhysicsVector velocity)
            //                              {
            //                                  falling = false;
            //                              };
            oprim.OnCollisionUpdate += delegate(EventArgs args)
                                           {
                                               CollisionEventUpdate arg = (CollisionEventUpdate)args;
                                               //simhinfo 58 58 30
                                               CollisionPlane.Debug("oprim OnCollisionUpdate " + args);
                                               falling = false;
                                           };
           
            oprim.SubscribeEvents(30000)
            ;
            
            while (falling)
            {
                ps.Simulate(0.133f);
                //Assert.That(oprim.prim_geom != (IntPtr)0);

                //Assert.That(oprim.m_targetSpace != (IntPtr)0);

                ////Assert.That(oprim.m_targetSpace == pscene.space);
                //Debug("TargetSpace: " + oprim.m_targetSpace + " - SceneMainSpace: " + pscene.space);

                //Assert.That(!oprim.m_taintadd);
                //Debug("Prim Position (" + oprim.m_localID + "): " + prim.Position.ToString());

                //// Make sure we're above the ground
                ////Assert.That(prim.Position.Z > 20f);
                ////m_log.Info("PrimCollisionScore (" + oprim.m_localID + "): " + oprim.m_collisionscore);

                //// Make sure we've got a Body
                //Assert.That(oprim.Body != (IntPtr)0);
                ////m_log.Info(
            }

            PhysicsVector primPosition = prim.Position;

            // Make sure we're not somewhere above the ground
 
            Vector3 v3 = new Vector3(primPosition.X,primPosition.Y,primPosition.Z);
            ps.RemovePrim(prim);
           // Assert.That(oprim.m_taintremove);
            ps.Simulate(0.133f); // for removal or not needed?
            // Assert.That(oprim.Body == (IntPtr)0);
            return v3;
        }