OSDN Git Service

merge from jme10694
authorkobayasi <kobayasi@pscnet.co.jp>
Sat, 6 Jul 2013 22:14:41 +0000 (07:14 +0900)
committerkobayasi <kobayasi@pscnet.co.jp>
Sat, 6 Jul 2013 22:14:41 +0000 (07:14 +0900)
engine/src/core/com/jme3/cinematic/Cinematic.java
engine/src/core/com/jme3/scene/control/AbstractControl.java
engine/src/core/com/jme3/scene/control/AreaUtils.java
engine/src/core/com/jme3/scene/control/BillboardControl.java
engine/src/core/com/jme3/scene/control/CameraControl.java
engine/src/core/com/jme3/scene/control/Control.java
engine/src/core/com/jme3/scene/control/LightControl.java
engine/src/core/com/jme3/scene/control/LodControl.java
engine/src/core/com/jme3/scene/control/UpdateControl.java
engine/src/test/jme3test/animation/TestCameraMotionPath.java

index 63204fe..f95792d 100644 (file)
@@ -47,6 +47,7 @@ import com.jme3.renderer.Camera;
 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;
@@ -277,7 +278,7 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
     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;
@@ -289,7 +290,7 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
 
     private void enableCurrentCam(boolean enabled) {
         if (currentCam != null) {
-            currentCam.getControl(0).setEnabled(enabled);
+            currentCam.getControl(CameraControl.class).setEnabled(enabled);
         }
     }
 
index 2f3875e..43cae6d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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;
@@ -55,7 +54,7 @@ public abstract class AbstractControl implements Control {
     }
 
     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;
@@ -83,6 +82,29 @@ public abstract class AbstractControl implements Control {
      */
     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;
index 47e7c5f..7def0e2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2010 jMonkeyEngine
+ * Copyright (c) 2009-2012 jMonkeyEngine
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -29,7 +29,6 @@
  * 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;
index d804bc3..7f54f90 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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;
@@ -47,6 +44,7 @@ import com.jme3.renderer.RenderManager;
 import com.jme3.renderer.ViewPort;
 import com.jme3.scene.Node;
 import com.jme3.scene.Spatial;
+import java.io.IOException;
 
 public class BillboardControl extends AbstractControl {
 
index 5dd559c..a154cbc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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;
@@ -64,7 +66,7 @@ public class CameraControl extends AbstractControl {
         SpatialToCamera;
     }
     private Camera camera;
-    private ControlDirection controlDir = ControlDirection.CameraToSpatial;
+    private ControlDirection controlDir = ControlDirection.SpatialToCamera;
 
     /**
      * Constructor used for Serialization.
@@ -142,18 +144,21 @@ public class CameraControl extends AbstractControl {
         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
index b5b0057..63d7b43 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2010 jMonkeyEngine
+ * Copyright (c) 2009-2012 jMonkeyEngine
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -29,7 +29,6 @@
  * 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;
@@ -62,18 +61,6 @@ public interface Control extends 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.
      */
index a515395..029cc1b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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;
@@ -130,12 +131,12 @@ public class LightControl extends AbstractControl {
         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());
-//        }
 
     }
 
@@ -174,18 +175,21 @@ public class LightControl extends AbstractControl {
         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
index 23aaed0..9bb5fd5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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;
index 7fbca01..a52bfb6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2010 jMonkeyEngine
+ * Copyright (c) 2009-2012 jMonkeyEngine
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
index 532e552..c6cb031 100644 (file)
@@ -49,6 +49,7 @@ import com.jme3.math.Vector3f;
 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;
 
@@ -73,7 +74,7 @@ public class TestCameraMotionPath extends SimpleApplication {
         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));
@@ -170,11 +171,11 @@ public class TestCameraMotionPath extends SimpleApplication {
                         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();
                     }
                 }