Skip to content

Commit

Permalink
fiddles with pan math. still not convinced it's as accurate as it cou…
Browse files Browse the repository at this point in the history
…ld be, but it does work
  • Loading branch information
elliotwoods committed Nov 11, 2011
1 parent bd1170f commit f2e5563
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
27 changes: 12 additions & 15 deletions ofxGrabCam-example/src/testApp.cpp
Expand Up @@ -16,11 +16,8 @@ void testApp::setup(){
ofBackground(100, 100, 100);
ofEnableSmoothing();

// REMEMBER! you have to init the camera
// in order for it to register events.
// I'd prefer to put this in the constructor (i.e. automatic)
// but since it's non-standard practise it's likely to break later
camera.init();
// You might need to do this in the future if openFrameworks changes currently it's done automatically in the constructor, but this may be too early for openFrameworks (if the current situation changes)
// camera.init();
}

//--------------------------------------------------------------
Expand Down Expand Up @@ -50,18 +47,18 @@ void testApp::draw(){

ofSetColor(0,0,0);

int row = 10;
ofDrawBitmapString("ofxGrabCam", 10, row+=10);
ofDrawBitmapString("Drag with left mouse to orbit", 10, row+=10);
ofDrawBitmapString("Drag with right mouse to zoom", 10, row+=10);
ofDrawBitmapString("Hold 'h' and drag with left mouse to pan", 10, row+=10);
ofDrawBitmapString("Press 'r' to reset", 10, row+=10);
int row = 1;
ofDrawBitmapString("ofxGrabCam", 10, row++ * 15);
ofDrawBitmapString("Drag with left mouse to orbit", 10, row++ * 15);
ofDrawBitmapString("Drag with right mouse to zoom", 10, row++ * 15);
ofDrawBitmapString("Hold 'h' and drag with left mouse to pan", 10, row++ * 15);
ofDrawBitmapString("Press 'r' to reset", 10, row++ * 15);

row+=10;
row++;

ofDrawBitmapString("This example", 10, row+=10);
ofDrawBitmapString("Press 'c' to toggleCursorDraw", 10, row+=10);
ofDrawBitmapString("Press 'u' to toggleFixUpwards", 10, row+=10);
ofDrawBitmapString("This example", 10, row++ * 15);
ofDrawBitmapString("Press 'c' to toggleCursorDraw", 10, row++ * 15);
ofDrawBitmapString("Press 'u' to toggleFixUpwards", 10, row++ * 15);
}

//--------------------------------------------------------------
Expand Down
15 changes: 9 additions & 6 deletions src/ofxGrabCam.cpp
Expand Up @@ -10,7 +10,7 @@

//--------------------------
ofxGrabCam::ofxGrabCam() : initialised(true), mouseDown(false), handDown(false), altDown(false), pickCursorFlag(false), drawCursor(false), drawCursorSize(0.1), fixUpwards(true) {
addListeners();
init();
}

//--------------------------
Expand Down Expand Up @@ -151,17 +151,19 @@ void ofxGrabCam::mouseDragged(ofMouseEventArgs &args) {
return;

ofVec3f p = ofCamera::getPosition();
ofVec3f uy = 2 * ofCamera::getUpDir();
ofVec3f ux = 2 * ofCamera::getSideDir();
ofVec3f uy = ofCamera::getUpDir();
ofVec3f ux = ofCamera::getSideDir();
float ar = ofGetViewportWidth() / ofGetViewportHeight();

if (handDown) {
//pan
float d = (p - mouseW).length();
//ofCamera::getFov() doesn't exist!!
ofCamera::move(dx * -ux * 2 * d * tan(60.0f) * ar);
ofCamera::move(dy * uy * 2 * d * tan(60.0f));
ofCamera::move(dx * -ux * d * tan(ar * 60.0f * PI / 180.0f));
ofCamera::move(dy * uy * d * tan(60.0f * PI / 180.0f) / 2.0f);
} else {
if (args.button==0 && !altDown) {
if (args.button==0 && !altDown) {
//orbit
rotation.makeRotate(dx * 90 * ar, -uy, dy * 90, -ux, 0, ofVec3f(0,0,1));

if (fixUpwards) {
Expand All @@ -174,6 +176,7 @@ void ofxGrabCam::mouseDragged(ofMouseEventArgs &args) {
ofCamera::setPosition((p - mouseW) * rotation + mouseW);
ofCamera::rotate(rotation);
} else {
//dolly
ofCamera::move(2 * (mouseW - p) * dy);
}
}
Expand Down

0 comments on commit f2e5563

Please sign in to comment.