Example #1
0
        public override void SetTerrain(float[] heightMap)
        {
            if (m_terrainShape != null)
            {
                DeleteTerrain();
            }

            float hfmax = -9000;
            float hfmin = 90000;

            for (int i = 0; i < heightMap.Length; i++)
            {
                if (Single.IsNaN(heightMap[i]) || Single.IsInfinity(heightMap[i]))
                {
                    heightMap[i] = 0f;
                }

                hfmin = (heightMap[i] < hfmin) ? heightMap[i] : hfmin;
                hfmax = (heightMap[i] > hfmax) ? heightMap[i] : hfmax;
            }
            // store this for later reference.
            // Note, we're storing it  after we check it for anomolies above
            _origheightmap = heightMap;

            hfmin = 0;
            hfmax = 256;

            m_terrainShape = new btHeightfieldTerrainShape((int)Constants.RegionSize, (int)Constants.RegionSize, heightMap,
                                                           1.0f, hfmin, hfmax, (int)btHeightfieldTerrainShape.UPAxis.Z,
                                                           (int)btHeightfieldTerrainShape.PHY_ScalarType.PHY_FLOAT, false);
            float AabbCenterX = Constants.RegionSize / 2f;
            float AabbCenterY = Constants.RegionSize / 2f;

            float AabbCenterZ = 0;
            float temphfmin, temphfmax;

            temphfmin = hfmin;
            temphfmax = hfmax;

            if (temphfmin < 0)
            {
                temphfmax = 0 - temphfmin;
                temphfmin = 0 - temphfmin;
            }
            else if (temphfmin > 0)
            {
                temphfmax = temphfmax + (0 - temphfmin);
                //temphfmin = temphfmin + (0 - temphfmin);
            }
            AabbCenterZ = temphfmax / 2f;

            if (m_terrainPosition == null)
            {
                m_terrainPosition = new btVector3(AabbCenterX, AabbCenterY, AabbCenterZ);
            }
            else
            {
                try
                {
                    m_terrainPosition.setValue(AabbCenterX, AabbCenterY, AabbCenterZ);
                }
                catch (ObjectDisposedException)
                {
                    m_terrainPosition = new btVector3(AabbCenterX, AabbCenterY, AabbCenterZ);
                }
            }
            if (m_terrainMotionState != null)
            {
                m_terrainMotionState.Dispose();
                m_terrainMotionState = null;
            }
            m_terrainTransform   = new btTransform(QuatIdentity, m_terrainPosition);
            m_terrainMotionState = new btDefaultMotionState(m_terrainTransform);
            TerrainBody          = new btRigidBody(0, m_terrainMotionState, m_terrainShape);
            TerrainBody.setUserPointer((IntPtr)0);
            m_world.addRigidBody(TerrainBody);
        }
Example #2
0
        public override void SetTerrain(bool[] heightMap)
        {
            if (m_terrainShape != null)
            {
                DeleteTerrain();
            }

            m_terrainShape = AddPrim(
                "__TERRAIN__",
                new Vector3(Constants.RegionSize / 2, Constants.RegionSize / 2, Constants.RegionSize / 2),
                new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionSize),
                Quaternion.Identity,
                voxmesher.ToMesh(heightMap),
                PrimitiveBaseShape.Default,
                false);
            //float AabbCenterX = Constants.RegionSize/2f;
            //float AabbCenterY = Constants.RegionSize/2f;

            //float AabbCenterZ = 0f;

            /*
             * float temphfmin, temphfmax;
             *
             * temphfmin = hfmin;
             * temphfmax = hfmax;
             *
             * if (temphfmin < 0)
             * {
             *  temphfmax = 0 - temphfmin;
             *  temphfmin = 0 - temphfmin;
             * }
             * else if (temphfmin > 0)
             * {
             *  temphfmax = temphfmax + (0 - temphfmin);
             *  //temphfmin = temphfmin + (0 - temphfmin);
             * }
             * AabbCenterZ = temphfmax/2f;
             *
             * if (m_terrainPosition == null)
             * {
             *  m_terrainPosition = new btVector3(AabbCenterX, AabbCenterY, AabbCenterZ);
             * }
             * else
             * {
             *  try
             *  {
             *      m_terrainPosition.setValue(AabbCenterX, AabbCenterY, AabbCenterZ);
             *  }
             *  catch (ObjectDisposedException)
             *  {
             *      m_terrainPosition = new btVector3(AabbCenterX, AabbCenterY, AabbCenterZ);
             *  }
             * }
             */
            if (m_terrainMotionState != null)
            {
                m_terrainMotionState.Dispose();
                m_terrainMotionState = null;
            }
            m_terrainTransform   = new btTransform(QuatIdentity, m_terrainPosition);
            m_terrainMotionState = new btDefaultMotionState(m_terrainTransform);
        }
Example #3
0
        public override void SetTerrain(short[] shortheightMap)
        {
            if (m_terrainShape != null)
            {
                DeleteTerrain();
            }

            float hfmax = 256;
            float hfmin = 0;

            // store this for later reference.
            // Note, we're storing it  after we check it for anomolies above
            _origheightmap = shortheightMap;

            hfmin = 0;
            hfmax = 256;

            float[] heightmap = new float[m_region.RegionSizeX * m_region.RegionSizeX];
            for (int i = 0; i < shortheightMap.Length; i++)
            {
                heightmap[i] = shortheightMap[i] / Constants.TerrainCompression;
            }

            m_terrainShape = new btHeightfieldTerrainShape(m_region.RegionSizeX, m_region.RegionSizeY, heightmap,
                                                           1.0f, hfmin, hfmax, (int)btHeightfieldTerrainShape.UPAxis.Z,
                                                           (int)btHeightfieldTerrainShape.PHY_ScalarType.PHY_FLOAT, false);
            float AabbCenterX = m_region.RegionSizeX / 2f;
            float AabbCenterY = m_region.RegionSizeY / 2f;

            float AabbCenterZ = 0;
            float temphfmin, temphfmax;

            temphfmin = hfmin;
            temphfmax = hfmax;

            if (temphfmin < 0)
            {
                temphfmax = 0 - temphfmin;
                temphfmin = 0 - temphfmin;
            }
            else if (temphfmin > 0)
            {
                temphfmax = temphfmax + (0 - temphfmin);
                //temphfmin = temphfmin + (0 - temphfmin);
            }
            AabbCenterZ = temphfmax / 2f;

            if (m_terrainPosition == null)
            {
                m_terrainPosition = new btVector3(AabbCenterX, AabbCenterY, AabbCenterZ);
            }
            else
            {
                try
                {
                    m_terrainPosition.setValue(AabbCenterX, AabbCenterY, AabbCenterZ);
                }
                catch (ObjectDisposedException)
                {
                    m_terrainPosition = new btVector3(AabbCenterX, AabbCenterY, AabbCenterZ);
                }
            }
            if (m_terrainMotionState != null)
            {
                m_terrainMotionState.Dispose();
                m_terrainMotionState = null;
            }
            m_terrainTransform   = new btTransform(QuatIdentity, m_terrainPosition);
            m_terrainMotionState = new btDefaultMotionState(m_terrainTransform);
            TerrainBody          = new btRigidBody(0, m_terrainMotionState, m_terrainShape);
            TerrainBody.setUserPointer((IntPtr)0);
            m_world.addRigidBody(TerrainBody);
        }