[help] goemetry shifted when toggling btw ortho() and perspective() in peasycam

oatoat
edited December 2014 in Library Questions

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);    
  }  
}

Answers

  • any advices?

    Much obliged!

  • can anybody kindly advise?

    Thanks!

  • can anybody familiar with peasycam advise on this issue? Thanks!

  • See: https://github.com/processing/processing/issues/1278

    This is probably not a peasycam issue, but a known bug.

  • Thanks, amnon! I'll take a look ...

    Thank you for your kind help in the forum, and Happy new year!

  • Hi all :), a lot of time has passed, from the last post, but I'll try anyway..

    why do we have to set two difference perspective(), one for the setupCamera() method and one for updateCam()?

    Why fov = PI/3; ? What this means? And why we have to update it in draw? Isn't PI/3 a costant?

    Thank you, your code helped me setting clipping boundaries for PeasyCam :)

Sign In or Register to comment.