Game Development Community

dev|Pro Game Development Curriculum

Add MinSlope groundcover setting

by Kenneth Eves · 09/27/2012 (11:36 am) · 10 comments

Here's code to add a minimum slope configuration option to the groundcover feature in T3D 1.2.

I find it useful as a way to keep grass off roads, plus it provides an easy and completely procedural means of diversifying ground cover for variety.

All the changes are in groundCover.cpp and groundCover.h. Just find the matching maxslope and add the minslope portion to your code. It's an easy patch.

One patched and compiled, you will find the configuration option in the Types section.

these are the change to groundCover.cpp:

      mMinSlope[i] = 0.0f;
      mMaxSlope[i] = 0.0f;

---

         addField( "minSlope",      TypeF32,       Offset( mMinSlope, GroundCover ), MAX_COVERTYPES,        "The minimum slope angle in degrees for placement." );

         addField( "maxSlope",      TypeF32,       Offset( mMaxSlope, GroundCover ), MAX_COVERTYPES,        "The maximum slope angle in degrees for placement." );

---

         stream->write( mMinSlope[i] );
	 stream->write( mMaxSlope[i] );

---

         stream->read( &mMinSlope[i] );
	 stream->read( &mMaxSlope[i] );

---

      const F32 typeMinSlope = mMinSlope[type];
      const F32 typeMaxSlope = mMaxSlope[type];

---

         // Do we need to check min slope?
         if ( !mIsZero( typeMinSlope ) )
         {
            if (mAcos(normal.z) < mDegToRad(typeMinSlope))
               continue;
         }

         // Do we need to check slope?
         if ( !mIsZero( typeMaxSlope ) )
         {
            if (mAcos(normal.z) > mDegToRad(typeMaxSlope))
               continue;
         }
---
this is the change to groundCover.h:

   /// The maximum slope angle in degrees for placement.
   F32 mMinSlope[MAX_COVERTYPES];

   /// The maximum slope angle in degrees for placement.
   F32 mMaxSlope[MAX_COVERTYPES];

---

#1
09/27/2012 (1:01 pm)
Do you have a pic or a video to show? Would be good to see what can be achieved by this.
#2
09/27/2012 (1:10 pm)
Thats a good idea! I already used other textures below the road's, to keep it clean. This is usefully.
#3
09/27/2012 (2:15 pm)
Edit quote bug in code and posted as blog not resource.
#4
09/27/2012 (8:11 pm)
Fixed the HTML encoding. I don't know how I ended up posting in the wrong section.
#5
09/27/2012 (11:48 pm)
Here's a screenshot of minSlope 10 maxSlope 20:

www.XAP.net/minSlopeExample.jpg
#6
09/28/2012 (11:06 am)
About posting in the wrong section: possibly you used the "More" button on the the blog page to select "Add A Resource" instead of using the one on the Resource page? I've noticed that causes misplaced Resources ever since the big page changeup a few years back.
#7
09/30/2012 (11:38 am)
seems like it could easily be added as a default part of the engine ...

combined with using terrain types to limit the ground cover, lots of possibilities.
#8
10/02/2012 (1:19 pm)
Pushed to resources! :)
#9
10/06/2012 (3:47 pm)
@David, thanks.
#10
03/18/2013 (4:55 pm)
Nice resource by the way Kenneth - works like a charm!