Jump to content

getSurfaceHeight


Gibby

Recommended Posts

Greets All:


I have a network-friendly submarine nearly finished but have an issue with waterblocks for which I've searched the net as well as the source code to solve:


I have a waterblock in my level:

 


  new WaterBlock(theOcean) {
     gridElementSize = "5";
     gridSize = "5";
     density = "1";

     ...blahblahblah

 

then in my commands.cs, I need to find the surface height so I do it like this:

 


...blahblahblah

if(isObject(theOcean))
{
     %id = theOcean.getID();
     %surface = %id.getSurfaceHeight();
     echo("water block id: "@%id@" surface level is: "@%surface);     
 }


...blahblahblah

 

which gives me a console error:

 


Unknown command getSurfaceHeight

 

in line 134 in waterBlock.h, I see in the public:

 


  virtual F32 getSurfaceHeight( const Point2F &pos ) const;

 

and this same code is in waterPlane and river - yet i can't seem to get a surfaceHeight from anything in the waterObject class- what am I missing?

Link to comment
Share on other sites

Yeah, have to add this in Engine/source/environment/waterBlock.cpp :

// up at the top with the other includes:
#include "console/engineAPI.h"
 
// ....
 
// down at the bottom of the file:
DefineEngineMethod(WaterBlock, getSurfaceHeight, F32, (const Point2F pos), ,
	"@brief Return the height of the waterblock surface at position pos.")
{
	return object->getSurfaceHeight(pos);
}

 

Note that it takes a Point2F parameter - so

%obj.getSurfaceHeight("0.0 0.0");

should get us the surface height at the center of the waterblock. I guess you could just default it to

// up at the top with the other includes:
DefineEngineMethod(WaterBlock, getSurfaceHeightAtCenter, F32, (), ,
	"@brief Return the height of the waterblock surface at position 0.0, 0.0.")
{
	Point2F pos = Point2F(0.0, 0.0);
	return object->getSurfaceHeight(pos);
}

I was thinking that you could make it a read-only property and just call this in the "getter," but hell, might as well just do this.


By the way - that compiles, but I haven't tested it....

Link to comment
Share on other sites

Yeah, have to add this in Engine/source/environment/waterBlock.cpp :
// up at the top with the other includes:
#include "console/engineAPI.h"
 
// ....
 
// down at the bottom of the file:
DefineEngineMethod(WaterBlock, getSurfaceHeight, F32, (const Point2F pos), ,
	"@brief Return the height of the waterblock surface at position pos.")
{
	return object->getSurfaceHeight(pos);
}

 

Oh duh, kinda missing a big piece...


...and yeah works like a charm, thank you!!!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...