//--------------------------------------------------------------
void testApp::setup(){
camera.position(ofGetWidth()/2, ofGetHeight()/2, 1000);
}
//--------------------------------------------------------------
void testApp::draw(){
camera.place();
if(mrp==true){
camera.moveLocal(0.0f,0.0f,20.0f);
}
ofTranslate(400,400,0);
glBegin(GL_TRIANGLES);
glColor3f(0.2f,0.0f,0.8f);
glVertex3f(0.0f,50.0f,0.0f);
glVertex3f(-50.0f,-50.0f,50.0f);
glVertex3f(50.0f,-50.0f,50.0f);
glColor3f(0.6f,1.0f,0.9f);
glVertex3f(0.0f,50.0f,0.0f);
glVertex3f(50.0f,-50.0f,50.0f);
glVertex3f(50.f,-50.0f,-50.0f);
glColor3f(0.0f,0.2f,0.5f);
glVertex3f(0.0f,50.0f,0.0f);
glVertex3f(50.0f,-50.0f,-50.0f);
glVertex3f(-50.0f,-50.0f,-50.0f);
glColor3f(1.0f,0.5f,0.5f);
glVertex3f(0.0f,50.0f,0.0f);
glVertex3f(-50.0f,-50.0f,-50.0f);
glVertex3f(-50.0f,-50.0f,50.0f);
glEnd();
}
//--------------------------------------------------------------
void testApp::keyPressed(int key){
keys[key] = true;
if(key == OF_KEY_UP){
camera.moveGlobal(0.0f,12.0f,0.0f);
}
if(key == OF_KEY_DOWN){
camera.moveGlobal(0.0f,-12.0f,0.0f);
}
if(key == OF_KEY_LEFT){
camera.moveLocal(-12.0f,0.0f,0.0f);
}
if(key == OF_KEY_RIGHT){
camera.moveLocal(12.0f,0.0f,0.0f);
}
}
//--------------------------------------------------------------
void testApp::keyReleased(int key){
keys[key] = false;
}
//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
if(pmousex==NULL){
pmousex=x;
pmousey=y;
}
camera.rotate(ofxVec3f(0.0f,-1.0f,0.0f) , (x-pmousex)*0.2f);
camera.rotate(ofxVec3f(-1.0f,0.0f,0.0f) , (y-pmousey)*0.2f);
pmousex=x;
pmousey=y;
}
//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
if(button==2){
mrp=true;
}
}
//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){
pmousex=NULL;
if(button==2){
mrp=false;
}
}
This piece of code is from my testApp.cpp and shows the way I use the camera. I deleted most of the other code to keep it as short as possible. I use the left mouse button to look around and the right mouse button to go forward in the direction you are looking.
Thanks