/// public initialization /** * Handles the work of constructors so that public constructors can be * backwards-compatible without a lot of copy/paste. */ public void Initialize(int heightStickWidth, int heightStickLength, Object heightfieldData, float heightScale, float minHeight, float maxHeight, int upAxis, PHY_ScalarType hdt, bool flipQuadEdges) { // validation Debug.Assert(heightStickWidth > 1, "bad width"); Debug.Assert(heightStickLength > 1, "bad length"); Debug.Assert(heightfieldData != null, "null heightfield data"); // Debug.Assert(heightScale) -- do we care? Trust caller here Debug.Assert(minHeight <= maxHeight, "bad min/max height"); Debug.Assert(upAxis >= 0 && upAxis < 3, "bad upAxis--should be in range [0,2]"); Debug.Assert(hdt != PHY_ScalarType.PHY_UCHAR || hdt != PHY_ScalarType.PHY_FLOAT || hdt != PHY_ScalarType.PHY_SHORT, "Bad height data type enum"); // initialize member variables m_shapeType = BroadphaseNativeTypes.TERRAIN_SHAPE_PROXYTYPE; m_heightStickWidth = heightStickWidth; m_heightStickLength = heightStickLength; m_minHeight = minHeight; m_maxHeight = maxHeight; m_width = (heightStickWidth - 1); m_length = (heightStickLength - 1); m_heightScale = heightScale; // copy the data in m_heightFieldDataByte = heightfieldData as byte[]; m_heightFieldDataFloat = heightfieldData as float[]; m_heightDataType = hdt; m_flipQuadEdges = flipQuadEdges; m_useDiamondSubdivision = false; m_upAxis = upAxis; m_localScaling = new IndexedVector3(1f); // determine min/max axis-aligned bounding box (aabb) values switch (m_upAxis) { case 0: { m_localAabbMin = new IndexedVector3(m_minHeight, 0, 0); m_localAabbMax = new IndexedVector3(m_maxHeight, m_width, m_length); break; } case 1: { m_localAabbMin = new IndexedVector3(0, m_minHeight, 0); m_localAabbMax = new IndexedVector3(m_width, m_maxHeight, m_length); break; }; case 2: { m_localAabbMin = new IndexedVector3(0, 0, m_minHeight); m_localAabbMax = new IndexedVector3(m_width, m_length, m_maxHeight); break; } default: { //need to get valid m_upAxis Debug.Assert(false, "Bad m_upAxis"); break; } } // remember origin (defined as exact middle of aabb) m_localOrigin = 0.5f * (m_localAabbMin + m_localAabbMax); }