void CloudsRGBDCamera::setPositionFromMouse() { float percentOnCurve = ofMap(GetCloudsInputX(), canvasWidth*.2, canvasWidth*.8, 0, 1, true); ofVec3f sidePositionLeft = lookTarget + ofVec3f(-sideDistance,0,sidePullback); ofVec3f sidePositionRight = lookTarget + ofVec3f( sideDistance,0,sidePullback); ofVec3f frontPosition = lookTarget + ofVec3f(0,0,-frontDistance); ofVec3f position; if(percentOnCurve > .5) { position = frontPosition.getInterpolated(sidePositionRight, ofMap(percentOnCurve, .5, 1.0, 0, 1.0) ); } else { position = sidePositionLeft.getInterpolated(frontPosition, ofMap(percentOnCurve, 0, .5, 0, 1.0) ); } float liftDrift = ofMap(GetCloudsInputY(), canvasHeight*.2, canvasHeight*.8, -liftRange,liftRange, true); position.y += ofMap(abs(.5 - percentOnCurve), 0, .5, (liftDrift + liftAmount), (liftDrift-liftAmount)*.5); position.z -= MAX(liftDrift,0) * .5; // zoom in on mouse up targetPosition = position; currentPosition += (targetPosition - currentPosition) * damp; currentLookTarget = lookTarget - ofVec3f(0,dropAmount,-sidePullback); //calculate drift; //ofVec3f driftOffset(0,0,0); ofVec3f driftPosition = currentPosition; float channelA = 1000; float channelB = 1500; if(maxDriftAngle > 0) { ofVec3f toCamera = currentPosition - currentLookTarget; ofQuaternion driftQuatX,driftQuatY; driftNoisePosition += driftNoiseSpeed;// * (ofGetElapsedTimef() - ofGetLastFrameTime()); float driftX = ofSignedNoise( channelA, driftNoisePosition ); float driftY = ofSignedNoise( channelB, driftNoisePosition ); driftPosition.rotate(driftX*maxDriftAngle, currentLookTarget, ofVec3f(0,1,0)); driftPosition.rotate(driftY*maxDriftAngle, currentLookTarget, ofVec3f(1,0,0)); // driftQuatX.makeRotate(maxDriftAngle*driftX, 0, 1, 0); // driftQuatY.makeRotate(maxDriftAngle*driftY, 1, 0, 0); // driftOffset = driftQuatX * driftQuatY * (ofVec3f(0,0,1) * toCamera.length()); } mouseBasedNode.setPosition(driftPosition); mouseBasedNode.lookAt(currentLookTarget); //Compute new FOV bool onEdge = GetCloudsInputX() < 20 || GetCloudsInputX() > canvasWidth - 40 || GetCloudsInputY() < 20 || GetCloudsInputY() > canvasHeight - 40; float newFov; if(onEdge) { newFov = getFov() + ( zoomFOVRange.max - getFov() ) * .05; } else { newFov = getFov() + (zoomFOVRange.min - getFov() ) * .005; } setFov(newFov); }
void TCompCamera::renderInMenu() { float fov_in_rad = getFov(); float znear = getZNear(); float zfar = getZFar(); float ar = getAspectRatio(); bool changed = false; //float fov_in_deg = rad2deg(fov_in_rad); //if (ImGui::SliderFloat("Fov", &fov_in_deg, 30.f, 110.f)) { // changed = true; // fov_in_rad = deg2rad(fov_in_deg); //} if (!isOrtho()) { float fov_in_deg = rad2deg(fov_in_rad); if (ImGui::DragFloat("Fov", &fov_in_deg, 0.1f, 1.f, 120.f)) { changed = true; fov_in_rad = deg2rad(clamp(fov_in_deg, 1.f, 120.f)); } } changed |= ImGui::DragFloat("ZNear", &znear, 0.01f, 0.01f); changed |= ImGui::DragFloat("ZFar", &zfar, 0.01f, 1.f, 1000.f); if (changed) setProjection(fov_in_rad, znear, zfar); if (ImGui::SliderFloat("a/r", &ar, 0.f, 10.f)) { //setAspectRatio(ar); } }
void Frustum::setNearFarDist( F32 nearDist, F32 farDist ) { if( mNearDist == nearDist && mFarDist == farDist ) return; // Recalculate the frustum. MatrixF xfm( mTransform ); set( mIsOrtho, getFov(), getAspectRatio(), nearDist, farDist, xfm ); }
void ZoomCamera::adjust(const Bounds2D& bounds, bool adjust_distance) { //center camera on bounds vec2f centre = bounds.centre(); //adjust by screen ratio dest.x = centre.x; dest.y = centre.y; if(!adjust_distance) return; //scale by 10% so we dont have stuff right on the edge of the screen float width = bounds.width() * padding; float height = bounds.height() * padding; float dratio = display.height / (float) display.width; if(dratio > 1.0) { height /= dratio; } else { width *= dratio; } //calc visible width of the opposite wall at a distance of 1 this fov float toa = tan( getFov() * 0.5f * DEGREES_TO_RADIANS ) * 2.0; float distance; //TOA = tan = opposite/adjacent (distance = adjacent) //use the larger side of the box //cropping: vertical, horizontal or none if(gGourceSettings.crop_vertical) { distance = width / toa ; } else if (gGourceSettings.crop_horizontal) { distance = height / toa ; } else { if(width > height) { distance = width / toa ; } else { distance = height / toa ; } } //debugLog("toa %.2f, distance %.2f width %.2f height %.2f dratio %.2f\n", toa, distance, width, height, dratio); //check bounds are valid if(distance < min_distance) distance = min_distance; if(distance > max_distance) distance = max_distance; this->dest.z = -distance; }
void Camera :: apply () { float m [16]; // create a coordinate space transform // (rotation) matrix m [0 ] = sideDir.x; m [1 ] = upDir.x; m [2 ] = -viewDir.x; m [3 ] = 0; m [4 ] = sideDir.y; m [5 ] = upDir.y; m [6 ] = -viewDir.y; m [7 ] = 0; m [8 ] = sideDir.z; m [9 ] = upDir.z; m [10] = -viewDir.z; m [11] = 0; m [12] = 0; m [13] = 0; m [14] = 0; m [15] = 1; // set current viewport glViewport ( 0, 0, getWidth (), getHeight () ); glMatrixMode ( GL_PROJECTION ); // select projection matrix glLoadIdentity (); // reset projection matrix // calculate aspect ratio of the window gluPerspective ( getFov (), getAspect (), getZNear (), getZFar () ); glMatrixMode ( GL_MODELVIEW ); // select modelview matrix glLoadIdentity (); // reset modelview matrix glMultMatrixf ( m ); glTranslatef ( -pos.x, -pos.y, -pos.z ); glGetFloatv ( GL_PROJECTION_MATRIX, proj ); }
// --------------------------------------------------------------------------------------------------------------------------------------------------- // 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() ); }