//--------------------------
void ofxGrabCam::mouseDragged(ofMouseEventArgs &args) {

	float dx = (args.x - mouseP.x) / ofGetViewportWidth();
	float dy = (args.y - mouseP.y) / ofGetViewportHeight();
	mouseP.x = args.x;
	mouseP.y = args.y;
	
	if (!mouseActions)
		return;

	if (!this->mouseDown)
		return;
	
	if (mouseP.z == 1.0f)
		mouseP.z = 0.5f;
	
	ofVec3f p = ofCamera::getPosition();
	ofVec3f uy = ofCamera::getUpDir();
	ofVec3f ux = ofCamera::getSideDir();
	float ar = float(ofGetViewportWidth()) / float(ofGetViewportHeight());
	
	if (handDown) {
		//dolly
		ofCamera::move(2 * (mouseW - p) * dy);
	} else {
		if (args.button==0 && !altDown) {
			//orbit
			ofVec3f arcEnd(dx, -dy, -trackballRadius);
			arcEnd = arcEnd;
			arcEnd.normalize();
			ofQuaternion orientation = this->getGlobalOrientation();
			rotation.makeRotate(orientation * ofVec3f(0.0f, 0.0f, -1.0f), orientation * arcEnd);
			
			if (fixUpwards) {
				ofQuaternion rotToUp;
				ofVec3f sideDir = ofCamera::getSideDir() * rotation;
				rotToUp.makeRotate(sideDir, sideDir * ofVec3f(1.0f, 0, 1.0f));
				rotation *= rotToUp;
			}
			
			this->setOrientation(this->getGlobalOrientation() * rotation);
			ofCamera::setPosition((p - mouseW) * rotation + mouseW);
		} else {
			//pan
			float d = (p - mouseW).length();
			//ofCamera::getFov() doesn't exist!!
			ofCamera::move(dx * -ux * d * ar);
			ofCamera::move(dy * uy * d);
		}
	}
}
Example #2
0
 ArcRange  arcs () const {   return make_iterator_range( arcBegin (), arcEnd () );   }