Using ortho() in 3D

Hi,

I'm currently working on a project where I'm supposed to make camera rig rotating around a stationary 3D object. I have the everything else ready but my perspectives aren't as supposed.

I would like to have the projection directly from side when it would look like this:

import processing.opengl.*;

float rot = 0;
float r;

void setup() {
  size(displayWidth/2, displayHeight/2, OPENGL);
  stroke(0);
  background(128);
  r = (height/2) / tan(PI/6);
}

void draw() {
  background(128);
  camera(r*sin(rot), 0, r*cos(rot), 0, 0, 0, 0, 1, 0);
  box(100, 100, 100);

  rot += PI/200;

  if(rot > 2*PI) {
    rot -= 2*PI;
  }
}

But the position of the object should be one fourth of the screen downwards so I shifted it with translate():

void draw() {
  background(128);
  camera(r*sin(rot), 0, r*cos(rot), 0, 0, 0, 0, 1, 0);
  translate(0,height/4,0);
  box(100, 100, 100);

  rot += PI/200;

  if(rot > 2*PI) {
    rot -= 2*PI;
  }
}

Now, as you can see, the perspective changes which is not intended. I was trying to add ortho() function which corrected the perspective but also messed up the position of the object:

void draw() {
  background(128);
  ortho(-width/2, width/2, -height/2, height/2, -width, width);
  camera(r*sin(rot), 0, r*cos(rot), 0, 0, 0, 0, 1, 0);
  translate(0,height/4,0);
  box(100, 100, 100);

  rot += PI/200;

  if(rot > 2*PI) {
    rot -= 2*PI;
  }
}

Any suggestions for a simple solution?

  • Ukkolas

Answers

  • instead of translate(0,height/4,0);

    can't you just move the cam down?

  • or
    just ortho(); without parameters ?

  • Moving the camera down would also change the perspective away from the desired "straight from a side". And using ortho(); without any parameters makes the object to move on the screen.

    One way would be shifting the whole view downwards but I suppose that's not possible.

  • Using ortho() without parameters would work if I wasn't trying to rotate the camera around the object.

Sign In or Register to comment.