Debug shapes not matching collision shapes?

Is it possible to make a BoxCollisionShape rotate along with the spatial it is attached to? In the following code the Debug shapes show the CollisionsShapes that I intend to use, but the BoxCollisionShape is apparently not rotated. It seems that the Collision Shape is Axis Aligned (global coordinates). Just like BoundinVolumes (AABB). The result is that the CollisionShapes are said to be overlapping when the Debug shapes are not. Is this the way it should be?



[java]import com.jme3.app.Application;

import com.jme3.scene.Node;

import com.jme3.app.SimpleApplication;

import com.jme3.bullet.BulletAppState;

import com.jme3.bullet.collision.shapes.BoxCollisionShape;

import com.jme3.bullet.control.GhostControl;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;



public class TestOverlap3 extends SimpleApplication {



protected Node robotANode;

protected Geometry geomA1;

protected Node robotBNode;

protected Geometry geomB1;



private BulletAppState bulletAppState;

private GhostControl ghostA;

private GhostControl ghostB;



public TestOverlap3() {

super();

}



public static void main(String[] args) {

Application app = new TestOverlap3();

app.start();

}



@Override

public void simpleInitApp() {

bulletAppState = new BulletAppState();

bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);

stateManager.attach(bulletAppState);



ghostA = new GhostControl(new BoxCollisionShape(new Vector3f(2f, 0.5f, 0.5f)));

ghostB = new GhostControl(new BoxCollisionShape(new Vector3f(2f, 0.5f, 0.5f)));



bulletAppState.getPhysicsSpace().enableDebug(assetManager);

bulletAppState.getPhysicsSpace().add(ghostA);

bulletAppState.getPhysicsSpace().add(ghostB);



robotANode = new Node();

rootNode.attachChild(robotANode);



Box boxA = new Box(new Vector3f(0, 0, 0), 2, 0.5f, 0.5f);

geomA1 = new Geometry("BoxA", boxA);

setMaterial(geomA1, ColorRGBA.Yellow, "Common/MatDefs/Misc/WireColor.j3md");

geomA1.addControl(ghostA);

robotANode.attachChild(geomA1);

robotANode.rotate(0,0,1);





robotBNode = new Node();

rootNode.attachChild(robotBNode);



geomB1 = new Geometry("BoxB", boxA);

setMaterial(geomB1, ColorRGBA.Green, "Common/MatDefs/Misc/WireColor.j3md");

geomB1.addControl(ghostB);

robotBNode.attachChild(geomB1);

robotBNode.move(3,0,0);

robotBNode.rotate(0,0,1);



flyCam.setDragToRotate(true);

flyCam.setMoveSpeed(20);

}



private void setMaterial(Geometry geometry, ColorRGBA color, String type) {

Material material = new Material(assetManager, type);

material.setColor("Color", color);

geometry.setMaterial(material);

}



@Override

public void simpleUpdate(float tpf) {

float curTime = timer.getTimeInSeconds();



robotANode.setLocalTranslation(2 * (float) Math.cos((double) curTime), 0, 0);



if (ghostB.getOverlappingCount() > 0) {

geomB1.getMaterial().setColor("Color",ColorRGBA.Red);

} else {

geomB1.getMaterial().setColor("Color",ColorRGBA.Green);

}

}

}[/java]

No they do rotate. Do you use the debug view (physicsSpace.enableDebug(assetManager)) and see that they dont??

The debug shapes rotate, but apparently the actual collision shapes do not.



getOverlappingCount() returns a value > 0 also when the debug shapes does not overlap. It seems like the OverlappingCount is based on Axis aligned bounding boxes (global coordinates).



Is it something Im not doing correctly?

Hm, check the bullet manual/forum if that is really so, from what I know GhostObjects do rotate. But I mainly used non-rotating ones so I might be wrong.

Hello!



Actually, a few months ago when I was playing around with occlusion using bounding boxes I ran into this as well. I fought and fought with it, but for the life of me I couldn’t get a BoxCollisionShape, on it’s own; no physics, to rotate… I think. However, since there wasn’t a way to visualize just the BoxCollisionShape back then other than mimicking it with an actual geometry, I couldn’t figure out what the heck was going on. The geometry looked good, but the way the collision shape was responding was not adding up to what I was seeing.



Ended up just giving up and accepting that the Axis Aligned version was good enough :stuck_out_tongue: Sorry if this is useless XD



~FlaH

Thank you both. It is definitely not useless. Now I wont have to spend a lot of time looking for an error in my own understanding of the code :slight_smile: I will check some other collisionShapes instead, or add some rotating functionality of my own (if Im able to…).

normen said:
debug view (physicsSpace.enableDebug(assetManager))


How can I see CapsuleCollisionShapes? This works on box and sphere rigidbodies but not capsules. attachDebugShape is also depreciated.

Also you can applyforce off center to rotate stuff, but it's hard to get accurate.

CapsuleCollisionShape get displayed in debug mode.