Skip to content

Commit

Permalink
Fixing syntax shown up by the cloud 9 IDE
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Tupper committed Jul 31, 2012
1 parent 22a3312 commit db5f33a
Show file tree
Hide file tree
Showing 14 changed files with 274 additions and 355 deletions.
55 changes: 11 additions & 44 deletions demoscene.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var inquisitiveturtle = inquisitiveturtle || { render3d : { prim: {}}};
var vector = inquisitiveturtle.render3d.vector;
var cube = inquisitiveturtle.render3d.prim.cube;

var display;
var world;
Expand All @@ -21,15 +21,15 @@ function range(start, stop, steps)
if (steps <= 1)
return [start];

var range = [];
var lrange = [];

var STEP = (stop - start) / (steps-1);

for (var i = 0; i < steps; i++)
{
range[i] = start + (i * STEP);
lrange[i] = start + (i * STEP);
}
return range;
return lrange;
}

function getHeight(x, y)
Expand Down Expand Up @@ -57,17 +57,6 @@ var colormap = [
[0,1,0,1,0,1]
];

var blankMap = [
[0,0,0,0,0,0],
[0,0,0,0,0,0],
[0,0,0,0,0,0],
[0,0,0,0,0,0],
[0,0,0,0,0,0],
[0,0,0,0,0,0]
];

var minxcol = 100;

function getColor(x, y)
{
var yt = Math.floor((y + 0.999) * (colormap.length/2));
Expand All @@ -85,29 +74,13 @@ function getColor(x, y)
function getAvgHeight(minx, miny, maxx, maxy)
{
return getHeight(minx, miny);

var maxheight = -1000;
var currentheight;
var yrange = range(miny, maxy, 4)
var xrange = range(minx, maxx, 4);
for (var s=0, ss=yrange.length; s < ss; s++)
{
for (var t=0, tt=xrange.length; t < tt; t++)
{
currentheight = getHeight(xrange[t], xrange[s]);
if (currentheight > maxheight)
maxheight = currentheight;
}
}

return maxheight;
}


function getAvgColor(minx, miny, maxx, maxy)
{
var color = new vector(0,0,0);
var yrange = range(miny, maxy, 4)
var yrange = range(miny, maxy, 4);
var xrange = range(minx, maxx, 4);
for (var s=0, ss=yrange.length; s < ss; s++)
{
Expand Down Expand Up @@ -171,7 +144,7 @@ var pauseset = 0;

var timer = null;
function doClick() {
if (animate > 0)
if (animate && animate > 0)
{
clearInterval(timer);
doFrame();
Expand All @@ -183,18 +156,12 @@ function doClick() {
animate = new Date().getTime();
nextexpected = new Date().getTime();
doFrame();
timer = setInterval("doFrame();", 1000/25);
timer = setInterval(function() { doFrame();}, 1000/25);
}
}






var rotate = new vector(0, 0.1, 0);
var move = new vector(0,0,4);

var pad = new vector(0,0,0);

function doAnimation(iteration){
Expand All @@ -207,8 +174,8 @@ function doAnimation(iteration){

world.prims[0].moveTo( pad );

pad.x = -15000 * Math.sin(iteration/10);
pad.z = -15000 * Math.cos(iteration/10);
pad.x = -10000 * Math.sin(iteration/10);
pad.z = -20000 * Math.cos(iteration/10);
pad.y = 2000 + (500 * Math.cos(iteration/50)) + getWorldHeight(pad.x,pad.z);
world.prims[1].moveTo( pad );

Expand Down Expand Up @@ -301,10 +268,10 @@ function doFrame() {
}


if (fpsspan != null)
if (fpsspan !== null)
fpsspan.innerHTML = "FPS " + totalfps/10 + " (" + display.camera._detailLevel.toFixed(5) + ")";

if (primCounter != null)
if (primCounter !== null)
primCounter.innerHTML = "Prims: " + display.renderinfo.primCount + "(" + (display.renderinfo.primCount / (timeend-timestart)).toFixed(2) + "Kp/s)";

if (animate > 0)
Expand Down
43 changes: 20 additions & 23 deletions lib/inquisitiveturtle.render3d.display.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
if (typeof inquisitiveturtle == "undefined")
inquisitiveturtle = function() {}

if (typeof inquisitiveturtle.render3d == "undefined")
inquisitiveturtle.render3d = function() {}

var inquisitiveturtle = inquisitiveturtle || function() {};
inquisitiveturtle.render3d = inquisitiveturtle.render3d || function() {};

if (typeof inquisitiveturtle.render3d.vector == "undefined")
throw "You must include 'inquisitiveturtle.render3d.vector.js' before including 'inquisitiveturtle.render3d.display.js'"
throw "You must include 'inquisitiveturtle.render3d.vector.js' before including 'inquisitiveturtle.render3d.display.js'";

if (typeof inquisitiveturtle.render3d.face == "undefined")
throw "You must include 'inquisitiveturtle.render3d.face.js' before including 'inquisitiveturtle.render3d.display.js'"
throw "You must include 'inquisitiveturtle.render3d.face.js' before including 'inquisitiveturtle.render3d.display.js'";

if (typeof inquisitiveturtle.render3d.prim == "undefined")
throw "You must include 'inquisitiveturtle.render3d.prim.js' before including 'inquisitiveturtle.render3d.display.js'"
throw "You must include 'inquisitiveturtle.render3d.prim.js' before including 'inquisitiveturtle.render3d.display.js'";

if (typeof inquisitiveturtle.render3d.prim.camera == "undefined")
throw "You must include 'inquisitiveturtle.render3d.prim.camera.js' before including 'inquisitiveturtle.render3d.display.js'"
throw "You must include 'inquisitiveturtle.render3d.prim.camera.js' before including 'inquisitiveturtle.render3d.display.js'";



Expand All @@ -27,13 +24,13 @@ inquisitiveturtle.render3d.display = function( container, width, height, campos,
this.height = height;

this.camera = new inquisitiveturtle.render3d.prim.camera();
if (campos != null)
if (campos)
this.camera.moveTo(campos);

if (camrot != null)
if (camrot)
this.camera.rotateTo(camrot);

this.camera.scaleTo( new vector(width, height, Math.max(width,height)));
this.camera.scaleTo( new inquisitiveturtle.render3d.vector(width, height, Math.max(width,height)));

this.container = null;
if (typeof container == "string") {
Expand All @@ -47,15 +44,15 @@ inquisitiveturtle.render3d.display = function( container, width, height, campos,
this.container.style.height=height + "px";

this._failoverCreateEngine();
}
};





inquisitiveturtle.render3d.display.prototype._getSupportedEngine = function() {
var supported = inquisitiveturtle.render3d.renderer.supportedEngines();
if (supported[0] != null)
if (supported[0])
{
return supported[0];
}
Expand All @@ -70,27 +67,27 @@ inquisitiveturtle.render3d.display.prototype._getSupportedEngine = function() {
container.innerHTML = "<span class='it-error'>No compatible renderer found, cannot continue</span>";
throw "No compatible renderer found, cannot continue";
}
}
};




inquisitiveturtle.render3d.display.prototype._doError = function(context, err) {
}
};





inquisitiveturtle.render3d.display.prototype._failRenderEngine = function(err)
{
if (this.renderinfo != null)
if (this.renderinfo)
{
this.renderinfo.supported = function() { return false; };
this.renderinfo.description += " - Failed: " + err;
this.renderinfo = null;
}
}
};



Expand All @@ -104,7 +101,7 @@ inquisitiveturtle.render3d.display.prototype._failoverCreateEngine = function()
while (container && container.firstChild)
container.removeChild(container.firstChild);

if (this.renderinfo == null)
if (!this.renderinfo)
this.renderinfo = this._getSupportedEngine();

try
Expand All @@ -113,7 +110,7 @@ inquisitiveturtle.render3d.display.prototype._failoverCreateEngine = function()

if (inquisitiveturtle.render3d.display.onenginestart)
{
if (inquisitiveturtle.render3d.display.onenginestartcontext != null)
if (inquisitiveturtle.render3d.display.onenginestartcontext)
inquisitiveturtle.render3d.display.onenginestartcontext.call(inquisitiveturtle.render3d.view.onenginestart, this, this.renderinfo);
else
inquisitiveturtle.render3d.display.onenginestart(this, this.renderinfo);
Expand All @@ -129,7 +126,7 @@ inquisitiveturtle.render3d.display.prototype._failoverCreateEngine = function()
this.renderer = null;
}
}
}
};



Expand All @@ -144,7 +141,7 @@ inquisitiveturtle.render3d.display.prototype.render = function() {

this.renderer.endFrame(this.camera._id);

}
};



Expand Down
38 changes: 18 additions & 20 deletions lib/inquisitiveturtle.render3d.face.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
if (typeof inquisitiveturtle == "undefined")
inquisitiveturtle = function() {}
var inquisitiveturtle = inquisitiveturtle || function() {};

if (typeof inquisitiveturtle.render3d == "undefined")
inquisitiveturtle.render3d = function() {}
inquisitiveturtle.render3d = inquisitiveturtle.render3d || function() {};

if (typeof inquisitiveturtle.render3d.vector == "undefined")
throw "You must include 'inquisitiveturtle.render3d.vector.js' before including 'inquisitiveturtle.render3d.face.js'";
Expand All @@ -14,7 +12,7 @@ inquisitiveturtle.render3d.face = function() {
this.__vector = inquisitiveturtle.render3d.vector;

this.init();
}
};



Expand All @@ -23,22 +21,22 @@ inquisitiveturtle.render3d.face.prototype.init = function() {
this.points = [];
this.normal = new this.__vector();
this.color = new this.__vector();
}
};




inquisitiveturtle.render3d.face.prototype.setPoints = function(points) {
this.points = points;
return this;
}
};




inquisitiveturtle.render3d.face.prototype.getPoints = function() {
return this.points;
}
};



Expand All @@ -63,44 +61,44 @@ inquisitiveturtle.render3d.face.prototype.calcNormal = function() {

this.normal.normalize();
return this;
}
};




inquisitiveturtle.render3d.face.prototype.setColor = function(color) {
this.color = color;
return this;
}
};




inquisitiveturtle.render3d.face.prototype.getColor = function() {
return this.color;
}
};




inquisitiveturtle.render3d.face.prototype.resetSpares = function() {
this._sparesIndex = 0;
}
};


inquisitiveturtle.render3d.face.prototype.getSpare = function() {
if (this._spares == null)
if (!this._spares)
this._spares = [];

if (this._sparesIndex == 0)
if (this._sparesIndex === 0)
this._sparesIndex = 0;

if (this._sparesIndex >= this._spares.length)
{
this._spares[this._sparesIndex] = new this.__vector();
}
return this._spares[this._sparesIndex++];
}
};



Expand All @@ -118,7 +116,7 @@ inquisitiveturtle.render3d.face.prototype.clipTo = function( points, planepoint,

var output = [];

if (inLength == 0)
if (inLength === 0)
return output;

s = points[inLength-1];
Expand Down Expand Up @@ -154,7 +152,7 @@ inquisitiveturtle.render3d.face.prototype.clipTo = function( points, planepoint,
}

return output;
}
};



Expand All @@ -174,10 +172,10 @@ inquisitiveturtle.render3d.face.prototype.lineIntersect = function( linepointA,
var num = d - (pnx * lax) - (pny * lay) - (pnz * laz);
var den = (pnx * (linepointB.x - lax)) + (pny * (linepointB.y - lay)) + (pnz * (linepointB.z - laz));

if (num == 0 && den == 0)
if (num === 0 && den === 0)
return linepointA; // Entire line in is plane

if (den == 0)
if (den === 0)
return null; // Line is parallel to plane

var t = num/den;
Expand All @@ -186,7 +184,7 @@ inquisitiveturtle.render3d.face.prototype.lineIntersect = function( linepointA,
ret.y = linepointA.y + ( (linepointB.y - linepointA.y) * t );
ret.z = linepointA.z + ( (linepointB.z - linepointA.z) * t );
return ret;
}
};



Expand Down
Loading

0 comments on commit db5f33a

Please sign in to comment.