gl-matrix-rails 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  module GLMatrix
2
2
  module Version
3
- MAJOR, MINOR, TINY = 0, 1, 3
3
+ MAJOR, MINOR, TINY = 0, 1, 4
4
4
  STRING = [MAJOR, MINOR, TINY].join '.'
5
5
  end
6
6
 
@@ -2,7 +2,7 @@
2
2
  * @fileoverview gl-matrix - High performance matrix and vector operations
3
3
  * @author Brandon Jones
4
4
  * @author Colin MacKenzie IV
5
- * @version 2.1.0
5
+ * @version 2.2.0
6
6
  */
7
7
 
8
8
  /* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
@@ -28,7 +28,7 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
28
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29
29
 
30
30
 
31
- (function() {
31
+ (function(_global) {
32
32
  "use strict";
33
33
 
34
34
  var shim = {};
@@ -40,8 +40,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
40
40
  });
41
41
  } else {
42
42
  // gl-matrix lives in a browser, define its namespaces in global
43
- shim.exports = window;
44
- }
43
+ shim.exports = typeof(window) !== 'undefined' ? window : _global;
44
+ }
45
45
  }
46
46
  else {
47
47
  // gl-matrix lives in commonjs, define its namespaces in exports
@@ -1028,9 +1028,9 @@ vec3.transformMat4 = function(out, a, m) {
1028
1028
  */
1029
1029
  vec3.transformMat3 = function(out, a, m) {
1030
1030
  var x = a[0], y = a[1], z = a[2];
1031
- out[0] = x * m[0] + y * m[3] + z * m[6];
1032
- out[1] = x * m[1] + y * m[4] + z * m[7];
1033
- out[2] = x * m[2] + y * m[5] + z * m[8];
1031
+ out[0] = x * m[0] + y * m[1] + z * m[2];
1032
+ out[1] = x * m[3] + y * m[4] + z * m[5];
1033
+ out[2] = x * m[6] + y * m[7] + z * m[8];
1034
1034
  return out;
1035
1035
  };
1036
1036
 
@@ -1043,6 +1043,8 @@ vec3.transformMat3 = function(out, a, m) {
1043
1043
  * @returns {vec3} out
1044
1044
  */
1045
1045
  vec3.transformQuat = function(out, a, q) {
1046
+ // benchmarks: http://jsperf.com/quaternion-transform-vec3-implementations
1047
+
1046
1048
  var x = a[0], y = a[1], z = a[2],
1047
1049
  qx = q[0], qy = q[1], qz = q[2], qw = q[3],
1048
1050
 
@@ -2527,6 +2529,56 @@ mat3.fromQuat = function (out, q) {
2527
2529
  return out;
2528
2530
  };
2529
2531
 
2532
+ /**
2533
+ * Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix
2534
+ *
2535
+ * @param {mat3} out mat3 receiving operation result
2536
+ * @param {mat4} a Mat4 to derive the normal matrix from
2537
+ *
2538
+ * @returns {mat3} out
2539
+ */
2540
+ mat3.normalFromMat4 = function (out, a) {
2541
+ var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
2542
+ a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
2543
+ a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
2544
+ a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15],
2545
+
2546
+ b00 = a00 * a11 - a01 * a10,
2547
+ b01 = a00 * a12 - a02 * a10,
2548
+ b02 = a00 * a13 - a03 * a10,
2549
+ b03 = a01 * a12 - a02 * a11,
2550
+ b04 = a01 * a13 - a03 * a11,
2551
+ b05 = a02 * a13 - a03 * a12,
2552
+ b06 = a20 * a31 - a21 * a30,
2553
+ b07 = a20 * a32 - a22 * a30,
2554
+ b08 = a20 * a33 - a23 * a30,
2555
+ b09 = a21 * a32 - a22 * a31,
2556
+ b10 = a21 * a33 - a23 * a31,
2557
+ b11 = a22 * a33 - a23 * a32,
2558
+
2559
+ // Calculate the determinant
2560
+ det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
2561
+
2562
+ if (!det) {
2563
+ return null;
2564
+ }
2565
+ det = 1.0 / det;
2566
+
2567
+ out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
2568
+ out[1] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
2569
+ out[2] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
2570
+
2571
+ out[3] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
2572
+ out[4] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
2573
+ out[5] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
2574
+
2575
+ out[6] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
2576
+ out[7] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
2577
+ out[8] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
2578
+
2579
+ return out;
2580
+ };
2581
+
2530
2582
  /**
2531
2583
  * Returns a string representation of a mat3
2532
2584
  *
@@ -3519,11 +3571,13 @@ quat.rotationTo = (function() {
3519
3571
  vec3.cross(tmpvec3, yUnitVec3, a);
3520
3572
  vec3.normalize(tmpvec3, tmpvec3);
3521
3573
  quat.setAxisAngle(out, tmpvec3, Math.PI);
3574
+ return out;
3522
3575
  } else if (dot > 0.999999) {
3523
3576
  out[0] = 0;
3524
3577
  out[1] = 0;
3525
3578
  out[2] = 0;
3526
3579
  out[3] = 1;
3580
+ return out;
3527
3581
  } else {
3528
3582
  vec3.cross(tmpvec3, a, b);
3529
3583
  out[0] = tmpvec3[0];
@@ -3557,9 +3611,9 @@ quat.setAxes = (function() {
3557
3611
  matr[4] = up[1];
3558
3612
  matr[7] = up[2];
3559
3613
 
3560
- matr[2] = -view[0];
3561
- matr[5] = -view[1];
3562
- matr[8] = -view[2];
3614
+ matr[2] = view[0];
3615
+ matr[5] = view[1];
3616
+ matr[8] = view[2];
3563
3617
 
3564
3618
  return quat.normalize(out, quat.fromMat3(out, matr));
3565
3619
  };
@@ -3949,9 +4003,9 @@ quat.fromMat3 = (function() {
3949
4003
  fRoot = Math.sqrt(fTrace + 1.0); // 2w
3950
4004
  out[3] = 0.5 * fRoot;
3951
4005
  fRoot = 0.5/fRoot; // 1/(4w)
3952
- out[0] = (m[5]-m[7])*fRoot;
3953
- out[1] = (m[6]-m[2])*fRoot;
3954
- out[2] = (m[1]-m[3])*fRoot;
4006
+ out[0] = (m[7]-m[5])*fRoot;
4007
+ out[1] = (m[2]-m[6])*fRoot;
4008
+ out[2] = (m[3]-m[1])*fRoot;
3955
4009
  } else {
3956
4010
  // |w| <= 1/2
3957
4011
  var i = 0;
@@ -4002,4 +4056,4 @@ if(typeof(exports) !== 'undefined') {
4002
4056
 
4003
4057
 
4004
4058
  })(shim.exports);
4005
- })();
4059
+ })(this);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gl-matrix-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-22 00:00:00.000000000Z
12
+ date: 2013-03-10 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
16
- requirement: &79605980 !ruby/object:Gem::Requirement
16
+ requirement: &74330460 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *79605980
24
+ version_requirements: *74330460
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &79605750 !ruby/object:Gem::Requirement
27
+ requirement: &74330160 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *79605750
35
+ version_requirements: *74330160
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: tzinfo
38
- requirement: &79605460 !ruby/object:Gem::Requirement
38
+ requirement: &74329850 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *79605460
46
+ version_requirements: *74329850
47
47
  description: A gem to automate using gl-matrix with Rails 3
48
48
  email:
49
49
  - sinisterchipmunk@gmail.com