Hello Ahmed,

Muhammad Ahmed wrote:
> Hi,
> I am new to OpenSG and have a question as follows,
> I am loading a VRML file to display in my OpenSG scene , whenever I
> load the vrml file and dispaly, the object is created far away from
> the center or orign.
> I have to write a general purpose code that can bring that object
> approximately to the orign of the 3D coordinate system.
> I have read about translations a bit, but to apply a transformation or
> translation, I have to know what is the current position of my Node
> loaded through VRML file based upon which I can calculate my Matrix
> for translation. and I dont know exactly how to get current position
> of my object loaded through VRML file.

well, what exactly the position of a 3D object is, is up to definition, 
but for the general problem of centering an object around the origin, 
you can use the center of the bounding box as an approximation.
To get the bounding volume (in local coordinates) of a node you can use

NodePtr n;
DynamicVolume vol = n->getVolume(true);

or to get it in world coordinates:
NodePtr n;
DynamicVolume vol;
n->getWorldVolume(vol);

Then get the bounds from the volume:
Pnt3f min, max;
vol->getBounds(min, max);

And use that to compute the center of the objects bounding box and the 
translation to move that center into the origin.

> Any coding example to find position and calculate translation Matrix
> would be really helpful ,

If you have not seen it already I recommend taking a look at the 
tutorials <http://opensg.vrsource.org/trac/wiki/Tutorial>

        Hope it helps,
                Carsten


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to