Camera pan and zoom using trackpad

Hi there,
Am I the only one who finds the orthographic mode for ofCamera really weird ?

From the documentation :

There is no adjustment for distance from the camera made in these projections, meaning objects on the screen will appear the same size no matter how close or far away they are.

As far as I know, we can scale up / down our projection in orthographic mode inside any 3D software, if not, we can’t zoom on object in the scene… And easyCam uses nice features for zoom, including the MacBook trackpad, which is really cool when you don’t have a mouse, like me ^^’.

To more, orthographic mode keeps camera orientation enabled, which is a bit annoying when we just want pan and zoom features.

So my question is how to configure a camera to use it as 2D camera (pan and zoom, using trackpad) ?

Hi,
because of what you mention I made this addon

cheers

1 Like

Indeed, this is what I’m looking for ! Thank you for this.

Just one question, is it possible to limit the zoom out ? Because if not, we go from top view to bottom view.

no prob!
there’s nothing limiting it but you can change that quite easily.
just limit the scale factor to be on the positive range.
in ofxInfiniteCanvas.cpp.
inside the update method:
change this:

}else if(bDoScale){
            scale += move.z + move.z*scale;
            translation = clicTranslation - clicPoint*(scale - clicScale);
        }

for this:

}else if(bDoScale){
            scale += move.z + move.z*scale;
                if(scale<0)scale*=-1;
            translation = clicTranslation - clicPoint*(scale - clicScale);
        }

cheers

Thanks again, the trick works fine.

Unfortunately, I have an other problem, a bit weird… It seems using your addon flip vertically what I want to draw in the viewport.

easyCam working example

ofxInfiniteCanvas :

ofxInfiniteCanvas

Is it a known issue ? When I place my cursor to the upper-right of the viewport, my clic-point has negative Y value, which can confirm the viewport content is Vflipped.

It works for me correcly for me.
which OS are you in? OF version?

I am on Mac OSX 10.11 with XCode 7.3 and OF 0.9.3.

EDIT :

I found a work around, in your begin method I just reverse the scale on Y axis :

ofScale(scale,-scale,scale);

The navigation works even after this modification.

mmm thats odd. Right now I’m super busy so I cant check it rigth now, but I will one I have time.

Use the ofxInfiniteCanvas::drawDebug() method to check whats going on.

My guess is that this problem is more OF related that an problem in my addon.

If you find a fix don’t hesitate on making a PR.

Best!

Using debug, I can see my clic-point Y axis is negative instead of positive and vice versa, even with normal scale or reverse scale.

I am currently working on an infinte grid to use with the camera, could be nice to put with a PR :wink:
But for now I need to find why this axis is reversed…

    int xGridLinePos = 0;
    int yGridLinePos = 0;
    int xGridLineNeg = -1000;
    int yGridLineNeg = -1000;
    
    while (cam.worldToScreen(ofVec3f(xGridLinePos,0,0)).x <= mapViewport.x + mapViewport.width)
    {
        ofDrawLine(
                   xGridLinePos,
                   -cam.screenToWorld(ofVec3f(0,mapViewport.y+mapViewport.height,0)).y,
                   xGridLinePos,
                   -cam.screenToWorld(ofVec3f(0,mapViewport.y,0)).y);
        xGridLinePos += 1000;
    }
    while (cam.worldToScreen(ofVec3f(xGridLineNeg,0,0)).x > mapViewport.x)
    {
        ofDrawLine(
                   xGridLineNeg,
                   -cam.screenToWorld(ofVec3f(0,mapViewport.y+mapViewport.height,0)).y,
                   xGridLineNeg,
                   -cam.screenToWorld(ofVec3f(0,mapViewport.y,0)).y);
        xGridLineNeg -= 1000;
    }
    while (yGridLinePos < 50000) // need to change this after fixing Y axis
    {
        ofDrawLine(
                   cam.screenToWorld(ofVec3f(mapViewport.x,0,0)).x,
                   yGridLinePos,
                   cam.screenToWorld(ofVec3f(mapViewport.x + mapViewport.width,0,0)).x,
                   yGridLinePos);
        yGridLinePos += 1000;
    }
    while (yGridLineNeg > -50000) // need to change this after fixing Y axis
    {
        ofDrawLine(
                   cam.screenToWorld(ofVec3f(mapViewport.x,0,0)).x,
                   yGridLineNeg,
                   cam.screenToWorld(ofVec3f(mapViewport.x + mapViewport.width,0,0)).x,
                   yGridLineNeg);
        yGridLineNeg -= 1000;
    }

I made a quick check and it is now also inverted for me. I was using this addon a lot some months ago and I had no problems with it. No idea what might be going on. I´ll check it later this week.
cheers!

not 100% sure but i think this is correct, by default OF cameras, have y growing upwards while the default 2D perspective in OF has y growing downwards so it makes sense that a 2d camera has y in that direction too. i guess you original code was setup to work with ofEasyCam so it’ll be flipped when viewing it through the default 2d perspective.

1 Like

Hey @mickaelb91, as @arturo mentioned it is the expected behavior.
I just added and pushed a commit with a flag for switching the Y flipping.
Hope it still helps.
Best!