Skip to content

Commit

Permalink
Completed basic interface
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarnhart committed Jan 29, 2012
1 parent 5e2ab33 commit 5fdd66f
Show file tree
Hide file tree
Showing 10 changed files with 1,465 additions and 6 deletions.
Binary file modified app/assets/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions app/assets/javascripts/ConnectivityModifier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//= require Three
//= require Globe

GLOBE.ConnectivityModifier = function(radius) {
this.radius = radius;
};

GLOBE.ConnectivityModifier.prototype.constructor = GLOBE.ConnectivityModifier;

GLOBE.ConnectivityModifier.prototype.modify = function(geometry) {
var vertices = geometry.vertices;
var faces = geometry.faces;
var network = new Array(vertices.length);

for (i=0; i<network.length; i++) {
network[i] = { neighbours: [], normal: new THREE.Vector3(), position: vertices[i].position };
}

for (i=0; i<faces.length; i++) {
var face=faces[i];
var vertexSet = null;
if(face instanceof THREE.Face3) {
vertexSet = [face.a, face.b, face.c];
} else if(face instanceof THREE.Face4) {
vertexSet = [face.a, face.b, face.c, face.d];
}

vertexSet.forEach(function(value, index) {
var node=network[value];
var nextVertex=vertexSet[(index+1) % vertexSet.length];

if(node.neighbours.indexOf(nextVertex)==-1)
node.neighbours.push(nextVertex);

node.normal.addSelf(face.normal);
});
}

for (i=0; i<network.length; i++) {
network[i].normal.divideScalar(network[i].neighbours.length);
}

return network;
};
75 changes: 75 additions & 0 deletions app/assets/javascripts/Gameplay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//= require Globe

GLOBE.Gameplay = function(network, scene) {
this.scene=scene;
this.network=network;

this.reset();

//amount of manufactured goods required to build various things
this.FactoryCost = 10;
this.SpaceCost = 1000;
};

GLOBE.Gameplay.prototype.reset = function() {
this.pollution=0; //planetary pollution
this.capacity=0; //rate of manufacture
this.manufactured_goods=this.FactoryCost; //current stock of manufactured goods

for(i=0; i<this.network.length; i++) {
var node = this.network[i];
if("building" in node && node.building!=null) {
this.scene.removeObject(node.building);
delete node.building;
}
if("joins" in node) {
for(i=0; i<joins.length; i++) {
this.scene.removeObject(node.joins[i]);
delete node.joins[i];
}
}

this.network[i].building=null;
this.network[i].joins = [];
}
}

GLOBE.Gameplay.prototype.handlePlacement = function(placement) {
var node = this.network[placement];

if(node.building!=null) return;

var geometry = new THREE.CubeGeometry(50, 50, 50, 1, 1, 1);
material = new THREE.MeshLambertMaterial( { color: 0x999999 } );
building = new THREE.Mesh( geometry, material );

building.position = node.normal.clone().multiplyScalar(20);
building.position.addSelf(node.position);

building.lookAt(building.position.clone().addSelf(network[placement].normal));

this.scene.add(building);

node.building = building;

for(i=0; i<node.neighbours.length; i++) {
var neighbour = this.network[node.neighbours[i]];
if(neighbour.building != null) {
var midpoint = node.position.clone().addSelf(neighbour.position).multiplyScalar(0.5);
var avgnormal = node.normal.clone().addSelf(neighbour.normal);
var offset = avgnormal.multiplyScalar(40).addSelf(midpoint);
var joinCurve = new THREE.QuadraticBezierCurve3(node.position, offset, neighbour.position)
var joinGeom = new THREE.Geometry();
joinGeom.vertices = joinCurve.getSpacedPoints(8).map(function(value) { return new THREE.Vertex(value); });
var joinMaterial = new THREE.LineBasicMaterial( { color: 0x00ff00 });
var join = new THREE.Line( joinGeom, joinMaterial, THREE.LineStrip);

node.joins.push(join);
this.scene.add(join);
}
}
};

GLOBE.Gameplay.prototype.update = function() {
this.network
}
1 change: 1 addition & 0 deletions app/assets/javascripts/Globe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var GLOBE={};
22 changes: 22 additions & 0 deletions app/assets/javascripts/SphericalModifier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//= require Three
//= require Globe

GLOBE.SphericalModifier = function(radius) {
this.radius = radius;
};

GLOBE.SphericalModifier.prototype.constructor = GLOBE.SphericalModifier;

GLOBE.SphericalModifier.prototype.modify = function(geometry) {
var vertices = geometry.vertices;

for (i=0; i<vertices.length; i++) {
vertices[i].position.setLength(this.radius);
}

delete geometry.__tmpVertices;

geometry.computeCentroids();
geometry.computeFaceNormals();
geometry.computeVertexNormals();
};
Loading

0 comments on commit 5fdd66f

Please sign in to comment.