I have the following code to toggle between orthogonal and perspective view of a 3D scene. However, in the orthogonal view the geometry is shifted away from the camera and scaled down. May I ask how to avoid this so that the camera remains focusing on the geometry located at the center of the display window in orthogonal view? Thanks!
import peasy.*;
PeasyCam cam;
Boolean camOrtho = false;
//////////////////////////////////////////////////////////
void setup(){
size(1000, 1000, OPENGL);
setupCamera();
}
//////////////////////////////////////////////////////////
void draw(){
background(120);
updateCam();
// draw stuff here ...
drawBbox();
}
//////////////////////////////////////////////////////////
void setupCamera () {
hint(ENABLE_STROKE_PERSPECTIVE);
float fov = PI/3; // field of view
float nearClip = 1;
float farClip = 100000;
float aspect = float(width)/float(height);
perspective(fov, aspect, nearClip, farClip);
cam = new PeasyCam(this, 150);
}
void updateCam () {
if ( camOrtho == true ) {
ortho();
} else {
//----- perspective -----
float fov = PI/3; // field of view
float nearClip = 1;
float farClip = 100000;
float aspect = float(width)/float(height);
perspective(fov, aspect, nearClip, farClip);
}
}
void drawBbox () {
stroke(0);
noFill();
box(100);
}
void keyPressed () {
if ( key == 'o' ) {
camOrtho = (camOrtho == true) ? (false):(true);
}
}