Skip to content

Commit

Permalink
finished tests, only 1 failed test I still need to investigate.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andor committed Feb 17, 2010
1 parent c368f53 commit 55f458e
Show file tree
Hide file tree
Showing 4 changed files with 213 additions and 41 deletions.
3 changes: 2 additions & 1 deletion Makefile
@@ -1,6 +1,7 @@
# If your jsshell isn't at ./tools/js/src/js, update JS below
TOOLSDIR=./tools
JS=$(TOOLSDIR)/js/src/js
# JS=$(TOOLSDIR)/js/src/js
JS = /Users/andor/mozilla-central/obj-ff-dbg/dist/MinefieldDebug.app/Contents/MacOS/./js

# Rule for making pure JS code from a .pde (runs through parser + beautify)
%.js : %.pde
Expand Down
77 changes: 72 additions & 5 deletions processing.js
Expand Up @@ -516,6 +516,7 @@
modelView,
modelViewInv,
userMatrixStack,
inverseCopy,
projection,
frustumMode = false,
cameraFOV = 60 * (Math.PI / 180),
Expand Down Expand Up @@ -2698,6 +2699,22 @@
this.elements = result.slice();
}
},
invApply: function() {
if ( inverseCopy == null ) {
inverseCopy = new PMatrix3D();
}
var a = arguments;
inverseCopy.set( a[0], a[1], a[2], a[3],
a[4], a[5], a[6], a[7],
a[8], a[9], a[10], a[11],
a[12], a[13], a[14], a[15] );

if ( !inverseCopy.invert() ) {
return false;
}
this.preApply( inverseCopy );
return true;
},
rotateX: function( angle ){
var c = p.cos( angle );
var s = p.sin( angle );
Expand Down Expand Up @@ -2965,13 +2982,13 @@
cam.translate( -eyeX, -eyeY, -eyeZ );

cameraInv = new PMatrix3D();
cameraInv.set(x.x, x.y, x.z, 0,
y.x, y.y, y.z, 0,
z.x, z.y, z.z, 0,
0, 0, 0, 1);
cameraInv.invApply(x.x, x.y, x.z, 0,
y.x, y.y, y.z, 0,
z.x, z.y, z.z, 0,
0, 0, 0, 1);

cameraInv.translate( eyeX, eyeY, eyeZ );

modelView = new PMatrix3D();
modelView.set( cam );

Expand Down Expand Up @@ -3093,6 +3110,56 @@
}
};

////////////////////////////////////////////////////////////////////////////
// Coordinates
////////////////////////////////////////////////////////////////////////////
p.modelX = function modelX( x, y, z ) {
var mv = modelView.array();
//alert(mv);
var ci = cameraInv.array();
//alert(ci);

var ax = mv[ 0]*x + mv[ 1]*y + mv[ 2]*z + mv[ 3];
var ay = mv[ 4]*x + mv[ 5]*y + mv[ 6]*z + mv[ 7];
var az = mv[ 8]*x + mv[ 9]*y + mv[10]*z + mv[11];
var aw = mv[12]*x + mv[13]*y + mv[14]*z + mv[15];

var ox = ci[ 0]*ax + ci[ 1]*ay + ci[ 2]*az + ci[ 3]*aw;
var ow = ci[12]*ax + ci[13]*ay + ci[14]*az + ci[15]*aw;

return ( ow != 0 ) ? ox / ow : ox;
}

p.modelY = function modelY( x, y, z ) {
var mv = modelView.array();
var ci = cameraInv.array();

var ax = mv[ 0]*x + mv[ 1]*y + mv[ 2]*z + mv[ 3];
var ay = mv[ 4]*x + mv[ 5]*y + mv[ 6]*z + mv[ 7];
var az = mv[ 8]*x + mv[ 9]*y + mv[10]*z + mv[11];
var aw = mv[12]*x + mv[13]*y + mv[14]*z + mv[15];

var oy = ci[ 4]*ax + ci[ 5]*ay + ci[ 6]*az + ci[ 7]*aw;
var ow = ci[12]*ax + ci[13]*ay + ci[14]*az + ci[15]*aw;

return ( ow != 0 ) ? oy / ow : oy;
}

p.modelZ = function modelZ(x, y, z) {
var mv = modelView.array();
var ci = cameraInv.array();

var ax = mv[ 0]*x + mv[ 1]*y + mv[ 2]*z + mv[ 3];
var ay = mv[ 4]*x + mv[ 5]*y + mv[ 6]*z + mv[ 7];
var az = mv[ 8]*x + mv[ 9]*y + mv[10]*z + mv[11];
var aw = mv[12]*x + mv[13]*y + mv[14]*z + mv[15];

var oz = ci[ 8]*ax + ci[ 9]*ay + ci[10]*az + ci[11]*aw;
var ow = ci[12]*ax + ci[13]*ay + ci[14]*az + ci[15]*aw;

return ( ow != 0 ) ? oz / ow : oz;
}

////////////////////////////////////////////////////////////////////////////
// Style functions
////////////////////////////////////////////////////////////////////////////
Expand Down
107 changes: 97 additions & 10 deletions test/unit/model.pde
@@ -1,3 +1,4 @@
// import processing.opengl.*;
// Andor Salga
// Tests for modelX(), modelY(), modelZ()
//
Expand All @@ -6,61 +7,147 @@

// 1.0
size(100,100,OPENGL);
modelX(1,1,1);
_checkEqual( 1.0, modelX(1,1,1));

// 0.0
size(100,100,OPENGL);
rotateY(3.14);
modelX(0,0,0);
_checkEqual( 0.0, modelX(0,0,0) );

// -0.99840546
size(100,100,OPENGL);
rotateY(3.14);
modelX(1,1,1);
_checkEqual( -0.9984060788110511, modelX(1,1,1) );

// 0.0
size(200,100,OPENGL);
rotateY(3.14);
modelX(0,0,0);
_checkEqual( 0.0, modelX(0,0,0) );

// -10
size(200,100,OPENGL);
rotateY(PI);
modelX(10,0,0);
_checkEqual( -10, modelX(10,0,0) );

// -10
size(200,100,OPENGL);
rotateZ(PI);
modelX(10,0,0);
_checkEqual( -10, modelX(10,0,0) );

// -15
size(200,100,OPENGL);
rotateZ(PI);
translate(5,0,0);
modelX(10,0,0);
_checkEqual( -15, modelX(10,0,0) );

// -122.71631
size(200,100,OPENGL);
camera(100,50,0,0,-1,0,0,1,0);
modelX(0,0,0);
_checkEqual( -122.71630413980063, modelX(0,0,0) );

// -427.12918
size(500,500,OPENGL);
camera(250,250,0,0,-1,0,0,1,0);
modelX(0,0,0);
_checkEqual( -427.1291901466046, modelX(0,0,0) );


//////////////////////////////
// modelY

// 1.0
size(100,100,OPENGL);
_checkEqual( 1.0, modelY(1,1,1) );

// 0.0
size(100,100,OPENGL);
rotateX(3.14);
_checkEqual( 0.0, modelY(0,0,0) );

// modelY
// -1.0015907
size(100,100,OPENGL);
rotateX(3.14);
_checkEqual( -1.0015913846440299, modelY(1,1,1) );

// 0.0
size(200,100,OPENGL);
rotateY(3.14);
_checkEqual( 0.0, modelY(0,0,0) );

// 0.0
size(200,100,OPENGL);
rotateZ(PI);
_checkEqual( 0.0, modelY(10,0,0) );

// -10.0
size(200,100,OPENGL);
rotateX(PI);
_checkEqual( -10, modelY(10,10,10) );

// 5.0
size(200,100,OPENGL);
rotateY(PI);
_checkEqual( 5, modelY(10,5,9) );

// -49.0
size(200,100,OPENGL);
rotateX(PI);
translate(5,9,0);
_checkEqual( -49, modelY(0,40,0) );

// -5.458229
size(200,100,OPENGL);
camera(100,50,0,0,-1,0,0,1,0);
_checkEqual( -5.458227176861527, modelY(0,0,0) );

// -73.57651
size(500,500,OPENGL);
camera(250,250,0,0,-1,0,0,1,0);
_checkEqual( -73.57650383804321, modelY(0,0,0) );

//////////////////////////////
// modelZ

// 1.0
size(100,100,OPENGL);
_checkEqual( 1.0, modelZ(1,1,1) );

// 0.0
size(100,100,OPENGL);
rotateX(3.14);
_checkEqual(0.0, modelZ(0,0,0) );

// -0.99840546
size(100,100,OPENGL);
rotateX(3.14);
_checkEqual( -0.9984060788110583, modelZ(1,1,1) );

// 0.0
size(200,100,OPENGL);
rotateY(3.14);
_checkEqual(0.0, modelZ(0,0,0) );

// -10.0
size(200,100,OPENGL);
rotateY(PI);
_checkEqual( -10, modelZ(0,0,10) );

// -9.0
size(200,100,OPENGL);
rotateY(PI);
_checkEqual( -9, modelZ(10,5,9) );

// 49.999996
size(200,100,OPENGL);
rotateX(PI);
translate(5,9,0);
_checkEqual( 50.00000000000001, modelZ(30,40,-50) );

// -100.0
size(200,100,OPENGL);
camera(100,50,0,0,-1,0,0,1,0);
_checkEqual( -100, modelZ(0,0,0) );

// -250.0
size(500,500,OPENGL);
camera(250,250,0,0,-1,0,0,1,0);
_checkEqual( -250, modelZ(0,0,0) );
67 changes: 42 additions & 25 deletions tools/fake-dom.js
@@ -1,10 +1,9 @@
// Processing works with a canvas and the DOM, fake it.
var __empty_func__ = function () {};

var canvas = {
attachEvent: __empty_func__,
addEventListener: __empty_func__,
getContext: function() {
getContext: function() {
return {
translate: __empty_func__,
attachEvent: __empty_func__,
Expand All @@ -22,11 +21,29 @@ var canvas = {
arc: __empty_func__,
scale: __empty_func__,
restore: __empty_func__,
bezierCurveTo: __empty_func__
bezierCurveTo: __empty_func__,
viewport: __empty_func__,
clearColor: __empty_func__,
enable: __empty_func__,
createShader: __empty_func__,
shaderSource: __empty_func__,
compileShader: __empty_func__,
getShaderParameter: function() { return true; },
getShaderInfoLog: __empty_func__,
createProgram: __empty_func__,
attachShader: __empty_func__,
linkProgram: __empty_func__,
getProgramParameter: function() { return true; },
useProgram: __empty_func__,
createBuffer: __empty_func__,
bindBuffer: __empty_func__,
bufferData: __empty_func__
};
}
};


var WebGLFloatArray = __empty_func__;

// This is enough of the DOM to allow the parser work.
var document = {
attachEvent: __empty_func__,
Expand All @@ -39,41 +56,41 @@ var document = {
createElement: function () { return canvas },
addEventListener: __empty_func__
};

var addEventListener = __empty_func__;
var XMLHttpRequest = __empty_func__;
var setInterval = __empty_func__;
var clearInterval = __empty_func__;

var window = {
setInterval: __empty_func__,
XMLHttpRequest: __empty_func__
};

// Constructors not included in many parser tests to allow them to run
var Table = __empty_func__;
Table.prototype.getRowCount = __empty_func__;
Table.prototype.getTableMax = __empty_func__;

var FloatTable = __empty_func__;
FloatTable.prototype.getRowCount = __empty_func__;
FloatTable.prototype.getColumnCount = __empty_func__;
FloatTable.prototype.getRowNames = __empty_func__;
FloatTable.prototype.getTableMax = __empty_func__;

var FixedSpring = __empty_func__;
var Spring2D = __empty_func__;
var Particle = __empty_func__;
var ArrowParticle = __empty_func__;
var FixedSpring = __empty_func__;
var Spring2D = __empty_func__;
var Particle = __empty_func__;
var ArrowParticle = __empty_func__;
var LimitedParticle = __empty_func__;
var GenParticle = __empty_func__;
var DragButton = __empty_func__;
var Button = __empty_func__;
var Check = __empty_func__;
var Radio = __empty_func__;
var Scrollbar = __empty_func__;
var SpinArm = __empty_func__;
var EggRing = __empty_func__;
var OverRect = __empty_func__;
var OverCircle = __empty_func__;
var SpinSpots = __empty_func__;
var GenParticle = __empty_func__;
var DragButton = __empty_func__;
var Button = __empty_func__;
var Check = __empty_func__;
var Radio = __empty_func__;
var Scrollbar = __empty_func__;
var SpinArm = __empty_func__;
var EggRing = __empty_func__;
var OverRect = __empty_func__;
var OverCircle = __empty_func__;
var SpinSpots = __empty_func__;

0 comments on commit 55f458e

Please sign in to comment.