Search in sources :

Example 1 with PhysicsGhostObject

use of com.jme3.bullet.objects.PhysicsGhostObject in project jmonkeyengine by jMonkeyEngine.

the class BulletDebugAppState method updateGhosts.

private void updateGhosts() {
    HashMap<PhysicsGhostObject, Spatial> oldObjects = ghosts;
    ghosts = new HashMap<PhysicsGhostObject, Spatial>();
    Collection<PhysicsGhostObject> current = space.getGhostObjectList();
    //create new map
    for (Iterator<PhysicsGhostObject> it = current.iterator(); it.hasNext(); ) {
        PhysicsGhostObject physicsObject = it.next();
        //copy existing spatials
        if (oldObjects.containsKey(physicsObject)) {
            Spatial spat = oldObjects.get(physicsObject);
            ghosts.put(physicsObject, spat);
            oldObjects.remove(physicsObject);
        } else {
            if (filter == null || filter.displayObject(physicsObject)) {
                logger.log(Level.FINE, "Create new debug GhostObject");
                //create new spatial
                Node node = new Node(physicsObject.toString());
                node.addControl(new BulletGhostObjectDebugControl(this, physicsObject));
                ghosts.put(physicsObject, node);
                physicsDebugRootNode.attachChild(node);
            }
        }
    }
    //remove leftover spatials
    for (Map.Entry<PhysicsGhostObject, Spatial> entry : oldObjects.entrySet()) {
        PhysicsGhostObject object = entry.getKey();
        Spatial spatial = entry.getValue();
        spatial.removeFromParent();
    }
}
Also used : Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node) PhysicsGhostObject(com.jme3.bullet.objects.PhysicsGhostObject) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

PhysicsGhostObject (com.jme3.bullet.objects.PhysicsGhostObject)1 Node (com.jme3.scene.Node)1 Spatial (com.jme3.scene.Spatial)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1