Skip to content

Commit e385d01

Browse files
committed
added comments to ModelViewProjection pipeline component
1 parent 426bc4f commit e385d01

1 file changed

Lines changed: 94 additions & 8 deletions

File tree

src/renderer/webgl/pipelines/components/ModelViewProjection.js

Lines changed: 94 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,47 @@
44
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
55
*/
66

7-
// [pending] - please add comments explaining what all of these functions do
7+
8+
/**
9+
* Implements a model view projection matrices.
10+
* Pipelines can implement this for doing 2D and 3D rendering.
11+
*/
812

913
var ModelViewProjection = {
1014

15+
/**
16+
* Dirty flag for checking if model matrix needs to be updated on GPU.
17+
*/
1118
modelMatrixDirty: false,
19+
20+
/**
21+
* Dirty flag for checking if view matrix needs to be updated on GPU.
22+
*/
1223
viewMatrixDirty: false,
24+
25+
/**
26+
* Dirty flag for checking if projection matrix needs to be updated on GPU.
27+
*/
1328
projectionMatrixDirty: false,
29+
30+
/**
31+
* Model matrix
32+
*/
1433
modelMatrix: null,
34+
35+
/**
36+
* View matrix
37+
*/
1538
viewMatrix: null,
39+
40+
/**
41+
* Projection matrix
42+
*/
1643
projectionMatrix: null,
1744

45+
/**
46+
* Initializes MVP matrices with an identity matrix
47+
*/
1848
mvpInit: function ()
1949
{
2050
this.modelMatrixDirty = true;
@@ -45,6 +75,9 @@ var ModelViewProjection = {
4575
return this;
4676
},
4777

78+
/**
79+
* If dirty flags are set then the matrices are uploaded to the GPU.
80+
*/
4881
mvpUpdate: function ()
4982
{
5083
var program = this.program;
@@ -70,6 +103,9 @@ var ModelViewProjection = {
70103
return this;
71104
},
72105

106+
/**
107+
* Loads an identity matrix to the model matrix
108+
*/
73109
modelIdentity: function ()
74110
{
75111
var modelMatrix = this.modelMatrix;
@@ -96,6 +132,9 @@ var ModelViewProjection = {
96132
return this;
97133
},
98134

135+
/**
136+
* Scale model matrix
137+
*/
99138
modelScale: function (x, y, z)
100139
{
101140
var modelMatrix = this.modelMatrix;
@@ -118,6 +157,9 @@ var ModelViewProjection = {
118157
return this;
119158
},
120159

160+
/**
161+
* Translate model matrix
162+
*/
121163
modelTranslate: function (x, y, z)
122164
{
123165
var modelMatrix = this.modelMatrix;
@@ -132,6 +174,10 @@ var ModelViewProjection = {
132174
return this;
133175
},
134176

177+
178+
/**
179+
* Rotates the model matrix in the X axis.
180+
*/
135181
modelRotateX: function (radians)
136182
{
137183
var modelMatrix = this.modelMatrix;
@@ -160,6 +206,9 @@ var ModelViewProjection = {
160206
return this;
161207
},
162208

209+
/**
210+
* Rotates the model matrix in the Y axis.
211+
*/
163212
modelRotateY: function (radians)
164213
{
165214
var modelMatrix = this.modelMatrix;
@@ -187,7 +236,10 @@ var ModelViewProjection = {
187236

188237
return this;
189238
},
190-
239+
240+
/**
241+
* Rotates the model matrix in the Z axis.
242+
*/
191243
modelRotateZ: function (radians)
192244
{
193245
var modelMatrix = this.modelMatrix;
@@ -216,6 +268,9 @@ var ModelViewProjection = {
216268
return this;
217269
},
218270

271+
/**
272+
* Loads identity matrix into the view matrix
273+
*/
219274
viewIdentity: function ()
220275
{
221276
var viewMatrix = this.viewMatrix;
@@ -241,7 +296,10 @@ var ModelViewProjection = {
241296

242297
return this;
243298
},
244-
299+
300+
/**
301+
* Scales view matrix
302+
*/
245303
viewScale: function (x, y, z)
246304
{
247305
var viewMatrix = this.viewMatrix;
@@ -264,6 +322,9 @@ var ModelViewProjection = {
264322
return this;
265323
},
266324

325+
/**
326+
* Translates view matrix
327+
*/
267328
viewTranslate: function (x, y, z)
268329
{
269330
var viewMatrix = this.viewMatrix;
@@ -277,7 +338,10 @@ var ModelViewProjection = {
277338

278339
return this;
279340
},
280-
341+
342+
/**
343+
* Rotates view matrix in the X axis.
344+
*/
281345
viewRotateX: function (radians)
282346
{
283347
var viewMatrix = this.viewMatrix;
@@ -305,7 +369,10 @@ var ModelViewProjection = {
305369

306370
return this;
307371
},
308-
372+
373+
/**
374+
* Rotates view matrix in the Y axis.
375+
*/
309376
viewRotateY: function (radians)
310377
{
311378
var viewMatrix = this.viewMatrix;
@@ -333,7 +400,10 @@ var ModelViewProjection = {
333400

334401
return this;
335402
},
336-
403+
404+
/**
405+
* Rotates view matrix in the Z axis.
406+
*/
337407
viewRotateZ: function (radians)
338408
{
339409
var viewMatrix = this.viewMatrix;
@@ -362,6 +432,9 @@ var ModelViewProjection = {
362432
return this;
363433
},
364434

435+
/**
436+
* Loads a 2D view matrix (3x2 matrix) into a 4x4 view matrix
437+
*/
365438
viewLoad2D: function (matrix2D)
366439
{
367440
var vm = this.viewMatrix;
@@ -388,6 +461,10 @@ var ModelViewProjection = {
388461
return this;
389462
},
390463

464+
465+
/**
466+
* Copies a 4x4 matrix into the view matrix
467+
*/
391468
viewLoad: function (matrix)
392469
{
393470
var vm = this.viewMatrix;
@@ -413,7 +490,10 @@ var ModelViewProjection = {
413490

414491
return this;
415492
},
416-
493+
494+
/**
495+
* Loads identity matrix into the projection matrix.
496+
*/
417497
projIdentity: function ()
418498
{
419499
var projectionMatrix = this.projectionMatrix;
@@ -440,6 +520,9 @@ var ModelViewProjection = {
440520
return this;
441521
},
442522

523+
/**
524+
* Sets up an orthographics projection matrix
525+
*/
443526
projOrtho: function (left, right, bottom, top, near, far)
444527
{
445528
var projectionMatrix = this.projectionMatrix;
@@ -467,7 +550,10 @@ var ModelViewProjection = {
467550
this.projectionMatrixDirty = true;
468551
return this;
469552
},
470-
553+
554+
/**
555+
* Sets up a perspective projection matrix
556+
*/
471557
projPersp: function (fovy, aspectRatio, near, far)
472558
{
473559
var projectionMatrix = this.projectionMatrix;

0 commit comments

Comments
 (0)