//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);
        }
Beispiel #2
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);
            }
        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;
        }