Game Development Community

Water coverage calculation

by Shaderman · in Torque Game Engine Advanced · 10/02/2007 (3:35 am) · 7 replies

To get Erik Madison's swim code working, I fixed the water coverage calculation. I know there's a swim animations thread already describing this problem, but since the water coverage can be used in more places, I thought i might better start a new topic.

Maybe somebody is interested in getting other things to work as well like splash sounds (they don't seem to work properly out of the box for me), bubbles and a "isWet flag" for weapons for example :)

Here are the changes I made to TGEA 1.0.3:

In game/shapeBase.cpp - waterFind function I changed

if (wbox.isOverlapped(sbox)) {
      sWaterType = wb->getLiquidType();
      if (wbox.max.z < sbox.max.z)
         sWaterCoverage = (wbox.max.z - sbox.min.z) / (sbox.max.z - sbox.min.z);
      else
         sWaterCoverage = 1;

      sWaterViscosity = wb->getViscosity();
      sWaterDensity   = wb->getDensity();
      sWaterHeight    = wb->getSurfaceHeight();
   }

to

if (wbox.isOverlapped(sbox)) {
      sWaterType = wb->getLiquidType();
	  sWaterHeight = wb->getCenter();

	  if(sbox.min.z < sWaterHeight)
		sWaterCoverage = (sWaterHeight - sbox.min.z) / sbox.len_z();
   }

and in terrain/waterblock.h I added this single line almost at the bottom of the file:

virtual void updateReflection();
   virtual void inspectPostApply();

   [b]F32 getCenter ( void ) { return mObjToWorld.getPosition().z; }[/b]

   DECLARE_CONOBJECT(WaterBlock);

Enjoy!

#1
05/20/2008 (11:26 pm)
Thanks Stefan
#2
06/08/2008 (1:36 am)
Stefan I have a bit more with this I am hoping you have the solution to. If you are in 3rd person the animation will not update unless you move the camera below the surface.
#3
06/08/2008 (2:48 am)
Sorry Ron, I don't have this problem (now with 1.7). Check the sWaterCoverage value when the player gets his feet wet and when he's completely covered with water.
#4
06/10/2008 (8:26 pm)
Thanks Stefan, I go that part working, since you are using that resource I will ask, have you experienced any multiplayer issues? If so have you been able to fix them and how?

I ask because after adding that code I can no longer use multiplayer.
#5
06/10/2008 (9:20 pm)
Sorry, we're working on a SP only game and I never tried it with MP :/
#6
12/05/2008 (9:07 pm)
So then do I just uncomment out the whole function?
#7
12/05/2008 (9:27 pm)
Uncomment it, and replace the parts as specified above.