浏览代码

Tried to fix a bug in the PickManager which threw NullpointerExceptions when the picking location was null (could not be determined). Also refactored variable names to be less french :P

MeFisto94 8 年之前
父节点
当前提交
d6cfad5ba5
共有 1 个文件被更改,包括 13 次插入4 次删除
  1. 13 4
      jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/PickManager.java

+ 13 - 4
jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/PickManager.java

@@ -16,6 +16,7 @@ import com.jme3.scene.Geometry;
 import com.jme3.scene.Node;
 import com.jme3.scene.Spatial;
 import com.jme3.scene.shape.Quad;
+import java.util.logging.Logger;
 import org.openide.util.lookup.ServiceProvider;
 
 /**
@@ -155,14 +156,22 @@ public class PickManager {
     /**
      * Get the Rotation into a specific custom space.
      *
-     * @param transforme the rotation to the custom space (World to Custom
+     * @param transform the rotation to the custom space (World to Custom
      * space)
      * @return the Rotation in the custom space
      */
-    public Quaternion getRotation(Quaternion transforme) {
+    public Quaternion getRotation(Quaternion transform) {
+        if (startPickLoc == null) {
+            Logger.getLogger(this.getClass().getSimpleName()).warning("startPickLoc null in PickManager#getRotation()");
+            return transform;
+        } else if (finalPickLoc == null) {
+            Logger.getLogger(this.getClass().getSimpleName()).warning("finalPickLoc null in PickManager#getRotation()");
+            return transform;
+        }
+        
         Vector3f v1, v2;
-        v1 = transforme.mult(startPickLoc.subtract(startSpatialLocation).normalize());
-        v2 = transforme.mult(finalPickLoc.subtract(startSpatialLocation).normalize());
+        v1 = transform.mult(startPickLoc.subtract(startSpatialLocation).normalize());
+        v2 = transform.mult(finalPickLoc.subtract(startSpatialLocation).normalize());
         Vector3f axis = v1.cross(v2);
         float angle = v1.angleBetween(v2);
         return new Quaternion().fromAngleAxis(angle, axis);