void Intrinsics::loadProjectionMatrix(float nearDist, float farDist, cv::Point2d viewportOffset) const { ofViewport(viewportOffset.x, viewportOffset.y, imageSize.width, imageSize.height); ofSetMatrixMode(OF_MATRIX_PROJECTION); ofLoadIdentityMatrix(); float w = imageSize.width; float h = imageSize.height; float fx = cameraMatrix.at<double>(0, 0); float fy = cameraMatrix.at<double>(1, 1); float cx = principalPoint.x; float cy = principalPoint.y * aspectRatio; ofMatrix4x4 frustum; frustum.makeFrustumMatrix( nearDist * (-cx) / fx, nearDist * (w - cx) / fx, nearDist * (cy) / fy, nearDist * (cy - h) / fy, nearDist, farDist); ofMultMatrix(frustum); ofSetMatrixMode(OF_MATRIX_MODELVIEW); ofLoadIdentityMatrix(); ofMatrix4x4 lookAt; lookAt.makeLookAtViewMatrix(ofVec3f(0, 0, 0), ofVec3f(0, 0, 1), ofVec3f(0, -1, 0)); ofMultMatrix(lookAt); }
//---------- void ofxSplashScreen::begin(float minimumDuration) { if (!this->image.isAllocated()) { ofLogError("ofxSplashScreen") << "Cannot show splash screen since no image has been loaded"; return; } this->endTime = ofGetElapsedTimef() + minimumDuration; this->appWindow = glfwGetCurrentContext(); glfwHideWindow(this->appWindow); glfwWindowHint(GLFW_DECORATED, GL_FALSE); this->splashScreenWindow = glfwCreateWindow(this->image.getWidth(), this->image.getHeight(), "ofxSplashScreen", NULL, this->appWindow); glfwSetWindowPos(this->splashScreenWindow, (ofGetScreenWidth() - this->image.getWidth()) / 2.0f, (ofGetScreenHeight() - this->image.getHeight()) / 2.0f); glfwWindowHint(GLFW_DECORATED, GL_TRUE); glfwMakeContextCurrent(this->splashScreenWindow); //set the drawing matrices to normalised coordinates ofSetMatrixMode(OF_MATRIX_PROJECTION); ofLoadIdentityMatrix(); ofSetMatrixMode(OF_MATRIX_MODELVIEW); ofLoadIdentityMatrix(); //draw the images ofClear(0,0,0); this->image.update(); this->image.draw(-1,-1,2,2); glfwSwapBuffers(this->splashScreenWindow); glFlush(); //set the context back to main for rest of setup glfwMakeContextCurrent(this->appWindow); ofSetupScreen(); }
// --------------------------------------------------------------------------------------------------------------------------------------------------- // void ofxOculusRift::draw( ofVec2f pos, ofVec2f size ) { // Todo: rewrite this ofPushView(); // draw into the new fbo we have made ofSetColor( 255 ); glBindFramebuffer(GL_FRAMEBUFFER, framebufferID); ofClear(0,0,0); eyeFboLeft.draw( 0.0f, 0.0f ); eyeFboRight.draw( eyeFboLeft.getWidth(), 0.0f ); // is this being drawn correctly? glBindFramebuffer(GL_FRAMEBUFFER, 0); ofSetMatrixMode(OF_MATRIX_PROJECTION); ofLoadIdentityMatrix(); ofSetMatrixMode(OF_MATRIX_MODELVIEW); ofLoadIdentityMatrix(); ofSetColor( 255 ); if( doWarping ) { glEnable( GL_TEXTURE_2D ); glBindTexture(GL_TEXTURE_2D, colorTextureID); renderDistortedEyeNew( true, 0.0f, 0.0f, 0.5f, 1.0f); renderDistortedEyeNew( false, 0.5f, 0.0f, 0.5f, 1.0f); glDisable( GL_TEXTURE_2D ); } ofPopView(); /* glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(pos.x, pos.y ); glVertex2f(-1.0f, -1.0f); glTexCoord2f(pos.x+size.x, pos.y ); glVertex2f(0.0f, -1.0f); glTexCoord2f(pos.x, pos.y+size.y); glVertex2f(-1.0f, 1.0f); glTexCoord2f(pos.x+size.x, pos.y+size.y); glVertex2f(0.0f, 1.0f); glEnd(); */ if( !doWarping ) { ofSetColor(255); eyeFboLeft.draw( 0.0f, 0.0f ); eyeFboRight.draw( eyeFboLeft.getWidth(), 0.0f ); } needSensorReadingThisFrame = true; }
//---------------------------------------- void ofCamera::begin(ofRectangle viewport) { if(!isActive) ofPushView(); isActive = true; ofSetCoordHandedness(OF_RIGHT_HANDED); // autocalculate near/far clip planes if not set by user calcClipPlanes(viewport); glMatrixMode(GL_PROJECTION); ofLoadIdentityMatrix(); if(isOrtho) { // if(vFlip) glOrtho(0, width, height, 0, nearDist, farDist); // else #ifndef TARGET_OPENGLES glOrtho(0, viewport.width, 0, viewport.height, nearClip, farClip); #else ofMatrix4x4 ortho; ortho.makeOrthoMatrix(0, viewport.width, 0, viewport.height, nearClip, farClip); ofLoadMatrix( ortho ); #endif } else { ofMatrix4x4 persp; persp.makePerspectiveMatrix( fov, viewport.width/viewport.height, nearClip, farClip ); ofLoadMatrix( persp ); //gluPerspective(fov, viewport.width/viewport.height, nearClip, farClip); } glMatrixMode(GL_MODELVIEW); ofLoadMatrix( ofMatrix4x4::getInverseOf(getGlobalTransformMatrix()) ); ofViewport(viewport); }
void Camera::applyMatrix() { ofLoadIdentityMatrix(); ofMatrix4x4 tmp; tmp.rotate(rotX, 1.0, 0.0, 0.0); ofMultMatrix(tmp); matrix.rotate(rotY, 0.0, 1.0, 0.0); matrix.translate(deltaX, 0, deltaZ); ofMultMatrix(matrix); rotY = deltaX = deltaY = deltaZ = 0; }
//---------------------------------------- void ofCamera::begin(ofRectangle viewport) { if(!isActive) ofPushView(); isActive = true; ofSetCoordHandedness(OF_RIGHT_HANDED); // autocalculate near/far clip planes if not set by user calcClipPlanes(viewport); ofSetMatrixMode(OF_MATRIX_PROJECTION); ofLoadIdentityMatrix(); ofLoadMatrix( this->getProjectionMatrix(viewport) ); ofSetMatrixMode(OF_MATRIX_MODELVIEW); ofLoadMatrix( ofMatrix4x4::getInverseOf(getGlobalTransformMatrix()) ); ofViewport(viewport); }
// --------------------------------------------------------------------------------------------------------------------------------------------------- // 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 ofxOculusRift::setupScreenPerspective(float _interOcularDistance, 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; ofSetMatrixMode(OF_MATRIX_PROJECTION); ofLoadIdentityMatrix(); ofTranslate( ofPoint(_interOcularDistance,0,0) ); ofMatrix4x4 persp; persp.makePerspectiveMatrix(fov, aspect, nearDist, farDist); ofMultMatrix( persp ); //gluPerspective(fov, aspect, nearDist, farDist); ofSetMatrixMode(OF_MATRIX_MODELVIEW); ofLoadIdentityMatrix(); ofMatrix4x4 lookAt; lookAt.makeLookAtViewMatrix( ofVec3f(eyeX, eyeY, dist), ofVec3f(eyeX, eyeY, 0), ofVec3f(0, 1, 0) ); ofLoadMatrix( lookAt ); //note - theo checked this on iPhone and Desktop for both vFlip = false and true if(ofDoesHWOrientation()){ if(vFlip){ ofScale(1, -1, 1); ofTranslate(0, -height, 0); } }else{ if( orientation == OF_ORIENTATION_UNKNOWN ) orientation = ofGetOrientation(); switch(orientation) { case OF_ORIENTATION_180: ofRotate(-180, 0, 0, 1); if(vFlip){ ofScale(1, -1, 1); ofTranslate(-width, 0, 0); }else{ ofTranslate(-width, -height, 0); } break; case OF_ORIENTATION_90_RIGHT: ofRotate(-90, 0, 0, 1); if(vFlip){ ofScale(-1, 1, 1); }else{ ofScale(-1, -1, 1); ofTranslate(0, -height, 0); } break; case OF_ORIENTATION_90_LEFT: ofRotate(90, 0, 0, 1); if(vFlip){ ofScale(-1, 1, 1); ofTranslate(-width, -height, 0); }else{ ofScale(-1, -1, 1); ofTranslate(-width, 0, 0); } break; case OF_ORIENTATION_DEFAULT: default: if(vFlip){ ofScale(1, -1, 1); ofTranslate(0, -height, 0); } break; } } }