/** * Enable or disable this control. * <p> * When the control is disabled, the physics object is removed from physics * space. When the control is enabled again, the physics object is moved to * the spatial's location 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()); } addPhysics(space); added = true; } else if (!enabled && added) { removePhysics(space); added = false; } } }
/** * 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) { if (this.spatial != null && this.spatial != spatial) { removeSpatialData(this.spatial); } else if (this.spatial == spatial) { return; } this.spatial = spatial; if (spatial == null) { return; } createSpatialData(this.spatial); setPhysicsLocation(getSpatialTranslation()); setPhysicsRotation(getSpatialRotation()); }
/** * If enabled, add this control's physics object to the specified physics * space. If not enabled, alter where the object would be added. The object * is removed from any other space it's in. * * @param newSpace where to add, or null to simply remove */ @Override public void setPhysicsSpace(PhysicsSpace newSpace) { if (space == newSpace) { return; } if (added) { removePhysics(space); added = false; } if (newSpace != null && isEnabled()) { addPhysics(newSpace); added = true; } /* * If this control isn't enabled, its physics object will be * added to the new space when the control becomes enabled. */ space = newSpace; }
super.read(im); InputCapsule ic = im.getCapsule(this); String[] loadedBoneList = ic.readStringArray("boneList", new String[0]);
public void setPhysicsSpace(PhysicsSpace space) { if (space == null) { if (this.space != null) { removePhysics(this.space); added = false; } } else { if (this.space == space) { return; } else if (this.space != null) { removePhysics(this.space); } addPhysics(space); added = true; } this.space = space; }
/** * Render this control. Invoked once per view port per frame, provided the * control is added to a scene. Should be invoked only by a subclass or by * the RenderManager. * * @param rm the render manager (not null) * @param vp the view port to render (not null) */ @Override public void render(RenderManager rm, ViewPort vp) { super.render(rm, vp); }
/** * Callback from {@link com.jme3.util.clone.Cloner} to convert this * shallow-cloned control into a deep-cloned one, using the specified cloner * and original to resolve copied fields. * * @param cloner the cloner that's cloning this control (not null) * @param original the control from which this control was shallow-cloned * (unused) */ @Override public void cloneFields( Cloner cloner, Object original ) { this.spatial = cloner.clone(spatial); createSpatialData(this.spatial); }
public static void printControls(Spatial spatial) { System.out.println("Controls of "+spatial.getName()); for (int i = 0; i < spatial.getNumControls(); i++) { Control c = spatial.getControl(i); System.out.print("\t-" + c.getClass().getSimpleName()); if (c instanceof AbstractControl) { System.out.println(" " + ((AbstractControl) c).isEnabled()); } else if (c instanceof AbstractPhysicsControl) { System.out.println(" " + ((AbstractPhysicsControl) c).isEnabled()); } else { System.out.println(""); } } System.out.println(""); }
super.read(im); InputCapsule ic = im.getCapsule(this); String[] loadedBoneList = ic.readStringArray("boneList", new String[0]);
/** * Render this control. Invoked once per view port per frame, provided the * control is added to a scene. Should be invoked only by a subclass or by * the RenderManager. * * @param rm the render manager (not null) * @param vp the view port to render (not null) */ @Override public void render(RenderManager rm, ViewPort vp) { super.render(rm, vp); }
/** * Callback from {@link com.jme3.util.clone.Cloner} to convert this * shallow-cloned control into a deep-cloned one, using the specified cloner * and original to resolve copied fields. * * @param cloner the cloner that's cloning this control (not null) * @param original the control from which this control was shallow-cloned * (unused) */ @Override public void cloneFields( Cloner cloner, Object original ) { this.spatial = cloner.clone(spatial); createSpatialData(this.spatial); }
/** * 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) { if (this.spatial != null && this.spatial != spatial) { removeSpatialData(this.spatial); } else if (this.spatial == spatial) { return; } this.spatial = spatial; if (spatial == null) { return; } createSpatialData(this.spatial); setPhysicsLocation(getSpatialTranslation()); setPhysicsRotation(getSpatialRotation()); }
/** * Enable or disable this control. * <p> * When the control is disabled, the physics object is removed from physics * space. When the control is enabled again, the physics object is moved to * the spatial's location 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()); } addPhysics(space); added = true; } else if (!enabled && added) { removePhysics(space); added = false; } } }
/** * If enabled, add this control's physics object to the specified physics * space. If not enabled, alter where the object would be added. The object * is removed from any other space it's in. * * @param newSpace where to add, or null to simply remove */ @Override public void setPhysicsSpace(PhysicsSpace newSpace) { if (space == newSpace) { return; } if (added) { removePhysics(space); added = false; } if (newSpace != null && isEnabled()) { addPhysics(newSpace); added = true; } /* * If this control isn't enabled, its physics object will be * added to the new space when the control becomes enabled. */ space = newSpace; }
/** * De-serialize this control, for example when loading from a J3O file. * * @param im importer (not null) * @throws IOException from importer */ @Override public void read(JmeImporter im) throws IOException { super.read(im); InputCapsule in = im.getCapsule(this); this.radius = in.readFloat("radius", 1); this.height = in.readFloat("height", 2); this.mass = in.readFloat("mass", 80); this.physicsDamping = in.readFloat("physicsDamping", 0.9f); this.jumpForce.set((Vector3f) in.readSavable("jumpForce", new Vector3f(0, mass * 5, 0))); rigidBody = new PhysicsRigidBody(getShape(), mass); jumpForce.set(new Vector3f(0, mass * 5, 0)); rigidBody.setAngularFactor(0); } }
/** * Render this control. Invoked once per view port per frame, provided the * control is added to a scene. Should be invoked only by a subclass or by * the RenderManager. * * @param rm the render manager (not null) * @param vp the view port to render (not null) */ @Override public void render(RenderManager rm, ViewPort vp) { super.render(rm, vp); }
@Override public void cloneFields( Cloner cloner, Object original ) { this.spatial = cloner.clone(spatial); createSpatialData(this.spatial); }
public void setSpatial(Spatial spatial) { if (this.spatial != null && this.spatial != spatial) { removeSpatialData(this.spatial); } else if (this.spatial == spatial) { return; } this.spatial = spatial; if (spatial == null) { return; } createSpatialData(this.spatial); setPhysicsLocation(getSpatialTranslation()); setPhysicsRotation(getSpatialRotation()); }
public void setEnabled(boolean enabled) { this.enabled = enabled; if (space != null) { if (enabled && !added) { if (spatial != null) { setPhysicsLocation(getSpatialTranslation()); setPhysicsRotation(getSpatialRotation()); } addPhysics(space); added = true; } else if (!enabled && added) { removePhysics(space); added = false; } } }
/** * If enabled, add this control's physics object to the specified physics * space. If not enabled, alter where the object would be added. The object * is removed from any other space it's in. * * @param newSpace where to add, or null to simply remove */ @Override public void setPhysicsSpace(PhysicsSpace newSpace) { if (space == newSpace) { return; } if (added) { removePhysics(space); added = false; } if (newSpace != null && isEnabled()) { addPhysics(newSpace); added = true; } /* * If this control isn't enabled, its physics object will be * added to the new space when the control becomes enabled. */ space = newSpace; }