com.jme3.bullet.util.DebugShapeFactory Java Examples

The following examples show how to use com.jme3.bullet.util.DebugShapeFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BulletCharacterDebugControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Update this control. Invoked once per frame during the logical-state
 * update, provided the control is enabled and added to a scene. Should be
 * invoked only by a subclass or by AbstractControl.
 *
 * @param tpf the time interval between frames (in seconds, ≥0)
 */
@Override
protected void controlUpdate(float tpf) {
    CollisionShape newShape = body.getCollisionShape();
    Vector3f newScale = newShape.getScale();
    if (myShape != newShape || !oldScale.equals(newScale)) {
        myShape = newShape;
        oldScale.set(newScale);

        Node node = (Node) spatial;
        node.detachChild(geom);

        geom = DebugShapeFactory.getDebugShape(myShape);
        geom.setName(body.toString());

        node.attachChild(geom);
    }
    geom.setMaterial(debugAppState.DEBUG_PINK);

    body.getPhysicsLocation(location);
    applyPhysicsTransform(location, Quaternion.IDENTITY);
}
 
Example #2
Source File: BulletGhostObjectDebugControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Update this control. Invoked once per frame during the logical-state
 * update, provided the control is enabled and added to a scene. Should be
 * invoked only by a subclass or by AbstractControl.
 *
 * @param tpf the time interval between frames (in seconds, ≥0)
 */
@Override
protected void controlUpdate(float tpf) {
    CollisionShape newShape = body.getCollisionShape();
    Vector3f newScale = newShape.getScale();
    if (myShape != newShape || !oldScale.equals(newScale)) {
        myShape = newShape;
        oldScale.set(newScale);

        Node node = (Node) spatial;
        node.detachChild(geom);

        geom = DebugShapeFactory.getDebugShape(myShape);
        geom.setName(body.toString());

        node.attachChild(geom);
    }
    geom.setMaterial(debugAppState.DEBUG_YELLOW);

    body.getPhysicsLocation(location);
    body.getPhysicsRotation(rotation);
    applyPhysicsTransform(location, rotation);
}
 
Example #3
Source File: SceneToolController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected void attachPhysicsSelection(Spatial geom) {
    PhysicsCollisionObject control = geom.getControl(RigidBodyControl.class);
    if (control == null) {
        control = geom.getControl(VehicleControl.class);
    }
    if (control == null) {
        control = geom.getControl(GhostControl.class);
    }
    if (control == null) {
        control = geom.getControl(CharacterControl.class);
    }
    if (control == null) {
        return;
    }
    Spatial selectionGeometry = DebugShapeFactory.getDebugShape(control.getCollisionShape());
    if (selectionGeometry != null) {
        selectionGeometry.setMaterial(blueMat);
        selectionGeometry.setLocalTransform(geom.getWorldTransform());
        toolsNode.attachChild(selectionGeometry);
        selectionShape = selectionGeometry;
    }
}
 
Example #4
Source File: BulletCharacterDebugControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Instantiate an enabled control to visualize the specified character.
 *
 * @param debugAppState which app state (not null, alias created)
 * @param body the character to visualize (not null, alias created)
 */

public BulletCharacterDebugControl(BulletDebugAppState debugAppState, PhysicsCharacter body) {
    super(debugAppState);
    this.body = body;
    myShape = body.getCollisionShape();
    oldScale.set(myShape.getScale());

    this.geom = DebugShapeFactory.getDebugShape(myShape);
    this.geom.setName(body.toString());
    geom.setMaterial(debugAppState.DEBUG_PINK);
}
 
Example #5
Source File: BulletGhostObjectDebugControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Instantiate an enabled control to visualize the specified ghost object.
 *
 * @param debugAppState which app state (not null, alias created)
 * @param body which object to visualize (not null, alias created)
 */
public BulletGhostObjectDebugControl(BulletDebugAppState debugAppState, PhysicsGhostObject body) {
    super(debugAppState);
    this.body = body;
    myShape = body.getCollisionShape();
    oldScale.set(myShape.getScale());
    
    this.geom = DebugShapeFactory.getDebugShape(myShape);
    this.geom.setName(body.toString());
    geom.setMaterial(debugAppState.DEBUG_YELLOW);
}
 
Example #6
Source File: BulletRigidBodyDebugControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Instantiate an enabled control to visualize the specified body.
 *
 * @param debugAppState which app state (not null, alias created)
 * @param body which body to visualize (not null, alias created)
 */
public BulletRigidBodyDebugControl(BulletDebugAppState debugAppState, PhysicsRigidBody body) {
    super(debugAppState);
    this.body = body;
    myShape = body.getCollisionShape();
    oldScale.set(myShape.getScale());

    this.geom = DebugShapeFactory.getDebugShape(myShape);
    this.geom.setName(body.toString());
    geom.setMaterial(debugAppState.DEBUG_BLUE);
}
 
Example #7
Source File: BulletRigidBodyDebugControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Update this control. Invoked once per frame during the logical-state
 * update, provided the control is enabled and added to a scene. Should be
 * invoked only by a subclass or by AbstractControl.
 *
 * @param tpf the time interval between frames (in seconds, ≥0)
 */
@Override
protected void controlUpdate(float tpf) {
    CollisionShape newShape = body.getCollisionShape();
    Vector3f newScale = newShape.getScale();
    if (myShape != newShape || !oldScale.equals(newScale)) {
        myShape = newShape;
        oldScale.set(newScale);

        Node node = (Node) spatial;
        node.detachChild(geom);

        geom = DebugShapeFactory.getDebugShape(myShape);
        geom.setName(body.toString());

        node.attachChild(geom);
    }
    if(body.isActive()){
        geom.setMaterial(debugAppState.DEBUG_MAGENTA);
    }else{
        geom.setMaterial(debugAppState.DEBUG_BLUE);
    }

    body.getPhysicsLocation(location);
    body.getPhysicsRotation(rotation);
    applyPhysicsTransform(location, rotation);
}
 
Example #8
Source File: CollisionTester.java    From OpenRTS with MIT License 4 votes vote down vote up
public static boolean areColliding(Asset asset1, Asset asset2, boolean debug){
		Spatial s1 = getSpatialFromAsset(asset1); 
		Spatial s2 = getSpatialFromAsset(asset2);

		PhysicsSpace space = new PhysicsSpace();
		
		RigidBodyControl ghost1 = new RigidBodyControl(getCollisionShape(asset1));
		s1.addControl(ghost1);
		space.add(ghost1);

		RigidBodyControl ghost2 = new RigidBodyControl(getCollisionShape(asset2));
		s2.addControl(ghost2);
//		ghost2.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02);
//		space.add(ghost2);

		space.update(1);
		
//		int numCollision = ghost1.getOverlappingCount();
//		boolean collision = numCollision > 0;
		Transform t = new Transform();
		t.setRotation(s2.getLocalRotation());
		t.setTranslation(s2.getLocalTranslation());
		boolean collision = false;
		for(ChildCollisionShape hull : getCollisionShape(asset2).getChildren())
			if(!space.sweepTest(hull.shape, Transform.IDENTITY, t).isEmpty()){
				collision = true;
				break;
			}
				
		
		space.remove(ghost1);
//		space.remove(ghost2);

//		if(!collision){
//			Spatial debugS2 = DebugShapeFactory.getDebugShape(ghost2.getCollisionShape());
//			debugS2.setLocalRotation(ghost2.getPhysicsRotation());
////			Spatial debugS2 = s2;
//			Material m = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
//			m.getAdditionalRenderState().setWireframe(true);
//			m.setColor("Color", ColorRGBA.Red);
//			debugS2.setMaterial(m);
//			debugS2.setLocalTranslation(ghost2.getPhysicsLocation());
//			asset2.s = debugS2;
//			//EventManager.post(new GenericEvent(debugS2));
//		}
			
		if(!collision){// && debug){
			Material m = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
			m.getAdditionalRenderState().setWireframe(true);
			m.setColor("Color", ColorRGBA.Red);
			Spatial debugS2 = DebugShapeFactory.getDebugShape(getCollisionShape(asset2));
			debugS2.setLocalTransform(t);
//			debugS2.setLocalRotation(ghost2.getPhysicsRotation());
//			debugS2.setLocalTranslation(ghost2.getPhysicsLocation());
			debugS2.setMaterial(m);

			Material m2 = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
			m2.getAdditionalRenderState().setWireframe(true);
			m2.setColor("Color", ColorRGBA.Blue);
			Geometry linegeom = new Geometry();
			Line l = new Line(debugS2.getLocalTranslation().add(0,  0, 1), ghost1.getPhysicsLocation().add(0,  0, 1));
			linegeom.setMesh(l);
			linegeom.setMaterial(m2);
	
			asset2.s = debugS2;
			if(l.getStart().distance(l.getEnd())<2)
				asset2.links.add(linegeom);
//			EventManager.post(new GenericEvent(debugS2));
//			EventManager.post(new GenericEvent(linegeom));
			
			
		}

		return collision; 
	}