Re: [osg-users] Proximity Queries between objects

2010-08-22 Thread Sanat Talmaki
Hi Jean,

Yes, I have the local bounding spheres of each of the child nodes. But I'm 
still not clear what I need to do to join all the bounding spheres of the child 
nodes for the entire model ?

In the code below I'm loading the lwo files and creating local bounding spheres 
for each of the components:


Code:
//load the CAD files:
Backhoe = new osg::Group();
Stick = new osg::Node();
Boom = new osg::Node();
Target = new osg::Node();
Bucket = new osg::Node();
Track = new osg::Node();
Cabin = new osg::Node();
LoadBack = new osg::Node();
Stick = osgDB::readNodeFile(_BHStic_.lwo);
Boom = osgDB::readNodeFile(_BHBoom_.lwo);
Target = osgDB::readNodeFile(_BHTarg_.ac);
Bucket = osgDB::readNodeFile(_BHBuck_.lwo);
Track = osgDB::readNodeFile(_BHTrac_.lwo);
Cabin = osgDB::readNodeFile(_BHCabi_.lwo);
LoadBack = osgDB::readNodeFile(_BHLdBk_.lwo);

//bounding spheres:
//initialize here itself (unitialized references cannot exist)
const osg::BoundingSphere StickSphere = Stick-getBound();
const osg::BoundingSphere BoomSphere = Boom-getBound();
const osg::BoundingSphere TargetSphere = Bucket-getBound();
const osg::BoundingSphere BucketSphere = Cabin-getBound();
const osg::BoundingSphere TrackSphere = Target-getBound();
const osg::BoundingSphere CabinSphere = LoadBack-getBound();
const osg::BoundingSphere LoadBackSphere = Track-getBound();



Thanks,

Sanat

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=30979#30979





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Proximity Queries between objects

2010-08-22 Thread Jean-Sébastien Guay

Hello Sanat,


Yes, I have the local bounding spheres of each of the child nodes. But I'm 
still not clear what I need to do to join all the bounding spheres of the child 
nodes for the entire model ?


Please search the archives, this has been discussed before. Actually, if 
you have a hierarchy of nodes, the bounding sphere of the root of the 
subgraph contains the bounding spheres of all child nodes (thus the 
scene graph can test a single bounding sphere and discard a whole 
subgraph from rendering if it's outside the view frustum, and if it's 
inside or intersecting then it will descend and test the children, 
recursively). So you could just use the bounding sphere of your Backhoe 
Group if you've added the other models as children of it.


But what you're missing is the transformation of a bounding sphere in 
the model's local space into world space. If you have two models that 
are loaded from the same file, of course their local bounding spheres 
will be identical. It's their parents that will transform them to their 
final places in the scene. So when I talk about transforming the 
bounding sphere from local space to world space, I mean taking in 
account the models' parent transforms up to the root of the graph.


Also, a minor note, in the code you posted you're allocating a Node to 
each element, and then loading the models from the file. That's one 
unnecessary allocation for each node. For example, this:


Stick = new osg::Node();  // 1
// ...
Stick = osgDB::readNodeFile(_BHStic_.lwo);  // 2

could be replaced by only the last line:

Stick = osgDB::readNodeFile(_BHStic_.lwo);

with the same result, because in your code, a new Node will be allocated 
at line 1 above, and then in the assignment at line 2 above that Node 
will be deleted.


Hope this helps,

J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Proximity Queries between objects

2010-08-22 Thread Sanat Talmaki
Hi Jean,

I used bounding spheres on the transform nodes and that helped me get the 
distance.

Thanks

Sanat

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=30983#30983





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Proximity Queries between objects

2010-08-18 Thread Sanat Talmaki
Hi,

I tried the following code:


Code:
//BoundingSphere using computeBound()
osg::BoundingSphere bh1Sphere = backhoe1Group-computeBound();
osg::BoundingSphere bh1PATSphere = backhoe1PAT-computeBound();
//BoundingSpere using computeBound():
  osg::BoundingSphere bh2Sphere = backhoe2Group-computeBound();
  osg::BoundingSphere bh2PATSphere = backhoe2PAT-computeBound();
..
float x1, x2, y1, y2, distance;
  if(bh1Sphere.intersects(bh2Sphere))
  {
std::cout  The backhoes are colliding !! 
   std::endl;
x1 = bh1Sphere.center().x();
x2 = bh2Sphere.center().x();
y1 = bh1Sphere.center().y();
y2 = bh2Sphere.center().y();
distance = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
std::cout  distance =   distance;
std::cout  std::endl;
  }
  else
  {
x1 = bh1Sphere.center().x();
x2 = bh2Sphere.center().x();
y1 = bh1Sphere.center().y();
y2 = bh2Sphere.center().y();
distance = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
std::cout  distance =   distance;
std::cout  std::endl;
  }





However, both the spheres (1 and 2) have the same centre coordinates. When I 
try the same thing using spheres that are bounds for the top-most PATNodes, I 
again get the same result (i.e. centre coordinates are the same).

I find this confusing as both the nodes have different positions. Is this a 
sensible approach to take though ? 

Cheers,
Sanat

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=30880#30880





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Proximity Queries between objects

2010-08-18 Thread Paul Martz
Hi Sanat -- I posted to osgBullet-users with a possible fix for your osgBullet 
crash, but didn't see a reply from you. Did my suggestion resolve the issue you 
were encountering?

   -Paul

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Proximity Queries between objects

2010-08-18 Thread Jean-Sébastien Guay

Hello Sanat,


However, both the spheres (1 and 2) have the same centre coordinates. When I 
try the same thing using spheres that are bounds for the top-most PATNodes, I 
again get the same result (i.e. centre coordinates are the same).

I find this confusing as both the nodes have different positions. Is this a 
sensible approach to take though ?


getBound() returns the local bounding sphere. You need to transform it 
by the matrices (transforms) from the root to each of your models 
respectively, then you'll get the world-space bounding sphere for each 
model.


Hope this helps,

J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Proximity Queries between objects

2010-08-17 Thread J.P. Delport

Hi,

maybe you can use spheres to get an initial vector between the objects 
and then use this vector in the OSG intersection code to get more 
precision for where this vector intersects the two objects.


jp

On 16/08/10 19:00, Sanat Talmaki wrote:

Hi Paul,

That is the method I had initially thought of (i.e. the distance between 
centres of spheres obviously :) and not the other one !)

I was building osgbullet and am able to build the projects in visual studio 
successfully. All my dependencies are built right as osgWorks' binaries run 
alright. But osgBullet's binaries hang on me when I try to run them. I will 
post that in a seperate thread as it will be misleading to discuss it in this 
one.

Thanks.

Sanat

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=30798#30798





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. 
The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.


This message has been scanned for viruses and dangerous content by MailScanner, 
and is believed to be clean.  MailScanner thanks Transtec Computers for their support.


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Proximity Queries between objects

2010-08-17 Thread Sanat Talmaki
Hi,

My 3d model is a number of nodes linked by PATs and a Group node right on top. 

So when I was going through the methods, I observed that the getBound() works 
only for nodes.

Then I also came across the computeBound() which can be used with Group nodes. 

Code:
virtual BoundingSphere osg::Group::computeBound ()  
 const [virtual]

Compute the bounding sphere around Node's geometry or children.

This method is automatically called by getBound() when the bounding sphere has 
been marked dirty via dirtyBound().

Reimplemented from osg::Node.



So I wasn't sure which is the method to go ? If I compute bounding spheres for 
each node that makes up my 3d model, can I link all of them so that I can check 
for proximity between another 3d model and this one ?

If any of the examples deal with something similar, I would be glad to go 
through that but I didn't know which one. 

Thank You

Sincerely,
Sanat

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=30860#30860





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Proximity Queries between objects

2010-08-16 Thread Paul Martz

Sanat Talmaki wrote:

I am interested in knowing if there is some tool in osg that I can use to 
perform proximity queries between  a pair of objects. I looked at osgbullet. 
But it offers a lot more than what I basically need.


osgBullet doesn't do collision detection -- that would be redundant, as 
osgBullet apps already have access to Bullet. The place to look for collision 
detection operations would be Bullet's libBulletCollision. But I can tell you 
from personal experience that Bullet only cares whether two objects are in 
collision or not. It doesn't care about exact distances between non-colliding 
objects.


So, I wanted to know if there is some way in OSG I can compute the shortest distance between the boundaries of two objects. 


The obvious and simplest solution (but not very precise) would be to take the 
distance between two bounding sphere centers and subtract the two radii.


If you need a more exact solution, then I guess you could render the scene with 
the eye point at one object center looking at the other object center and 
calculate the window space z distance between the hulls of the two objects along 
the view vector and back-transform it to world space. (I know, I know... but he 
DID post this question to a 3D graphics group :-) .)


--
  -Paul Martz  Skew Matrix Software
   http://www.skew-matrix.com/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Proximity Queries between objects

2010-08-16 Thread Sanat Talmaki
Hi Jean,

I am looking at osgBullet but for some reason all the binaries dont run after 
building it. 
Also, is there any tutorial that explains how to link osgbullet with an already 
existing osg project ?

Thanks

Sanat

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=30797#30797





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Proximity Queries between objects

2010-08-16 Thread Sanat Talmaki
Hi Paul,

That is the method I had initially thought of (i.e. the distance between 
centres of spheres obviously :) and not the other one !)

I was building osgbullet and am able to build the projects in visual studio 
successfully. All my dependencies are built right as osgWorks' binaries run 
alright. But osgBullet's binaries hang on me when I try to run them. I will 
post that in a seperate thread as it will be misleading to discuss it in this 
one.

Thanks.

Sanat

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=30798#30798





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Proximity Queries between objects

2010-08-15 Thread Sanat Talmaki
Hi,

I am interested in knowing if there is some tool in osg that I can use to 
perform proximity queries between  a pair of objects. I looked at osgbullet. 
But it offers a lot more than what I basically need.

One approach that I have thought of is using distance formula between the 
PATs-position of the two objects. But with this, I won't get the object edge 
to object edge distance (i think)

So, I wanted to know if there is some way in OSG I can compute the shortest 
distance between the boundaries of two objects. 

Thank You.

Sincerely,
Sanat

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=30749#30749





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Proximity Queries between objects

2010-08-15 Thread Jean-Sébastien Guay

Hello Sanat,


So, I wanted to know if there is some way in OSG I can compute the shortest 
distance between the boundaries of two objects.


Well, in OSG you have access to an approximated bounding sphere and 
bounding box of your geometry (these may be very approximate though, 
i.e. they may not closely match the actual geometry). You can easily 
calculate the distance between two boxes or even more easily between two 
spheres.


But I would look into using some physics engine for this anyways, even 
if it offers more than what you need at present, because it's likely 
you'll need what it offers eventually... It's really a matter of using 
the best tool for the job, and physics/collision detection engines are 
specialized at that sort of stuff.


Hope this helps,

J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org