use of com.jme3.bullet.collision.shapes.CollisionShape in project jmonkeyengine by jMonkeyEngine.
the class VehicleControl method cloneForSpatial.
@Override
public Control cloneForSpatial(Spatial spatial) {
VehicleControl control = new VehicleControl(collisionShape, mass);
control.setAngularFactor(getAngularFactor());
control.setAngularSleepingThreshold(getAngularSleepingThreshold());
control.setAngularVelocity(getAngularVelocity());
control.setCcdMotionThreshold(getCcdMotionThreshold());
control.setCcdSweptSphereRadius(getCcdSweptSphereRadius());
control.setCollideWithGroups(getCollideWithGroups());
control.setCollisionGroup(getCollisionGroup());
control.setDamping(getLinearDamping(), getAngularDamping());
control.setFriction(getFriction());
control.setGravity(getGravity());
control.setKinematic(isKinematic());
control.setLinearSleepingThreshold(getLinearSleepingThreshold());
control.setLinearVelocity(getLinearVelocity());
control.setPhysicsLocation(getPhysicsLocation());
control.setPhysicsRotation(getPhysicsRotationMatrix());
control.setRestitution(getRestitution());
control.setFrictionSlip(getFrictionSlip());
control.setMaxSuspensionTravelCm(getMaxSuspensionTravelCm());
control.setSuspensionStiffness(getSuspensionStiffness());
control.setSuspensionCompression(tuning.suspensionCompression);
control.setSuspensionDamping(tuning.suspensionDamping);
control.setMaxSuspensionForce(getMaxSuspensionForce());
for (Iterator<VehicleWheel> it = wheels.iterator(); it.hasNext(); ) {
VehicleWheel wheel = it.next();
VehicleWheel newWheel = control.addWheel(wheel.getLocation(), wheel.getDirection(), wheel.getAxle(), wheel.getRestLength(), wheel.getRadius(), wheel.isFrontWheel());
newWheel.setFrictionSlip(wheel.getFrictionSlip());
newWheel.setMaxSuspensionTravelCm(wheel.getMaxSuspensionTravelCm());
newWheel.setSuspensionStiffness(wheel.getSuspensionStiffness());
newWheel.setWheelsDampingCompression(wheel.getWheelsDampingCompression());
newWheel.setWheelsDampingRelaxation(wheel.getWheelsDampingRelaxation());
newWheel.setMaxSuspensionForce(wheel.getMaxSuspensionForce());
//TODO: bad way finding children!
if (spatial instanceof Node) {
Node node = (Node) spatial;
Spatial wheelSpat = node.getChild(wheel.getWheelSpatial().getName());
if (wheelSpat != null) {
newWheel.setWheelSpatial(wheelSpat);
}
}
}
control.setApplyPhysicsLocal(isApplyPhysicsLocal());
return control;
}
use of com.jme3.bullet.collision.shapes.CollisionShape in project jmonkeyengine by jMonkeyEngine.
the class CollisionShapeFactory method getTransform.
/**
* returns the correct transform for a collisionshape in relation
* to the ancestor for which the collisionshape is generated
* @param spat
* @param parent
* @return
*/
private static Transform getTransform(Spatial spat, Spatial parent) {
Transform shapeTransform = new Transform();
Spatial parentNode = spat.getParent() != null ? spat.getParent() : spat;
Spatial currentSpatial = spat;
//if we have parents combine their transforms
while (parentNode != null) {
if (parent == currentSpatial) {
//real parent -> only apply scale, not transform
Transform trans = new Transform();
trans.setScale(currentSpatial.getLocalScale());
shapeTransform.combineWithParent(trans);
parentNode = null;
} else {
shapeTransform.combineWithParent(currentSpatial.getLocalTransform());
parentNode = currentSpatial.getParent();
currentSpatial = parentNode;
}
}
return shapeTransform;
}
use of com.jme3.bullet.collision.shapes.CollisionShape in project jmonkeyengine by jMonkeyEngine.
the class CollisionShapeFactory method shiftCompoundShapeContents.
/**
* This method moves each child shape of a compound shape by the given vector
* @param vector
*/
public static void shiftCompoundShapeContents(CompoundCollisionShape compoundShape, Vector3f vector) {
for (Iterator<ChildCollisionShape> it = new LinkedList(compoundShape.getChildren()).iterator(); it.hasNext(); ) {
ChildCollisionShape childCollisionShape = it.next();
CollisionShape child = childCollisionShape.shape;
Vector3f location = childCollisionShape.location;
Matrix3f rotation = childCollisionShape.rotation;
compoundShape.removeChildShape(child);
compoundShape.addChildShape(child, location.add(vector), rotation);
}
}
use of com.jme3.bullet.collision.shapes.CollisionShape in project jmonkeyengine by jMonkeyEngine.
the class CollisionShapeFactory method createCompoundShape.
private static CompoundCollisionShape createCompoundShape(Node realRootNode, Node rootNode, CompoundCollisionShape shape, boolean meshAccurate, boolean dynamic) {
for (Spatial spatial : rootNode.getChildren()) {
if (spatial instanceof TerrainQuad) {
Boolean bool = spatial.getUserData(UserData.JME_PHYSICSIGNORE);
if (bool != null && bool.booleanValue()) {
// go to the next child in the loop
continue;
}
TerrainQuad terrain = (TerrainQuad) spatial;
Transform trans = getTransform(spatial, realRootNode);
shape.addChildShape(new HeightfieldCollisionShape(terrain.getHeightMap(), trans.getScale()), trans.getTranslation(), trans.getRotation().toRotationMatrix());
} else if (spatial instanceof Node) {
createCompoundShape(realRootNode, (Node) spatial, shape, meshAccurate, dynamic);
} else if (spatial instanceof TerrainPatch) {
Boolean bool = spatial.getUserData(UserData.JME_PHYSICSIGNORE);
if (bool != null && bool.booleanValue()) {
// go to the next child in the loop
continue;
}
TerrainPatch terrain = (TerrainPatch) spatial;
Transform trans = getTransform(spatial, realRootNode);
shape.addChildShape(new HeightfieldCollisionShape(terrain.getHeightMap(), terrain.getLocalScale()), trans.getTranslation(), trans.getRotation().toRotationMatrix());
} else if (spatial instanceof Geometry) {
Boolean bool = spatial.getUserData(UserData.JME_PHYSICSIGNORE);
if (bool != null && bool.booleanValue()) {
// go to the next child in the loop
continue;
}
if (meshAccurate) {
CollisionShape childShape = dynamic ? createSingleDynamicMeshShape((Geometry) spatial, realRootNode) : createSingleMeshShape((Geometry) spatial, realRootNode);
if (childShape != null) {
Transform trans = getTransform(spatial, realRootNode);
shape.addChildShape(childShape, trans.getTranslation(), trans.getRotation().toRotationMatrix());
}
} else {
Transform trans = getTransform(spatial, realRootNode);
shape.addChildShape(createSingleBoxShape(spatial, realRootNode), trans.getTranslation(), trans.getRotation().toRotationMatrix());
}
}
}
return shape;
}
use of com.jme3.bullet.collision.shapes.CollisionShape in project jmonkeyengine by jMonkeyEngine.
the class DebugShapeFactory method getDebugShape.
/** The maximum corner for the aabb used for triangles to include in ConcaveShape processing.*/
// private static final Vector3f aabbMax = new Vector3f(1e30f, 1e30f, 1e30f);
/** The minimum corner for the aabb used for triangles to include in ConcaveShape processing.*/
// private static final Vector3f aabbMin = new Vector3f(-1e30f, -1e30f, -1e30f);
/**
* Creates a debug shape from the given collision shape. This is mostly used internally.<br>
* To attach a debug shape to a physics object, call <code>attachDebugShape(AssetManager manager);</code> on it.
* @param collisionShape
* @return
*/
public static Spatial getDebugShape(CollisionShape collisionShape) {
if (collisionShape == null) {
return null;
}
Spatial debugShape;
if (collisionShape instanceof CompoundCollisionShape) {
CompoundCollisionShape shape = (CompoundCollisionShape) collisionShape;
List<ChildCollisionShape> children = shape.getChildren();
Node node = new Node("DebugShapeNode");
for (Iterator<ChildCollisionShape> it = children.iterator(); it.hasNext(); ) {
ChildCollisionShape childCollisionShape = it.next();
CollisionShape ccollisionShape = childCollisionShape.shape;
Geometry geometry = createDebugShape(ccollisionShape);
// apply translation
geometry.setLocalTranslation(childCollisionShape.location);
// apply rotation
TempVars vars = TempVars.get();
Matrix3f tempRot = vars.tempMat3;
tempRot.set(geometry.getLocalRotation());
childCollisionShape.rotation.mult(tempRot, tempRot);
geometry.setLocalRotation(tempRot);
vars.release();
node.attachChild(geometry);
}
debugShape = node;
} else {
debugShape = createDebugShape(collisionShape);
}
if (debugShape == null) {
return null;
}
debugShape.updateGeometricState();
return debugShape;
}
Aggregations