Example #1
0
//----------------------------------------
void ofCamera::setupPerspective(bool vFlip, float fov, float nearDist, float farDist, const ofVec2f & lensOffset){
	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;

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

	setFov(fov);
	setNearClip(nearDist);
	setFarClip(farDist);
	setLensOffset(lensOffset);
	setForceAspectRatio(false);

	setPosition(eyeX,eyeY,dist);
	lookAt(ofVec3f(eyeX,eyeY,0),ofVec3f(0,1,0));


	if(vFlip){
		setScale(1,-1,1);
	}
}
// ---------------------------------------------------------------------------------------------------------------------------------------------------
//
bool ofxOculusRift::init( int _width, int _height, int _fboNumSamples )
{
	initFBO( _width, _height );
	
	hmdWarpShader.load("Shaders/HmdWarp");
	
	ofDisableArbTex();

		ofFbo::Settings tmpSettings = ofFbo::Settings();
		tmpSettings.width			= _width/2;
		tmpSettings.height			= _height;
		tmpSettings.internalformat	= GL_RGB;
		tmpSettings.textureTarget	= GL_TEXTURE_2D;
		tmpSettings.numSamples		= _fboNumSamples;
		
		eyeFboLeft.allocate( tmpSettings );
		eyeFboRight.allocate( tmpSettings );
	
	ofEnableArbTex();
	
	setNearClip( 0.001f );
	setFarClip( 2048.0f );
	setFov( 90.0f );

	setInterOcularDistance( -0.6f );
	setShaderScaleFactor( 1.0f );
	setDoWarping( true );

	
	return initSensor();
}
CameraNode::CameraNode()
	: width(1280), height(720), near(0.01f), far(100.0f), fovy(29.8f)
{
	setNearClip(near);
	setFarClip(far);
	setFov(fovy);
	setScale(0.5f);
	
	vidGrabber.setDeviceID(1);
	vidGrabber.initGrabber(width, height);
}
Example #4
0
void SecondCamera::setFromOtherCamera(ofCamera& other)
{
	setFarClip(other.getFarClip());
	setNearClip(other.getNearClip());
	setFov(other.getFov());
	
	matProjection = other.getProjectionMatrix();
	matModelView = other.getModelViewMatrix();
	
	matModelView.postMultTranslate(-_offset);
	
	isActive = true;
}
Example #5
0
//----------------------------------------
void ofCamera::setupPerspective(bool _vFlip, float fov, float nearDist, float farDist, const ofVec2f & lensOffset){
	ofRectangle orientedViewport = ofGetNativeViewport();
	float eyeX = orientedViewport.width / 2;
	float eyeY = orientedViewport.height / 2;
	float halfFov = PI * fov / 360;
	float theTan = tanf(halfFov);
	float dist = eyeY / theTan;

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

	setFov(fov);
	setNearClip(nearDist);
	setFarClip(farDist);
	setLensOffset(lensOffset);
	setForceAspectRatio(false);

	setPosition(eyeX,eyeY,dist);
	lookAt(ofVec3f(eyeX,eyeY,0),ofVec3f(0,1,0));
	vFlip = _vFlip;
}