This method does not take into account that nodes can have bounding boxes with a center thai is not located on [0,0,0] .
After a lot of gnashing of teeth I finally found that the ChildCollisionShape object has a field to store the location of the bounding box and I was able to solve the problem :
[java]
BoundingVolume bv = node.getWorldBound();
if (bv instanceof BoundingBox) {
BoundingBox bb = (BoundingBox) bv;
Vector3f center = new Vector3f();
@daenim said:
This method does not take into account that nodes can have bounding boxes with a center thai is not located on [0,0,0] .
After a lot of gnashing of teeth I finally found that the ChildCollisionShape object has a field to store the location of the bounding box and I was able to solve the problem :
[java]
BoundingVolume bv = node.getWorldBound();
if (bv instanceof BoundingBox) {
BoundingBox bb = (BoundingBox) bv;
Vector3f center = new Vector3f();
The question is : Should this not be a default behaviour for the createBoxShape method.
I think the question is: Is the center of your boxes where you think it is? I guess you use the Box mesh constructor like “new Box(position,size);” which creates a mesh that is at (position) but you attach it to a geometry that is at 0/0/0. Now what you see is at (position) but the center of the object and hence the center of gravity for the derived collision shape is at 0/0/0. As explained in the physics tutorials and manual btw but you’re not the first to fall for this constructor. Probably you learned lesson one from “SceneGraph for Dummies” forever now
Edit: Ah, I see what could go wrong now actually or what you actually mean. There was another workaround in the method that set a new bounding box to the geometry which was even more confusing but was just removed and not replaced yet. (see line 228 of CollisionShapeFactory) Thanks.
Yes, I don’t create box meshes, this is about random props for a game with bounding boxes that are not necessarily centered on the origin. Most of these props are very rectangular (like tables, benches, closets ,…) so for these props I reworked the solution a bit:
[java]
BoundingBox bb = (BoundingBox) bv;
Vector3f center = new Vector3f();
bb.getCenter(center);
Vector3f exts = new Vector3f();
bb.getExtent(exts);
BoxCollisionShape shape = new BoxCollisionShape(exts);
CompoundCollisionShape finalShape = new CompoundCollisionShape();
finalShape.addChildShape(shape, center);
RigidBodyControl rbc = new RigidBodyControl(finalShape, 0);
This works offcourse, but it would be nice (for beginners as well) that the physics creation method take into account that the center of a boundingbox is not always at the origin.
@daenim said:This works offcourse, but it would be nice (for beginners as well) that the physics creation method take into account that the center of a boundingbox is not always at the origin.
Right, and the needed origin and shape position is not the same as that of the world or local bounding box, so the factory would have to consider not only that. See the getTransform() method, something similar would have to exist for the bounding boxes, hence "TODO".