ofx3DUtils camera to look around

Hello,

I’ve been using the camera fuctionality of ofx3DUtils to ‘look around’ my 3d space like a first person view. The problem I have is with looking up and down.
I use:

  
camera.rotate(ofxVec3f(-1.0f,0.0f,0.0f) , myVariable);  

To look ‘up and down’. This works just fine if I face forward (facing the negative side of the Z-axis) but when I turn around (facing the positive side of the Z-axis) the way the camera behaves changes; and now when I look up the screen goes down and vice-versa.

This change happens quite gradually and midway of turning, facing either side of the X-axis, it’s not possible to look up/down at all.

I find it quite difficult to get good camera movement and was hoping to find a nice library to help me with this (that’s how I did it in Processing). If anybody has any idea what I might be doing wrong, or if anybody has a better way of dealing with the camera I would love to hear it!
Thanks.

Could you maybe post a more complete code sample? Then I could test it out and see what the problem is exactly.

  
  
//--------------------------------------------------------------  
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

What exactly are the variables pmousex and pmousex?
They look like pointer variables, especially since you set them to NULL at some stage, but maybe they’re not.

Hmm yes sorry if I wasn’t to clear about some things. pmousex and pmousey hold the previous mouse x and y coordinates. In order to reset them once a mouse button is released I make them NULL. If the button is pressed again I check if they are NULL and if they are, give them the current x and y coordinates.
I geuss the resetting of the coordinates could also be in the mousePressed function. I’m not even sure why I used NULL here because actually I never do!