Saving a few instructions

Quaternion.mult() / multLocal() has some duplicate computations.

I don’t know whether compiler does this for us or not.



[patch]

Index: src/core/com/jme3/math/Quaternion.java

===================================================================

— src/core/com/jme3/math/Quaternion.java (revision 6599)

+++ src/core/com/jme3/math/Quaternion.java (working copy)

@@ -888,16 +888,7 @@

  • @return v

    */

    public Vector3f multLocal(Vector3f v) {
  •    float tempX, tempY;<br />
    
  •    tempX = w * w * v.x + 2 * y * w * v.z - 2 * z * w * v.y + x * x * v.x<br />
    
  •            + 2 * y * x * v.y + 2 * z * x * v.z - z * z * v.x - y * y * v.x;<br />
    
  •    tempY = 2 * x * y * v.x + y * y * v.y + 2 * z * y * v.z + 2 * w * z<br />
    
  •            * v.x - z * z * v.y + w * w * v.y - 2 * x * w * v.z - x * x<br />
    
  •            * v.y;<br />
    
  •    v.z = 2 * x * z * v.x + 2 * y * z * v.y + z * z * v.z - 2 * w * y * v.x<br />
    
  •            - y * y * v.z + 2 * w * x * v.y - x * x * v.z + w * w * v.z;<br />
    
  •    v.x = tempX;<br />
    
  •    v.y = tempY;<br />
    
  •    mult(v, v);<br />
    

return v;

}



@@ -966,15 +957,20 @@

store.set(0, 0, 0);

} else {

float vx = v.x, vy = v.y, vz = v.z;

  •        store.x = w * w * vx + 2 * y * w * vz - 2 * z * w * vy + x * x<br />
    
  •                * vx + 2 * y * x * vy + 2 * z * x * vz - z * z * vx - y<br />
    
  •                * y * vx;<br />
    
  •        store.y = 2 * x * y * vx + y * y * vy + 2 * z * y * vz + 2 * w<br />
    
  •                * z * vx - z * z * vy + w * w * vy - 2 * x * w * vz - x<br />
    
  •                * x * vy;<br />
    
  •        store.z = 2 * x * z * vx + 2 * y * z * vy + z * z * vz - 2 * w<br />
    
  •                * y * vx - y * y * vz + 2 * w * x * vy - x * x * vz + w<br />
    
  •                * w * vz;<br />
    
  •        float ww = w*w;<br />
    
  •        float xx = x*x;<br />
    
  •        float yy = y*y;<br />
    
  •        float zz = z*z;<br />
    
  •        float xy = x*y;<br />
    
  •        float yz = y*z;<br />
    
  •        float zw = z*w;<br />
    
  •        float wx = w*x;<br />
    
  •        float wy = w*y;<br />
    
  •        float xz = x*z;<br />
    

+

  •        store.x = ww * vx + 2 * wy * vz - 2 * zw * vy + xx * vx + 2 * xy * vy + 2 * xz * vz - zz * vx - yy * vx;<br />
    
  •        store.y = 2 * xy * vx + yy * vy + 2 * yz * vz + 2 * zw * vx - zz * vy + ww * vy - 2 * wx * vz - xx * vy;<br />
    
  •        store.z = 2 * xz * vx + 2 * yz * vy + zz * vz - 2 * wy * vx - yy * vz + 2 * wx * vy - xx * vz + ww * vz;<br />
    

}

return store;

}



[/patch]

Thanks!

Committed in svn. rev 6616