Skip to content
This repository has been archived by the owner on Aug 10, 2024. It is now read-only.

Commit

Permalink
Rotate world with quaternions
Browse files Browse the repository at this point in the history
  • Loading branch information
renatocf committed May 12, 2015
1 parent 969aea3 commit 8ef8a02
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions App/objViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var ambientColor, diffuseColor, specularColor;

// camera definitions
var trackball;
var camera_rotate = new RotationQuaternion(1.0, vec3(0.0, 0.0, 0.0));

var eye = vec4(1.0, 0.0, 0.0, 1.0);
var at = vec4(0.0, 0.0, 0.0, 1.0);
Expand Down Expand Up @@ -247,12 +248,10 @@ window.onload = function init() {
}
else {
if (mousedownL) {
var camera_rotate = trackball.rotation(actualcanX, actualcanY,
lastcanX, lastcanY, 'm');
var trackball_q = trackball.rotation(actualcanX, actualcanY,
lastcanX, lastcanY, 'q');

eye = camera_rotate.rotate(eye);
at = camera_rotate.rotate(at);
up = camera_rotate.rotate(up);
camera_rotate = camera_rotate.mul(trackball_q);
}
}
break;
Expand Down Expand Up @@ -391,9 +390,10 @@ var render = function() {
var ratio = wrapper.clientHeight/wrapper.clientWidth;

// create model view matrix
var e = vec3(eye[0], eye[1], eye[2]);
var a = vec3(at[0], at[1], at[2]);
var u = vec3(up[0], up[1], up[2]);
var e = camera_rotate.rotate(eye);
var a = camera_rotate.rotate(at);
var u = camera_rotate.rotate(up);

modelViewMatrix = lookAt(e, a, u);
modelViewMatrix = mult(modelViewMatrix, scaleM(vec3(ratio, ratio, ratio)));

Expand Down

0 comments on commit 8ef8a02

Please sign in to comment.