Exemplo n.º 1
0
//----------------------------------------
void ofEasyCam::updateMouse(const ofMouseEventArgs & mouse){
	ofRectangle area = getControlArea();
	int vFlip;
	if(isVFlipped()){
		vFlip = -1;
	}else{
		vFlip =  1;
	}
	if(bDoTranslate){
		moveX = 0;
		moveY = 0;
		moveZ = 0;
		if(mouse.button == OF_MOUSE_BUTTON_RIGHT){
			moveZ = mouseVel.y * (sensitivityZ * 0.7f) * (getDistance() + FLT_EPSILON)/ area.height;
		}else{
			moveX = -mouseVel.x * (sensitivityX * 0.5f) * (getDistance() + FLT_EPSILON)/ area.width;
			moveY = vFlip * mouseVel.y * (sensitivityY* 0.5f) * (getDistance() + FLT_EPSILON)/ area.height;
		}
	}else if(bDoRotate){
		xRot = 0;
		yRot = 0;
		zRot = 0;
		if(bInsideArcball){
			xRot = vFlip * -mouseVel.y * sensitivityRotX * glm::pi<float>() / std::min(area.width, area.height);
			yRot = -mouseVel.x * sensitivityRotY * glm::pi<float>() / std::min(area.width, area.height);
		}else{
			glm::vec2 center(area.width/2, area.height/2);
			zRot = -vFlip * glm::orientedAngle(glm::normalize(glm::vec2(mouse.x - area.x - center.x, mouse.y - area.y - center.y)),
														 glm::normalize(lastMouse - glm::vec2(area.x, area.y) - center));
			zRot *=  sensitivityRotZ;
		}
	}
}
Exemplo n.º 2
0
//----------------------------------------
void ofEasyCam::mouseReleased(ofMouseEventArgs & mouse){
	if(doInertia){
		unsigned long curTap = ofGetElapsedTimeMillis();
		ofRectangle area = getControlArea();
		if(lastTap != 0 && curTap - lastTap < doubleclickTime){
			reset();
			return;
		}
		lastTap = curTap;
		bApplyInertia = true;
		mouseVel = mouse  - prevMouse;

		updateMouse(mouse);
		glm::vec2 center(area.width/2, area.height/2);
		int vFlip;
		if(isVFlipped()){
			vFlip = -1;
		}else{
			vFlip =  1;
		}
		zRot = -vFlip * glm::orientedAngle(
			glm::normalize(glm::vec2(mouse.x - area.x - center.x, mouse.y - area.y - center.y)),
			glm::normalize(prevMouse - glm::vec2(area.x, area.y) - center));
	}else{
		bDoRotate = false;
		xRot = 0;
		yRot = 0;
		zRot = 0;

		bDoTranslate = false;
		moveX = 0;
		moveY = 0;
		moveZ = 0;
	}
}
Exemplo n.º 3
0
void ofEasyCam::updateMouse(const ofMouseEventArgs & mouse){
	ofRectangle viewport = getViewport(this->viewport);
	int vFlip;
	if(isVFlipped()){
		vFlip = -1;
	}else{
		vFlip =  1;
	}
	if (bDoTranslate) {
		moveX = 0;
		moveY = 0;
		moveZ = 0;
		if (mouse.button == OF_MOUSE_BUTTON_RIGHT) {
			moveZ = mouseVel.y * sensitivityZ * (getDistance() + FLT_EPSILON)/ viewport.height;
		}else {
			moveX = -mouseVel.x * sensitivityXY * (getDistance() + FLT_EPSILON)/viewport.width;
			moveY = vFlip * mouseVel.y * sensitivityXY * (getDistance() + FLT_EPSILON)/viewport.height;
		}
	}else {
		xRot = 0;
		yRot = 0;
		zRot = 0;
		if (bInsideArcball) {
			xRot = vFlip * -mouseVel.y * rotationFactor;
			yRot = -mouseVel.x * rotationFactor;
		}else {
			ofVec2f center(viewport.width/2, viewport.height/2);
			zRot = - vFlip * ofVec2f(mouse.x - viewport.x - center.x, mouse.y - viewport.y - center.y).angle(lastMouse - ofVec2f(viewport.x, viewport.y) - center);
		}
	}
}
Exemplo n.º 4
0
ofRectangle ofMatrixStack::getCurrentViewport() const{
	ofRectangle tmpCurrentViewport = currentViewport;
	if (isVFlipped()){
		tmpCurrentViewport.y = getRenderSurfaceHeight() - (tmpCurrentViewport.y + tmpCurrentViewport.height);
	}

	if(!doesHWOrientation() && (orientation==OF_ORIENTATION_90_LEFT || orientation==OF_ORIENTATION_90_RIGHT)){
		swap(tmpCurrentViewport.width,tmpCurrentViewport.height);
		swap(tmpCurrentViewport.x,tmpCurrentViewport.y);
	}
	return tmpCurrentViewport;
}
Exemplo n.º 5
0
ofRectangle ofMatrixStack::getCurrentViewport(){
	ofRectangle currentViewport = this->currentViewport;
	if (isVFlipped()){
		currentViewport.y = getRenderSurfaceHeight() - (currentViewport.y + currentViewport.height);
	}

	if(!doesHWOrientation() && (orientation==OF_ORIENTATION_90_LEFT || orientation==OF_ORIENTATION_90_RIGHT)){
		swap(currentViewport.width,currentViewport.height);
		swap(currentViewport.x,currentViewport.y);
	}
	return currentViewport;
}
Exemplo n.º 6
0
void ofEasyCam::mouseReleased(ofMouseEventArgs & mouse){
	unsigned long curTap = ofGetElapsedTimeMillis();
	ofRectangle viewport = getViewport(this->viewport);
	if(lastTap != 0 && curTap - lastTap < doubleclickTime){
		reset();
		return;
	}
	lastTap = curTap;
	bApplyInertia = true;
	mouseVel = mouse  - prevMouse;

	updateMouse(mouse);
	ofVec2f center(viewport.width/2, viewport.height/2);
	zRot = - isVFlipped() * ofVec2f(mouse.x - viewport.x - center.x, mouse.y - viewport.y - center.y).angle(prevMouse - ofVec2f(viewport.x, viewport.y) - center);
}
Exemplo n.º 7
0
void ofMatrixStack::viewport(float x, float y, float width, float height, bool vflip){
	if(!doesHWOrientation() && (orientation==OF_ORIENTATION_90_LEFT || orientation==OF_ORIENTATION_90_RIGHT)){
		swap(width,height);
		swap(x,y);
	}

	if(width < 0 || height < 0){
		width = getRenderSurfaceWidth();
		height = getRenderSurfaceHeight();
		vflip = isVFlipped();
	}

	if (vflip){
		y = getRenderSurfaceHeight() - (y + height);
	}

	currentViewport.set(x,y,width,height);
}
void ofCairoRenderer::setupScreenOrtho(float width, float height, float nearDist, float farDist){
	if(!b3D) return;
	if(width == 0) width = ofGetWidth();
	if(height == 0) height = ofGetHeight();
	ofOrientation orientation = ofGetOrientation();

	float viewW = viewportRect.width;
	float viewH = viewportRect.height;

	ofSetCoordHandedness(OF_RIGHT_HANDED);

	if(isVFlipped()) {
		ofSetCoordHandedness(OF_LEFT_HANDED);
	}
	projection.makeOrthoMatrix(0, viewW, 0, viewH, nearDist, farDist);

	modelView.makeIdentityMatrix();

	//note - theo checked this on iPhone and Desktop for both vFlip = false and true
	switch(orientation) {
		case OF_ORIENTATION_180:
			modelView.glRotate(-180,0,0,1);
			if(isVFlipped()){
				modelView.glScale(-1,-1,1);
				modelView.glTranslate(width,0,0);
			}else{
				modelView.glTranslate(width,-height,0);
			}

			break;

		case OF_ORIENTATION_90_RIGHT:
			modelView.glRotate(-90,0,0,1);
			if(isVFlipped()){
				modelView.glScale(1,1,1);
			}else{
				modelView.glScale(1,-1,1);
				modelView.glTranslate(-width,-height,0);
			}
			break;

		case OF_ORIENTATION_90_LEFT:
			modelView.glRotate(90,0,0,1);
			if(isVFlipped()){
				modelView.glScale(1,1,1);
				modelView.glTranslate(0,-height,0);
			}else{

				modelView.glScale(1,-1,1);
				modelView.glTranslate(0,0,0);
			}
			break;

		case OF_ORIENTATION_DEFAULT:
		default:
			if(isVFlipped()){
				modelView.glScale(-1,-1,1);
				modelView.glTranslate(-width,-height,0);
			}
			break;
	}
};
void ofCairoRenderer::setupScreenPerspective(float width, float height, float fov, float nearDist, float farDist){
	if(!b3D) return;
	if(width == 0) width = ofGetWidth();
	if(height == 0) height = ofGetHeight();
	ofOrientation orientation = ofGetOrientation();

	float viewW = viewportRect.width;
	float viewH = viewportRect.height;

	float eyeX = viewW / 2;
	float eyeY = viewH / 2;
	float halfFov = PI * fov / 360;
	float theTan = tanf(halfFov);
	float dist = eyeY / theTan;
	float aspect = (float) viewW / viewH;

	if(nearDist == 0) nearDist = dist / 10.0f;
	if(farDist == 0) farDist = dist * 10.0f;

	projection.makePerspectiveMatrix(fov,aspect,nearDist,farDist);
	modelView.makeLookAtViewMatrix(ofVec3f(eyeX,eyeY,dist),ofVec3f(eyeX,eyeY,0),ofVec3f(0,1,0));


	//note - theo checked this on iPhone and Desktop for both vFlip = false and true
	switch(orientation) {
		case OF_ORIENTATION_180:
			modelView.glRotate(-180,0,0,1);
			if(isVFlipped()){
				modelView.glScale(-1,-1,1);
				modelView.glTranslate(width,0,0);
			}else{
				modelView.glTranslate(width,-height,0);
			}

			break;

		case OF_ORIENTATION_90_RIGHT:
			modelView.glRotate(-90,0,0,1);
			if(isVFlipped()){
				modelView.glScale(1,1,1);
			}else{
				modelView.glScale(1,-1,1);
				modelView.glTranslate(-width,-height,0);
			}
			break;

		case OF_ORIENTATION_90_LEFT:
			modelView.glRotate(90,0,0,1);
			if(isVFlipped()){
				modelView.glScale(1,1,1);
				modelView.glTranslate(0,-height,0);
			}else{

				modelView.glScale(1,-1,1);
				modelView.glTranslate(0,0,0);
			}
			break;

		case OF_ORIENTATION_DEFAULT:
		default:
			if(isVFlipped()){
				modelView.glScale(-1,-1,1);
				modelView.glTranslate(-width,-height,0);
			}
			break;
	}
};
Exemplo n.º 10
0
//----------------------------------------
void ofEasyCamExt::updateMouse(){
		
	
	mouse = ofVec2f(ofGetMouseX(), ofGetMouseY());
	
	if(viewport.inside(mouse.x, mouse.y) && !bValidClick && (ofGetMousePressed(OF_MOUSE_BUTTON_RIGHT) || ofGetMousePressed(OF_MOUSE_BUTTON_MIDDLE)) )
	{
				
		unsigned long curTap = ofGetElapsedTimeMillis();
		if(lastTap != 0 && curTap - lastTap < doubleclickTime)
		{
			reset();
		}
		
		if ((bEnableMouseMiddleButton && ofGetMousePressed(OF_MOUSE_BUTTON_MIDDLE)) ||
			ofGetKeyPressed(doTranslationKey) ||
			ofGetKeyPressed(doDollyKey) /*|| ofGetMousePressed(OF_MOUSE_BUTTON_RIGHT)*/ )
		{
			bDoTranslate = true;
			bDoRotate = false;
			bApplyInertia = false;
		}
		else if (ofGetMousePressed(OF_MOUSE_BUTTON_RIGHT) )
		{			
			bDoTranslate = false;
			bDoRotate = true;
			bApplyInertia = false;
			if(ofVec2f(mouse.x - viewport.x - (viewport.width/2), mouse.y - viewport.y - (viewport.height/2)).length() < min(viewport.width/2, viewport.height/2))
			{
				bInsideArcball = true;
			}
			else
			{
				bInsideArcball = false;
			}
		}
		
		lastTap = curTap;
		//lastMouse = ofVec2f(ofGetPreviousMouseX(),ofGetPreviousMouseY()); //this was causing the camera to have a tiny "random" rotation when clicked.
		lastMouse = mouse;
		bValidClick = true;
		bApplyInertia = false;
	}
	
	
	if (bValidClick)
	{
		if ( !(ofGetMousePressed(OF_MOUSE_BUTTON_RIGHT) || ofGetMousePressed(OF_MOUSE_BUTTON_MIDDLE)) )
		{
			bApplyInertia = true;
			bValidClick = false;
		}
		else
		{
			int vFlip;
			if(isVFlipped()){
				vFlip = -1;
			}else{
				vFlip =  1;
			}
			
			mouseVel = mouse  - lastMouse;
			
			if (bDoTranslate)
			{
				moveX = 0;
				moveY = 0;
				//moveZ = 0;
				
				//if ( ofGetMousePressed(OF_MOUSE_BUTTON_RIGHT))
				if ( ofGetKeyPressed(doDollyKey) )
				{
					//moveZ = mouseVel.y * sensitivityZ * (getDistance() + FLT_EPSILON)/ viewport.height;
					moveZ += mouseVel.y * sensitivityZ * (getDistance() + FLT_EPSILON)/ viewport.height;
				}
				else
				{
					moveX = -mouseVel.x * sensitivityXY * (getDistance() + FLT_EPSILON)/viewport.width;
					moveY = vFlip * mouseVel.y * sensitivityXY * (getDistance() + FLT_EPSILON)/viewport.height;
				}
			}
			else
			{
				//xRot = 0;
				//yRot = 0;
				//zRot = 0;
				
				if (bInsideArcball)
				{
					//xRot = vFlip * -mouseVel.y * rotationFactor;
					//yRot = -mouseVel.x * rotationFactor;
					
					xRot += vFlip * -mouseVel.y * rotationFactor;
					yRot += -mouseVel.x * rotationFactor;
				}
				else
				{
					ofVec2f center(viewport.width/2, viewport.height/2);
					//zRot = -vFlip * ofVec2f(mouse.x - viewport.x - center.x, mouse.y - viewport.y - center.y).angle(lastMouse - ofVec2f(viewport.x, viewport.y) - center);
					zRot += (-vFlip * ofVec2f(mouse.x - viewport.x - center.x, mouse.y - viewport.y - center.y).angle(lastMouse - ofVec2f(viewport.x, viewport.y) - center)) * sensitivityRot;
				}
			}
			lastMouse = mouse;
		}
	}

}
Exemplo n.º 11
0
//----------------------------------------------------------
void ofGLRenderer::viewport(ofRectangle viewport_){
	viewport(viewport_.x, viewport_.y, viewport_.width, viewport_.height, isVFlipped());
}