Commits

Sam Skillman committed 975daf3

rotations are now working better.

Comments (0)

Files changed (1)

 		this.curX = e.x;
 		this.curY = e.y;
 		this.dist = camGetOffset(this.camera).norm();
-
 	    },
 	    onDragEnd: function(e) {
 		pos = {
 	    onDragMove: function(e) {
 		var c = this.camera;
 		var off = camGetOffset(c);
-		this.dist = off.norm();
-
-		var side_rot = new PhiloGL.Mat4();
+		
+		// Get Horizontal vector
 		var horiz = PhiloGL.Vec3.cross(c.up, 
 					       camGetOffset(c))
+		horiz.$scale(1./horiz.norm());
 
-		side_rot.id();
-		side_rot.$rotateAxis(-(e.x-this.curX)/100., c.up);
-		side_rot.$mulVec3(c.position);
-
-		var off = camGetOffset(c);
-		updateBasedOnOffset(c, PhiloGL.Vec3.scale(
-		    off, this.dist/off.norm()));
-
-		this.dist = off.norm();
-		c.update();
-
+		// Do vertical rotation about horizontal vector
 		var vert_rot = new PhiloGL.Mat4();
 		vert_rot.id();
 		vert_rot.$rotateAxis((e.y-this.curY)/100., horiz);
-		PhiloGL.Mat4.$mulVec3(vert_rot, c.position);
+		PhiloGL.Mat4.$mulVec3(vert_rot, off);
 		PhiloGL.Mat4.$mulVec3(vert_rot, c.up);
 		c.up.$scale(1./c.up.norm());
 
-		var off = camGetOffset(c);
-		updateBasedOnOffset(c, PhiloGL.Vec3.scale(
-		    off, this.dist/off.norm()));
-
+		// Do horizontal rotation about up vector
+		var side_rot = new PhiloGL.Mat4();
+		side_rot.id();
+		side_rot.$rotateAxis(-(e.x-this.curX)/100., c.up);
+		side_rot.$mulVec3(off);
+		
+		// Update current positions
 		this.curX = e.x;
 		this.curY = e.y;
 		this.dist = off.norm();
+		updateBasedOnOffset(c, off);
 		c.update();
-
-
 	    },
 	    onMouseWheel: function(e){
 		e.stop();
 	    	var offset = PhiloGL.Vec3.scale(camGetOffset(this.camera),
-						1.0 - e.wheel/100.);
+						1.0 - e.wheel/10.);
 		updateBasedOnOffset(this.camera, offset);
 	    	this.camera.update();
 	    }
 	    var gl = app.gl,
             canvas = app.canvas,
             program = app.program,
-            camera = app.camera;
- 
+            scene = app.scene,
+	    camera = app.camera;
+	    
 	    gl.viewport(0, 0, canvas.width, canvas.height);
 	    gl.clearColor(0, 0, 0, 1);
 	    gl.clearDepth(1);
 	    gl.enable(gl.DEPTH_TEST);
 	    gl.depthFunc(gl.LEQUAL);
 
-
 	    program.setBuffers({
 		'shapeset': {
 		    attribute: 'aVertexPosition',
 		
 	    });
 	    camera.modelView.id();
-	    //camera.modelView.$translate(-0.5, -0.5, -0.5);
 	    
 	    setInterval(draw, 100/60);
-	    //draw
 	    //Draw the scene
 	    function draw() {
 		gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
     });  
 }
 
-
-
-	    //Setup lighting
-		// var lights = scene.config.lights;
-		// lights.enable = lighting.checked;
-		// lights.ambient = {
-		//     r: +ambient.r.value,
-		//     g: +ambient.g.value,
-		//     b: +ambient.b.value
-		// };
-		// lights.directional = {
-		//     color: {
-		// 	r: +direction.r.value,
-		// 	g: +direction.g.value,
-		// 	b: +direction.b.value
-		//     },
-		//     direction: {
-		// 	x: +direction.x.value,
-		// 	y: +direction.y.value,
-		// 	z: +direction.z.value
-		//     }
-		// };	
-	//}
-	    // gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
-	    // camera.modelView.id();
-	    // //Draw Triangle
-	    // camera.modelView.$translate(-0.5, -0.5, -7);
-	    // program.setUniform('uMVMatrix', camera.modelView);
-	    // program.setUniform('uPMatrix', camera.projection);
-	    // program.setBuffer('triangle');
-	    // gl.drawArrays(gl.LINES, 0, n_vertices);
-
-	    //
-
-