Skip to content

Commit

Permalink
Merge branch 'master' into gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
deanm committed Jun 12, 2010
2 parents b0a539d + 3ea4ab2 commit a75a05a
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions demos/demo_utils.js
Expand Up @@ -191,7 +191,7 @@ DemoUtils = (function() {
// Mouse + ctrl -> pan x / y.
// Mouse + shift -> pan z.
// Mouse + ctrl + shift -> adjust focal length.
function autoCamera(renderer, ix, iy, iz, tx, ty, tz, draw_callback) {
function autoCamera(renderer, ix, iy, iz, tx, ty, tz, draw_callback, opts) {
var camera_state = {
rotate_x: tx,
rotate_y: ty,
Expand All @@ -201,6 +201,8 @@ DemoUtils = (function() {
z: iz
};

opts = opts !== undefined ? opts : { };

function set_camera() {
var ct = renderer.camera.transform;
ct.reset();
Expand All @@ -222,6 +224,13 @@ DemoUtils = (function() {
renderer.camera.focal_length + (info.delta_y * 0.01));
} else if (info.shift) {
camera_state.z += info.delta_y * 0.01;
if (opts.zAxisLimit !== undefined && camera_state.z > opts.zAxisLimit) {
camera_state.z = opts.zAxisLimit;
// TODO(deanm): This still does a redraw even though maybe the camera
// didn't actually move (camera_state.z was the same before/after).
// Since this is user interaction I'm not going to worry about it now.
// TODO(deanm): This only limits in one direction.
}
} else if (info.ctrl) {
camera_state.x -= info.delta_x * 0.01;
camera_state.y -= info.delta_y * 0.01;
Expand All @@ -241,19 +250,24 @@ DemoUtils = (function() {
}

registerMouseListener(renderer.canvas, handleCameraMouse);
registerMouseWheelListener(renderer.canvas, function(delta_y) {
// Create a fake info to act as if shift + drag happened.
var fake_info = {
is_clicking: true,
canvas_x: null,
canvas_y: null,
delta_x: 0,
delta_y: delta_y * 30,
shift: true,
ctrl: false
};
handleCameraMouse(fake_info);
});

if (opts.panZOnMouseWheel === true) {
var wheel_scale = opts.panZOnMouseWheelScale !== undefined ?
opts.panZOnMouseWheelScale : 30;
registerMouseWheelListener(renderer.canvas, function(delta_y) {
// Create a fake info to act as if shift + drag happened.
var fake_info = {
is_clicking: true,
canvas_x: null,
canvas_y: null,
delta_x: 0,
delta_y: delta_y * wheel_scale,
shift: true,
ctrl: false
};
handleCameraMouse(fake_info);
});
}

// Set up the initial camera.
set_camera();
Expand Down

0 comments on commit a75a05a

Please sign in to comment.