Skip to content

Commit 543b891

Browse files
committed
More fixes
1 parent d94e3be commit 543b891

File tree

4 files changed

+81
-73
lines changed

4 files changed

+81
-73
lines changed

cocos2d/kazmath/mat3.js

+34-21
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@
2929
window.Uint16Array = window.Uint16Array || window.Array;
3030
window.Float32Array = window.Float32Array || window.Array;
3131
(function(cc){
32+
/**
33+
* <p>
34+
* A 3x3 matrix </br>
35+
* </p>
36+
* @class
37+
* @param {cc.math.Matrix3} [mat3]
38+
*/
3239
cc.math.Matrix3 = function(mat3) {
3340
if (mat3 && mat3.mat) {
3441
this.mat = new Float32Array(mat3.mat);
@@ -37,9 +44,16 @@ window.Float32Array = window.Float32Array || window.Array;
3744
}
3845
};
3946
cc.kmMat3 = cc.math.Matrix3;
40-
var proto = cc.math.Matrix3.prototype;
41-
42-
proto.fill = function(mat3) { //cc.kmMat3Fill
47+
var _p = cc.math.Matrix3.prototype;
48+
49+
/**
50+
* Copy matrix.
51+
* @fn fill
52+
* @memberof cc.math.Matrix3
53+
* @param {cc.math.Matrix3} mat3 Matrix to copy
54+
* @return {cc.math.Matrix3} this
55+
*/
56+
_p.fill = function(mat3) { //cc.kmMat3Fill
4357
var mat = this.mat, matIn = mat3.mat;
4458
mat[0] = matIn[0];
4559
mat[1] = matIn[1];
@@ -53,7 +67,7 @@ window.Float32Array = window.Float32Array || window.Array;
5367
return this;
5468
};
5569

56-
proto.adjugate = function(){ //= cc.kmMat3Adjugate
70+
_p.adjugate = function(){ //= cc.kmMat3Adjugate
5771
var mat = this.mat;
5872
var m0 = mat[0], m1 = mat[1], m2 = mat[2], m3 = mat[3], m4 = mat[4],
5973
m5 = mat[5], m6 = mat[6], m7 = mat[7], m8 = mat[8];
@@ -71,7 +85,13 @@ window.Float32Array = window.Float32Array || window.Array;
7185
return this;
7286
};
7387

74-
proto.identity = function() { //cc.kmMat3Identity
88+
/**
89+
* Sets pOut to an identity matrix returns pOut
90+
* @memberof cc.math.Matrix3
91+
* @param {cc.math.Matrix3} pOut - A pointer to the matrix to set to identity
92+
* @return {cc.math.Matrix3} this
93+
*/
94+
_p.identity = function() { //cc.kmMat3Identity
7595
var mat = this.mat;
7696
mat[1] = mat[2] = mat[3] =
7797
mat[5] = mat[6] = mat[7] = 0;
@@ -81,7 +101,7 @@ window.Float32Array = window.Float32Array || window.Array;
81101

82102
var tmpMatrix = new cc.math.Matrix3(); // internal matrix
83103

84-
proto.inverse = function(determinate){ //cc.kmMat3Inverse
104+
_p.inverse = function(determinate){ //cc.kmMat3Inverse
85105
if (determinate === 0.0)
86106
return this;
87107
tmpMatrix.assignFrom(this);
@@ -91,14 +111,14 @@ window.Float32Array = window.Float32Array || window.Array;
91111
return this;
92112
};
93113

94-
proto.isIdentity = function(){ //= cc.kmMat3IsIdentity
114+
_p.isIdentity = function(){ //= cc.kmMat3IsIdentity
95115
var mat = this.mat;
96116
return (mat[0] === 1 && mat[1] === 0 && mat[2] === 0
97117
&& mat[3] === 0 && mat[4] === 1 && mat[5] === 0
98118
&& mat[6] === 0 && mat[7] === 0 && mat[8] === 1);
99119
};
100120

101-
proto.transpose = function(){ // cc.kmMat3Transpose
121+
_p.transpose = function(){ // cc.kmMat3Transpose
102122
var mat = this.mat;
103123
var m1 = mat[1], m2 = mat[2], m3 = mat[3], m5 = mat[5],
104124
m6 = mat[6], m7 = mat[7];
@@ -115,7 +135,7 @@ window.Float32Array = window.Float32Array || window.Array;
115135
return this;
116136
};
117137

118-
proto.determinant = function(){
138+
_p.determinant = function(){
119139
var mat = this.mat;
120140
/*
121141
calculating the determinant following the rule of sarus,
@@ -130,7 +150,7 @@ window.Float32Array = window.Float32Array || window.Array;
130150
return output;
131151
};
132152

133-
proto.multiply = function(mat3){
153+
_p.multiply = function(mat3){
134154
var m1 = this.mat, m2 = mat3.mat;
135155
var a0 = m1[0], a1 = m1[1], a2 = m1[2], a3 = m1[3], a4 = m1[4], a5 = m1[5],
136156
a6 = m1[6], a7 = m1[7], a8 = m1[8];
@@ -151,7 +171,7 @@ window.Float32Array = window.Float32Array || window.Array;
151171
return this;
152172
};
153173

154-
proto.multiplyScalar = function(factor) {
174+
_p.multiplyScalar = function(factor) {
155175
var mat = this.mat;
156176
mat[0] *= factor;
157177
mat[1] *= factor;
@@ -185,7 +205,7 @@ window.Float32Array = window.Float32Array || window.Array;
185205
return retMat;
186206
};
187207

188-
proto.assignFrom = function(matIn){ // cc.kmMat3Assign
208+
_p.assignFrom = function(matIn){ // cc.kmMat3Assign
189209
if(this === matIn) {
190210
cc.log("cc.math.Matrix3.assign(): current matrix equals matIn");
191211
return this;
@@ -203,7 +223,7 @@ window.Float32Array = window.Float32Array || window.Array;
203223
return this;
204224
};
205225

206-
proto.equals = function(mat3) {
226+
_p.equals = function(mat3) {
207227
if (this === mat3)
208228
return true;
209229
var EPSILON = cc.math.EPSILON,m1 = this.mat, m2 = mat3.mat;
@@ -331,14 +351,7 @@ window.Float32Array = window.Float32Array || window.Array;
331351
return ret;
332352
};
333353

334-
proto.rotationToAxisAngle = function() { //cc.kmMat3RotationToAxisAngle
354+
_p.rotationToAxisAngle = function() { //cc.kmMat3RotationToAxisAngle
335355
return cc.math.Quaternion.rotationMatrix(this).toAxisAndAngle();
336356
}
337357
})(cc);
338-
339-
340-
341-
342-
343-
344-

cocos2d/kazmath/mat4.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
* | 2 6 10 14 | </br>
3838
* | 3 7 11 15 |
3939
* </p>
40+
* @class
4041
* @param {cc.math.Matrix4} [mat4]
4142
*/
4243
cc.math.Matrix4 = function (mat4) {
@@ -63,8 +64,8 @@
6364

6465
/**
6566
* Sets pOut to an identity matrix returns pOut
66-
* @Params pOut - A pointer to the matrix to set to identity
67-
* @Return Returns pOut so that the call can be nested
67+
* @param pOut - A pointer to the matrix to set to identity
68+
* @returns Returns pOut so that the call can be nested
6869
*/
6970
cc.kmMat4Identity = function (pOut) {
7071
var mat = pOut.mat;
@@ -1008,7 +1009,3 @@
10081009
return temp.toAxisAndAngle();
10091010
};
10101011
})(cc);
1011-
1012-
1013-
1014-

cocos2d/kazmath/vec3.js

+27-29
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@
2727
*/
2828

2929
(function(cc) {
30-
cc.kmVec3 = cc.math.Vec3 = function (x, y, z) {
30+
/**
31+
* A 3d vector.
32+
* @class
33+
* @param {number} [x]
34+
* @param {number} [y]
35+
* @param {number} [z]
36+
*/
37+
38+
cc.math.Vec3 = cc.kmVec3 = function (x, y, z) {
3139
if(x && y === undefined){
3240
this.x = x.x;
3341
this.y = x.y;
@@ -43,9 +51,9 @@
4351
return new cc.math.Vec3(x, y, z);
4452
};
4553

46-
var proto = cc.math.Vec3.prototype;
54+
var _p = cc.math.Vec3._ptype;
4755

48-
proto.fill = function (x, y, z) { // =cc.kmVec3Fill
56+
_p.fill = function (x, y, z) { // =cc.kmVec3Fill
4957
if (x && y === undefined) {
5058
this.x = x.x;
5159
this.y = x.y;
@@ -58,57 +66,57 @@
5866
return this;
5967
};
6068

61-
proto.length = function () { //=cc.kmVec3Length
69+
_p.length = function () { //=cc.kmVec3Length
6270
return Math.sqrt(cc.math.square(this.x) + cc.math.square(this.y) + cc.math.square(this.z));
6371
};
6472

65-
proto.lengthSq = function () { //=cc.kmVec3LengthSq
73+
_p.lengthSq = function () { //=cc.kmVec3LengthSq
6674
return cc.math.square(this.x) + cc.math.square(this.y) + cc.math.square(this.z)
6775
};
6876

69-
proto.normalize = function () { //= cc.kmVec3Normalize
77+
_p.normalize = function () { //= cc.kmVec3Normalize
7078
var l = 1.0 / this.length();
7179
this.x *= l;
7280
this.y *= l;
7381
this.z *= l;
7482
return this;
7583
};
7684

77-
proto.cross = function (vec3) { //= cc.kmVec3Cross
85+
_p.cross = function (vec3) { //= cc.kmVec3Cross
7886
var x = this.x, y = this.y, z = this.z;
7987
this.x = (y * vec3.z) - (z * vec3.y);
8088
this.y = (z * vec3.x) - (x * vec3.z);
8189
this.z = (x * vec3.y) - (y * vec3.x);
8290
return this;
8391
};
8492

85-
proto.dot = function (vec) { //= cc.kmVec3Dot
93+
_p.dot = function (vec) { //= cc.kmVec3Dot
8694
return ( this.x * vec.x + this.y * vec.y + this.z * vec.z );
8795
};
8896

89-
proto.add = function(vec){ //= cc.kmVec3Add
97+
_p.add = function(vec){ //= cc.kmVec3Add
9098
this.x += vec.x;
9199
this.y += vec.y;
92100
this.z += vec.z;
93101
return this;
94102
};
95103

96-
proto.subtract = function (vec) { // = cc.kmVec3Subtract
104+
_p.subtract = function (vec) { // = cc.kmVec3Subtract
97105
this.x -= vec.x;
98106
this.y -= vec.y;
99107
this.z -= vec.z;
100108
return this;
101109
};
102110

103-
proto.transform = function (mat4) { // = cc.kmVec3Transform
111+
_p.transform = function (mat4) { // = cc.kmVec3Transform
104112
var x = this.x, y = this.y, z = this.z, mat = mat4.mat;
105113
this.x = x * mat[0] + y * mat[4] + z * mat[8] + mat[12];
106114
this.y = x * mat[1] + y * mat[5] + z * mat[9] + mat[13];
107115
this.z = x * mat[2] + y * mat[6] + z * mat[10] + mat[14];
108116
return this;
109117
};
110118

111-
proto.transformNormal = function(mat4){
119+
_p.transformNormal = function(mat4){
112120
/*
113121
a = (Vx, Vy, Vz, 0)
114122
b = (a×M)T
@@ -122,7 +130,7 @@
122130
return this;
123131
};
124132

125-
proto.transformCoord = function(mat4){ // = cc.kmVec3TransformCoord
133+
_p.transformCoord = function(mat4){ // = cc.kmVec3TransformCoord
126134
/*
127135
a = (Vx, Vy, Vz, 1)
128136
b = (a×M)T
@@ -136,21 +144,21 @@
136144
return this;
137145
};
138146

139-
proto.scale = function(scale){ // = cc.kmVec3Scale
147+
_p.scale = function(scale){ // = cc.kmVec3Scale
140148
this.x *= scale;
141149
this.y *= scale;
142150
this.z *= scale;
143151
return this;
144152
};
145153

146-
proto.equals = function(vec){ // = cc.kmVec3AreEqual
154+
_p.equals = function(vec){ // = cc.kmVec3AreEqual
147155
var EPSILON = cc.math.EPSILON;
148156
return (this.x < (vec.x + EPSILON) && this.x > (vec.x - EPSILON)) &&
149157
(this.y < (vec.y + EPSILON) && this.y > (vec.y - EPSILON)) &&
150158
(this.z < (vec.z + EPSILON) && this.z > (vec.z - EPSILON));
151159
};
152160

153-
proto.inverseTransform = function(mat4){ //= cc.kmVec3InverseTransform
161+
_p.inverseTransform = function(mat4){ //= cc.kmVec3InverseTransform
154162
var mat = mat4.mat;
155163
var v1 = new cc.math.Vec3(this.x - mat[12], this.y - mat[13], this.z - mat[14]);
156164
this.x = v1.x * mat[0] + v1.y * mat[1] + v1.z * mat[2];
@@ -159,15 +167,15 @@
159167
return this;
160168
};
161169

162-
proto.inverseTransformNormal = function(mat4){ // = cc.kmVec3InverseTransformNormal
170+
_p.inverseTransformNormal = function(mat4){ // = cc.kmVec3InverseTransformNormal
163171
var x = this.x, y = this.y, z = this.z, mat = mat4.mat;
164172
this.x = x * mat[0] + y * mat[1] + z * mat[2];
165173
this.y = x * mat[4] + y * mat[5] + z * mat[6];
166174
this.z = x * mat[8] + y * mat[9] + z * mat[10];
167175
return this;
168176
};
169177

170-
proto.assignFrom = function(vec){
178+
_p.assignFrom = function(vec){
171179
if(!vec)
172180
return this;
173181
this.x = vec.x;
@@ -181,21 +189,11 @@
181189
return vec;
182190
};
183191

184-
proto.toTypeArray = function(){ //cc.kmVec3ToTypeArray
192+
_p.toTypeArray = function(){ //cc.kmVec3ToTypeArray
185193
var tyArr = new Float32Array(3);
186194
tyArr[0] = this.x;
187195
tyArr[1] = this.y;
188196
tyArr[2] = this.z;
189197
return tyArr;
190198
};
191199
})(cc);
192-
193-
194-
195-
196-
197-
198-
199-
200-
201-

0 commit comments

Comments
 (0)