topical media & game development
graphic-canvas-experiment-raytracer-script-camera.js / js
/* Fake a Flog.* namespace */
if(typeof(Flog) == 'undefined') var Flog = {};
if(typeof(Flog.RayTracer) == 'undefined') Flog.RayTracer = {};
Flog.RayTracer.Camera = Class.create();
Flog.RayTracer.Camera.prototype = {
position: null,
lookAt: null,
equator: null,
up: null,
screen: null,
initialize : function(pos, lookAt, up) {
this.position = pos;
this.lookAt = lookAt;
this.up = up;
this.equator = lookAt.normalize().cross(this.up);
this.screen = Flog.RayTracer.Vector.prototype.add(this.position, this.lookAt);
},
getRay: function(vx, vy){
var pos = Flog.RayTracer.Vector.prototype.subtract(
this.screen,
Flog.RayTracer.Vector.prototype.subtract(
Flog.RayTracer.Vector.prototype.multiplyScalar(this.equator, vx),
Flog.RayTracer.Vector.prototype.multiplyScalar(this.up, vy)
)
);
pos.y = pos.y * -1;
var dir = Flog.RayTracer.Vector.prototype.subtract(
pos,
this.position
);
var ray = new Flog.RayTracer.Ray(pos, dir.normalize());
return ray;
},
toString : function () {
return 'Ray []';
}
}
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.