use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.
the class TestCollisionShapeFactory method simpleInitApp.
@Override
public void simpleInitApp() {
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
bulletAppState.setDebugEnabled(true);
createMaterial();
Node node = new Node("node1");
attachRandomGeometry(node, mat1);
randomizeTransform(node);
Node node2 = new Node("node2");
attachRandomGeometry(node2, mat2);
randomizeTransform(node2);
node.attachChild(node2);
rootNode.attachChild(node);
RigidBodyControl control = new RigidBodyControl(0);
node.addControl(control);
getPhysicsSpace().add(control);
//test single geometry too
Geometry myGeom = new Geometry("cylinder", new Cylinder(16, 16, 0.5f, 1));
myGeom.setMaterial(mat3);
randomizeTransform(myGeom);
rootNode.attachChild(myGeom);
RigidBodyControl control3 = new RigidBodyControl(0);
myGeom.addControl(control3);
getPhysicsSpace().add(control3);
}
use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.
the class BezierCurve method getControlPoints.
/**
* This method returns a list of control points for this curve.
* @return a list of control points for this curve.
*/
public List<Vector3f> getControlPoints() {
List<Vector3f> controlPoints = new ArrayList<Vector3f>(bezierPoints.length * 3);
for (int i = 0; i < bezierPoints.length; ++i) {
controlPoints.add(new Vector3f((float) bezierPoints[i][0][0], (float) bezierPoints[i][0][1], (float) bezierPoints[i][0][2]));
controlPoints.add(new Vector3f((float) bezierPoints[i][1][0], (float) bezierPoints[i][1][1], (float) bezierPoints[i][1][2]));
controlPoints.add(new Vector3f((float) bezierPoints[i][2][0], (float) bezierPoints[i][2][1], (float) bezierPoints[i][2][2]));
}
return controlPoints;
}
use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.
the class RagdollUtils method setTransform.
/**
* Updates a bone position and rotation.
* if the child bones are not in the bone list this means, they are not associated with a physic shape.
* So they have to be updated
* @param bone the bone
* @param pos the position
* @param rot the rotation
*/
public static void setTransform(Bone bone, Vector3f pos, Quaternion rot, boolean restoreBoneControl, Set<String> boneList) {
//we ensure that we have the control
if (restoreBoneControl) {
bone.setUserControl(true);
}
//we set te user transforms of the bone
bone.setUserTransformsInModelSpace(pos, rot);
for (Bone childBone : bone.getChildren()) {
//each child bone that is not in the list is updated
if (!boneList.contains(childBone.getName())) {
Transform t = childBone.getCombinedTransform(pos, rot);
setTransform(childBone, t.getTranslation(), t.getRotation(), restoreBoneControl, boneList);
}
}
//we give back the control to the keyframed animation
if (restoreBoneControl) {
bone.setUserControl(false);
}
}
use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.
the class KinematicRagdollControl method createSpatialData.
@Override
protected void createSpatialData(Spatial model) {
targetModel = model;
Node parent = model.getParent();
Vector3f initPosition = model.getLocalTranslation().clone();
Quaternion initRotation = model.getLocalRotation().clone();
initScale = model.getLocalScale().clone();
model.removeFromParent();
model.setLocalTranslation(Vector3f.ZERO);
model.setLocalRotation(Quaternion.IDENTITY);
model.setLocalScale(1);
//HACK ALERT change this
//I remove the skeletonControl and readd it to the spatial to make sure it's after the ragdollControl in the stack
//Find a proper way to order the controls.
SkeletonControl sc = model.getControl(SkeletonControl.class);
if (sc == null) {
throw new IllegalArgumentException("The root node of the model should have a SkeletonControl. Make sure the control is there and that it's not on a sub node.");
}
model.removeControl(sc);
model.addControl(sc);
// put into bind pose and compute bone transforms in model space
// maybe dont reset to ragdoll out of animations?
scanSpatial(model);
if (parent != null) {
parent.attachChild(model);
}
model.setLocalTranslation(initPosition);
model.setLocalRotation(initRotation);
model.setLocalScale(initScale);
if (added) {
addPhysics(space);
}
logger.log(Level.FINE, "Created physics ragdoll for skeleton {0}", skeleton);
}
use of com.jme3.scene.control.Control 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;
}
Aggregations