//------------------------------------------------------------
void ofxFensterManager::motion_cb(GLFWwindow* windowP_, double x, double y) {
	rotateMouseXY(ofGetOrientation(), x, y);

	ofxFensterPtr fenster = get()->getFensterByGlfwHandle(windowP_);

	fenster->curMouseX = x;
	fenster->curMouseY = y;

	if(!fenster->buttonPressed) {
		if(fenster == get()->mainWindow)
			ofNotifyMouseMoved(x, y);

		ofMouseEventArgs args;
		args.x = fenster->curMouseX;
		args.y = fenster->curMouseY;
		args.type = ofMouseEventArgs::Moved;
		ofNotifyEvent(fenster->onMouseMoved, args);
	} else {
		if(fenster == get()->mainWindow)
			ofNotifyMouseDragged(x, y, fenster->buttonInUse);

		ofMouseEventArgs args;
		args.x = fenster->curMouseX;
		args.y = fenster->curMouseY;
		args.type = ofMouseEventArgs::Dragged;
		ofNotifyEvent(fenster->onMouseDragged, args);
	}

}
Exemple #2
0
bool ofApp::isTabletInPortrait() {

  // check iPad in portrait
  #if defined TARGET_OF_IOS
    if (ofxiOSGetDeviceType() == OFXIOS_DEVICE_IPAD) {
        if (ofGetOrientation() == OF_ORIENTATION_DEFAULT || ofGetOrientation() == OF_ORIENTATION_180) {
            return true;
        }
    }
  #endif

  // check Android in portrait
  // TODO

  // Otherwise, is false
  return false;

}
void ofFbo::begin() {
	bind();
	ofPushView();
	if(ofGetGLRenderer()){
		ofGetGLRenderer()->setCurrentFBO(this);
	}
	ofViewport(0, 0, getWidth(), getHeight(), false);
	ofSetupScreenPerspective(getWidth(), getHeight(), ofGetOrientation(), false);
}
Exemple #4
0
bool ofApp::isTabletInLandscape() {

  // iPad in portrait
  #if defined TARGET_OF_IOS
  if (ofxiOSGetDeviceType() == OFXIOS_DEVICE_IPAD) {
      if (ofGetOrientation() == OF_ORIENTATION_90_LEFT || ofGetOrientation() == OF_ORIENTATION_90_RIGHT) {
          return true;
      }
  }
  #endif

  // Android in portrait
  // TODO: check for android tablet in portrait too

  // Otherwise, is false
  return false;

}
Exemple #5
0
//--------------------------------------------------------------
void ofApp::draw(){    
	// Calculate aspect ratio of grabber image
	float grabberAspectRatio = grabber.getWidth() / grabber.getHeight();

	// Draw camera image centered in the window
	ofPushMatrix();
	ofSetHexColor(0xFFFFFF);
	ofSetRectMode(OF_RECTMODE_CENTER);

	ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2);

	int wOrientation = ofOrientationToDegrees(ofGetOrientation());
	ofLogNotice()<<"Orientation: "<<ofGetOrientation()<<endl;

	if(ofGetWidth() > ofGetHeight()) {
		grabber.draw(0,0, ofGetHeight() * grabberAspectRatio,
					 ofGetHeight());
	} else {
		grabber.draw(0,0, ofGetWidth(),
					 ofGetWidth()  * 1.0/grabberAspectRatio);

	}
	ofPopMatrix();
	ofSetRectMode(OF_RECTMODE_CORNER);

	// Draw the image through raw pixels
	grabberImage.draw(0,110, 300, 300*1.0/grabberAspectRatio);

	// Draw text gui
	ofDrawRectangle(0, 0, 300, 100);
	ofSetHexColor(0x000000);
	ofDrawBitmapString("fps: " + ofToString(ofGetFrameRate()),20,20);
	ofDrawBitmapString("camera fps: " + ofToString(camera_fps),20,40);

	if(facing == 1) {
		ofDrawBitmapString("facing: front", 20, 60);
	}  else {
		ofDrawBitmapString("facing: back", 20, 60);
	}
	ofDrawBitmapString("orientation: " + ofToString(orientation) ,20,80);
}
//----------------------------------------
void ofCamera::begin(ofRectangle viewport) {
	if(!isActive) ofPushView();
	isActive = true;

	ofViewport(viewport.x,viewport.y,viewport.width,viewport.height);
	ofSetOrientation(ofGetOrientation(),vFlip);

	ofSetMatrixMode(OF_MATRIX_PROJECTION);
	ofLoadMatrix( getProjectionMatrix(viewport) );

	ofSetMatrixMode(OF_MATRIX_MODELVIEW);
	ofLoadViewMatrix( getModelViewMatrix() );
}
Exemple #7
0
void ofApp::drawArrow(bool up) {
#ifndef TARGET_OF_IOS
    ofPushStyle();
    ofEnableAlphaBlending();

    if (up) {
        if (ofGetOrientation() == OF_ORIENTATION_DEFAULT || ofGetOrientation() == OF_ORIENTATION_180) {
            imgArrow.draw(barRect.x + ARROW_OFFSET, barRect.y + ARROW_OFFSET, barRect.width - 2*ARROW_OFFSET, barRect.height - 2*ARROW_OFFSET);
        } else {
            imgArrow.draw(barRect.x + ARROW_OFFSET, barRect.y + ARROW_OFFSET, barRect.width - 2*ARROW_OFFSET, barRect.height - 2*ARROW_OFFSET);
        }
    }

    else {
        imgArrow.draw(barRect.x + barRect.width - ARROW_OFFSET, barRect.y + barRect.height - ARROW_OFFSET, -barRect.width + 2*ARROW_OFFSET, -barRect.height +2*ARROW_OFFSET);
    }

    ofDisableAlphaBlending();

    ofPopStyle();
#endif
}
Exemple #8
0
//--------------------------------------------------------------
void ofApp::setup(){
	 connected = false;

	 ofxAccelerometer.setup();
	// make a web socket connection that we can stream data to
	client.Create();
	client.Connect("192.168.42.1", 3000);
	client.SetNonBlocking(true);

	switch (ofGetOrientation()) {
		case OF_ORIENTATION_DEFAULT:
			ofSetOrientation(OF_ORIENTATION_90_LEFT);
			break;
		case OF_ORIENTATION_180:
			ofSetOrientation(OF_ORIENTATION_90_LEFT);
			break;
		case OF_ORIENTATION_90_LEFT:
			ofSetOrientation(OF_ORIENTATION_90_LEFT);
			break;
		case OF_ORIENTATION_90_RIGHT:
			ofSetOrientation(OF_ORIENTATION_90_RIGHT);
			break;
		default:
			break;
	}

	int count = 0;
	for( float i = 0; i < 1.0; i+=0.05 )
	{
		arcPoint p;
		p.position = i;

		if(count % 2)
		{
			p.fill.set(122, 122, 122);
		}
		else
		{
			p.fill.set(255, 255, 255);
		}

		arcPoints.push_back(p);
		count++;
	}

	left = 0;
	right = 0;

	carIcon.load("car2.png");

}
Exemple #9
0
void ofFbo::begin(bool setupScreen) {
	ofPushView();
	if(ofGetGLRenderer()){
		ofGetGLRenderer()->setCurrentFBO(this);
	}
	ofViewport(0, 0, getWidth(), getHeight(), false);
	if(setupScreen){
        ofOrientation orient = ofGetOrientation();
#ifdef TARGET_OF_IPHONE
        orient = OF_ORIENTATION_DEFAULT;
#endif
		ofSetupScreenPerspective(getWidth(), getHeight(), orient, false);
	}
	bind();
}
void
Java_cc_openframeworks_OFAndroid_onSurfaceCreated( JNIEnv*  env, jclass  thiz ){
	ofLog(OF_LOG_NOTICE,"onSurfaceCreated");
	if(!surfaceDestroyed){
		ofUnloadAllFontTextures();
		ofPauseVideoGrabbers();
	}
	reloadTextures();
	if(androidApp){
		androidApp->reloadTextures();
	}
	ofSetStyle(ofGetStyle());
	ofSetOrientation(ofGetOrientation());
	surfaceDestroyed = false;

}
Exemple #11
0
ofMatrix4x4 headTracking::getLastHeadView(ofMatrix4x4 headView)
{
    if (!mTracker.isReady()) {
        return headView;
    }

    ofOrientation fooRot = ofGetOrientation();
    double rotation = 0.0;

    if (fooRot == OF_ORIENTATION_DEFAULT) {
        rotation = 0.0;
    } else if (fooRot == OF_ORIENTATION_90_LEFT) {
        rotation = 90.0;
    } else if (fooRot == OF_ORIENTATION_90_RIGHT) {
        rotation = 180.0;
    } else {
        rotation = 270.0;
    }

    if (fooRot != mDisplayRotation) {
        mDisplayRotation = fooRot;

        mSensorToDisplay.makeRotationMatrix(
            ofQuaternion(0.0, ofVec3f(1, 0, 0), -rotation, ofVec3f(0, 0, 1),
                         0.0, ofVec3f(0, 1, 0)));
        mEkfToHeadTracker.makeRotationMatrix(
            ofQuaternion(0.0, ofVec3f(1, 0, 0), rotation, ofVec3f(0, 0, 1),
                         0.0, ofVec3f(0, 1, 0)));
    }

    double secondsSinceLastGyroEvent = (ofGetElapsedTimeMicros() -
                                        mLastGyroEventTimeNanos) * 1E-6;


    double secondsToPredictForward = secondsSinceLastGyroEvent + 0.0166666666;
    mTmpHeadView = mTracker.getPredictedGLMatrix(secondsToPredictForward);
    mTmpHeadView2.makeFromMultiplicationOf(mSensorToDisplay, mTmpHeadView);
    headView.makeFromMultiplicationOf(mTmpHeadView2, mEkfToHeadTracker);

    if (mNeckModelEnabled) {
        mTmpHeadView.makeFromMultiplicationOf(mNeckModelTranslation, headView);
        mTmpHeadView.translate(ofVec3f(0, 0.075, 0.0));
        headView = mTmpHeadView;
    }

    return headView;
}
// ---------------------------------------------------------------------------------------------------------------------------------------------------
//
void ofxOculusRift::beginRender( float _interOcularShift, ofFbo* _fbo  )
{
	ofPushView();

		_fbo->begin();
		ofClear(0,0,0); // Todo: get the proper clear color
	
		setupScreenPerspective( _interOcularShift, ofGetWidth(), ofGetHeight(), ofGetOrientation(), false, getFov(), getNearClip(), getFarClip()  );
	
		ofSetMatrixMode(OF_MATRIX_MODELVIEW);
		ofLoadIdentityMatrix();
	
		ofPushMatrix();
	
			// flip for FBO
			ofScale(1,-1,1);
	
			ofMultMatrix( getHeadsetViewOrientationMat() );
			ofTranslate( getPosition() );
}
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;
	}
};
void ofImage_<PixelType>::grabScreen(int _x, int _y, int _w, int _h){

	allocate(_w, _h, OF_IMAGE_COLOR);

    int sw = ofGetViewportWidth();
    int sh = ofGetViewportHeight();     // if we are in a FBO or other viewport, this fails: ofGetHeight();
    
	if (!((width == _w) && (height == _h))){
		resize(_w, _h);
	}

	#ifndef TARGET_OPENGLES
    
    _y = sh - _y;
    _y -= _h; // top, bottom issues
    
    glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT );											// be nice to anyone else who might use pixelStore
    glPixelStorei(GL_PACK_ALIGNMENT, 1);
    glReadPixels(_x, _y, _w, _h, ofGetGlInternalFormat(pixels), GL_UNSIGNED_BYTE, pixels.getPixels()); // read the memory....
    glPopClientAttrib();
    
	int sizeOfOneLineOfPixels = pixels.getWidth() * pixels.getBytesPerPixel();
	PixelType * tempLineOfPix = new PixelType[sizeOfOneLineOfPixels];
	PixelType * linea;
	PixelType * lineb;
	for (int i = 0; i < pixels.getHeight()/2; i++){
		linea = pixels.getPixels() + i * sizeOfOneLineOfPixels;
		lineb = pixels.getPixels() + (pixels.getHeight()-i-1) * sizeOfOneLineOfPixels;
		memcpy(tempLineOfPix, linea, sizeOfOneLineOfPixels);
		memcpy(linea, lineb, sizeOfOneLineOfPixels);
		memcpy(lineb, tempLineOfPix, sizeOfOneLineOfPixels);
	}
	delete [] tempLineOfPix;
	
    #else
    
    int numPixels   = width*height;
    if( numPixels == 0 ){
        ofLog(OF_LOG_ERROR, "grabScreen width or height is 0 - returning");
        return;
    }
    
    int numRGBA         = numPixels*4;
    GLubyte *bufferRGBA = (GLubyte *) malloc(numRGBA);

    if(ofGetOrientation() == OF_ORIENTATION_DEFAULT) {
        
        _y = sh - _y;   // screen is flipped vertically.
        _y -= _h;
        
        glPixelStorei(GL_PACK_ALIGNMENT, 1);
        glReadPixels(_x, _y, _w, _h, GL_RGBA, GL_UNSIGNED_BYTE, bufferRGBA);
        
        for(int y = 0; y < _h; y++){  
            for(int x = 0; x < _w; x++){
                
                int i = y * _w * 3 + x * 3;
                int j = (_h-1-y) * _w * 4 + x * 4;  // rotate 90.
                
                pixels.getPixels()[i]   = bufferRGBA[j];
                pixels.getPixels()[i+1] = bufferRGBA[j+1];
                pixels.getPixels()[i+2] = bufferRGBA[j+2];
            }
        }
    }
    else if(ofGetOrientation() == OF_ORIENTATION_180) {
        
        _x = sw - _x;   // screen is flipped horizontally.
        _x -= _w;
        
        glPixelStorei(GL_PACK_ALIGNMENT, 1);
        glReadPixels(_x, _y, _w, _h, GL_RGBA, GL_UNSIGNED_BYTE, bufferRGBA);
        
        for(int y = 0; y < _h; y++){  
            for(int x = 0; x < _w; x++){
                
                int i = y * _w * 3 + x * 3;
                int j = y * _w * 4 + (_w-1-x) * 4;  // rotate 90.
                
                pixels.getPixels()[i]   = bufferRGBA[j];
                pixels.getPixels()[i+1] = bufferRGBA[j+1];
                pixels.getPixels()[i+2] = bufferRGBA[j+2];
            }
        }
    }
    else if(ofGetOrientation() == OF_ORIENTATION_90_RIGHT) {
        
        int tempW = _w;     // swap width and height.
        _w = _h;
        _h = tempW;
        
        int tempY = _y;     // swap x and y.
        _y = _x;
        _x = tempY;
        
        glPixelStorei(GL_PACK_ALIGNMENT, 1);
        glReadPixels(_x, _y, _w, _h, GL_RGBA, GL_UNSIGNED_BYTE, bufferRGBA);
        
        for(int y = 0; y < _h; y++){  
            for(int x = 0; x < _w; x++){
                
                int i = x * _h * 3 + y * 3;
                int j = y * _w * 4 + x * 4;
                
                pixels.getPixels()[i]   = bufferRGBA[j];
                pixels.getPixels()[i+1] = bufferRGBA[j+1];
                pixels.getPixels()[i+2] = bufferRGBA[j+2];
            }
        }
    }
    else if(ofGetOrientation() == OF_ORIENTATION_90_LEFT) {
        
        int tempW = _w; // swap width and height.
        _w = _h;
        _h = tempW;
        
        int tempY = _y; // swap x and y.
        _y = _x;
        _x = tempY;
        
        _x = sw - _x;   // screen is flipped horizontally.
        _x -= _w;
        
        _y = sh - _y;   // screen is flipped vertically.
        _y -= _h;
        
        glPixelStorei(GL_PACK_ALIGNMENT, 1);
        glReadPixels(_x, _y, _w, _h, GL_RGBA, GL_UNSIGNED_BYTE, bufferRGBA);
        
        for(int y = 0; y < _h; y++){  
            for(int x = 0; x < _w; x++){
                
                int i = x * _h * 3 + y * 3;
                int j = (_h-1-y) * _w * 4 + (_w-1-x) * 4;
                
                pixels.getPixels()[i]   = bufferRGBA[j];
                pixels.getPixels()[i+1] = bufferRGBA[j+1];
                pixels.getPixels()[i+2] = bufferRGBA[j+2];
            }
        }
    }
    
    free(bufferRGBA);    
    
    #endif

	update();
}
Exemple #16
0
void ofFbo::begin() {
	bind();
	ofPushView();
	ofViewport(0, 0, getWidth(), getHeight(), false);
	ofSetupScreenPerspective(getWidth(), getHeight(), ofGetOrientation(), false);
}
//----------------------------------------------------------
void ofGLRenderer::setupScreenPerspective(float width, float height, ofOrientation orientation, bool vFlip, float fov, float nearDist, float farDist) {
	if(width == 0) width = ofGetWidth();
	if(height == 0) height = ofGetHeight();

	float viewW = ofGetViewportWidth();
	float viewH = ofGetViewportHeight();

	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;

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
		
	ofMatrix4x4 persp;
	persp.makePerspectiveMatrix(fov, aspect, nearDist, farDist);
	loadMatrix( persp );
	//gluPerspective(fov, aspect, nearDist, farDist);


	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	
	ofMatrix4x4 lookAt;
	lookAt.makeLookAtViewMatrix( ofVec3f(eyeX, eyeY, dist),  ofVec3f(eyeX, eyeY, 0),  ofVec3f(0, 1, 0) );
	loadMatrix( lookAt );
	//gluLookAt(eyeX, eyeY, dist, eyeX, eyeY, 0, 0, 1, 0);

	//note - theo checked this on iPhone and Desktop for both vFlip = false and true
	if(ofDoesHWOrientation()){
		if(vFlip){
			glScalef(1, -1, 1);
			glTranslatef(0, -height, 0);
		}
	}else{
		if( orientation == OF_ORIENTATION_UNKNOWN ) orientation = ofGetOrientation();
		switch(orientation) {
			case OF_ORIENTATION_180:
				glRotatef(-180, 0, 0, 1);
				if(vFlip){
					glScalef(1, -1, 1);
					glTranslatef(-width, 0, 0);
				}else{
					glTranslatef(-width, -height, 0);
				}

				break;

			case OF_ORIENTATION_90_RIGHT:
				glRotatef(-90, 0, 0, 1);
				if(vFlip){
					glScalef(-1, 1, 1);
				}else{
					glScalef(-1, -1, 1);
					glTranslatef(0, -height, 0);
				}
				break;

			case OF_ORIENTATION_90_LEFT:
				glRotatef(90, 0, 0, 1);
				if(vFlip){
					glScalef(-1, 1, 1);
					glTranslatef(-width, -height, 0);
				}else{
					glScalef(-1, -1, 1);
					glTranslatef(-width, 0, 0);
				}
				break;

			case OF_ORIENTATION_DEFAULT:
			default:
				if(vFlip){
					glScalef(1, -1, 1);
					glTranslatef(0, -height, 0);
				}
				break;
		}
	}

}
//----------------------------------------------------------
void ofGLRenderer::setupScreenPerspective(float width, float height, int orientation, bool vFlip, float fov, float nearDist, float farDist) {
	if(width == 0) width = ofGetWidth();
	if(height == 0) height = ofGetHeight();
	if( orientation == 0 ) orientation = ofGetOrientation();

	float w = width;
	float h = height;

	//we do this because ofGetWidth and ofGetHeight return orientated widths and height
	//for the camera we need width and height of the actual screen
	if( orientation == OF_ORIENTATION_90_LEFT || orientation == OF_ORIENTATION_90_RIGHT ){
		h = width;
		w = height;
	}

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

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

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(fov, aspect, nearDist, farDist);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(eyeX, eyeY, dist, eyeX, eyeY, 0, 0, 1, 0);

	//note - theo checked this on iPhone and Desktop for both vFlip = false and true
	switch(orientation) {
		case OF_ORIENTATION_180:
			glRotatef(-180, 0, 0, 1);
			if(vFlip){
				glScalef(1, -1, 1);
				glTranslatef(-width, 0, 0);
			}else{
				glTranslatef(-width, -height, 0);
			}

			break;

		case OF_ORIENTATION_90_RIGHT:
			glRotatef(-90, 0, 0, 1);
			if(vFlip){
				glScalef(-1, 1, 1);
			}else{
				glScalef(-1, -1, 1);
				glTranslatef(0, -height, 0);
			}
			break;

		case OF_ORIENTATION_90_LEFT:
			glRotatef(90, 0, 0, 1);
			if(vFlip){
				glScalef(-1, 1, 1);
				glTranslatef(-width, -height, 0);
			}else{
				glScalef(-1, -1, 1);
				glTranslatef(-width, 0, 0);
			}
			break;

		case OF_ORIENTATION_DEFAULT:
		default:
			if(vFlip){
				glScalef(1, -1, 1);
				glTranslatef(0, -height, 0);
			}
			break;
	}

}
//----------------------------------------------------------
void ofGLRenderer::setupScreenOrtho(float width, float height, ofOrientation orientation, bool vFlip, float nearDist, float farDist) {
	if(width == 0) width = ofGetWidth();
	if(height == 0) height = ofGetHeight();
	
	float viewW = ofGetViewportWidth();
	float viewH = ofGetViewportHeight();
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	ofSetCoordHandedness(OF_RIGHT_HANDED);
	if(vFlip) {
		ofMatrix4x4 ortho = ofMatrix4x4::newOrthoMatrix(0, width, height, 0, nearDist, farDist);
		ofSetCoordHandedness(OF_LEFT_HANDED);
	}
	
	ofMatrix4x4 ortho = ofMatrix4x4::newOrthoMatrix(0, viewW, 0, viewH, nearDist, farDist);
	glMultMatrixf(ortho.getPtr());	

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	//note - theo checked this on iPhone and Desktop for both vFlip = false and true
	if(ofDoesHWOrientation()){
		if(vFlip){
			glScalef(1, -1, 1);
			glTranslatef(0, -height, 0);
		}
	}else{
		if( orientation == OF_ORIENTATION_UNKNOWN ) orientation = ofGetOrientation();
		switch(orientation) {
			case OF_ORIENTATION_180:
				glRotatef(-180, 0, 0, 1);
				if(vFlip){
					glScalef(1, -1, 1);
					glTranslatef(-width, 0, 0);
				}else{
					glTranslatef(-width, -height, 0);
				}

				break;

			case OF_ORIENTATION_90_RIGHT:
				glRotatef(-90, 0, 0, 1);
				if(vFlip){
					glScalef(-1, 1, 1);
				}else{
					glScalef(-1, -1, 1);
					glTranslatef(0, -height, 0);
				}
				break;

			case OF_ORIENTATION_90_LEFT:
				glRotatef(90, 0, 0, 1);
				if(vFlip){
					glScalef(-1, 1, 1);
					glTranslatef(-width, -height, 0);
				}else{
					glScalef(-1, -1, 1);
					glTranslatef(-width, 0, 0);
				}
				break;

			case OF_ORIENTATION_DEFAULT:
			default:
				if(vFlip){
					glScalef(1, -1, 1);
					glTranslatef(0, -height, 0);
				}
				break;
		}
	}

}
void ofCairoRenderer::setupScreenPerspective(float width, float height, int orientation, bool vFlip, float fov, float nearDist, float farDist){
	if(!b3D) return;
	if(width == 0) width = ofGetWidth();
	if(height == 0) height = ofGetHeight();
	if( orientation == 0 ) orientation = ofGetOrientation();

	float w = width;
	float h = height;

	//we do this because ofGetWidth and ofGetHeight return oriented widths and height
	//for the camera we need width and height of the actual screen
	if( orientation == OF_ORIENTATION_90_LEFT || orientation == OF_ORIENTATION_90_RIGHT ){
		h = width;
		w = height;
	}

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

	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(vFlip){
				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(vFlip){
				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(vFlip){
				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(vFlip){
				modelView.glScale(-1,-1,1);
				modelView.glTranslate(-width,-height,0);
			}
			break;
	}
};