HashMap<PhysicsVehicle, Spatial> oldObjects = vehicles;
vehicles = new HashMap<PhysicsVehicle, Spatial>();
Collection<PhysicsVehicle> current = space.getVehicleList();
//create new map
for (Iterator<PhysicsVehicle> it = current.iterator(); it.hasNext();) {
PhysicsVehicle physicsObject = it.next();
//copy existing spatials
if (oldObjects.containsKey(physicsObject)) {
Spatial spat = oldObjects.get(physicsObject);
vehicles.put(physicsObject, spat);
oldObjects.remove(physicsObject);
} else {
if (filter == null || filter.displayObject(physicsObject)) {
logger.log(Level.FINE, "Create new debug Vehicle");
//create new spatial
Node node = new Node(physicsObject.toString());
node.addControl(new BulletVehicleDebugControl(this, physicsObject));
vehicles.put(physicsObject, node);
physicsDebugRootNode.attachChild(node);
}
}
}
//remove leftover spatials
for (Map.Entry<PhysicsVehicle, Spatial> entry : oldObjects.entrySet()) {
PhysicsVehicle object = entry.getKey();
Spatial spatial = entry.getValue();
spatial.removeFromParent();
}
}