use of com.jme3.math.Matrix3f in project jmonkeyengine by jMonkeyEngine.
the class BoundingBox method transform.
/**
* <code>transform</code> modifies the center of the box to reflect the
* change made via a rotation, translation and scale.
*
* @param trans
* the transform to apply
* @param store
* box to store result in
*/
public BoundingVolume transform(Transform trans, BoundingVolume store) {
BoundingBox box;
if (store == null || store.getType() != Type.AABB) {
box = new BoundingBox();
} else {
box = (BoundingBox) store;
}
center.mult(trans.getScale(), box.center);
trans.getRotation().mult(box.center, box.center);
box.center.addLocal(trans.getTranslation());
TempVars vars = TempVars.get();
Matrix3f transMatrix = vars.tempMat3;
transMatrix.set(trans.getRotation());
// Make the rotation matrix all positive to get the maximum x/y/z extent
transMatrix.absoluteLocal();
Vector3f scale = trans.getScale();
vars.vect1.set(xExtent * FastMath.abs(scale.x), yExtent * FastMath.abs(scale.y), zExtent * FastMath.abs(scale.z));
transMatrix.mult(vars.vect1, vars.vect2);
// Assign the biggest rotations after scales.
box.xExtent = FastMath.abs(vars.vect2.getX());
box.yExtent = FastMath.abs(vars.vect2.getY());
box.zExtent = FastMath.abs(vars.vect2.getZ());
vars.release();
return box;
}
use of com.jme3.math.Matrix3f in project jmonkeyengine by jMonkeyEngine.
the class ChildCollisionShape method read.
public void read(JmeImporter im) throws IOException {
InputCapsule capsule = im.getCapsule(this);
location = (Vector3f) capsule.readSavable("location", new Vector3f());
rotation = (Matrix3f) capsule.readSavable("rotation", new Matrix3f());
shape = (CollisionShape) capsule.readSavable("shape", new BoxCollisionShape(new Vector3f(1, 1, 1)));
}
use of com.jme3.math.Matrix3f in project jmonkeyengine by jMonkeyEngine.
the class TestFancyCar method onAction.
public void onAction(String binding, boolean value, float tpf) {
if (binding.equals("Lefts")) {
if (value) {
steeringValue += .5f;
} else {
steeringValue += -.5f;
}
player.steer(steeringValue);
} else if (binding.equals("Rights")) {
if (value) {
steeringValue += -.5f;
} else {
steeringValue += .5f;
}
player.steer(steeringValue);
} else //note that our fancy car actually goes backwards..
if (binding.equals("Ups")) {
if (value) {
accelerationValue -= 800;
} else {
accelerationValue += 800;
}
player.accelerate(accelerationValue);
player.setCollisionShape(CollisionShapeFactory.createDynamicMeshShape(findGeom(carNode, "Car")));
} else if (binding.equals("Downs")) {
if (value) {
player.brake(40f);
} else {
player.brake(0f);
}
} else if (binding.equals("Reset")) {
if (value) {
System.out.println("Reset");
player.setPhysicsLocation(Vector3f.ZERO);
player.setPhysicsRotation(new Matrix3f());
player.setLinearVelocity(Vector3f.ZERO);
player.setAngularVelocity(Vector3f.ZERO);
player.resetSuspension();
} else {
}
}
}
use of com.jme3.math.Matrix3f in project jmonkeyengine by jMonkeyEngine.
the class BufferedTriangleCallback method getDebugShape.
/**
* 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;
}
use of com.jme3.math.Matrix3f in project jmonkeyengine by jMonkeyEngine.
the class CompoundCollisionShape method addChildShape.
/**
* adds a child shape at the given local translation
* @param shape the child shape to add
* @param location the local location of the child shape
*/
public void addChildShape(CollisionShape shape, Vector3f location) {
Transform transA = new Transform(Converter.convert(new Matrix3f()));
Converter.convert(location, transA.origin);
children.add(new ChildCollisionShape(location.clone(), new Matrix3f(), shape));
((CompoundShape) cShape).addChildShape(transA, shape.getCShape());
}
Aggregations