#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# Using ortho() in 3D

edited May 2014

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
Tagged: