Esempio n. 1
0
        // TODO: redo terrain implementation selection to allow other base types than heightMap.
        private BSTerrainPhys BuildPhysicalTerrain(Vector3 terrainRegionBase, uint id, float[] heightMap, Vector3 minCoords, Vector3 maxCoords)
        {
            m_physicsScene.Logger.DebugFormat("{0} Terrain for {1}/{2} created with {3}",
                                              LogHeader, m_physicsScene.RegionName, terrainRegionBase,
                                              (BSTerrainPhys.TerrainImplementation)BSParam.TerrainImplementation);
            BSTerrainPhys newTerrainPhys = null;

            switch ((int)BSParam.TerrainImplementation)
            {
            case (int)BSTerrainPhys.TerrainImplementation.Heightmap:
                newTerrainPhys = new BSTerrainHeightmap(m_physicsScene, terrainRegionBase, id,
                                                        heightMap, minCoords, maxCoords);
                break;

            case (int)BSTerrainPhys.TerrainImplementation.Mesh:
                newTerrainPhys = new BSTerrainMesh(m_physicsScene, terrainRegionBase, id,
                                                   heightMap, minCoords, maxCoords);
                break;

            default:
                m_physicsScene.Logger.ErrorFormat("{0} Bad terrain implementation specified. Type={1}/{2},Region={3}/{4}",
                                                  LogHeader,
                                                  (int)BSParam.TerrainImplementation,
                                                  BSParam.TerrainImplementation,
                                                  m_physicsScene.RegionName, terrainRegionBase);
                break;
            }
            return(newTerrainPhys);
        }
Esempio n. 2
0
        // Create the initial instance of terrain and the underlying ground plane.
        // This is called from the initialization routine so we presume it is
        //    safe to call Bullet in real time. We hope no one is moving prims around yet.
        public void CreateInitialGroundPlaneAndTerrain()
        {
            DetailLog("{0},BSTerrainManager.CreateInitialGroundPlaneAndTerrain,region={1}", BSScene.DetailLogZero, m_physicsScene.RegionName);
            // The ground plane is here to catch things that are trying to drop to negative infinity
            BulletShape groundPlaneShape    = m_physicsScene.PE.CreateGroundPlaneShape(BSScene.GROUNDPLANE_ID, 1f, BSParam.TerrainCollisionMargin);
            Vector3     groundPlaneAltitude = new Vector3(0f, 0f, BSParam.TerrainGroundPlane);

            m_groundPlane = m_physicsScene.PE.CreateBodyWithDefaultMotionState(groundPlaneShape,
                                                                               BSScene.GROUNDPLANE_ID, groundPlaneAltitude, Quaternion.Identity);

            // Everything collides with the ground plane.
            m_groundPlane.collisionType = CollisionType.Groundplane;

            m_physicsScene.PE.AddObjectToWorld(m_physicsScene.World, m_groundPlane);
            m_physicsScene.PE.UpdateSingleAabb(m_physicsScene.World, m_groundPlane);

            // Ground plane does not move
            m_physicsScene.PE.ForceActivationState(m_groundPlane, ActivationState.DISABLE_SIMULATION);

            BSTerrainPhys initialTerrain = new BSTerrainHeightmap(m_physicsScene, Vector3.Zero, BSScene.TERRAIN_ID, DefaultRegionSize);

            m_terrainsRwLock.AcquireWriterLock(-1);
            try
            {
                // Build an initial terrain and put it in the world. This quickly gets replaced by the real region terrain.
                m_terrains.Add(Vector3.Zero, initialTerrain);
            }
            finally
            {
                m_terrainsRwLock.ReleaseWriterLock();
            }
        }
        // TODO: redo terrain implementation selection to allow other base types than heightMap.
        private BSTerrainPhys BuildPhysicalTerrain(uint id, float[] heightMap)
        {
            // Find high and low points of passed heightmap.
            // The min and max passed in is usually the area objects can be in (maximum
            //     object height, for instance). The terrain wants the bounding box for the
            //     terrain so replace passed min and max Z with the actual terrain min/max Z.
            float minZ = float.MaxValue;
            float maxZ = float.MinValue;

            foreach (float height in heightMap)
            {
                if (height < minZ)
                {
                    minZ = height;
                }
                if (height > maxZ)
                {
                    maxZ = height;
                }
            }
            if (minZ == maxZ)
            {
                // If min and max are the same, reduce min a little bit so a good bounding box is created.
                minZ -= BSTerrainManager.HEIGHT_EQUAL_FUDGE;
            }
            Vector3 minCoords = new Vector3(0, 0, minZ);
            Vector3 maxCoords = new Vector3(PhysicsScene.Scene.RegionInfo.RegionSizeX, PhysicsScene.Scene.RegionInfo.RegionSizeY, maxZ);

            PhysicsScene.Logger.DebugFormat("{0} Terrain for {1}/ created with {2}",
                                            LogHeader, PhysicsScene.RegionName,
                                            (BSTerrainPhys.TerrainImplementation)BSParam.TerrainImplementation);
            BSTerrainPhys newTerrainPhys = null;

            switch ((int)BSParam.TerrainImplementation)
            {
            case (int)BSTerrainPhys.TerrainImplementation.Heightmap:
                newTerrainPhys = new BSTerrainHeightmap(PhysicsScene, Vector3.Zero, id,
                                                        heightMap, minCoords, maxCoords);
                break;

            case (int)BSTerrainPhys.TerrainImplementation.Mesh:
                newTerrainPhys = new BSTerrainMesh(PhysicsScene, Vector3.Zero, id,
                                                   heightMap, minCoords, maxCoords);
                break;

            default:
                PhysicsScene.Logger.ErrorFormat("{0} Bad terrain implementation specified. Type={1}/{2},Region={3}",
                                                LogHeader,
                                                (int)BSParam.TerrainImplementation,
                                                BSParam.TerrainImplementation,
                                                PhysicsScene.RegionName);
                break;
            }
            return(newTerrainPhys);
        }
Esempio n. 4
0
        // Create the initial instance of terrain and the underlying ground plane.
        // This is called from the initialization routine so we presume it is
        //    safe to call Bullet in real time. We hope no one is moving prims around yet.
        public void CreateInitialGroundPlaneAndTerrain()
        {
            // The ground plane is here to catch things that are trying to drop to negative infinity
            BulletShape groundPlaneShape = PhysicsScene.PE.CreateGroundPlaneShape(BSScene.GROUNDPLANE_ID, 1f, BSParam.TerrainCollisionMargin);

            m_groundPlane = PhysicsScene.PE.CreateBodyWithDefaultMotionState(groundPlaneShape,
                                                                             BSScene.GROUNDPLANE_ID, Vector3.Zero, Quaternion.Identity);

            PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, m_groundPlane);
            PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, m_groundPlane);
            // Ground plane does not move
            PhysicsScene.PE.ForceActivationState(m_groundPlane, ActivationState.DISABLE_SIMULATION);
            // Everything collides with the ground plane.
            m_groundPlane.collisionType = CollisionType.Groundplane;
            m_groundPlane.ApplyCollisionMask(PhysicsScene);

            // Build an initial terrain and put it in the world. This quickly gets replaced by the real region terrain.
            BSTerrainPhys initialTerrain = new BSTerrainHeightmap(PhysicsScene, Vector3.Zero, BSScene.TERRAIN_ID, DefaultRegionSize);

            m_terrains.Add(Vector3.Zero, initialTerrain);
        }
Esempio n. 5
0
 // TODO: redo terrain implementation selection to allow other base types than heightMap.
 private BSTerrainPhys BuildPhysicalTerrain(Vector3 terrainRegionBase, uint id, float[] heightMap, Vector3 minCoords, Vector3 maxCoords)
 {
     PhysicsScene.Logger.DebugFormat("{0} Terrain for {1}/{2} created with {3}", 
                                         LogHeader, PhysicsScene.RegionName, terrainRegionBase, 
                                         (BSTerrainPhys.TerrainImplementation)BSParam.TerrainImplementation);
     BSTerrainPhys newTerrainPhys = null;
     switch ((int)BSParam.TerrainImplementation)
     {
         case (int)BSTerrainPhys.TerrainImplementation.Heightmap:
             newTerrainPhys = new BSTerrainHeightmap(PhysicsScene, terrainRegionBase, id,
                                         heightMap, minCoords, maxCoords);
             break;
         case (int)BSTerrainPhys.TerrainImplementation.Mesh:
             newTerrainPhys = new BSTerrainMesh(PhysicsScene, terrainRegionBase, id,
                                         heightMap, minCoords, maxCoords);
             break;
         default:
             PhysicsScene.Logger.ErrorFormat("{0} Bad terrain implementation specified. Type={1}/{2},Region={3}/{4}",
                                         LogHeader, 
                                         (int)BSParam.TerrainImplementation, 
                                         BSParam.TerrainImplementation,
                                         PhysicsScene.RegionName, terrainRegionBase);
             break;
     }
     return newTerrainPhys;
 }
Esempio n. 6
0
    // Create the initial instance of terrain and the underlying ground plane.
    // This is called from the initialization routine so we presume it is
    //    safe to call Bullet in real time. We hope no one is moving prims around yet.
    public void CreateInitialGroundPlaneAndTerrain()
    {
        // The ground plane is here to catch things that are trying to drop to negative infinity
        BulletShape groundPlaneShape = PhysicsScene.PE.CreateGroundPlaneShape(BSScene.GROUNDPLANE_ID, 1f, BSParam.TerrainCollisionMargin);
        m_groundPlane = PhysicsScene.PE.CreateBodyWithDefaultMotionState(groundPlaneShape, 
                                        BSScene.GROUNDPLANE_ID, Vector3.Zero, Quaternion.Identity);

        PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, m_groundPlane);
        PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, m_groundPlane);
        // Ground plane does not move
        PhysicsScene.PE.ForceActivationState(m_groundPlane, ActivationState.DISABLE_SIMULATION);
        // Everything collides with the ground plane.
        m_groundPlane.collisionType = CollisionType.Groundplane;
        m_groundPlane.ApplyCollisionMask(PhysicsScene);

        // Build an initial terrain and put it in the world. This quickly gets replaced by the real region terrain.
        BSTerrainPhys initialTerrain = new BSTerrainHeightmap(PhysicsScene, Vector3.Zero, BSScene.TERRAIN_ID, DefaultRegionSize);
        m_terrains.Add(Vector3.Zero, initialTerrain);
    }
    // Create the initial instance of terrain and the underlying ground plane.
    // This is called from the initialization routine so we presume it is
    //    safe to call Bullet in real time. We hope no one is moving prims around yet.
    public void CreateInitialGroundPlaneAndTerrain()
    {
        DetailLog("{0},BSTerrainManager.CreateInitialGroundPlaneAndTerrain,region={1}", BSScene.DetailLogZero, m_physicsScene.RegionName);
        // The ground plane is here to catch things that are trying to drop to negative infinity
        BulletShape groundPlaneShape = m_physicsScene.PE.CreateGroundPlaneShape(BSScene.GROUNDPLANE_ID, 1f, BSParam.TerrainCollisionMargin);
        Vector3 groundPlaneAltitude = new Vector3(0f, 0f, BSParam.TerrainGroundPlane);
        m_groundPlane = m_physicsScene.PE.CreateBodyWithDefaultMotionState(groundPlaneShape,
                                        BSScene.GROUNDPLANE_ID, groundPlaneAltitude, Quaternion.Identity);

        // Everything collides with the ground plane.
        m_groundPlane.collisionType = CollisionType.Groundplane;

        m_physicsScene.PE.AddObjectToWorld(m_physicsScene.World, m_groundPlane);
        m_physicsScene.PE.UpdateSingleAabb(m_physicsScene.World, m_groundPlane);

        // Ground plane does not move
        m_physicsScene.PE.ForceActivationState(m_groundPlane, ActivationState.DISABLE_SIMULATION);

        BSTerrainPhys initialTerrain = new BSTerrainHeightmap(m_physicsScene, Vector3.Zero, BSScene.TERRAIN_ID, DefaultRegionSize);
        m_terrainsRwLock.AcquireWriterLock(-1);
        try
        {
            // Build an initial terrain and put it in the world. This quickly gets replaced by the real region terrain.
            m_terrains.Add(Vector3.Zero, initialTerrain);
        }
        finally
        {
            m_terrainsRwLock.ReleaseWriterLock();
        }
    }
Esempio n. 8
0
        // TODO: redo terrain implementation selection to allow other base types than heightMap.
        private BSTerrainPhys BuildPhysicalTerrain(uint id, float[] heightMap)
        {
            // Find high and low points of passed heightmap.
            // The min and max passed in is usually the area objects can be in (maximum
            //     object height, for instance). The terrain wants the bounding box for the
            //     terrain so replace passed min and max Z with the actual terrain min/max Z.
            float minZ = float.MaxValue;
            float maxZ = float.MinValue;
            foreach (float height in heightMap)
            {
            if (height < minZ) minZ = height;
            if (height > maxZ) maxZ = height;
            }
            if (minZ == maxZ)
            {
            // If min and max are the same, reduce min a little bit so a good bounding box is created.
            minZ -= BSTerrainManager.HEIGHT_EQUAL_FUDGE;
            }
            Vector3 minCoords = new Vector3(0, 0, minZ);
            Vector3 maxCoords = new Vector3(PhysicsScene.Scene.RegionInfo.RegionSizeX, PhysicsScene.Scene.RegionInfo.RegionSizeY, maxZ);

            PhysicsScene.Logger.DebugFormat("{0} Terrain for {1}/ created with {2}",
                                            LogHeader, PhysicsScene.RegionName,
                                            (BSTerrainPhys.TerrainImplementation)BSParam.TerrainImplementation);
            BSTerrainPhys newTerrainPhys = null;
            switch ((int)BSParam.TerrainImplementation)
            {
            case (int)BSTerrainPhys.TerrainImplementation.Heightmap:
                newTerrainPhys = new BSTerrainHeightmap(PhysicsScene, Vector3.Zero, id,
                                            heightMap, minCoords, maxCoords);
                break;
            case (int)BSTerrainPhys.TerrainImplementation.Mesh:
                newTerrainPhys = new BSTerrainMesh(PhysicsScene, Vector3.Zero, id,
                                            heightMap, minCoords, maxCoords);
                break;
            default:
                PhysicsScene.Logger.ErrorFormat("{0} Bad terrain implementation specified. Type={1}/{2},Region={3}",
                                            LogHeader,
                                            (int)BSParam.TerrainImplementation,
                                            BSParam.TerrainImplementation,
                                            PhysicsScene.RegionName);
                break;
            }
            return newTerrainPhys;
        }