Esempio n. 1
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);

	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);
}
Esempio n. 2
0
//----------------------------------------------------------
void ofTexture::bind(int textureLocation){
	//we could check if it has been allocated - but we don't do that in draw() 
	if(texData.alphaMask){
		ofGetGLRenderer()->setAlphaMaskTex(*texData.alphaMask);
	}
	enableTextureTarget(textureLocation);
	

	if(ofGetUsingNormalizedTexCoords()) {
		ofSetMatrixMode(OF_MATRIX_TEXTURE);
		ofPushMatrix();
		ofMatrix4x4 m;
		
#ifndef TARGET_OPENGLES	
		if(texData.textureTarget == GL_TEXTURE_RECTANGLE_ARB)
			m.makeScaleMatrix(texData.width, texData.height, 1.0f);
		else 
#endif			
			m.makeScaleMatrix(texData.width / texData.tex_w, texData.height / texData.tex_h, 1.0f);
		
		ofLoadMatrix(m);
		ofSetMatrixMode(OF_MATRIX_MODELVIEW);
	}
	if(texData.useTextureMatrix){
		ofSetMatrixMode(OF_MATRIX_TEXTURE);
		if(!ofGetUsingNormalizedTexCoords()) ofPushMatrix();
		ofMultMatrix(texData.textureMatrix);
		ofSetMatrixMode(OF_MATRIX_MODELVIEW);
	}

	texData.isBound = true;
}
Esempio n. 3
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 ofxFaceTracker2Instance::loadPoseMatrix(){
    if(!poseCalculated){
        calculatePoseMatrix();
    }
    
    ofMatrix4x4 matrix = getPoseMatrix();
    
    loadPoseProjectionMatrix();
    ofLoadMatrix(matrix);
}
Esempio n. 5
0
//----------------------------------------
void ofCamera::begin(ofRectangle viewport) {
	if(!isActive) ofPushView();
	isActive = true;

	ofViewport(viewport.x,viewport.y,viewport.width,viewport.height);
	ofSetOrientation(ofGetOrientation(),vFlip);

	ofSetMatrixMode(OF_MATRIX_PROJECTION);
	ofLoadMatrix( getProjectionMatrix(viewport) );

	ofSetMatrixMode(OF_MATRIX_MODELVIEW);
	ofLoadViewMatrix( getModelViewMatrix() );
}
Esempio n. 6
0
 void PostProcessing::begin(ofCamera& cam)
 {
     // update camera matrices
     cam.begin();
     cam.end();
     
     raw.begin(ofFboBeginMode::NoDefaults);
     
     ofMatrixMode(OF_MATRIX_PROJECTION);
     ofPushMatrix();
     ofLoadMatrix(cam.getProjectionMatrix(ofRectangle(0, 0, width, height)));
     
     ofMatrixMode(OF_MATRIX_MODELVIEW);
     ofPushMatrix();
     ofLoadMatrix(cam.getModelViewMatrix());
     
     ofViewport(0, 0, raw.getWidth(), raw.getHeight());
     
     glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
     
     ofPushStyle();
     glPushAttrib(GL_ENABLE_BIT);
 }
Esempio n. 7
0
void Rail::draw() {
    ofPushMatrix();
    ofSetColor(255,255,255);
    ofTranslate(loc);
    ofRotateX(ang.x);
    ofRotateY(ang.y);
    ofRotateZ(ang.z);
    ofDrawBox(length,10,10);
    motor->draw();
    ofPopMatrix();
    ofPushMatrix();
    ofLoadMatrix(ofMatrix4x4::newIdentityMatrix());
    motor->drawLoom();
    ofPopMatrix();
    
}
// ---------------------------------------------------------------------------------------------------------------------------------------------------
//
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;
		}
	}
	
}