/** * Create a shallow clone for the JME cloner. * * @return a new control (not null) */ @Override public Object jmeClone() { GhostControl control = new GhostControl(collisionShape); control.setCcdMotionThreshold(getCcdMotionThreshold()); control.setCcdSweptSphereRadius(getCcdSweptSphereRadius()); control.setCollideWithGroups(getCollideWithGroups()); control.setCollisionGroup(getCollisionGroup()); control.setPhysicsLocation(getPhysicsLocation()); control.setPhysicsRotation(getPhysicsRotationMatrix()); control.setApplyPhysicsLocal(isApplyPhysicsLocal()); control.spatial = this.spatial; return control; }
/** * Update this control. Invoked once per frame during the logical-state * update, provided the control is added to a scene. Do not invoke directly * from user code. * * @param tpf the time interval between frames (in seconds, ≥0) */ public void update(float tpf) { if (!enabled) { return; } setPhysicsLocation(getSpatialTranslation()); setPhysicsRotation(getSpatialRotation()); }
@Override public void simpleInitApp() { flyCam.setEnabled(false); BulletAppState bulletAppState = new BulletAppState(); bulletAppState.setDebugEnabled(true); bulletAppState.setSpeed(0f); stateManager.attach(bulletAppState); PhysicsSpace space = bulletAppState.getPhysicsSpace(); float radius = 1f; CollisionShape sphere = new SphereCollisionShape(radius); CollisionShape box = new BoxCollisionShape(Vector3f.UNIT_XYZ); RigidBodyControl rbc = new RigidBodyControl(box); rbc.setEnabled(false); rbc.setPhysicsSpace(space); rootNode.addControl(rbc); BetterCharacterControl bcc = new BetterCharacterControl(radius, 4f, 1f); bcc.setEnabled(false); bcc.setPhysicsSpace(space); rootNode.addControl(bcc); GhostControl gc = new GhostControl(sphere); gc.setEnabled(false); gc.setPhysicsSpace(space); rootNode.addControl(gc); } }
private void initGhostObject() { Vector3f halfExtents = new Vector3f(3, 4.2f, 1); ghostControl = new GhostControl(new BoxCollisionShape(halfExtents)); Node node=new Node("Ghost Object"); node.addControl(ghostControl); rootNode.attachChild(node); getPhysicsSpace().add(ghostControl); }
public void setupJoint() { Node holderNode = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(.1f, .1f, .1f)), 0); holderNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, 0, 0f)); rootNode.attachChild(holderNode); getPhysicsSpace().add(holderNode); Node hammerNode = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(.3f, .3f, .3f)), 1); hammerNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -1, 0f)); rootNode.attachChild(hammerNode); getPhysicsSpace().add(hammerNode); //immovable collisionNode = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(.3f, .3f, .3f)), 0); collisionNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(1.8f, 0, 0f)); rootNode.attachChild(collisionNode); getPhysicsSpace().add(collisionNode); //ghost node ghostControl = new GhostControl(new SphereCollisionShape(0.7f)); hammerNode.addControl(ghostControl); getPhysicsSpace().add(ghostControl); joint = new HingeJoint(holderNode.getControl(RigidBodyControl.class), hammerNode.getControl(RigidBodyControl.class), Vector3f.ZERO, new Vector3f(0f, -1, 0f), Vector3f.UNIT_Z, Vector3f.UNIT_Z); getPhysicsSpace().add(joint); }
/** * Create a shallow clone for the JME cloner. * * @return a new control (not null) */ @Override public Object jmeClone() { GhostControl control = new GhostControl(collisionShape); control.setCcdMotionThreshold(getCcdMotionThreshold()); control.setCcdSweptSphereRadius(getCcdSweptSphereRadius()); control.setCollideWithGroups(getCollideWithGroups()); control.setCollisionGroup(getCollisionGroup()); control.setPhysicsLocation(getPhysicsLocation()); control.setPhysicsRotation(getPhysicsRotationMatrix()); control.setApplyPhysicsLocal(isApplyPhysicsLocal()); control.spatial = this.spatial; return control; }
/** * Update this control. Invoked once per frame during the logical-state * update, provided the control is added to a scene. Do not invoke directly * from user code. * * @param tpf the time interval between frames (in seconds, ≥0) */ public void update(float tpf) { if (!enabled) { return; } setPhysicsLocation(getSpatialTranslation()); setPhysicsRotation(getSpatialRotation()); }
pickUps.attachChild(pickUp); pickUp.addControl(new GhostControl(new SphereCollisionShape(PICKUP_SIZE)));
public Control cloneForSpatial(Spatial spatial) { GhostControl control = new GhostControl(collisionShape); control.setCcdMotionThreshold(getCcdMotionThreshold()); control.setCcdSweptSphereRadius(getCcdSweptSphereRadius()); control.setCollideWithGroups(getCollideWithGroups()); control.setCollisionGroup(getCollisionGroup()); control.setPhysicsLocation(getPhysicsLocation()); control.setPhysicsRotation(getPhysicsRotationMatrix()); control.setApplyPhysicsLocal(isApplyPhysicsLocal()); control.setSpatial(spatial); return control; }
/** * Alter which spatial is controlled. Invoked when the control is added to * or removed from a spatial. Should be invoked only by a subclass or from * Spatial. Do not invoke directly from user code. * * @param spatial the spatial to control (or null) */ public void setSpatial(Spatial spatial) { this.spatial = spatial; setUserObject(spatial); if (spatial == null) { return; } setPhysicsLocation(getSpatialTranslation()); setPhysicsRotation(getSpatialRotation()); }
@Override public Control cloneForSpatial(Spatial spatial) { GhostControl control = new GhostControl(collisionShape); control.setCcdMotionThreshold(getCcdMotionThreshold()); control.setCcdSweptSphereRadius(getCcdSweptSphereRadius()); control.setCollideWithGroups(getCollideWithGroups()); control.setCollisionGroup(getCollisionGroup()); control.setPhysicsLocation(getPhysicsLocation()); control.setPhysicsRotation(getPhysicsRotationMatrix()); control.setApplyPhysicsLocal(isApplyPhysicsLocal()); return control; }
/** * Alter which spatial is controlled. Invoked when the control is added to * or removed from a spatial. Should be invoked only by a subclass or from * Spatial. Do not invoke directly from user code. * * @param spatial the spatial to control (or null) */ public void setSpatial(Spatial spatial) { this.spatial = spatial; setUserObject(spatial); if (spatial == null) { return; } setPhysicsLocation(getSpatialTranslation()); setPhysicsRotation(getSpatialRotation()); }
@Override public Object jmeClone() { GhostControl control = new GhostControl(collisionShape); control.setCcdMotionThreshold(getCcdMotionThreshold()); control.setCcdSweptSphereRadius(getCcdSweptSphereRadius()); control.setCollideWithGroups(getCollideWithGroups()); control.setCollisionGroup(getCollisionGroup()); control.setPhysicsLocation(getPhysicsLocation()); control.setPhysicsRotation(getPhysicsRotationMatrix()); control.setApplyPhysicsLocal(isApplyPhysicsLocal()); control.spatial = this.spatial; return control; }
/** * Enable or disable this control. * <p> * When the control is disabled, the ghost object is removed from physics * space. When the control is enabled again, the object is moved to the * current location of the spatial and then added to the physics space. * * @param enabled true→enable the control, false→disable it */ public void setEnabled(boolean enabled) { this.enabled = enabled; if (space != null) { if (enabled && !added) { if (spatial != null) { setPhysicsLocation(getSpatialTranslation()); setPhysicsRotation(getSpatialRotation()); } space.addCollisionObject(this); added = true; } else if (!enabled && added) { space.removeCollisionObject(this); added = false; } } }
/** * Clone this control for a different spatial. No longer used as of JME 3.1. * * @param spatial the spatial for the clone to control (or null) * @return a new control (not null) */ @Override public Control cloneForSpatial(Spatial spatial) { GhostControl control = new GhostControl(collisionShape); control.setCcdMotionThreshold(getCcdMotionThreshold()); control.setCcdSweptSphereRadius(getCcdSweptSphereRadius()); control.setCollideWithGroups(getCollideWithGroups()); control.setCollisionGroup(getCollisionGroup()); control.setPhysicsLocation(getPhysicsLocation()); control.setPhysicsRotation(getPhysicsRotationMatrix()); control.setApplyPhysicsLocal(isApplyPhysicsLocal()); return control; }
/** * Enable or disable this control. * <p> * When the control is disabled, the ghost object is removed from physics * space. When the control is enabled again, the object is moved to the * current location of the spatial and then added to the physics space. * * @param enabled true→enable the control, false→disable it */ public void setEnabled(boolean enabled) { this.enabled = enabled; if (space != null) { if (enabled && !added) { if (spatial != null) { setPhysicsLocation(getSpatialTranslation()); setPhysicsRotation(getSpatialRotation()); } space.addCollisionObject(this); added = true; } else if (!enabled && added) { space.removeCollisionObject(this); added = false; } } }
/** * Create a shallow clone for the JME cloner. * * @return a new control (not null) */ @Override public Object jmeClone() { GhostControl control = new GhostControl(collisionShape); control.setCcdMotionThreshold(getCcdMotionThreshold()); control.setCcdSweptSphereRadius(getCcdSweptSphereRadius()); control.setCollideWithGroups(getCollideWithGroups()); control.setCollisionGroup(getCollisionGroup()); control.setPhysicsLocation(getPhysicsLocation()); control.setPhysicsRotation(getPhysicsRotationMatrix()); control.setApplyPhysicsLocal(isApplyPhysicsLocal()); control.spatial = this.spatial; return control; }
public void update(float tpf) { if (!enabled) { return; } setPhysicsLocation(getSpatialTranslation()); setPhysicsRotation(getSpatialRotation()); }
public void setSpatial(Spatial spatial) { this.spatial = spatial; setUserObject(spatial); if (spatial == null) { return; } setPhysicsLocation(getSpatialTranslation()); setPhysicsRotation(getSpatialRotation()); }
public void update(float tpf) { if (!enabled) { return; } setPhysicsLocation(getSpatialTranslation()); setPhysicsRotation(getSpatialRotation()); }