Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updaed mickey demo with mouse button controls
- Loading branch information
Andor
committed
Jul 6, 2010
1 parent
415c1cb
commit 99d3151
Showing
1 changed file
with
39 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,65 @@ | ||
var ps; | ||
|
||
var buttonDown = false; | ||
var zoomed = 0; | ||
var rot = 0; | ||
|
||
var rot =[0,0]; | ||
var curCoords = [0,0]; | ||
|
||
var size = 500; | ||
|
||
function zoom(amt){ | ||
zoomed += amt * 2; | ||
size += amt * 10; | ||
|
||
if(ps.mouseX < 25 && ps.mouseY < 25){ | ||
ps.resize(size, size); | ||
ps.background([0,0,0,1]); | ||
} | ||
} | ||
|
||
function mousePressed(){ | ||
curCoords[0] = ps.mouseX; | ||
curCoords[1] = ps.mouseY; | ||
buttonDown = true; | ||
} | ||
|
||
function mouseReleased(){ | ||
buttonDown = false; | ||
} | ||
|
||
function render() { | ||
|
||
var deltaX = ps.mouseX - curCoords[0]; | ||
var deltaY = ps.mouseY - curCoords[1]; | ||
|
||
if(buttonDown){ | ||
rot[0] += deltaX / 250; | ||
rot[1] += deltaY / 250; | ||
curCoords[0] = ps.mouseX; | ||
curCoords[1] = ps.mouseY; | ||
} | ||
|
||
// transform point cloud | ||
ps.translate(0,0,zoomed); | ||
ps.rotateY(rot+=0.01); | ||
|
||
ps.rotateY(rot[0]); | ||
ps.rotateX(rot[1]); | ||
|
||
// redraw | ||
ps.clear(); | ||
ps.render(); | ||
|
||
window.status = Math.floor(ps.frameRate); | ||
} | ||
|
||
function start(){ | ||
ps = new PointStream(); | ||
|
||
ps.setup(document.getElementById('canvas'), render); | ||
ps.background([.2,.5,.7,1]); | ||
ps.background([0.3,0.5,0.7,1]); | ||
|
||
ps.onMouseScroll = zoom; | ||
ps.onMousePressed = mousePressed; | ||
ps.onMouseReleased = mouseReleased; | ||
|
||
ps.loadFile({path:"mickey.asc", autoCenter: true}); | ||
} |