Normalized coordinate system

It would be super useful to have an easy way to setup OF to use normalized coordinates with 0,0 at the center of the screen. For 2D it makes sense to work with coordinates in pixels and 0,0 at top left but for 3D or when integrating other libraries it’s usually way easier to work with 0…1

Perhaps it should be a parameter in ofCamera and then the glRenderer can contain a camera to set the perspective.

Also there should be an easy way to know in which coordinate system is the world currently set so other parts can change to work in that. For example ofxAssimpModelLoader scales the model to fit the screen width and height but if you setup the screen to normalized coordinates it should scale the model to 0…1

I’d agree. I find normalized co-ordinates for 3d a lot easier to think through.

I think that from an openGL perspective having it in ofCamera makes more sense, but from an OF perspective, having it be a property of the renderer that can be set through the app like the rest of the ofEnable…() methods seems friendlier.

+1

Guess for now you could just do…

[pre]
ofCamera cam;
cam.setPosition(0, 0, 1);
cam.setFov(90);
cam.setNearClip(0.1);
cam.lookAt(ofVec3f(0, 0, 0));
[/pre]

…or something.

  
  
void ofLoadIdentity() {  
    glMatrixMode(GL_PERSPECTIVE);  
    glLoadIdentity();  
    glMatrixMode(GL_MODELVIEW);  
    glLoadIdentity();  
}  
  

?

yes, the thing is some addons and parts of the core assume that coordinates are in pixels. Also what happens with ofGetWidth/Height() if the coordinate system is normalized? i think apart from having a way to set it up as normalized coordinates it can be useful to have an easy way for other parts of OF to know about that

I think commonly if you work with ‘normalised’ you often end up transforming the view.
This could make the ofGetWidth / Height functions very interesting

i guess it’s a question of whether it should be more like ofScale/Translate/Rotate, or more like ofSetupScreenPerspective
(i’m getting all my names wrong here)

i think unnormalized makes a lot of sense given the history of OF. it stands on contrast to something like vvvv which uses normalized by default.

arturo’s point about ofGetWidth()/ofGetHeight() is important. i think trying to support too many different paradigms inside OF can make it confusing to figure out what any given statement means at a given moment.

also, i’m a fan of Apex’s solution rather than ofLoadIdentity(). if it’s possible to avoid talking about things in terms of the perspective and modelview matrix, i think we should. it helps maintain compatibility between cairo and GL. for example, these proposals https://github.com/openframeworks/openFrameworks/issues/765 should be rephrased in terms of ofCamera and ofMatrix4x4 if possible.

OpenGL uses normalised by default of course
I think in terms of a 3D scene, an ofNormalisedCamera makes some sense
but in terms of getting back to the raw OpenGL viewport, ofLoadIdentity makes sense

for note - how does cairo deal with 3D?
does it do some getmatrix / matrix multiplications?

cairo itself is only 2D, the ofCairoRenderer though has a stack of projection and modelview ofMatrix4x4 and calculates the projection before rendering in 2D. Of course there’s no depth test and you can only render wireframes in 3D

does cairo deal with ofTextures?

it only works with ofPixels, ofImage knows if the current renderer is able to render textures or pixels and passes the correct one. The same could be done for the rest of the classes that have pixels and textures. For ofTexture there could be a call to readToPixels

yes, definitely. i was referring more to the history of OF as being about pixel-based-imaging, photoshop-drawing-metaphors, turtle/logo-style drawing, etc.

unlike cinder, which embraces and exposes opengl, OF has tried (like processing) to make the pixel grid a fundamental concept that the rest of API rests on. this is also one of the reasons arb/RECTANGLE mode textures are used by default, i would guess.

1 Like