Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

...More Terrain

...More Terrain

Ceoddyn
The Wild West of Programming · · 1 min read
1,326 0
So today I decided to implement this rendering list I've been thinking about for the terrain quadtree. After some mucking about I came up with a pretty awesome method that maintains a static list of nodes. This way I only add/remove nodes that have either become hidden or visible since the last frame rather than rebuilding the entire thing every time. This only applies generally to 10 or less nodes a frame so it ends up being pretty fast. Most of the nodes also stay in order which cuts down on the sort run time as well.

This bit of code isn't long, but I'm particularly proud of it for some reason:

private void FillList(){    if (CameraManager.ActiveCamera.Frustum.Contains(mNodeBoundingBox) != ContainmentType.Disjoint)    {        if (mIsEndNode)        {            mDistance = Vector3.DistanceSquared(mPosition, CameraManager.ActiveCamera.Position);            if (!mIsListed)                mRenderSort.Add(this);        }        else        {            mNodeUL.FillList();            mNodeUR.FillList();            mNodeLL.FillList();            mNodeLR.FillList();        }        mIsListed = true;    }    else if (mIsListed)        RemoveChildren();}private void RemoveChildren(){    mIsListed = false;    if (mIsEndNode)        mRenderSort.Remove(this);    else    {        mNodeUL.RemoveChildren();        mNodeUR.RemoveChildren();        mNodeLL.RemoveChildren();        mNodeLR.RemoveChildren();    }}


You guys are probably starting to hate pictures of the same old terrain, so I promise this will be the last one. Tomorrow I move on to something new!

Discussion

Loading comments...