com.jme3.bullet.control.PhysicsControl Java Examples
The following examples show how to use
com.jme3.bullet.control.PhysicsControl.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PhysicsSpace.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * adds an object to the physics space * @param obj the PhysicsControl or Spatial with PhysicsControl to add */ public void add(Object obj) { if (obj instanceof PhysicsControl) { ((PhysicsControl) obj).setPhysicsSpace(this); } else if (obj instanceof Spatial) { Spatial node = (Spatial) obj; PhysicsControl control = node.getControl(PhysicsControl.class); control.setPhysicsSpace(this); } else if (obj instanceof PhysicsCollisionObject) { addCollisionObject((PhysicsCollisionObject) obj); } else if (obj instanceof PhysicsJoint) { addJoint((PhysicsJoint) obj); } else { throw (new UnsupportedOperationException("Cannot add this kind of object to the physics space.")); } }
Example #2
Source File: SceneToolController.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
protected void attachSelectionShape(Spatial spat) { if (selectionShape != null) { selectionShape.removeFromParent(); selectionShape = null; } selctionShapeOffset.set(Vector3f.ZERO); if (spat instanceof ParticleEmitter) { attachBoxSelection(spat); } else if (spat instanceof Geometry) { attachGeometrySelection((Geometry) spat); } else if (spat.getControl(PhysicsControl.class) != null) { attachPhysicsSelection(spat); } else { attachBoxSelection(spat); } }
Example #3
Source File: PhysicsSpace.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * removes an object from the physics space * @param obj the PhysicsControl or Spatial with PhysicsControl to remove */ public void remove(Object obj) { if (obj instanceof PhysicsControl) { ((PhysicsControl) obj).setPhysicsSpace(null); } else if (obj instanceof Spatial) { Spatial node = (Spatial) obj; PhysicsControl control = node.getControl(PhysicsControl.class); control.setPhysicsSpace(null); } else if (obj instanceof PhysicsCollisionObject) { removeCollisionObject((PhysicsCollisionObject) obj); } else if (obj instanceof PhysicsJoint) { removeJoint((PhysicsJoint) obj); } else { throw (new UnsupportedOperationException("Cannot remove this kind of object from the physics space.")); } }
Example #4
Source File: PhysicsSpace.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * adds an object to the physics space * @param obj the PhysicsControl or Spatial with PhysicsControl to add */ public void add(Object obj) { if (obj instanceof PhysicsControl) { ((PhysicsControl) obj).setPhysicsSpace(this); } else if (obj instanceof Spatial) { Spatial node = (Spatial) obj; PhysicsControl control = node.getControl(PhysicsControl.class); control.setPhysicsSpace(this); } else if (obj instanceof PhysicsCollisionObject) { addCollisionObject((PhysicsCollisionObject) obj); } else if (obj instanceof PhysicsJoint) { addJoint((PhysicsJoint) obj); } else { throw (new UnsupportedOperationException("Cannot add this kind of object to the physics space.")); } }
Example #5
Source File: PhysicsSpace.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * removes an object from the physics space * @param obj the PhysicsControl or Spatial with PhysicsControl to remove */ public void remove(Object obj) { if (obj instanceof PhysicsControl) { ((PhysicsControl) obj).setPhysicsSpace(null); } else if (obj instanceof Spatial) { Spatial node = (Spatial) obj; PhysicsControl control = node.getControl(PhysicsControl.class); control.setPhysicsSpace(null); } else if (obj instanceof PhysicsCollisionObject) { removeCollisionObject((PhysicsCollisionObject) obj); } else if (obj instanceof PhysicsJoint) { removeJoint((PhysicsJoint) obj); } else if (obj == null) { return; } else { throw (new UnsupportedOperationException("Cannot remove this kind of object from the physics space."+obj)); } }
Example #6
Source File: PhysicsSpace.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * removes an object from the physics space * * @param obj the PhysicsControl or Spatial with PhysicsControl to remove */ public void remove(Object obj) { if (obj == null) return; if (obj instanceof PhysicsControl) { ((PhysicsControl) obj).setPhysicsSpace(null); } else if (obj instanceof Spatial) { Spatial node = (Spatial) obj; for (int i = 0; i < node.getNumControls(); i++) { if (node.getControl(i) instanceof PhysicsControl) { remove(node.getControl(i)); } } } else if (obj instanceof PhysicsCollisionObject) { removeCollisionObject((PhysicsCollisionObject) obj); } else if (obj instanceof PhysicsJoint) { removeJoint((PhysicsJoint) obj); } else { throw (new UnsupportedOperationException("Cannot remove this kind of object from the physics space.")); } }
Example #7
Source File: PhysicsSpace.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * adds an object to the physics space * @param obj the PhysicsControl or Spatial with PhysicsControl to add */ public void add(Object obj) { if (obj == null) return; if (obj instanceof PhysicsControl) { ((PhysicsControl) obj).setPhysicsSpace(this); } else if (obj instanceof Spatial) { Spatial node = (Spatial) obj; for (int i = 0; i < node.getNumControls(); i++) { if (node.getControl(i) instanceof PhysicsControl) { add(node.getControl(i)); } } } else if (obj instanceof PhysicsCollisionObject) { addCollisionObject((PhysicsCollisionObject) obj); } else if (obj instanceof PhysicsJoint) { addJoint((PhysicsJoint) obj); } else { throw (new UnsupportedOperationException("Cannot add this kind of object to the physics space.")); } }
Example #8
Source File: PhysicsSpace.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Remove the specified object from this space. * * @param obj the PhysicsCollisionObject to add, or null (modified) */ public void remove(Object obj) { if (obj == null) return; if (obj instanceof PhysicsControl) { ((PhysicsControl) obj).setPhysicsSpace(null); } else if (obj instanceof Spatial) { Spatial node = (Spatial) obj; for (int i = 0; i < node.getNumControls(); i++) { if (node.getControl(i) instanceof PhysicsControl) { remove(node.getControl(i)); } } } else if (obj instanceof PhysicsCollisionObject) { removeCollisionObject((PhysicsCollisionObject) obj); } else if (obj instanceof PhysicsJoint) { removeJoint((PhysicsJoint) obj); } else { throw (new UnsupportedOperationException("Cannot remove this kind of object from the physics space.")); } }
Example #9
Source File: PhysicsSpace.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Add the specified object to this space. * * @param obj the PhysicsControl, Spatial-with-PhysicsControl, * PhysicsCollisionObject, or PhysicsJoint to add (not null, modified) */ public void add(Object obj) { if (obj instanceof PhysicsControl) { ((PhysicsControl) obj).setPhysicsSpace(this); } else if (obj instanceof Spatial) { Spatial node = (Spatial) obj; for (int i = 0; i < node.getNumControls(); i++) { if (node.getControl(i) instanceof PhysicsControl) { add(node.getControl(i)); } } } else if (obj instanceof PhysicsCollisionObject) { addCollisionObject((PhysicsCollisionObject) obj); } else if (obj instanceof PhysicsJoint) { addJoint((PhysicsJoint) obj); } else { throw (new UnsupportedOperationException("Cannot add this kind of object to the physics space.")); } }
Example #10
Source File: ModelEditorBulletPart.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * Update a spatial. * * @param spatial the spatial. * @param physicsSpace the new physical space or null. */ @JmeThread private void updateNode(@NotNull final Spatial spatial, @Nullable final PhysicsSpace physicsSpace) { spatial.depthFirstTraversal(sub -> { final int numControls = sub.getNumControls(); for (int i = 0; i < numControls; i++) { final Control control = sub.getControl(i); if (control instanceof PhysicsControl) { ((PhysicsControl) control).setPhysicsSpace(physicsSpace); } } }); }
Example #11
Source File: ControlUtils.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * Change the enabled status of the control. * * @param control the control. * @param enabled true if the control should be enabled. */ @FromAnyThread public static void setEnabled(@NotNull Control control, boolean enabled) { if (control instanceof AbstractControl) { ((AbstractControl) control).setEnabled(enabled); } else if (control instanceof PhysicsControl) { ((PhysicsControl) control).setEnabled(enabled); } }
Example #12
Source File: ControlUtils.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * Check enabled status of the control. * * @param control the control. * @return true if this control is enabled. */ @FromAnyThread public static boolean isEnabled(@NotNull Control control) { if (control instanceof AbstractControl) { return ((AbstractControl) control).isEnabled(); } else if (control instanceof PhysicsControl) { return ((PhysicsControl) control).isEnabled(); } else { return true; } }
Example #13
Source File: DefaultControlPropertyBuilder.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
@FxThread protected @NotNull List<EditableProperty<?, ?>> getProperties(@NotNull PhysicsControl control) { var result = new ArrayList<EditableProperty<?, ?>>(); result.add(new SimpleProperty<>(BOOLEAN, Messages.MODEL_PROPERTY_IS_ENABLED, control, PhysicsControl::isEnabled, PhysicsControl::setEnabled)); return result; }
Example #14
Source File: TestAttachGhostObject.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void simpleUpdate(float tpf) { if (ghostControl.getOverlappingObjects().contains(collisionNode.getControl(PhysicsControl.class))) { fpsText.setText("collide"); } }
Example #15
Source File: PhysicsSpace.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
/** * adds all physics controls and joints in the given spatial node to the physics space * (e.g. after loading from disk) - recursive if node * @param spatial the rootnode containing the physics objects */ public void addAll(Spatial spatial) { if (spatial.getControl(RigidBodyControl.class) != null) { RigidBodyControl physicsNode = spatial.getControl(RigidBodyControl.class); if (!physicsNodes.containsValue(physicsNode)) { physicsNode.setPhysicsSpace(this); } //add joints List<PhysicsJoint> joints = physicsNode.getJoints(); for (Iterator<PhysicsJoint> it1 = joints.iterator(); it1.hasNext();) { PhysicsJoint physicsJoint = it1.next(); //add connected physicsnodes if they are not already added if (!physicsNodes.containsValue(physicsJoint.getBodyA())) { if (physicsJoint.getBodyA() instanceof PhysicsControl) { add(physicsJoint.getBodyA()); } else { addRigidBody(physicsJoint.getBodyA()); } } if (!physicsNodes.containsValue(physicsJoint.getBodyB())) { if (physicsJoint.getBodyA() instanceof PhysicsControl) { add(physicsJoint.getBodyB()); } else { addRigidBody(physicsJoint.getBodyB()); } } if (!physicsJoints.contains(physicsJoint)) { addJoint(physicsJoint); } } } else if (spatial.getControl(PhysicsControl.class) != null) { spatial.getControl(PhysicsControl.class).setPhysicsSpace(this); } //recursion if (spatial instanceof Node) { List<Spatial> children = ((Node) spatial).getChildren(); for (Iterator<Spatial> it = children.iterator(); it.hasNext();) { Spatial spat = it.next(); addAll(spat); } } }
Example #16
Source File: PhysicsSpace.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
/** * Removes all physics controls and joints in the given spatial from the physics space * (e.g. before saving to disk) - recursive if node * @param spatial the rootnode containing the physics objects */ public void removeAll(Spatial spatial) { if (spatial.getControl(RigidBodyControl.class) != null) { RigidBodyControl physicsNode = spatial.getControl(RigidBodyControl.class); if (physicsNodes.containsValue(physicsNode)) { physicsNode.setPhysicsSpace(null); } //remove joints List<PhysicsJoint> joints = physicsNode.getJoints(); for (Iterator<PhysicsJoint> it1 = joints.iterator(); it1.hasNext();) { PhysicsJoint physicsJoint = it1.next(); //add connected physicsnodes if they are not already added if (physicsNodes.containsValue(physicsJoint.getBodyA())) { if (physicsJoint.getBodyA() instanceof PhysicsControl) { remove(physicsJoint.getBodyA()); } else { removeRigidBody(physicsJoint.getBodyA()); } } if (physicsNodes.containsValue(physicsJoint.getBodyB())) { if (physicsJoint.getBodyA() instanceof PhysicsControl) { remove(physicsJoint.getBodyB()); } else { removeRigidBody(physicsJoint.getBodyB()); } } if (physicsJoints.contains(physicsJoint)) { removeJoint(physicsJoint); } } } else if (spatial.getControl(PhysicsControl.class) != null) { spatial.getControl(PhysicsControl.class).setPhysicsSpace(null); } //recursion if (spatial instanceof Node) { List<Spatial> children = ((Node) spatial).getChildren(); for (Iterator<Spatial> it = children.iterator(); it.hasNext();) { Spatial spat = it.next(); removeAll(spat); } } }
Example #17
Source File: PhysicsSpace.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
/** * adds all physics controls and joints in the given spatial node to the physics space * (e.g. after loading from disk) - recursive if node * @param spatial the rootnode containing the physics objects */ public void addAll(Spatial spatial) { if (spatial.getControl(RigidBodyControl.class) != null) { RigidBodyControl physicsNode = spatial.getControl(RigidBodyControl.class); if (!physicsNodes.containsValue(physicsNode)) { physicsNode.setPhysicsSpace(this); } //add joints List<PhysicsJoint> joints = physicsNode.getJoints(); for (Iterator<PhysicsJoint> it1 = joints.iterator(); it1.hasNext();) { PhysicsJoint physicsJoint = it1.next(); //add connected physicsnodes if they are not already added if (!physicsNodes.containsValue(physicsJoint.getBodyA())) { if (physicsJoint.getBodyA() instanceof PhysicsControl) { add(physicsJoint.getBodyA()); } else { addRigidBody(physicsJoint.getBodyA()); } } if (!physicsNodes.containsValue(physicsJoint.getBodyB())) { if (physicsJoint.getBodyA() instanceof PhysicsControl) { add(physicsJoint.getBodyB()); } else { addRigidBody(physicsJoint.getBodyB()); } } if (!physicsJoints.contains(physicsJoint)) { addJoint(physicsJoint); } } } else if (spatial.getControl(PhysicsControl.class) != null) { spatial.getControl(PhysicsControl.class).setPhysicsSpace(this); } //recursion if (spatial instanceof Node) { List<Spatial> children = ((Node) spatial).getChildren(); for (Iterator<Spatial> it = children.iterator(); it.hasNext();) { Spatial spat = it.next(); addAll(spat); } } }
Example #18
Source File: PhysicsSpace.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
/** * Removes all physics controls and joints in the given spatial from the physics space * (e.g. before saving to disk) - recursive if node * @param spatial the rootnode containing the physics objects */ public void removeAll(Spatial spatial) { if (spatial.getControl(RigidBodyControl.class) != null) { RigidBodyControl physicsNode = spatial.getControl(RigidBodyControl.class); if (physicsNodes.containsValue(physicsNode)) { physicsNode.setPhysicsSpace(null); } //remove joints List<PhysicsJoint> joints = physicsNode.getJoints(); for (Iterator<PhysicsJoint> it1 = joints.iterator(); it1.hasNext();) { PhysicsJoint physicsJoint = it1.next(); //add connected physicsnodes if they are not already added if (physicsNodes.containsValue(physicsJoint.getBodyA())) { if (physicsJoint.getBodyA() instanceof PhysicsControl) { remove(physicsJoint.getBodyA()); } else { removeRigidBody(physicsJoint.getBodyA()); } } if (physicsNodes.containsValue(physicsJoint.getBodyB())) { if (physicsJoint.getBodyA() instanceof PhysicsControl) { remove(physicsJoint.getBodyB()); } else { removeRigidBody(physicsJoint.getBodyB()); } } if (physicsJoints.contains(physicsJoint)) { removeJoint(physicsJoint); } } } else if (spatial.getControl(PhysicsControl.class) != null) { spatial.getControl(PhysicsControl.class).setPhysicsSpace(null); } //recursion if (spatial instanceof Node) { List<Spatial> children = ((Node) spatial).getChildren(); for (Iterator<Spatial> it = children.iterator(); it.hasNext();) { Spatial spat = it.next(); removeAll(spat); } } }
Example #19
Source File: TestAttachGhostObject.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void simpleUpdate(float tpf) { if (ghostControl.getOverlappingObjects().contains(collisionNode.getControl(PhysicsControl.class))) { fpsText.setText("collide"); } }