Skip to content

ofEasyCam : fix wrong scaling center in ortho mode - #8026

Merged
danoli3 merged 1 commit into
openframeworks:masterfrom
hiroMTB:ofEasyCam-bugfix-ortho-mode-scaling-center
Jul 11, 2024
Merged

ofEasyCam : fix wrong scaling center in ortho mode#8026
danoli3 merged 1 commit into
openframeworks:masterfrom
hiroMTB:ofEasyCam-bugfix-ortho-mode-scaling-center

Conversation

@hiroMTB

@hiroMTB hiroMTB commented Jun 25, 2024

Copy link
Copy Markdown
Contributor

This only happens with ofEasyCam's ortho mode + custom viewport.

Expected behavour

Expected behavour is to zoom in/out into the mouse pointer position when user scroll mouse wheel (or R click drag). It works fine with normal viewport with 0,0 position and full window w, h. But when we use custom viewport (e.g. camera.begin(viewport); ) then it zoom in/out into wrong position.

Issue

The problem is that ofEasyCam forgots to give viewport parameter to screenToWorld(). screenToWorld() calls ofCamera::getViewport() internaly but ofCamera seems not storing custom viewport parameter but just get current window's viewport, which is {0,0,fullW, fullH}. Hence it gives wrong world position.

Reproducing this bug

tested on

  • macOS 14.5
  • Xcode 15.4
  • openFrameworks(latest master at the time of this writting)

ofApp.h

#pragma once

#include "ofMain.h"

class ofApp : public ofBaseApp {
public:
    void setup();
    void draw();
    void drawViewportOutline(const ofRectangle & viewport);

    ofRectangle viewport;
    ofEasyCam camera;
};

ofApp.cpp

#include "ofApp.h"

void ofApp::setup(){
    ofBackground(90);
    ofEnableSmoothing();
    
    camera.enableOrtho();
    camera.setNearClip(-1000000);
    camera.setFarClip(1000000);
    // camera.setVFlip(true);
    
    viewport.x = 500;
    viewport.y = 200;
    viewport.width = 500;
    viewport.height = 500;
}

void ofApp::draw(){

    drawViewportOutline(viewport);
    //camera.setControlArea(viewport);
	
    camera.begin(viewport);
    ofSetColor(255, 0, 0);
    ofFill();
    ofDrawCircle(0,0,0,10);
    ofDrawGrid(100);
    camera.end();
}

Before and after

Before

before

After

after

@danoli3

danoli3 commented Jul 11, 2024

Copy link
Copy Markdown
Member

OMG you fixed it!!! This one plagued me in easy cam many moons ago!! Wicked!

@danoli3 danoli3 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clean change

@danoli3
danoli3 merged commit 7f32b03 into openframeworks:master Jul 11, 2024
@danoli3 danoli3 added this to the 0.13.0 milestone Jul 11, 2024
@hiroMTB

hiroMTB commented Jul 11, 2024

Copy link
Copy Markdown
Contributor Author

thanks for your review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants