OceanExample - MakeTransform - Much different results with different boat model

Hi,

I need help understanding what may be at play here...

With the testCollision option to secure a boat for myself on the ocean, I promptly used a different boat I got from a collada dae file (a wooden dory from google sketchup 3dwarehouse), and ignored the one coming with the example because it was white and devoid of interesting texture.

Iwas surprised to see my boat (finally when I figured out where it was) merrily bouncy along... not on the ocean surface, mind you... but moving up and down what would look like 20 feet in the air.

So... please help me understand what I will have to watch out for using different models... and how to allow for and correct for these differences?

I tried changing the scale returned from GetOceanSurfaceHeightAt(), and to no avail... then I tried just using 0 in the makeTranslate just to shut it up... and was surprised when it just ignored me and kept bobbing up and down in the air. I guess something else is responsible for positioning the boat on the surface? And NOT the node update visitor boatPositionCallback?

well...
I finally got my boat INTO the water after findiing that the one supplied with the example was perfectly happy sitting IN the water instead of floating around in the air...

I also got a shark model which exhibited the same characteristic of floating 10 feet ABOVE the water instead of IN it... so I applied a negative value of 1.5 to 2 to each of the models z axis height parameters with regard to the matrixTraslate in the callback to get them in the water...

I still would like to know the whys and wherefors and how comes surrounding this effect.... do different models have built in heights with respect to 0,0,0?

OceanExample - MakeTransform - Much different results with different boat model

Hi Tim,

Quote:

I still would like to know the whys and wherefors and how comes surrounding this effect.... do different models have built in heights with respect to 0,0,0?

It all depends on how the model was built in the modeling program...
Clearly if one model's local origin (its own (0,0,0)) is 10 meters below
the bottom of the hull, then when just naively placing it in the scene
at the world origin, it will look like it's floating in the air...

If you can't load the boat model in a modeling program, you can easily
make a model that is just a plane at Z=0. Then load that along with your
boat model, and see if the boat model floats high above that plane.

There are a few solutions you could adopt to make sure this doesn't
happen. You could make sure your models are built with a local origin
that makes sense. For a boat it could be the center in XY, and Z at the
"normal" waterline. For a car it might be in the center in XY, and Z at
the bottom of the wheels.

Or you could make a small function that would find the bounding box of
the model (try the osg::ComputeBoundsVisitor) and then from that tries
to find a correct position to move the local origin to, using a
MatrixTransform to decorate your model's subgraph and setting that
matrix to translate the local origin. For example if your boat was 10m
higher than you wanted, the MatrixTransform would have a translation by
(0,0,-10). Then you just pass that node as the new root of the model,
and from then on the model will be placed correctly. This offset could
also be stored in a config file, or you can save out the transform I
just mentioned and use that instead of your previous model with a bad
local origin.

Only registered users can see emails on this board!Get registred or enter the forums!

)> wrote:

Quote:

Hi Tim,

Quote:

I still would like to know the whys and wherefors and how comes surrounding this effect.... do different models have built in heights with respect to 0,0,0?

It all depends on how the model was built in the modeling program... Clearly if one model's local origin (its own (0,0,0)) is 10 meters below the bottom of the hull, then when just naively placing it in the scene at the world origin, it will look like it's floating in the air...

If you can't load the boat model in a modeling program, you can easily make a model that is just a plane at Z=0. Then load that along with your boat model, and see if the boat model floats high above that plane.

There are a few solutions you could adopt to make sure this doesn't happen. You could make sure your models are built with a local origin that makes sense. For a boat it could be the center in XY, and Z at the "normal" waterline. For a car it might be in the center in XY, and Z at the bottom of the wheels.

Or you could make a small function that would find the bounding box of the model (try the osg::ComputeBoundsVisitor) and then from that tries to find a correct position to move the local origin to, using a MatrixTransform to decorate your model's subgraph and setting that matrix to translate the local origin. For example if your boat was 10m higher than you wanted, the MatrixTransform would have a translation by (0,0,-10). Then you just pass that node as the new root of the model, and from then on the model will be placed correctly. This offset could also be stored in a config file, or you can save out the transform I just mentioned and use that instead of your previous model with a bad local origin.

Thank you!
I wasn't expecting multiple models to exhibit the same behaviour. I'll try some different types other than collada models to see how they do.

I'll see about the bounding box idea... sounds useful... Thanks for the tips.

I'll keep studying... there is much I would like to do with this over and under water world... mostly under, but I'm really interested in my own project of building a nice underwater vehicle with navigation, sonar, inertial guidance and hopefully without tether... of course I need to start with tether so far, and will have to learn much to get there.

As part of the design... modeling came into play, and I am trying to get up to speed. OSGOcean will be a neat way of realizing part of my hopes.

A small step in this direction is trying to place my vehicle model into the environment and be able to control its multiple motors within OSGOcean.
Ahhh.... so much time and so little to do.

I did a small bit of Blender, then switched to sketchup for speed, and then found the relationship of it to collada. I'll get it over here soon.

I'm a diver, and so found e-diving on the net... and the Venus underwater simulator project sounds great. Hope to know enough to help some day.

osg::ref_ptr<osg::PositionAttitudeTransform> boatTransform = new osg::PositionAttitudeTransform;
//Name that NODE!
//Hmmm... there seems to be some discussion on wether to use the node of the
// transform or the node of the boat! (which... I wonder?...)
boatTransform->setName("BOAT");
boatTransform->addChild(boat.get());
//This I did for my collada models... and it seems to help... but still needs "tweaking"
//Like... "You've... got (to bail)" (sorry... old movie)
const osg::BoundingSphere& bs = boat->getBound();
boatTransform->setPivotPoint(bs.center());
//I want my boat pointing in a direction I can manipulate easily... "y"
osg::Vec3 boatPosit(0,100,1.5);
boatTransform->setPosition( boatPosit );
boatTransform->setAttitude(osg::Quat( osg::DegreesToRadians(90.0) , osg::Vec3(0,0,1) ));
//I hope this is the right thing to do...
boatTransform->setUpdateCallback( new BoatPositionCallback(scene->getOceanScene()) );

scene->getOceanScene()->addChild(boatTransform.get());
}

[

The above stuff at least landed my collada boat in the water... and then...
"tweaking" for the appropriate waterline.

Oh... I left the "hmmm... " note in there because I started using a PositionAttitudeTransform in my call back for a camera lately... and there has been a discussion on using the transform or its child when adding the node... (sigh)

Thank you!
Please comment if you feel any need... because I need a disturbance in the force...

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou cannot download files in this forum