Commits

Sam Skillman  committed 414474b

Adding move to right-click-drag. Moves both the target and the camera in the plane of the image.

  • Participants
  • Parent commits 975daf3

Comments (0)

Files changed (1)

File gistfile2.js

 	    onDragMove: function(e) {
 		var c = this.camera;
 		var off = camGetOffset(c);
-		
 		// Get Horizontal vector
 		var horiz = PhiloGL.Vec3.cross(c.up, 
 					       camGetOffset(c))
 		horiz.$scale(1./horiz.norm());
 
-		// 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, off);
-		PhiloGL.Mat4.$mulVec3(vert_rot, c.up);
-		c.up.$scale(1./c.up.norm());
+		if (e.event.button == 0){ // Rotation
+		    // 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, off);
+		    PhiloGL.Mat4.$mulVec3(vert_rot, c.up);
+		    c.up.$scale(1./c.up.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);
+		    // 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();
+		} else if (e.event.button = 2){ // Right click - transpose
+		    var move_up = c.up.scale(-(e.y-this.curY)/200.);
+		    var move_over = horiz.scale(-(e.x-this.curX)/200.);
+		    c.position.$add(move_up);
+		    c.position.$add(move_over);
+		    c.target.$add(move_up);
+		    c.target.$add(move_over);
+		    // Update current positions
+		    this.curX = e.x;
+		    this.curY = e.y;
+		    c.update();
+		}
 		
-		// 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();