private Geometry getRandomBall(Vector3f location) { Vector3f localLocation = new Vector3f(); localLocation.set(location); localLocation.addLocal(new Vector3f(random.nextFloat() - 0.5f, random.nextFloat() - 0.5f, random.nextFloat() - 0.5f).normalize().mult(3)); Geometry poiGeom = new Geometry("ball", ballMesh); poiGeom.setLocalTranslation(localLocation); poiGeom.setMaterial(ballMaterial); RigidBodyControl control = new RigidBodyControl(ballCollisionShape, 1); //!!! Important control.setApplyPhysicsLocal(true); poiGeom.addControl(control); float x = (random.nextFloat() - 0.5f) * 100; float y = (random.nextFloat() - 0.5f) * 100; float z = (random.nextFloat() - 0.5f) * 100; control.setLinearVelocity(new Vector3f(x, y, z)); return poiGeom; }
physicsSphere.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true); rootNode.attachChild(physicsSphere); getPhysicsSpace().add(physicsSphere); physicsSphere2.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true); rootNode.attachChild(physicsSphere2); getPhysicsSpace().add(physicsSphere2); physicsBox.getControl(RigidBodyControl.class).setFriction(0.1f); physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f)); physicsBox.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true); rootNode.attachChild(physicsBox); getPhysicsSpace().add(physicsBox); physicsCylinder.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true); rootNode.attachChild(physicsCylinder); getPhysicsSpace().add(physicsCylinder); node2.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true); rootNode.attachChild(node2); getPhysicsSpace().add(node2); node3.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true); rootNode.attachChild(node3); getPhysicsSpace().add(node3);
private void initData() { getRootNode(); physicsState = new BulletAppState(); physicsState.startPhysics(); physicsState.getPhysicsSpace().setGravity(Vector3f.ZERO); //horizon physicsState.getPhysicsSpace().add(new RigidBodyControl(poiHorizonCollisionShape, 0)); int hashCode = inParentPosition.hashCode(); Vector3f[] positions = getPositions(poiCount, hashCode); for (int i = 0; i < positions.length; i++) { Vector3f vector3f = positions[i]; Geometry poiGeom = new Geometry("poi", poiMesh); poiGeom.setLocalTranslation(vector3f); poiGeom.setMaterial(poiMaterial); RigidBodyControl control = new RigidBodyControl(poiCollisionShape, 0); //!!! Important control.setApplyPhysicsLocal(true); poiGeom.addControl(control); physicsState.getPhysicsSpace().add(poiGeom); rootNode.attachChild(poiGeom); } //add balls after so first 10 geoms == locations for (int i = 0; i < positions.length; i++) { Vector3f vector3f = positions[i]; Geometry ball = getRandomBall(vector3f); physicsState.getPhysicsSpace().add(ball); rootNode.attachChild(ball); } }
control.setLinearVelocity(getLinearVelocity()); control.setApplyPhysicsLocal(isApplyPhysicsLocal()); control.spatial = this.spatial; control.setEnabled(isEnabled());
control.setLinearVelocity(getLinearVelocity()); control.setApplyPhysicsLocal(isApplyPhysicsLocal()); control.spatial = this.spatial; control.setEnabled(isEnabled());
@Override public Control cloneForSpatial(Spatial spatial) { RigidBodyControl control = new RigidBodyControl(collisionShape, mass); control.setAngularFactor(getAngularFactor()); control.setAngularSleepingThreshold(getAngularSleepingThreshold()); 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.setKinematicSpatial(isKinematicSpatial()); control.setLinearSleepingThreshold(getLinearSleepingThreshold()); control.setPhysicsLocation(getPhysicsLocation(null)); control.setPhysicsRotation(getPhysicsRotationMatrix(null)); control.setRestitution(getRestitution()); if (mass > 0) { control.setAngularVelocity(getAngularVelocity()); control.setLinearVelocity(getLinearVelocity()); } control.setApplyPhysicsLocal(isApplyPhysicsLocal()); return control; }
public Control cloneForSpatial(Spatial spatial) { RigidBodyControl control = new RigidBodyControl(collisionShape, mass); control.setAngularFactor(getAngularFactor()); control.setAngularSleepingThreshold(getAngularSleepingThreshold()); 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.setKinematicSpatial(isKinematicSpatial()); control.setLinearSleepingThreshold(getLinearSleepingThreshold()); control.setPhysicsLocation(getPhysicsLocation(null)); control.setPhysicsRotation(getPhysicsRotationMatrix(null)); control.setRestitution(getRestitution()); if (mass > 0) { control.setAngularVelocity(getAngularVelocity()); control.setLinearVelocity(getLinearVelocity()); } control.setApplyPhysicsLocal(isApplyPhysicsLocal()); control.setSpatial(spatial); return control; }
control.setLinearVelocity(getLinearVelocity()); control.setApplyPhysicsLocal(isApplyPhysicsLocal()); return control;
@Override public Object jmeClone() { RigidBodyControl control = new RigidBodyControl(collisionShape, mass); control.setAngularFactor(getAngularFactor()); control.setAngularSleepingThreshold(getAngularSleepingThreshold()); 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.setKinematicSpatial(isKinematicSpatial()); control.setLinearSleepingThreshold(getLinearSleepingThreshold()); control.setPhysicsLocation(getPhysicsLocation(null)); control.setPhysicsRotation(getPhysicsRotationMatrix(null)); control.setRestitution(getRestitution()); if (mass > 0) { control.setAngularVelocity(getAngularVelocity()); control.setLinearVelocity(getLinearVelocity()); } control.setApplyPhysicsLocal(isApplyPhysicsLocal()); control.spatial = this.spatial; control.setEnabled(isEnabled()); return control; }
control.setLinearVelocity(getLinearVelocity()); control.setApplyPhysicsLocal(isApplyPhysicsLocal()); control.spatial = this.spatial; control.setEnabled(isEnabled());