OSDN Git Service

Applied parent transforms if any in the lookAt method of Spatial.
authorremy.bouquet@gmail.com <remy.bouquet@gmail.com@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Mon, 28 Jan 2013 21:01:19 +0000 (21:01 +0000)
committerremy.bouquet@gmail.com <remy.bouquet@gmail.com@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Mon, 28 Jan 2013 21:01:19 +0000 (21:01 +0000)
updated javadoc

git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@10225 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

engine/src/core/com/jme3/scene/Spatial.java

index c8a91b7..72927d7 100644 (file)
@@ -409,11 +409,16 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
 
     /**
      * <code>lookAt</code> is a convenience method for auto-setting the local
-     * rotation based on a position and an up vector. It computes the rotation
+     * rotation based on a position in world space and an up vector. It computes the rotation
      * to transform the z-axis to point onto 'position' and the y-axis to 'up'.
      * Unlike {@link Quaternion#lookAt(com.jme3.math.Vector3f, com.jme3.math.Vector3f) } 
      * this method takes a world position to look at and not a relative direction.
      *
+     * Note : 28/01/2013 this method has been fixed as it was not taking into account the parent rotation.
+     * This was resulting in improper rotation when the spatial had rotated parent nodes.
+     * This method is intended to work in world space, so no matter what parent graph the 
+     * spatial has, it will look at the given position in world space.
+     * 
      * @param position
      *            where to look at in terms of world coordinates
      * @param upVector
@@ -426,11 +431,17 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab
         TempVars vars = TempVars.get();
 
         Vector3f compVecA = vars.vect4;
-        vars.release();
-
+      
         compVecA.set(position).subtractLocal(worldTranslation);
-        getLocalRotation().lookAt(compVecA, upVector);
-
+        getLocalRotation().lookAt(compVecA, upVector);        
+        
+        if ( getParent() != null ) {
+            Quaternion rot=vars.quat1;
+            rot =  rot.set(parent.getWorldRotation()).inverseLocal().multLocal(getLocalRotation());
+            rot.normalizeLocal();
+            setLocalRotation(rot);
+        }
+        vars.release();
         setTransformRefresh();
     }