Skip to content

Commit

Permalink
fix to make ofCAmera ortientation aware
Browse files Browse the repository at this point in the history
  • Loading branch information
roymacdonald committed Feb 4, 2013
1 parent 27b4f5d commit ef9bccc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
16 changes: 12 additions & 4 deletions libs/openFrameworks/3d/ofCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include "ofCamera.h"
#include "ofLog.h"

//----------------------------------------
ofCamera::ofCamera() :
isOrtho(false),
Expand All @@ -20,6 +19,10 @@ lensOffset(0.0f, 0.0f),
forceAspectRatio(false),
isActive(false)
{
orientationMatrices[1].rotate(180, 0, 0, 1);
orientationMatrices[2].rotate(-90, 0, 0, 1);
orientationMatrices[3].rotate(90, 0, 0, 1);

}

//----------------------------------------
Expand Down Expand Up @@ -139,10 +142,15 @@ void ofCamera::begin(ofRectangle viewport) {
ofMatrixMode(OF_MATRIX_PROJECTION);
ofLoadIdentityMatrix();

ofLoadMatrix( this->getProjectionMatrix(viewport) );


ofLoadMatrix( this->getProjectionMatrix(viewport) );

ofMatrixMode(OF_MATRIX_MODELVIEW);
ofLoadMatrix( ofMatrix4x4::getInverseOf(getGlobalTransformMatrix()) );
if (ofGetOrientation() != OF_ORIENTATION_UNKNOWN) {
ofLoadMatrix( ofMatrix4x4::getInverseOf(getGlobalTransformMatrix()) * orientationMatrices[int(ofGetOrientation())-1]);
}else{
ofLoadMatrix( ofMatrix4x4::getInverseOf(getGlobalTransformMatrix()) );
}
ofViewport(viewport);
}

Expand Down
1 change: 1 addition & 0 deletions libs/openFrameworks/3d/ofCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@ class ofCamera : public ofNode {
bool forceAspectRatio;
float aspectRatio; // only used when forceAspect=true, = w / h
bool isActive;
ofMatrix4x4 orientationMatrices [4];
};

0 comments on commit ef9bccc

Please sign in to comment.