Permalink
Browse files

First public version. Still a lot to do

  • Loading branch information...
mrdoob committed Apr 24, 2010
1 parent 214dd9d commit a90c4e107ff6e3b148458c96965e876f9441b147
View
@@ -0,0 +1,61 @@
// http://ejohn.org/blog/simple-javascript-inheritance/
// Inspired by base2 and Prototype
(function(){
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
// The base Class implementation (does nothing)
this.Class = function(){};
// Create a new Class that inherits from this class
Class.extend = function(prop) {
var _super = this.prototype;
// Instantiate a base class (but only create the instance,
// don't run the init constructor)
initializing = true;
var prototype = new this();
initializing = false;
// Copy the properties over onto the new prototype
for (var name in prop) {
// Check if we're overwriting an existing function
prototype[name] = typeof prop[name] == "function" &&
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
(function(name, fn){
return function() {
var tmp = this._super;
// Add a new ._super() method that is the same method
// but on the super-class
this._super = _super[name];
// The method only need to be bound temporarily, so we
// remove it when we're done executing
var ret = fn.apply(this, arguments);
this._super = tmp;
return ret;
};
})(name, prop[name]) :
prop[name];
}
// The dummy class constructor
function Class() {
// All construction is actually done in the init method
if ( !initializing && this.init )
this.init.apply(this, arguments);
}
// Populate our constructed prototype object
Class.prototype = prototype;
// Enforce the constructor to be what we expect
Class.constructor = Class;
// And make this class extendable
Class.extend = arguments.callee;
return Class;
};
})();
View
@@ -0,0 +1,32 @@
var Camera = Vector3.extend
({
up: null,
target: null,
zoom: null,
focus: null,
roll: null,
matrix: null,
init: function(x, y, z)
{
this._super(x, y, z);
this.up = new Vector3( 0, 1, 0 );
this.target = new Vector3( 0, 0, 0 );
this.zoom = 3;
this.focus = 500;
this.roll = 0;
this.matrix = new Matrix4();
},
updateMatrix: function()
{
this.matrix.lookAt( this, this.target, this.up );
},
toString: function()
{
return 'Camera ( ' + this.x + ', ' + this.y + ', ' + this.z + ' )';
}
});
View
@@ -0,0 +1,31 @@
var Face3 = Vector3.extend
({
a: null, b: null, c: null,
screen: null,
uv: null,
normal: null,
color: null,
colorString: null,
init: function(a, b, c, uv, normal, color)
{
this._super((a.x + b.x + c.x) / 3, (a.y + b.y + c.y) / 3, (a.z + b.z + c.z) / 3);
this.a = a;
this.b = b;
this.c = c;
this.screen = new Vector3();
this.uv = uv ? uv : [ [0, 0], [0, 0], [0, 0] ];
this.normal = normal ? normal : new Vector3();
this.color = color ? color : [0, 0, 0];
this.colorString = 'rgb(' + this.color[0] + ', ' + this.color[1] + ', ' + this.color[2] + ')';
},
toString: function()
{
return 'Face ( ' + this.a + ', ' + this.b + ', ' + this.c + ' )';
}
});
View
@@ -0,0 +1,28 @@
var Face4 = Vector3.extend
({
a: null, b: null, c: null, d: null,
normal: null,
screen: null,
color: null,
colorString: null,
init: function(a, b, c, d, uv, normal, color)
{
this._super((a.x + b.x + c.x + d.x) / 4, (a.y + b.y + c.y + d.y) / 4, (a.z + b.z + c.z + d.z) / 4);
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.screen = new Vector3();
this.color = color ? color : [0, 0, 0];
this.colorString = 'rgb(' + this.color[0] + ', ' + this.color[1] + ', ' + this.color[2] + ')';
},
toString: function()
{
return 'Face ( ' + this.a + ', ' + this.b + ', ' + this.c + ' )';
}
});
View
@@ -0,0 +1,11 @@
var Geometry = Class.extend
({
vertices: null,
faces: null,
init: function()
{
this.vertices = new Array();
this.faces = new Array();
}
});
View
@@ -0,0 +1,71 @@
var Matrix3 = Class.extend
({
n11: null, n12: null, n13: null,
n21: null, n22: null, n23: null,
n31: null, n32: null, n33: null,
init: function()
{
this.identity();
},
identity: function()
{
this.n11 = 1; this.n12 = 0; this.n13 = 0;
this.n21 = 0; this.n22 = 1; this.n23 = 0;
this.n31 = 0; this.n32 = 0; this.n33 = 1;
},
assign: function(m)
{
this.n11 = m.n11; this.n12 = m.n12; this.n13 = m.n13;
this.n21 = m.n21; this.n22 = m.n22; this.n23 = m.n23;
this.n31 = m.n31; this.n32 = m.n32; this.n33 = m.n33;
},
multiplySelf: function(m)
{
var n11 = this.n11, n12 = this.n12, n13 = this.n13, n14 = this.n14;
var n21 = this.n21, n22 = this.n22, n23 = this.n23, n24 = this.n24;
var n31 = this.n31, n32 = this.n32, n33 = this.n33, n34 = this.n34;
this.n11 = n11 * m.n11 + n12 * m.n21 + n13 * m.n31;
this.n12 = n11 * m.n12 + n12 * m.n22 + n13 * m.n32;
this.n13 = n11 * m.n13 + n12 * m.n23 + n13 * m.n33;
this.n21 = n21 * m.n11 + n22 * m.n21 + n23 * m.n31;
this.n22 = n21 * m.n12 + n22 * m.n22 + n23 * m.n32;
this.n23 = n21 * m.n13 + n22 * m.n23 + n23 * m.n33;
this.n31 = n31 * m.n11 + n32 * m.n21 + n33 * m.n31;
this.n32 = n31 * m.n12 + n32 * m.n22 + n33 * m.n32;
this.n33 = n31 * m.n13 + n32 * m.n23 + n33 * m.n33;
},
inverse: function()
{
var n11 = this.n11, n12 = this.n12, n13 = this.n13, n14 = this.n14;
var n21 = this.n21, n22 = this.n22, n23 = this.n23, n24 = this.n24;
var n31 = this.n31, n32 = this.n32, n33 = this.n33, n34 = this.n34;
this.n11 = n11; this.n12 = n21; this.n13 = n31;
this.n21 = n12; this.n22 = n22; this.n23 = n32;
this.n31 = n13; this.n32 = n23; this.n33 = n33;
},
clone: function()
{
var m = new Matrix3();
m.n11 = this.n11; m.n12 = this.n12; m.n13 = this.n13;
m.n21 = this.n21; m.n22 = this.n22; m.n23 = this.n23;
m.n31 = this.n31; m.n32 = this.n32; m.n33 = this.n33;
return m;
},
toString: function()
{
return "| " + this.n11 + " " + this.n12 + " " + this.n13 + " |\n" +
"| " + this.n21 + " " + this.n22 + " " + this.n23 + " |\n" +
"| " + this.n31 + " " + this.n32 + " " + this.n33 + " |";
}
});
Oops, something went wrong.

0 comments on commit a90c4e1

Please sign in to comment.