Permalink
Browse files

wow I need to commit in case my hard drive failes

  • Loading branch information...
1 parent f193034 commit 68c1ab20e5794307726df35b5bce51ebf2e523ba @jlongster committed Nov 12, 2012
View
@@ -1,10 +1,26 @@
-all: main.js
+all: built
-main.js: main.ljs
- ./LLJS/bin/ljc -o main.js main.ljs
-
-built:
+built: *.js
+ rm -rf built
+ mkdir built
+ cat gl-matrix-min.js \
+ simplex-noise.js \
+ input.js \
+ resources.js \
+ scene.js \
+ mesh.js \
+ terrain.js \
+ camera.js \
+ shaders.js \
+ renderer.js \
+ mesh-loader.js \
+ stats.min.js \
+ main.js > built/bundled.js
+ cp index-built.html built/index.html
+ cp -r resources built
+ java -jar compiler.jar --js built/bundled.js > built/bundled-out.js
+ mv built/bundled-out.js built/bundled.js
clean:
- rm main.js
+ rm -rf built
View
Oops, something went wrong.
View
@@ -0,0 +1,101 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8" />
+ <title>Github Game Off 2012</title>
+
+ <style>
+ html {
+ height: 100%;
+ }
+
+ body {
+ font-size: 0;
+ height: 100%;
+ width: 100%;
+ margin: 0;
+ padding: 0;
+ background-color: #222222;
+ }
+
+ canvas {
+ width: 100%;
+ height: 100%;
+ display: block;
+ margin: 0 auto;
+
+ image-rendering: optimizeSpeed;
+ image-rendering: -moz-crisp-edges;
+ image-rendering: -webkit-optimize-contrast;
+ }
+
+ .debug {
+ position: absolute;
+ top: 0;
+ left: 0;
+ padding: .5em;
+ background-color: #333333;
+ color: #d0d0d0;
+ font-size: 16px;
+ }
+ </style>
+ </head>
+
+ <script id="default-fragment" type="x-shader/x-fragment">
+ void main() {
+ gl_FragColor = vec4(1.0, .8, .8, 1.0);
+ }
+ </script>
+
+ <script id="default-vertex" type="x-shader/x-vertex">
+ attribute vec3 a_position;
+ uniform mat4 pers;
+ uniform mat4 transform;
+
+ void main() {
+ gl_Position = pers * transform * vec4(a_position, 1);
+ }
+ </script>
+
+ <script id="fragment-shader" type="x-shader/x-fragment">
+ precision highp float;
+ varying vec3 v;
+ varying vec2 texcoord;
+ uniform sampler2D sampler;
+
+ void main() {
+ float density = 0.002;
+ float z = gl_FragCoord.z / gl_FragCoord.w;
+ float LOG2 = 1.442695;
+ float fogFactor = exp2(-density*density*z*z*LOG2);
+ fogFactor = clamp(fogFactor, 0.0, 1.0);
+
+ gl_FragColor = mix(vec4(0.0, 0.0, 0.0, 1.0), texture2D(sampler, texcoord.xy), fogFactor);
+ }
+ </script>
+
+ <script id="vertex-shader" type="x-shader/x-vertex">
+ attribute vec3 a_position;
+ attribute vec2 a_texcoord;
+ uniform mat4 pers;
+ uniform mat4 transform;
+ varying vec3 v;
+ varying vec2 texcoord;
+
+ float rand(vec2 n) {
+ return 0.5 + 0.5 *
+ fract(sin(dot(n.xy, vec2(12.9898, 78.233)))* 43758.5453);
+ }
+
+ void main() {
+ gl_Position = pers * transform * vec4(a_position, 1);
+ v = a_position;
+ texcoord = a_texcoord;
+ }
+ </script>
+ <body>
+ <canvas id="canvas"></canvas>
+
+ <script src="bundled.js"></script>
+ </body>
+</html>
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -1,70 +1,96 @@
-function Camera(pos) {
- this.pos = pos;
- this.pitch = 0.;
- this.yaw = 0.;
-}
-
-Camera.prototype.update = function(dt) {
- this.transform = mat4.create();
- mat4.identity(this.transform);
-
- var mouse = getMouseMoved();
- this.pitch += mouse[0] * .5 * dt;
- this.yaw += mouse[1] * .5 * dt;
-
- if((isDown('LEFT') || isDown('a')) && !isMouseDown()) {
- this.pitch -= 1 * dt;
- }
+quat4.rotateX = function (quat, angle, dest) {
+ if (!dest) { dest = quat; }
- if((isDown('RIGHT') || isDown('d')) && !isMouseDown()) {
- this.pitch += 1 * dt;
- }
+ angle *= 0.5;
- mat4.rotate(this.transform, Math.PI, [0, 1, 0]);
- mat4.rotate(this.transform, -this.yaw, [1, 0, 0]);
- mat4.rotate(this.transform, this.pitch, [0, 1, 0]);
-
- var forward = vec3.create();
- var side = vec3.create();
- mat4.multiplyVec3(this.transform, [0, 0, -1], forward);
- mat4.multiplyVec3(this.transform, [1, 0, 0], side);
- vec3.scale(forward, 100*dt, forward);
- vec3.scale(side, 100*dt, side);
- forward[0] = -forward[0];
- side[2] = -side[2];
-
- if((isDown('LEFT') || isDown('a')) && isMouseDown()) {
- var res = vec3.create();
- vec3.subtract(this.pos, side, res);
- this.pos = res;
- }
+ var qax = quat[0], qay = quat[1], qaz = quat[2], qaw = quat[3],
+ qbx = Math.sin(angle), qbw = Math.cos(angle);
- if((isDown('RIGHT') || isDown('d')) && isMouseDown()) {
- var res = vec3.create();
- vec3.add(this.pos, side, res);
- this.pos = res;
- }
+ dest[0] = qax * qbw + qaw * qbx;
+ dest[1] = qay * qbw + qaz * qbx;
+ dest[2] = qaz * qbw - qay * qbx;
+ dest[3] = qaw * qbw - qax * qbx;
+};
- if(isDown('UP') || isDown('w')) {
- var res = vec3.create();
- vec3.add(this.pos, forward, res);
- this.pos = res;
- }
+quat4.rotateY = function (quat, angle, dest) {
+ if (!dest) { dest = quat; }
- if(isDown('DOWN') || isDown('s')) {
- var res = vec3.create();
- vec3.subtract(this.pos, forward, res);
- this.pos = res;
- }
+ angle *= 0.5;
- if(isDown('SPACE')) {
- renderer.addObject(new Ball());
- }
-
- var x = this.pos[0];
- var y = this.pos[1];
- var z = this.pos[2];
- this.pos[1] = Terrain.getHeight(x, z, true) + 20.0;
- mat4.translate(this.transform, [-this.pos[0], -this.pos[1], -this.pos[2]]);
+ quat4.multiply(quat,
+ [0, Math.sin(angle), 0, Math.cos(angle)],
+ dest);
};
+
+var Camera = SceneNode.extend({
+ init: function(pos) {
+ this.parent(pos);
+ // Default position should be looking at a positive Z axis
+ this.yaw = Math.PI;
+ this.pitch = 0.;
+ },
+
+ update: function(dt) {
+ this.transform = mat4.create();
+
+ var mouse = getMouseMoved();
+ this.yaw -= mouse[0] * .25 * dt;
+ this.pitch -= mouse[1] * .25 * dt;
+
+ if((isDown('LEFT') || isDown('a')) && !isMouseDown()) {
+ this.yaw += 1 * dt;
+ }
+
+ if((isDown('RIGHT') || isDown('d')) && !isMouseDown()) {
+ this.yaw -= 1 * dt;
+ }
+
+ // TODO: optimize this
+ var globalQuat = quat4.fromAngleAxis(-this.pitch, [1, 0, 0]);
+ quat4.rotateY(globalQuat, -this.yaw);
+ quat4.toMat4(globalQuat, this.transform);
+
+ this.rot = quat4.fromAngleAxis(this.pitch, [1, 0, 0]);
+ quat4.rotateY(this.rot, this.yaw);
+
+ var forward = vec3.create([0, 0, -1]);
+ var left = vec3.create([-1, 0, 0]);
+ quat4.multiplyVec3(this.rot, forward);
+ quat4.multiplyVec3(this.rot, left);
+
+ vec3.scale(forward, 180*dt, forward);
+ vec3.scale(left, 100*dt, left);
+
+ if((isDown('LEFT') || isDown('a')) && isMouseDown()) {
+ vec3.add(this.pos, left);
+ }
+
+ if((isDown('RIGHT') || isDown('d')) && isMouseDown()) {
+ vec3.subtract(this.pos, left);
+ }
+
+ if(isDown('UP') || isDown('w')) {
+ vec3.add(this.pos, forward);
+ }
+
+ if(isDown('DOWN') || isDown('s')) {
+ vec3.subtract(this.pos, forward);
+ }
+
+ var x = this.pos[0];
+ var y = this.pos[1];
+ var z = this.pos[2];
+ this.pos[1] = Terrain.getHeight(x, z, true) + 20.0;
+ mat4.translate(this.transform, [-this.pos[0], -this.pos[1], -this.pos[2]]);
+
+ this._dirty = true;
+ this.globalTransform = this.transform;
+ },
+
+ prerender: function() {
+ },
+
+ render: function() {
+ }
+});
View
Binary file not shown.
Oops, something went wrong.

0 comments on commit 68c1ab2

Please sign in to comment.