Window orientation

Hello i want to use the display in vertical but dont want to set “monitor rotation in OS”

I know i can use, to set window orientation, but problem is that im using a gui and mouse coords must not adapt to the orientation and is not possible to use it
https://openframeworks.cc/documentation/application/ofAppBaseWindow/#show_setOrientation

Is there any way to solve this?

Thanks

which OS are you developing for?

Linaro in arm board

you expect mouse coordinates are rotated too? like swapping x and y?

I think so, as i cant use the gui, dont respond to mouse and I suspect is for the swapped axis

there is a function called rotateMouseXY which does this case by case, it is not applied by default.
I’m working on a idea of having a matrix to multiply and translate rotation and scale (in the case of high density screens) to translate mouse coordinates, something like this

// seems to work with -90, 90, 180
	float angle = glm::radians(180.0);
	glm::mat4 t1 = glm::translate(glm::mat4(1.0), glm::vec3(-ofGetHeight() * .5, -ofGetWidth() * .5, 0));
	glm::mat4 r1 = glm::rotate(glm::mat4(1.0), angle, glm::vec3(0.f, 0.f, 1.f));
	glm::mat4 t2 = glm::translate(glm::mat4(1.0), glm::vec3(ofGetWidth() * .5, ofGetHeight() * .5, 0));
	// glm::mat4 s1 = glm::scale(glm::mat4(), glm::vec3(2.0, 2.0, 0.0));
	glm::mat4 model = t2 * r1 * t1;
	glm::vec4 mouse2 = model * glm::vec4{ mouseX, mouseY, 1, 1 } ;
	
	ofSetColor(0, 255, 0);
	ofDrawCircle(mouseX, mouseY, 30);
	ofSetColor(255,0,30);
	ofDrawCircle(mouse2.x, mouse2.y, 30);
	ofDrawLine(mouseX, mouseY, mouse2.x, mouse2.y);

I didnt know about that function, however seems to be implemented

I checked and that function is called… however at least in my case i have to swap the values of 90_RIGHT to 90_LEFT and reverse… dont know if is the expected behaviour or i should post an issue with a pr…

@arturo should i post a pr?

static void rotateMouseXY(ofOrientation orientation, int w, int h, double &x, double &y) {
int savedY;
switch(orientation) {
case OF_ORIENTATION_180:
x = w - x;
y = h - y;
break;

	case OF_ORIENTATION_90_LEFT:
		savedY = y;
		y = x;
		x = w-savedY;
	    break;

	case OF_ORIENTATION_90_RIGHT:
		savedY = y;
		y = h - x;
		x = savedY;
	    break;

	case OF_ORIENTATION_DEFAULT:
	default:
	    break;
}

}

Hey, there are deeper issues with orientation right now and things will change in this code when they are correctly handled. my suggestion is you use your transformation for now, using matrixes or code from rotateMouseXY

related:

Yep i saw those but think was related to ios, anyway for me is solved changing that lines in the function you told me, thanks!!

1 Like