simCheckCollision(objectHandle, sim_handle_all) not working
Posted: 26 May 2016, 13:20
Hi Coppelia Robotics,
Through a C++ plugin I am trying to detect collisions between objects and I noticed that it does not always work. When I know that two objects are colliding simCheckCollision(objectHandle1, objectHandle2) returns true but simCheckCollision(objectHandle1, sim_handle_all) returns false.
The plugin operates similarly to the bubblerob plugin. When the simulation starts, objects are created, set to a position and orientation, and finally checked for collision. Here is some relevant code:
if (message == sim_message_eventcallback_simulationabouttostart) {
float size1[3] = { 0.1,0.1,0.1 };
float position1[3] = { 0,-0.4,0.2 };
float orientation1[3] = { -0.3,0.8,-0.5 } ;
float size2[3] = { 0.1,0.1,0.1 };
float position2[3] = { 0,-0.45,0.25 };
float orientation2[3] = { 0.3, 0.2, 0 };
int cube1 = simCreatePureShape(0, 16, size1, 1, NULL);
simSetObjectPosition(cube1, -1, position1);
simSetObjectOrientation(cube1, -1, orientation1);
int cube2 = simCreatePureShape(0, 16, size2, 1, NULL);
simSetObjectPosition(cube2, -1, position2);
simSetObjectOrientation(cube2, -1, orientation2);
std::cout << "cube 1 to cube 2 collision = " << simCheckCollision(cube1, cube2) << std::endl; // prints 1 (prints 0 if cube 1 and 2 are in the same position and orientation)
std::cout << "cube 1 to all_except_self collision = " << simCheckCollision(cube1, sim_handle_all_except_self) << std::endl; // prints -1
std::cout << "cube 1 to all collision = " << simCheckCollision(cube1, sim_handle_all) << std::endl; // prints 0
std::cout << "cube 2 to all collision = " << simCheckCollision(cube2, sim_handle_all) << std::endl; // prints 0
if (simCheckCollision(cube1, sim_handle_all) == true) {
std::cout << "objects collided" << std::endl; // never gets here...
}
}
I am not sure what is going wrong.
Cheers, Frank
- edit: just a small update, when the objects cube1 and cube2 are in the exact same position and orientation simCheckObjectCollision(cube1, cube2) also doesn't work anymore.
Through a C++ plugin I am trying to detect collisions between objects and I noticed that it does not always work. When I know that two objects are colliding simCheckCollision(objectHandle1, objectHandle2) returns true but simCheckCollision(objectHandle1, sim_handle_all) returns false.
The plugin operates similarly to the bubblerob plugin. When the simulation starts, objects are created, set to a position and orientation, and finally checked for collision. Here is some relevant code:
if (message == sim_message_eventcallback_simulationabouttostart) {
float size1[3] = { 0.1,0.1,0.1 };
float position1[3] = { 0,-0.4,0.2 };
float orientation1[3] = { -0.3,0.8,-0.5 } ;
float size2[3] = { 0.1,0.1,0.1 };
float position2[3] = { 0,-0.45,0.25 };
float orientation2[3] = { 0.3, 0.2, 0 };
int cube1 = simCreatePureShape(0, 16, size1, 1, NULL);
simSetObjectPosition(cube1, -1, position1);
simSetObjectOrientation(cube1, -1, orientation1);
int cube2 = simCreatePureShape(0, 16, size2, 1, NULL);
simSetObjectPosition(cube2, -1, position2);
simSetObjectOrientation(cube2, -1, orientation2);
std::cout << "cube 1 to cube 2 collision = " << simCheckCollision(cube1, cube2) << std::endl; // prints 1 (prints 0 if cube 1 and 2 are in the same position and orientation)
std::cout << "cube 1 to all_except_self collision = " << simCheckCollision(cube1, sim_handle_all_except_self) << std::endl; // prints -1
std::cout << "cube 1 to all collision = " << simCheckCollision(cube1, sim_handle_all) << std::endl; // prints 0
std::cout << "cube 2 to all collision = " << simCheckCollision(cube2, sim_handle_all) << std::endl; // prints 0
if (simCheckCollision(cube1, sim_handle_all) == true) {
std::cout << "objects collided" << std::endl; // never gets here...
}
}
I am not sure what is going wrong.
Cheers, Frank
- edit: just a small update, when the objects cube1 and cube2 are in the exact same position and orientation simCheckObjectCollision(cube1, cube2) also doesn't work anymore.