//---------------------------------------------------------- void ofGLRenderer::setupScreenPerspective(float width, float height, float fov, float nearDist, float farDist) { float viewW, viewH; if(width<0 || height<0){ ofRectangle currentViewport = getCurrentViewport(); viewW = currentViewport.width; viewH = currentViewport.height; }else{ viewW = width; viewH = 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; matrixMode(OF_MATRIX_PROJECTION); ofMatrix4x4 persp; persp.makePerspectiveMatrix(fov, aspect, nearDist, farDist); loadMatrix( persp ); matrixMode(OF_MATRIX_MODELVIEW); ofMatrix4x4 lookAt; lookAt.makeLookAtViewMatrix( ofVec3f(eyeX, eyeY, dist), ofVec3f(eyeX, eyeY, 0), ofVec3f(0, 1, 0) ); loadViewMatrix(lookAt); }
// コンストラクタ CameraWorkManager::CameraWorkManager() : m_CurCamMode(RotateCamOnGazePoint), //m_dTilt(DX_PI*0.5), m_dTilt(DX_PI*0.05), m_dHead(0), m_dCamDistFrmFP(100.0), m_dCamHight(30.0), m_dDstCamToTrgtDef(30.0), m_TrgtHight(20.0), m_MViewLocal( MGetIdent() ), m_MViewWorld( MGetIdent() ) { m_dSqDstCamToTrgtDef = m_dDstCamToTrgtDef * m_dDstCamToTrgtDef; m_vFinalCamPos = Vector3D(0,m_dCamHight,0); m_TargetPos = Vector3D(0,0,0); // カメラのビュー行列を外部ファイルから変数に読み込む loadViewMatrix(); }
//---------------------------------------------------------- void ofGLRenderer::setupScreenOrtho(float width, float height, float nearDist, float farDist) { float viewW, viewH; if(width<0 || height<0){ ofRectangle currentViewport = getCurrentViewport(); viewW = currentViewport.width; viewH = currentViewport.height; }else{ viewW = width; viewH = height; } ofMatrix4x4 ortho; ortho = ofMatrix4x4::newOrthoMatrix(0, viewW, 0, viewH, nearDist, farDist); matrixMode(OF_MATRIX_PROJECTION); loadMatrix(ortho); // make ortho our new projection matrix. matrixMode(OF_MATRIX_MODELVIEW); loadViewMatrix(ofMatrix4x4::newIdentityMatrix()); }