How to use Orthographic mode while keeping the same scale?

I’m trying to use orthographic mode so I can draw the 3d shapes identically.

Here’s my code without enabling the orthographic mode.

void ofApp::draw(){
    camera.setNearClip(0.001);
    camera.begin();
    ofNoFill();
    ofDrawSphere(0.0, 0.0, -1.0, 0.2);
    ofDrawSphere(-0.5, 0.4, -1.0, 0.2);
    ofDrawSphere(0.5, 0.4, -1.0, 0.2);
    ofDrawSphere(-0.5, -0.4, -1, 0.2);
    ofDrawSphere(0.5, -0.4, -1, 0.2);
    camera.end();
}

And here’s the resulting screenshot:

And as I said, I would like to draw all five spheres to look identical just like the one in the center.

So I added camera.enableOrtho(); but here’s the resulting screenshot:

Why they look so different and how can I fix this?

Hi!
You basically have to blow up your coordinate values & radius, they’re too small. Multiply your x, y, z by 1000 (except for the central sphere’s [x, y, z] because we want it in the center of our canvas):

  cam.enableOrtho();
  cam.setNearClip(0.001);
  cam.begin();
  ofNoFill();
  ofDrawSphere(0.0, 0.0, 0, 200);
  ofDrawSphere(-500, 400, 0, 200);
  ofDrawSphere(500, 400, 0, 200);
  ofDrawSphere(-500, -400, 0, 200);
  ofDrawSphere(500, -400, 0, 200);
  cam.end();

You can read more about Coordinate Systems in OpenGL here:
https://learnopengl.com/Getting-started/Coordinate-Systems

1 Like

Thank you for you answer. That roughly works.

Would there be any way to accurately calculate and convert them to an orthographic mode?

Hi, I use ortho mode a lot along with ofEasyCam.

just add a regular ofEasyCam to your sketch and
add the following lines in setup

//ofEasyCam cam; //put this line in your ofApp.h file and uncomment it
cam.removeAllInteractions();
cam.addInteraction(ofEasyCam::TRANSFORM_TRANSLATE_XY, OF_MOUSE_BUTTON_LEFT);
cam.addInteraction(ofEasyCam::TRANSFORM_TRANSLATE_Z, OF_MOUSE_BUTTON_RIGHT);
cam.enableOrtho();
cam.setNearClip(-1000000);
cam.setFarClip(1000000);
cam.setVFlip(true);

then just draw as you’d regularly do with teh ofeasy cam.
if you want to use ofCamera instead just dont add the addInteraction lines

it should look like this


//--------------------------------------------------------------
void ofApp::setup(){
	
	cam.removeAllInteractions();
	cam.addInteraction(ofEasyCam::TRANSFORM_TRANSLATE_XY, OF_MOUSE_BUTTON_LEFT);
	cam.addInteraction(ofEasyCam::TRANSFORM_TRANSLATE_Z, OF_MOUSE_BUTTON_RIGHT);
	cam.enableOrtho();
	cam.setNearClip(-1000000);
	cam.setFarClip(1000000);
	cam.setVFlip(true);
	
}
//--------------------------------------------------------------
void ofApp::draw(){
    cam.begin();
	
	ofNoFill();
	ofDrawSphere(0.0, 0.0, 0, 200);
	ofDrawSphere(-500, 400, 0, 200);
	ofDrawSphere(500, 400, 0, 200);
	ofDrawSphere(-500, -400, 0, 200);
	ofDrawSphere(500, -400, 0, 200);
    cam.end();

}

I tested it and works properly. you can now move around the “canvas” by draging the mouse, and zoom in/out by scrolling or right clicking :smiley:

5 Likes

Heres something I wrote about this feature a while ago, but I can not recall if this ended up in some other documentation

4 Likes

Ah, yes @cuinjune , I was using ofEasyCam and not ofCamera for the record! :slight_smile: like Roy just said!
Also, super cool with the custom mouse interaction, @roymacdonald !!!

1 Like