Axiom.Components.Terrain.TerrainQuadTreeNode.TerrainQuadTreeNode C# (CSharp) Method

TerrainQuadTreeNode() public method

Default constructor.
public TerrainQuadTreeNode ( Axiom.Components.Terrain.Terrain terrain, TerrainQuadTreeNode parent, ushort xOff, ushort yOff, ushort size, ushort lod, ushort depth, ushort quadrant ) : System
terrain Axiom.Components.Terrain.Terrain The ultimate parent terrain
parent TerrainQuadTreeNode ptional parent node (in which case xoff, yoff are 0 and size must be entire terrain)
xOff ushort Offsets from the start of the terrain data in 2D
yOff ushort Offsets from the start of the terrain data in 2D
size ushort The size of the node in vertices at the highest LOD
lod ushort The base LOD level
depth ushort The depth that this node is at in the tree (or convenience)
quadrant ushort The index of the quadrant (0, 1, 2, 3)
return System
        public TerrainQuadTreeNode(Terrain terrain, TerrainQuadTreeNode parent, ushort xOff, ushort yOff,
            ushort size, ushort lod, ushort depth, ushort quadrant)
        {
            mTerrain = terrain;
            mParent = parent;
            mOffsetX = xOff;
            mOffsetY = yOff;
            mBoundaryX = (ushort)(xOff + size);
            mBoundaryY = (ushort)(yOff + size);
            mSize = size;
            mBaseLod = lod;
            mDepth = depth;
            mQuadrant = quadrant;
            mBoundingRadius = 0;
            mCurrentLod = -1;
            mMaterialLodIndex = 0;
            mLodTransition = 0;
            mChildWithMaxHeightDelta = null;
            mSelfOrChildRendered = false;
            mNodeWithVertexData = null;
           // mMovable = null;
            mRend = null;
            mAABB = new AxisAlignedBox();
            if (mTerrain.MaxBatchSize < size)
            {
                ushort childSize = (ushort)(((size - 1) * 0.5f) + 1);
                ushort childOff = (ushort)(childSize - 1);
                ushort childLod = (ushort)(lod - 1);
                ushort childDepth = (ushort)(depth + 1);

                mChildren[0] = new TerrainQuadTreeNode(mTerrain, this, xOff, yOff, childSize, childLod, childDepth, 0);
                mChildren[1] = new TerrainQuadTreeNode(mTerrain, this, (ushort)(xOff + childOff), yOff, childSize, childLod, childDepth, 1);
                mChildren[2] = new TerrainQuadTreeNode(mTerrain, this, xOff, (ushort)(yOff + childOff), childSize, childLod, childDepth, 2);
                mChildren[3] = new TerrainQuadTreeNode(mTerrain, this, (ushort)(xOff + childOff), (ushort)(yOff + childOff), childSize, childLod, childDepth, 3);

                LodLevel ll = new LodLevel();
                // non-leaf nodes always render with minBatchSize vertices
                ll.BatchSize = mTerrain.MinBatchSize;
                ll.MaxHeightDelta = 0;
                ll.CalcMaxHeightDelta = 0;
                mLodLevels.Add(ll);
            }
            else
            {
                //no children
                Array.Clear(mChildren, 0, mChildren.Length);
                // this is a leaf node and may have internal LODs of its own
                ushort ownLod = mTerrain.LodLevelsPerLeafCount;

                Debug.Assert(lod == (ownLod - 1),
                    "The lod passed in should reflect the number of lods in a leaf");
                // leaf nodes always have a base LOD of 0, because they're always handling
                // the highest level of detail
                mBaseLod = 0;
                ushort sz = mTerrain.MaxBatchSize;

                while (ownLod-- != 0)
                {
                    LodLevel ll = new LodLevel();
                    ll.BatchSize = sz;
                    ll.MaxHeightDelta = 0;
                    ll.CalcMaxHeightDelta = 0;
                    mLodLevels.Add(ll);
                    if(ownLod != 0)
                        sz = (ushort)(((sz - 1) * 0.5) + 1);

                }
                Debug.Assert(sz == mTerrain.MinBatchSize);
            }

            // local centre calculation
            // because of pow2 +1 there is always a middle point
            ushort midoffset = (ushort)((size - 1) / 2);
            ushort midpointX = (ushort)(mOffsetX + midoffset);
            ushort midpointY = (ushort)(mOffsetY + midoffset);

            //derive the local centry, but give it a height if 0
            //TODO: - what if we actually centred this at the terrain height at this point?
            //would this be better?
            mTerrain.GetPoint(midpointX, midpointY, 0, ref mLocalCentre);
            /*mRend = new Rend(this);
            mMovable = new Movable(this,mRend);*/
            mRend= new TerrainRendable(this);
            SceneNode sn = mTerrain.RootSceneNode.CreateChildSceneNode(mLocalCentre);
            sn.AttachObject(mRend);
           // sn.AttachObject(mRend);

        }