Game Development Community

dev|Pro Game Development Curriculum

Scaling DebrisData in T3D

by Andrew Edmonds · 10/20/2009 (6:36 am) · 2 comments

I found that some of the art for my projectiles was way too big when being ejected from the weapon on firing but there was no way to scale this down without jumping back over to 3DS and scaling it. This resource adds a scale attribute to DebrisData which allows you to do just that.

Essentially, it is just a port of the excellent Scaling a mounted ShapeBaseImage resource from Konrad Kiss over to the DebrisData class.

There are only a couple of small changes to make:

In debris.h at around line 62, inside the DebrisData struct:

after
F32      terminalVelocity;    // max velocity magnitude
bool     ignoreWater;

add
Point3F  scale; // scale debris

Then, in debris.cpp after the #includes, add:

#include "math/mathIO.h"

At around line 66, add this to the end of the DebrisData constructor:
scale = Point3F(1, 1, 1);

In DebrisData::initPersistFields(), add this line inside the "Physical Properties" group:
addField("scale",	TypePoint3F, Offset(scale, DebrisData));

At the end of DebrisData::packData at around line 256, add:
mathWrite(*stream, scale);

At the end of DebrisData::unpackData at around line 303, add:
mathRead(*stream, &scale);

In the function Debris::prepBatchRender() at around line 794:

change this:
if( mShape )
   {
      MatrixF mat = getRenderTransform();
      GFX->setWorldMatrix( mat );

      rdata.setFadeOverride( alpha );
      mShape->render( rdata );
   }
   else
   {
      if (mPart->getCurrentObjectDetail() != -1)
      {
         MatrixF mat = getRenderTransform();
         GFX->setWorldMatrix( mat );

         rdata.setFadeOverride( alpha );
         mPart->render( rdata );
      }
   }

to this:
if( mShape )
   {
      MatrixF mat = getRenderTransform();
      GFX->setWorldMatrix( mat );

	  // scale debris >>>
	  MatrixF s(true);
	  s.scale(mDataBlock->scale);
	  GFX->multWorld(s);
	  // scale debris <<<

      rdata.setFadeOverride( alpha );
      mShape->render( rdata );
   }
   else
   {
      if (mPart->getCurrentObjectDetail() != -1)
      {
         MatrixF mat = getRenderTransform();
         GFX->setWorldMatrix( mat );

	  // scale debris >>>
	  MatrixF s(true);
	  s.scale(mDataBlock->scale);
	  GFX->multWorld(s);
	  // scale debris <<<

         rdata.setFadeOverride( alpha );
         mPart->render( rdata );
      }
   }

Recompile and you're good to go.

Inside your DebrisData datablocks, simply add a scale attribute:
scale = "0.5 0.5 0.5";

If no scale is set in the datablock, it will default to "1 1 1".

This has only been tested in Torque3D (v1.0.1) but may well work in TGEA also.

About the author

Formed in 2005, EiKON Games is an indie games development project based in the UK working on the tactical first person shooter "Epoch: Incursion". See the Join Us or Contact Us pages at http://www.eikon-games.com/


#1
10/21/2009 (5:29 am)
Thank you! I'll compile this in soon. Weird I didn't even think of this - even when I had the same problems as you did. :) Many thanks again.
#2
10/21/2009 (8:43 am)
No, thank you! It's essentially your code. I've just moved it somewhere else.. Now - where else can I put it...? :o)