Hi B,
nice to see you here.
In an empty OF program (using the project generator) (0,0,0) is on the top left, running bottom right to (window width, window height, 0).
When using ofEasyCam, the necessary matrices are automatically generated so that the middle of the screen is at (0,0,0), the viewport is as big as you set at main.cpp or using ofSetWindowShape(w,h), and the camera exactly far away so that the viewport is as big as your window.
An interesting concept in this regard is the ofNode class. You can see this as a 3D object that holds transformation data. So, an object that you want to control in 3D, is best to be paired with a node. The node holds all the scaling, orientation and positioning.
In OF, every camera is deriving from the ofNode class. As such, you can transform a camera using all the built in functions of ofNodes. Check link
A starting point for your problem could be the following for instance. Note that I’m using ofCamera instead of ofEasycam.
ofApp.h
ofCamera cam;
ofBoxPrimitive box;
float angle;
ofLight light;
bool bOrbit, bRoll;
float angleH, roll, distance;
ofApp.cpp
//--------------------------------------------------------------
void ofApp::setup(){
ofSetVerticalSync(true);
ofEnableDepthTest();
box.set(100);
light.enable();
bOrbit = bRoll = false;
angleH = roll = 0.0f;
distance = 500.f;
}
//--------------------------------------------------------------
void ofApp::update(){
if (bOrbit) angleH += 1.f;
if (bRoll) roll += 0.5f;
// here's where the transformation happens, using the orbit and roll member functions of the ofNode class,
// since angleH and distance are initialised to 0 and 500, we start up as how we want it
cam.orbit(angleH, 0, distance);
cam.roll(roll);
}
//--------------------------------------------------------------
void ofApp::draw(){
ofSetBackgroundColor(128);
// use our camera matrices: translate to center of camera viewport and draw scene seen from transformed cam
cam.begin();
ofSetColor(200, 100, 0);
box.draw();
box.drawAxes(200);
cam.end();
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
if (key == 'h') {
bOrbit = !bOrbit;
}
else if (key == 'r') {
bRoll = !bRoll;
}
else if (key == OF_KEY_UP) {
distance = MIN( (distance += 2.5f), 1000);
cout << distance << endl;
}
else if (key == OF_KEY_DOWN) {
distance = MAX( (distance -= 2.5f), 150);
cout << distance << endl;
}
}