Perspective correction

edited March 2016 in Questions about Code

Hi..I am trying to build a mouse coupled perspective with the following sketch.It is doing well in X axis but for nearly the same settings it is totally wrong with Y axis.What is the wrong with it?

int sketch_width=600;
int sketch_height=400;

void setup() {
  size(sketch_width, sketch_height, P3D);
}

void draw() {
  background(100);
  lights();

  float near = 0.1;
  float far = 1000.0;
  float fov = tan( 120 *(PI / 360));
  float ratio = sketch_width / sketch_height;
  float mouse_X;
  float mouse_Y;
  float dis = -200;

mouse_X = ((mouseX/2) / 950.0 * 2.0) - 1.0;
  mouse_Y = ((500.0 - (mouseY/2)) / 500.0 * 2.0) - 1.0;
  mouse_X *= 0.5;
  mouse_Y *= 0.25;

  frustum(near*(-fov * ratio + mouse_X),
               near*(fov * ratio + mouse_X),
               near*(-fov + mouse_Y),
               near*(fov + mouse_Y),
               near, far);



camera( mouse_X * dis, mouse_Y * dis, 0, mouse_X * dis, mouse_Y * dis, -1, 0, 1, 0);
   translate( 0.0, 0.0, dis);

  println(mouseX);


  translate(0,0,0);
  box(50);

}
Sign In or Register to comment.