void ofAppAndroidWindow::setOrientation(ofOrientation _orientation){ //if(orientation==_orientation) return; orientation = _orientation; jclass javaClass = ofGetJNIEnv()->FindClass("cc/openframeworks/OFAndroid"); if(javaClass==0){ ofLogError("ofAppAndroidWindow") << "setOrientation(): couldn't find OFAndroid java class"; return; } jmethodID setScreenOrientation = ofGetJNIEnv()->GetStaticMethodID(javaClass,"setScreenOrientation","(I)V"); if(!setScreenOrientation){ ofLogError("ofAppAndroidWindow") << "setOrientation(): couldn't find OFAndroid setScreenOrientation method"; return; } if(orientation==OF_ORIENTATION_UNKNOWN) ofGetJNIEnv()->CallStaticVoidMethod(javaClass,setScreenOrientation,-1); else ofGetJNIEnv()->CallStaticVoidMethod(javaClass,setScreenOrientation,ofOrientationToDegrees(orientation)); }
//-------------------------------------------------------------- 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 ofApp::deviceOrientationChanged(ofOrientation newOrientation){ appOrientation = ofOrientationToDegrees(newOrientation); }