import com.jme3.renderer.RenderManager;
import com.jme3.scene.CameraNode;
import com.jme3.scene.Node;
+import com.jme3.scene.control.CameraControl;
import com.jme3.scene.control.CameraControl.ControlDirection;
import de.lessvoid.nifty.Nifty;
import java.io.IOException;
public CameraNode bindCamera(String cameraName, Camera cam) {
CameraNode node = new CameraNode(cameraName, cam);
node.setControlDir(ControlDirection.SpatialToCamera);
- node.getControl(0).setEnabled(false);
+ node.getControl(CameraControl.class).setEnabled(false);
cameras.put(cameraName, node);
scene.attachChild(node);
return node;
private void enableCurrentCam(boolean enabled) {
if (currentCam != null) {
- currentCam.getControl(0).setEnabled(enabled);
+ currentCam.getControl(CameraControl.class).setEnabled(enabled);
}
}
/*
- * Copyright (c) 2009-2010 jMonkeyEngine
+ * Copyright (c) 2009-2012 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package com.jme3.scene.control;
+import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
-import com.jme3.export.InputCapsule;
import com.jme3.export.OutputCapsule;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
}
public void setSpatial(Spatial spatial) {
- if (this.spatial != null && spatial != null) {
+ if (this.spatial != null && spatial != null && spatial != this.spatial) {
throw new IllegalStateException("This control has already been added to a Spatial");
}
this.spatial = spatial;
*/
protected abstract void controlRender(RenderManager rm, ViewPort vp);
+ /**
+ * Default implementation of cloneForSpatial() that
+ * simply clones the control and sets the spatial.
+ * <pre>
+ * AbstractControl c = clone();
+ * c.spatial = null;
+ * c.setSpatial(spatial);
+ * </pre>
+ *
+ * Controls that wish to be persisted must be Cloneable.
+ */
+ @Override
+ public Control cloneForSpatial(Spatial spatial) {
+ try {
+ AbstractControl c = (AbstractControl)clone();
+ c.spatial = null; // to keep setSpatial() from throwing an exception
+ c.setSpatial(spatial);
+ return c;
+ } catch(CloneNotSupportedException e) {
+ throw new RuntimeException( "Can't clone control for spatial", e );
+ }
+ }
+
public void update(float tpf) {
if (!enabled)
return;
/*
- * Copyright (c) 2009-2010 jMonkeyEngine
+ * Copyright (c) 2009-2012 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package com.jme3.scene.control;
import com.jme3.bounding.BoundingBox;
/*
- * Copyright (c) 2009-2010 jMonkeyEngine
+ * Copyright (c) 2009-2012 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package com.jme3.scene.control;
-import java.io.IOException;
-
import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
+import java.io.IOException;
public class BillboardControl extends AbstractControl {
/*
- * Copyright (c) 2009-2010 jMonkeyEngine
+ * Copyright (c) 2009-2012 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*/
package com.jme3.scene.control;
+import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
+import com.jme3.export.OutputCapsule;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera;
SpatialToCamera;
}
private Camera camera;
- private ControlDirection controlDir = ControlDirection.CameraToSpatial;
+ private ControlDirection controlDir = ControlDirection.SpatialToCamera;
/**
* Constructor used for Serialization.
return control;
}
private static final String CONTROL_DIR_NAME = "controlDir";
-
+ private static final String CAMERA_NAME = "camera";
+
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
- im.getCapsule(this).readEnum(CONTROL_DIR_NAME,
- ControlDirection.class, ControlDirection.SpatialToCamera);
+ InputCapsule ic = im.getCapsule(this);
+ controlDir = ic.readEnum(CONTROL_DIR_NAME, ControlDirection.class, ControlDirection.SpatialToCamera);
+ camera = (Camera)ic.readSavable(CAMERA_NAME, null);
}
@Override
public void write(JmeExporter ex) throws IOException {
super.write(ex);
- ex.getCapsule(this).write(controlDir, CONTROL_DIR_NAME,
- ControlDirection.SpatialToCamera);
+ OutputCapsule oc = ex.getCapsule(this);
+ oc.write(controlDir, CONTROL_DIR_NAME, ControlDirection.SpatialToCamera);
+ oc.write(camera, CAMERA_NAME, null);
}
}
\ No newline at end of file
/*
- * Copyright (c) 2009-2010 jMonkeyEngine
+ * Copyright (c) 2009-2012 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package com.jme3.scene.control;
import com.jme3.export.Savable;
public void setSpatial(Spatial spatial);
/**
- * @param enabled Enable or disable the control. If disabled, update()
- * should do nothing.
- */
- public void setEnabled(boolean enabled);
-
- /**
- * @return True if enabled, false otherwise.
- * @see Control#setEnabled(boolean)
- */
- public boolean isEnabled();
-
- /**
* Updates the control. This should not be called from user code.
* @param tpf Time per frame.
*/
/*
- * Copyright (c) 2009-2010 jMonkeyEngine
+ * Copyright (c) 2009-2012 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*/
package com.jme3.scene.control;
+import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
+import com.jme3.export.OutputCapsule;
import com.jme3.light.DirectionalLight;
import com.jme3.light.Light;
import com.jme3.light.PointLight;
-import com.jme3.math.Quaternion;
+import com.jme3.light.SpotLight;
import com.jme3.math.Vector3f;
-import com.jme3.renderer.Camera;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Spatial;
if (light instanceof DirectionalLight) {
((DirectionalLight) light).setDirection(vars.vect1.set(spatial.getWorldTranslation()).multLocal(-1.0f));
}
+
+ if (light instanceof SpotLight) {
+ ((SpotLight) light).setPosition(spatial.getWorldTranslation());
+ ((SpotLight) light).setDirection(spatial.getWorldRotation().multLocal(vars.vect1.set(Vector3f.UNIT_Y).multLocal(-1)));
+ }
vars.release();
- //TODO add code for Spot light here when it's done
-// if( light instanceof SpotLight){
-// ((SpotLight)light).setPosition(spatial.getWorldTranslation());
-// ((SpotLight)light).setRotation(spatial.getWorldRotation());
-// }
}
return control;
}
private static final String CONTROL_DIR_NAME = "controlDir";
-
+ private static final String LIGHT_NAME = "light";
+
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
- im.getCapsule(this).readEnum(CONTROL_DIR_NAME,
- ControlDirection.class, ControlDirection.SpatialToLight);
+ InputCapsule ic = im.getCapsule(this);
+ controlDir = ic.readEnum(CONTROL_DIR_NAME, ControlDirection.class, ControlDirection.SpatialToLight);
+ light = (Light)ic.readSavable(LIGHT_NAME, null);
}
@Override
public void write(JmeExporter ex) throws IOException {
super.write(ex);
- ex.getCapsule(this).write(controlDir, CONTROL_DIR_NAME,
- ControlDirection.SpatialToLight);
+ OutputCapsule oc = ex.getCapsule(this);
+ oc.write(controlDir, CONTROL_DIR_NAME, ControlDirection.SpatialToLight);
+ oc.write(light, LIGHT_NAME, null);
}
}
\ No newline at end of file
/*
- * Copyright (c) 2009-2010 jMonkeyEngine
+ * Copyright (c) 2009-2012 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package com.jme3.scene.control;
import com.jme3.bounding.BoundingVolume;
+import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
-import com.jme3.export.InputCapsule;
import com.jme3.export.OutputCapsule;
import com.jme3.math.FastMath;
import com.jme3.renderer.Camera;
/*
- * Copyright (c) 2009-2010 jMonkeyEngine
+ * Copyright (c) 2009-2012 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
import com.jme3.scene.CameraNode;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
+import com.jme3.scene.control.CameraControl;
import com.jme3.scene.control.CameraControl.ControlDirection;
import com.jme3.scene.shape.Box;
cam.setLocation(new Vector3f(8.4399185f, 11.189463f, 14.267577f));
camNode = new CameraNode("Motion cam", cam);
camNode.setControlDir(ControlDirection.SpatialToCamera);
- camNode.getControl(0).setEnabled(false);
+ camNode.getControl(CameraControl.class).setEnabled(false);
path = new MotionPath();
path.setCycle(true);
path.addWayPoint(new Vector3f(20, 3, 0));
playing = false;
cameraMotionControl.stop();
chaser.setEnabled(true);
- camNode.getControl(0).setEnabled(false);
+ camNode.getControl(CameraControl.class).setEnabled(false);
} else {
playing = true;
chaser.setEnabled(false);
- camNode.getControl(0).setEnabled(true);
+ camNode.getControl(CameraControl.class).setEnabled(true);
cameraMotionControl.play();
}
}