roboticslibrary / rl

The Robotics Library (RL) is a self-contained C++ library for rigid body kinematics and dynamics, motion planning, and control.
https://www.roboticslibrary.org/
BSD 2-Clause "Simplified" License
880 stars 206 forks source link

Using scene to load and SimpleScene to check collision #14

Open svenkatachalam opened 4 years ago

svenkatachalam commented 4 years ago

I am trying to replicate the provided code snipets on loading a scene with rl::sg::so::scene and then performing dynamic_cast to convert the scene object into SimpleScene. Code: rl::sg::SimpleScene simpleScene = dynamic_cast<rl::sg::SimpleScene>(&scene) As both doesnt hold Base and derived class relationship between each other, this conversion fails (Getting null object). My idea is to find if two Robots collide with each other in the given scene environment.

rickertm commented 4 years ago

In order to perform collision checking with a rl::sg::SimpleScene, please make sure to use an engine that is derived from this class. rl::sg::so::Scene (an Open Inventor/Coin3D abstraction) only supports 3D visualization and does not implement rl::sg::SimpleScene..

Please use either the Bullet, FCL, ODE, PQP, or SOLID engine for this:

rl::sg::solid::Scene scene;
rl::sg::XmlFactory factory;
factory.load("scene.xml", &scene);
bool isColliding = scene.isColliding();
bool areColliding = dynamic_cast<rl::sg::SimpleScene*>(&scene)->areColliding(
  scene.getModel(0), scene.getModel(1)
);
rickertm commented 4 years ago

Since 35dc4a37de4f180da8b0422c8e64e25f2bc94c51 the dynamic_cast is no longer necessary and you can also use

bool areColliding = scene.areColliding(scene.getModel(0), scene.getModel(1));