Schroedingers-Hat/jsphys

Minor cleanup.

• Loading branch information...
capnrefsmmat committed Jan 28, 2012
1 parent 3b0e5f3 commit f188696dc3b0e0e422c9539fafc0236bef713d1b
Showing with 45 additions and 44 deletions.
1. +28 −15 relativity/js/relLibs.js
2. +17 −29 relativity/js/scene.js
 @@ -2,6 +2,12 @@ "use strict"; +// glMatrix defaults to 32-bit arrays, but we'd like 64-bit arrays +// as we sometimes get nasty rounding errors otherwise. +if (typeof Float64Array !== "undefined") { + glMatrixArrayType = Float64Array; +} + // Convenient constants. var c; // Default value set in scene.defaults var nullQuat4 = quat4.create([0,0,0,0]); @@ -70,24 +76,32 @@ function genEnergy(P,c,m) { } /** - * Takes a velocity and a speed of light and returns a boost matrix - * A bit less efficient than it should be, create some temporary variables lazy git. :/ - * - * Until that time, here's an explanation. - * An acceleration (or boost) in relativity is almost exactly equivalent to a rotation. - * You can think of a particle/object as moving at the speed of light at all times in the t direction, - * The acceleration 'rotates' that path so that it is moving in the x direction a little bit as well as the y. - * This matrix implements the appropriate cosh(artanh(B)) and similar values, using linear algebra for speed (although not clarity) - * One way to get an idea for how hyperbolic space works is to play with a triangle. Declare the wrong side to be the hypotenuse, and change - * The angles. You'll notice that both the opposite and adjacent tend to infinity, so too do x and t intervals for a given proper time (hypotenuse) + * Takes a velocity and a speed of light and returns a boost matrix + * + * A bit less efficient than it should be, create some temporary variables lazy + * git. :/ + * + * Until that time, here's an explanation. An acceleration (or boost) in + * relativity is almost exactly equivalent to a rotation. You can think of a + * particle/object as moving at the speed of light at all times in the t + * direction. The acceleration 'rotates' that path so that it is moving in the x + * direction a little bit as well as the y. This matrix implements the + * appropriate cosh(artanh(B)) and similar values, using linear algebra for + * speed (although not clarity). + * + * One way to get an idea for how hyperbolic space works is to play with a + * triangle. Declare the wrong side to be the hypotenuse, and change the angles. + * You'll notice that both the opposite and adjacent tend to infinity, so too do + * x and t intervals for a given proper time (hypotenuse). + * * I plan to make a demo of this some time. - * - * NB: Does not yet handle boost in z direction. If you give it a z component it will not work correctly. + * + * NB: Does not yet handle boost in z direction. If you give it a z component it + * will not work correctly. */ function cBoostMat(boostV, c) { var gamma = boostV[3] / c; - if (gamma - 1 < 0.0000001) - { + if (gamma - 1 < 0.0000001) { return (mat4.create([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])); } var bx = boostV[0] / boostV[3]; @@ -103,7 +117,6 @@ function cBoostMat(boostV, c) { /** * Take a 3-velocity and return a boost matrix from cBoostMat. - * */ function boostFrom3Vel(vx, vy, vz) { var gamma = vToGamma([vx, vy, vz]);
 @@ -6,31 +6,19 @@ * demo and set of interacting objects. */ function Scene() { - // glMatrix defaults to 32-bit arrays, but we'd like 64-bit arrays - // as we sometimes get nasty rounding errors otherwise. - if (typeof Float64Array !== "undefined") { - glMatrixArrayType = Float64Array; - } - this.initialTime = new Date().getTime(); - if (typeof FlashCanvas != "undefined") { + this.lightConeCanvas = document.createElement('canvas'); + if (typeof FlashCanvas !== "undefined") { FlashCanvas.initElement(\$('#canvas-2d')[0]); FlashCanvas.initElement(\$('#canvas-minkowski')[0]); FlashCanvas.initElement(\$('#canvas-3d')[0]); + FlashCanvas.initElement(this.lightConeCanvas); } this.g = \$('#canvas-2d')[0].getContext("2d"); this.h = \$('#canvas-minkowski')[0].getContext("2d"); this.TDC = \$('#canvas-3d')[0].getContext("2d"); - - this.loaded = false; - - this.lightConeCanvas = document.createElement('canvas'); - if (typeof FlashCanvas != "undefined") { - FlashCanvas.initElement(this.lightConeCanvas); - } - this.lCCtx = this.lightConeCanvas.getContext('2d'); // fillText was only introduced with Firefox 3.5, and some older browsers do @@ -49,6 +37,10 @@ function Scene() { this.timeZoom = 0.25; this.t = 0; this.keyDown = false; + this.loaded = false; + this.drawing = false; + this.debug = false; + this.audio = new AudioManager(); // The default set of object-specific settings. These can be overridden by // a specific demo, and by individual objects in that demo. @@ -74,11 +66,7 @@ function Scene() { "neverShowFramePos": false, "alwaysShowVisualPos": false, "neverShowVisualPos": false, - "interactions": true - }; - - this.drawing = false; - this.debug = false; + "interactions": true}; // Records whether the keys for various actions are currently pressed // interface.js binds various key events to these actions and toggles their @@ -98,14 +86,9 @@ function Scene() { "zoomOut": false, "timeZoomIn": false, "timeZoomOut": false}; - this.audio = new AudioManager(); } Scene.prototype = { - toggle3D: function() { - this.curOptions.show3D = !this.curOptions.show3D; - }, - /** * Load the specified demo at the given step. (The step indexes into * the demo's steps array.) @@ -133,7 +116,7 @@ Scene.prototype = { // Clone our default object-specific options into curOptions, rather than // getting a reference - this.curOptions = jQuery.extend({}, this.defaults); + this.curOptions = \$.extend({}, this.defaults); // If the demo specifies option overrides, apply them if (typeof demo.steps[step].options === "object") { @@ -255,9 +238,10 @@ Scene.prototype = { this.clear(); - // Draw the light cone; if we're using flashCanvas, don't use offscreen canvas. + // Draw the light cone; if we're using flashCanvas, don't use offscreen + // canvas. if (typeof FlashCanvas != "undefined") { - drawLightCone(this,this.h); + drawLightCone(this, this.h); } else { this.h.drawImage(this.lightConeCanvas, 0, 0); } @@ -467,6 +451,10 @@ Scene.prototype = { this.replay(); } }, + + toggle3D: function() { + this.curOptions.show3D = !this.curOptions.show3D; + }, /** * Reload the current demo from scratch and restart the animation. @@ -535,7 +523,7 @@ Scene.prototype = { /** * Helper function to draw the scene. Necessary because of the setInterval() - * this problem. + * `this` problem. */ function drawScene(scene) { return function (event) {

0 comments on commit `f188696`

Please sign in to comment.