Created
July 28, 2017 17:04
-
-
Save tgfrerer/28b2bf3ad689e4f8cc778644c9d6595e to your computer and use it in GitHub Desktop.
minimal demo app showing camera frustum drawing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofMain.h" | |
class ofApp: public ofBaseApp { | |
ofEasyCam cam[2]; | |
size_t activeCam = 1; | |
public: | |
void ofApp::setup() { | |
cam[0].setupPerspective( false, 30, 20.f, 500.f ); | |
cam[0].setDistance( 20 ); | |
cam[1].setupPerspective( false, 60, 5.f, 2000.f ); | |
cam[1].setDistance( 50 ); | |
ofSetBackgroundColor( ofColor::fromHex( 0x333333 ) ); | |
}; | |
//-------------------------------------------------------------- | |
void ofApp::update() { | |
}; | |
//-------------------------------------------------------------- | |
void ofApp::draw() { | |
ofEnableDepthTest(); | |
glCullFace( GL_CCW ); | |
glEnable( GL_CULL_FACE ); | |
cam[activeCam].begin(); | |
ofSetColor( ofColor::blueSteel, 128 ); | |
ofDrawSphere( { 0,0,-200 }, 50 ); | |
ofSetColor( ofColor::white ); | |
cam[( activeCam + 1 ) % 2].drawFrustum(); | |
cam[( activeCam + 1 ) % 2].draw(); | |
cam[activeCam].end(); | |
glDisable( GL_CULL_FACE ); | |
ofDisableDepthTest(); | |
}; | |
//-------------------------------------------------------------- | |
void ofApp::keyPressed( int key ) { | |
}; | |
//-------------------------------------------------------------- | |
void ofApp::keyReleased( int key ) { | |
switch ( key ) { | |
case 'o': | |
( !cam[0].getOrtho() ) ? cam[0].enableOrtho() : cam[0].disableOrtho(); | |
break; | |
case 'c': | |
cam[activeCam].disableMouseInput(); | |
activeCam = ( activeCam + 1 ) % 2; | |
cam[activeCam].enableMouseInput(); | |
default: | |
break; | |
} | |
}; | |
void mouseMoved( int x, int y ) {}; | |
void mouseDragged( int x, int y, int button ) {}; | |
void mousePressed( int x, int y, int button ) {}; | |
void mouseReleased( int x, int y, int button ) {}; | |
void mouseEntered( int x, int y ) {}; | |
void mouseExited( int x, int y ) {}; | |
void windowResized( int w, int h ) {}; | |
void dragEvent( ofDragInfo dragInfo ) {}; | |
void gotMessage( ofMessage msg ) {}; | |
}; | |
//======================================================================== | |
int main( ){ | |
ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context | |
// this kicks off the running of my app | |
// can be OF_WINDOW or OF_FULLSCREEN | |
// pass in width and height too: | |
ofRunApp(new ofApp()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment