Skip to content

Commit df58577

Browse files
committed
fixes xy bug in camera orbit control; updates texture to handle video; wraps generic rotate(angle,axis) in webgl
1 parent 309d005 commit df58577

File tree

5 files changed

+33
-19
lines changed

5 files changed

+33
-19
lines changed

src/3d/camera.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
var p5 = require('../core/core');
1111

1212
/**
13-
* set camera position
13+
* sets camera position
1414
* @method camera
1515
* @param {Number} x camera postion value on x axis
1616
* @param {Number} y camera postion value on y axis
@@ -19,7 +19,6 @@ var p5 = require('../core/core');
1919
* @example
2020
* <div>
2121
* <code>
22-
* //please call this function before doing any transformation
2322
* function setup(){
2423
* createCanvas(windowWidth, windowHeight, 'webgl');
2524
* }
@@ -41,14 +40,13 @@ p5.prototype.camera = function(x, y, z){
4140
};
4241

4342
/**
44-
* setup perspective camera
43+
* sets perspective camera
4544
* @method perspective
4645
* @param {Number} fovy camera frustum vertical field of view,
4746
* from bottom to top of view, in degrees
48-
* @param {Number} aspect camera frustum aspect ratio,
49-
* window width divided by window height
50-
* @param {Number} near camera frustum near plane
51-
* @param {Number} far camera frustum far plane
47+
* @param {Number} aspect camera frustum aspect ratio
48+
* @param {Number} near frustum near plane length
49+
* @param {Number} far frustum far plane length
5250
* @return {p5}
5351
* @example
5452
* <div>
@@ -98,8 +96,6 @@ p5.prototype.perspective = function(fovy,aspect,near,far) {
9896
* @example
9997
* <div>
10098
* <code>
101-
* //drag mouse to toggle the world
102-
* //you will see there's no vanish point
10399
* function setup(){
104100
* createCanvas(windowWidth, windowHeight, 'webgl');
105101
* ortho(-width/2, width/2, height/2, -height/2, 0.1, 100);

src/3d/interaction.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
var p5 = require('../core/core');
44

5-
//@TODO: fix this fake orbitControl
5+
//@TODO: implement full orbit controls including
6+
//pan, zoom, quaternion rotation, etc.
67
p5.prototype.orbitControl = function(){
78
if(this.mouseIsPressed){
8-
this.rotateX((this.mouseX - this.width / 2) / (this.width / 2));
9-
this.rotateY((this.mouseY - this.height / 2) / (this.width / 2));
9+
this.rotateY((this.mouseX - this.width / 2) / (this.width / 2));
10+
this.rotateX((this.mouseY - this.height / 2) / (this.width / 2));
1011
}
1112
return this;
1213
};

src/3d/material.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ p5.prototype.texture = function(image){
8989
//@TODO handle following cases:
9090
//- 2D canvas (p5 inst)
9191
}
92-
9392
if (_isPowerOf2(image.width) && _isPowerOf2(image.height)) {
9493
gl.generateMipmap(gl.TEXTURE_2D);
9594
} else {

src/3d/p5.Renderer3D.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ p5.Renderer3D.prototype.resetStack = function(){
243243
shaderStack = [];
244244
//holding colors declaration, like [0, 120, 0]
245245
this.colorStack = [];
246-
//holding mode, like TIANGLE or 'LINES'
246+
//holding mode, like TRIANGLE or 'LINES'
247247
this.modeStack = [];
248248
//holding 'fill' or 'stroke'
249249
this.drawModeStack = [];
@@ -367,9 +367,20 @@ p5.Renderer3D.prototype.scale = function(x, y, z) {
367367
return this;
368368
};
369369

370+
/**
371+
* [rotate description]
372+
* @param {Number} rad angle in radians
373+
* @param {p5.Vector | Array} axis axis to rotate around
374+
* @return {p5.Renderer3D} [description]
375+
*/
376+
p5.Renderer3D.prototype.rotate = function(rad, axis){
377+
this.uMVMatrix.rotate(rad, axis);
378+
return this;
379+
};
380+
370381
/**
371382
* [rotateX description]
372-
* @param {[type]} rad [description]
383+
* @param {Number} rad radians to rotate
373384
* @return {[type]} [description]
374385
*/
375386
p5.Renderer3D.prototype.rotateX = function(rad) {
@@ -379,7 +390,7 @@ p5.Renderer3D.prototype.rotateX = function(rad) {
379390

380391
/**
381392
* [rotateY description]
382-
* @param {[type]} rad [description]
393+
* @param {Number} rad rad radians to rotate
383394
* @return {[type]} [description]
384395
*/
385396
p5.Renderer3D.prototype.rotateY = function(rad) {
@@ -389,7 +400,7 @@ p5.Renderer3D.prototype.rotateY = function(rad) {
389400

390401
/**
391402
* [rotateZ description]
392-
* @param {[type]} rad [description]
403+
* @param {Number} rad rad radians to rotate
393404
* @return {[type]} [description]
394405
*/
395406
p5.Renderer3D.prototype.rotateZ = function(rad) {

src/core/transform.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,18 @@ p5.prototype.resetMatrix = function() {
9595
* </code>
9696
* </div>
9797
*/
98-
p5.prototype.rotate = function(r) {
98+
p5.prototype.rotate = function() {
99+
var r = arguments[0];
99100
if (this._angleMode === constants.DEGREES) {
100101
r = this.radians(r);
101102
}
102-
this._graphics.rotate(r);
103+
//in webgl mode
104+
if(arguments.length > 1){
105+
this._graphics.rotate(r, arguments[1]);
106+
}
107+
else {
108+
this._graphics.rotate(r);
109+
}
103110
return this;
104111
};
105112

0 commit comments

Comments
 (0)