ofEasyCam change from mousePressed to mouseMoved?


I’m using ofEasyCam and ofSphere, where the sphere rotates with the default mouse interaction controls of ofEasyCam. I am checking if certain points on the sphere is in the center region of the screen and if so various images get drawn. Everything works perfectly on that front.

But I am now going to use a tracking ball instead of a mouse for controlling the rotation of the sphere, and it doesn’t have any buttons.

Does anyone have suggestions for how I can rotate the camera without having to use click and drag? So when I move mouse the sphere rotates? I have tried modify the addon library code, but things then get too messy in my head. I’ve also tried not using ofEasyCam and instead rotate manually by using ofRotate, but then I loose some other good aspects of ofEasyCam.

Any suggestions on how to proceed? I did have a look at @roymacdonald 's ofEasyCam custom mouse interaction - but can’t seem to find a good way to disable mouse drag and enable mouse move…

Kindly appreciate any suggestions!

not sure if it would work but a kind of nasty hack would would be to make ofEasyCam’s mousePressed function public.
Then when you want to start the trackball to work of maybe in ofApp::setup, call something like.

ofMouseEventArgs m(ofMouseEventArgs::Pressed, ofGetWidth()/2.0f, ofGetHeight()/2.0f, OF_MOUSE_BUTTON_LEFT);
cam.mousePressed(m);//where cam is an instance of ofEasyCam

Then you might also want to comment out in ofEasyCam::enableMouseInput the lines that read


Check if this works. If it does I recommend you to make a copy of ofEasyCam.h and ofEasyCam.cpp, put in your project’s src folder and rename to ofxEasyCam. Then inside this files rename the class to ofxEasyCam, which can be done easily with a find and replace on both files (find ofEasyCam replace for ofxEasyCam). Then include in your ofApp.h #include “ofxEasyCam.h” and use an instance of ofxEasyCam instead of ofEasyCam. All this so you dont mess with of source code and dont break other projects.

Maybe it is a better idea to do this the other way round, duplicate ofEasyCam, rename, apply mods. Leave ofEasyCam untouched.
Let me know if it works

Thanks @roymacdonald ! Getting much closer!

It works making mousePressed public, I disabled:


as well as

if(events->getMousePressed()) in ofEasyCam::update

But I kept listeners.push(events->mousePressed.....

and now it works if I click once, then it rotates by just moving mouse (I don’t have to keep mouse pressed). I’m trying to find where in ofEasyCam I could disable that initial mouse click. Is it maybe something in ofEasyCam::mousePressed(ofMouseEventArgs & mouse) I should modify?

void ofEasyCam::mousePressed(ofMouseEventArgs & mouse){
	ofRectangle area = getControlArea();
	if(area.inside(mouse.x, mouse.y)){
		lastPressMouse = mouse;
		prevMouse = mouse;
		lastPressAxisX = getXAxis();
		lastPressAxisY = getYAxis();
		lastPressAxisZ = getZAxis();
		lastPressPosition = ofCamera::getGlobalPosition();
		lastPressOrientation = ofCamera::getGlobalOrientation();

		currentTransformType = TRANSFORM_NONE;
		if (events) {
			for (const auto& i: interactions) {
                if (i.mouseButton == mouse.button && ((i.key == -1) || events->getKeyPressed(i.key)) ) {
					currentTransformType = i.transformType;
		if(currentTransformType == TRANSFORM_ROTATE){
			bInsideArcball = glm::length(mouse - glm::vec2(area.getCenter())) < std::min(area.width/2, area.height/2);
		bApplyInertia = false;

Hi @oximble
Thats why I said you need to add the following code to you ofApp setup or when you want it to start.

It might not work if you call at setup, so you might need to call manually or wait a few frames and then make the call

Yep - solved by waiting a few frames before calling mousePressed. Thanks @roymacdonald !

1 Like