Permalink
Browse files

2nd commit; fixed looking at

  • Loading branch information...
1 parent ac70434 commit 3512173077bcdb769b62396558703e2081ec46c5 Your Name committed Oct 7, 2012
Showing with 2,544 additions and 533 deletions.
  1. +22 −6 simple.py
  2. +22 −27 web/public/client.js
  3. +2,500 −500 web/test.json
View
@@ -1,5 +1,6 @@
import math
+
class Vec3:
def __init__(self,X=0.0,Y=0.0,Z=0.0):
self.x = X
@@ -22,6 +23,9 @@ def mag(self):
def scale(self,dt):
return Vec3( dt * self.x, dt * self.y, dt * self.z)
+
+ def dot(self,other):
+ return (self.x*other.x + self.y*other.y + self.z*other.z)
def __repr__(self):
return '{ "x":'+str(self.x)+',"y":'+str(self.y)+',"z":'+str(self.z)+' }'
@@ -39,12 +43,21 @@ def __init__(self):
self.acc = Vec3()
self.look = Vec3()
+ self.maxAcc = 0.03
+ self.maxSpeed = 1.0
+
def update(self, dt):
if self.look.mag() != 0.0:
- self.acc = self.vel + (- self.look)
+ b = self.look.normalize()
+ a1 = b.scale(self.vel.dot(b))
+ a2 = self.vel + (-a1)
+ self.acc = (b + a2.scale(-1.0)).scale(self.maxAcc)
+ if self.vel.mag() >= self.maxSpeed:
+ self.vel = self.vel.scale( self.maxSpeed / self.vel.mag() )
+
self.vel += self.acc.scale(dt)
self.pos += self.vel.scale(dt)
@@ -58,17 +71,20 @@ def __repr__(self):
o = Object()
o.pos.set([200,0,0])
-o.vel.set([0,4,0])
-o.acc.set([-0.1,0,0])
+o.vel.set([-1,1,-1])
+#o.acc.set([-0.1,0,0])
-simSteps = 500
+simSteps = 2500
print '['
for i in range(simSteps):
o.update(1)
- d = ( - o.pos.normalize()).scale(0.1);
- o.acc = d
+ #d = ( - o.pos.normalize()).scale(0.1);
+ #o.acc = d
+
+ if i == 650:
+ o.look.set([0,0,1])
if i != (simSteps-1):
print o,','
View
@@ -29,10 +29,10 @@ function init() {
scene = new THREE.Scene();
- geometry = new THREE.CubeGeometry( 20, 20, 20 );
+ geometry = new THREE.CylinderGeometry( 10, 0, 20 );
material = new THREE.MeshBasicMaterial( { color: 0x0000ff, wireframe: false } );
-
mesh = new THREE.Mesh( geometry, material );
+ console.log(mesh);
scene.add( mesh );
addOriginLines();
@@ -46,8 +46,10 @@ function init() {
document.body.appendChild( renderer.domElement );
fps = new THREE.FirstPersonControls(camera,renderer.domElement);
- fps.movementSpeed = 100;
- fps.lookSpeed = 0.06;
+ fps.movementSpeed = 250;
+ fps.lookSpeed = 0.25;
+ fps.freeze = true;
+ //fps.target = new THREE.Vector3(0,0,-1.0);
}
@@ -59,12 +61,26 @@ function animate() {
mesh.position.x = sim[index].pos.x;
mesh.position.y = sim[index].pos.y;
+ mesh.position.z = sim[index].pos.z;
+ var vel = v(sim[index].vel.x, sim[index].vel.y, sim[index].vel.z);
+ vel.normalize();
+
+ var xRot = Math.acos( vel.dot(v(1,0,0)));
+ var yRot = Math.acos( vel.dot(v(0,1,0)));
+ var zRot = Math.acos( vel.dot(v(0,0,1)));
+
+ mesh.rotation.x = -xRot;
+ mesh.rotation.y = yRot;
+ mesh.rotation.z = -zRot;
+
+ //mesh.rotation.y = Math.PI;
+
if(index < (sim.length-1))
index++;
- mesh.rotation.x += 0.01;
- mesh.rotation.y += 0.02;
+ //mesh.rotation.x += 0.01;
+ //mesh.rotation.y += 0.02;
renderer.render( scene, camera );
//setTimeout(animate,1000);
}
@@ -124,26 +140,5 @@ function addBoxOutline(){
}
-function addGridLines(){
- var lineGeo = new THREE.Geometry();
- var gridSize = 16;
-
-
- //for(var i = -SimBox.X; i < SimBox.X; i+= 16)
-
-
- lineGeo.vertices.push(
- v(-l, 0, 0), v(l,0,0),
- v(0, -l, 0), v(0,l,0),
- v(0, 0, -l), v(0,0,l)
- );
- var lineMat = new THREE.LineBasicMaterial( {
- color: 0xffffff, lineWidth: 2});
- var line = new THREE.Line(lineGeo, lineMat);
- line.type = THREE.Lines;
- scene.add(line);
-
-}
-
});
Oops, something went wrong.

0 comments on commit 3512173

Please sign in to comment.