I'm currently using openscenegraph for my class project to simulate traffic. I have a problem in that , i need to find collision detection between consecutive cars and stop the car if there is a collision. I have followed the osgExample- for animation. I have used an animationpath and animationpathcallback and i have implemented my own spline interpolation for the car to traverse on a spline. I tried to get the world coordinate of the bounding box like this..
* i have a class Vehicle that stores the node to which an openflight model is read into.
* the leaf node is the node having the vehicle, the parent node of this node is a transformation node which has an animationpathcallback set to, and this also has a parent node to initially set the location and orientation, (just like in the osgExample animation).
* i have a node visitor that traverses parents..so it goes from the current node to the root concatenating all the world coordinates.
* then i get the local bounding box of the node and get the minimum and maximum and multiply the world coord matrix with these points to form a new min and max point and create a new bounding box. I do this for every two node to check the intersection of two consecutive nodes.
//getWorldCoords() - forwards to a nodevisitor to get world coords matrix.
osg::Matrixd* WorldCoordsMatrix = getWorldCoords(this->m_Vehicle) ;
osg::BoundingBox VehicleBBox ;
VehicleBBox.expandBy(m_Vehicle->getBound()) ;
//Convert the vehicle local coords to world coordinates.
osg::Vec3f MinPt(VehicleBBox.xMin() , VehicleBBox.yMin() , VehicleBBox.zMin()) ;
osg::Vec3f MaxPt(VehicleBBox.xMax() , VehicleBBox.yMax() , VehicleBBox.zMax()) ;
osg::Vec3f NewMinPt , NewMaxPt ;
NewMinPt = MinPt * (*WorldCoordsMatrix) ;
NewMaxPt = MaxPt * (*WorldCoordsMatrix) ;
this->m_VehicleBoundingBox = new osg::BoundingBox(NewMinPt , NewMaxPt) ;
I am not getting correct results. I get that the bounding boxes dont intersect at all or sometimes intersect at odd places. Please let me know if i'm doing something stupid or if i my understanding of anything wrong.
Thank you,
Yours Sincerely,
Siddharth
____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
don't you have to multiply the matrix from the left side with the
vector, like this:
M * x = x',
whereas M is your 'WorldCoordsMatrix', x is your local BBox vector and
x' is the same in world coords.
hope this helps.
daniel
I read thru this at the osg site :
http://www.openscenegraph.org/projects/osg/wiki/Support/Maths/MatrixTransformations
In the end , robert says ways are defined ... i initially multiplied the matrix on the left side. But after reading this i changed it...am i wrong ?
Siddharth
Sorry for the misunderstanding...yes you're right, it has to be done on the left side. But i still dont get any valid results. Can you suggest how i can test if the world coordinates of the box after multiplication is correct or not?
Thank you,
Siddharth
Hi daniel,
http://www.openscenegraph.org/projects/osg/wiki/Support/Maths/MatrixTransformations
Siddharth
hi,
hope this helps.
daniel
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
____________________________________________________________________________________
Be a better pen pal.
Text or chat with friends inside Yahoo! Mail. See how. http://overview.mail.yahoo.com/
i just started being confused reading the link you sent me when i got
this new email of yours :)
if i am in a situation like this what i usually do is i draw what i
can't see. in your case it is the bounding box PRIOR to your
transformation to world coordinates and the one AFTER transforming. just
render to boxes or render spheres in two different colors marking the
positions of the corners.
i am sure, having something visually, you will be able to figure out the
problem.
cheers,
Yes thats a good idea..I will definitely try that and let you know how it works out. Thank you.
Siddharth
hi siddharth,
cheers,
daniel
____________________________________________________________________________________
Get easy, one-click access to your favorites.
Make Yahoo! your homepage.
I tried out a seperate code example and it did work. But i couldnt get
it working for my project. Like i previously mentioned i needed to get
the world coordinates of the boundingboxes of the loaded openflight
models and if the bounding boxes intersected , i wanted to stop the
vehicle on the animation path. The world coordinates matrix that i receive
each time, seems to be correct as i checked the position of the
ControlPointMap by using the write() in the AnimationPath class. I am now trying
to manually get the worldcoordinates and keep altering a geode and
attach it to the root node to see if the transformation made to the local
coordinates do infact match.
Is there any code snippet around that tells how to get the world
coordinates for a model on an AnimationPath? To get the world coordinates
this is what i did -
class getWorldCoordOfNodeVisitor : public osg::NodeVisitor
{
public:
getWorldCoordOfNodeVisitor():
osg::NodeVisitor(NodeVisitor::TRAVERSE_PARENTS), done(false)
{
wcMatrix= new osg::Matrixd() ;
}
virtual void apply(osg::Node &node)
{
if (!done)
{
if ( 0 == node.getNumParents() ) // no parents
{
wcMatrix->set(
osg::computeLocalToWorld(this->getNodePath()) ) ;
done = true ;
}
traverse(node) ;
}
}
osg::Matrixd* giveUpDaMat()
{
return wcMatrix ;
}
private:
bool done ;
osg::Matrix* wcMatrix ;
} ;
osg::Matrixd* getWorldCoords( osg::Node* node)
{
getWorldCoordOfNodeVisitor* ncv = new getWorldCoordOfNodeVisitor() ;
if (node && ncv)
{
node->accept(*ncv) ;
return ncv->giveUpDaMat() ;
}
else
{
return NULL ;
}
}
I have two MatrixTransform node above my vehicle model node. And i use
this to get the World Coord transfomation matrix. The first/topmost
transformation node is a static node to set the initial position and its
child node is another transformation matrix which has an
AnimationPathCallback set to(which moves the vehicle on a spline).
I also see that the animationpathcallback has an update function. Now , does the animationpathcallback automatically update my TransformMatrix to which i have set this as a callback?
Do you think the workflow is correct? Am i missing anything? ANy
suggestions?
Thanks for your help...
i can't tell you much about AnimationPath objects since i never used
them but a short glimpse on the api reference tells me that you can
easily get a transformation matrix for any point in time of the running
animation by using the method osg::AnimationPath::getMatrix(...).
(cf.
http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs/a01017.html)
another way is using a ControlPoint in your TimeControlPointMap:
osg::AnimationPath::ControlPoint::getMatrix(...)
(cf.
http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs/a01018.html)
anyway, since you control the hierarchy of the scenegraph you don't need
a nodevisitor to find the transform of the vehicle in world cords. you
KNOW how the transformations are done:
your scenegraph probably looks like this:
'rootNode'
|
osg::MatrixTransform 'vehicleAnimationX' (with
vehicleNode->setUpdateCallback(new osg::AnimationPathCallback(...))
|
'vehicleX'
...whereas X refers to one of your vehicles in the scene, meaning that
you have ONE osg::MatrixTransform node for each vehicle.
then for every time step you obtain your world transform matrix for
vehicle X by multiplying all the matrices of the scenegraph nodes
"bottom-up" and "right-to-left" like this:
transform of 'rootNode' * transform of 'vehicleAnimationX' * transform
of 'vehicleX'
probably the rootNode transformation is the identity and the vehicle has
no transform node at all so that the transformation in world coords is
simply the transformation of 'vehicleAnimation'!
i hope this helps.
if not, try looking at this example:
http://osgcvs.no-ip.com/osgarchiver/archives/February2005/0270.html
I tried getting the WC from the animationpathcallback and concatenating with other matrices along the nodes. I get wierd results. When the vehicle goes diagonally, the bounding box shrinks and otherwise it is correct. I have included two images as to what i mean. Any ideas as to what and why this might happen? I get the reasons why the bounding boxes never intersect!!
http://i226.photobucket.com/albums/dd18/siddharth_univ/ErrorBeforeIntersection.jpg
http://i226.photobucket.com/albums/dd18/siddharth_univ/ErrorAtIntersection.jpg
Thanks for your help..i havent yet tried getting the transformation matrix from controlPoint .. although i suspect it to give me the same results..
BoundingBoxes are axis-aligned, so if you have any rotations in your
transform, I don't think your method of calculating the world bounding
box will work. Try calculating the world coordinates of each of the
corners of the box rather than just the min and max, then get the min
and max to create the world-coordinate bounding box.
Also, for testing, you could try creating an AnimationPath with identity
matrices, or one with simple rotations or translations. Those make it
easy to compare the results you are getting with the ones you should
get.
Hope this helps!
--
Bryan Thrall
FlightSafety International
Bryan....@flightsafety.com
Your correct. I fixed the problem and it works well.
Thanx a lot. Thanx daniel for your suggestions too.
Siddharth
Hope this helps!
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ