Hi. I was wondering if it is possible to convert a point that is inside an Fbo, which is not drawn at 0, 0, into it’s position in the window. For example:
ofRect(0, 0, 50, 50);
So now the top-left corner of the rectangle is at point 10,10 in the main window, although it is an point 0,0 in the Fbo. Is there any convenient method to get a certain point (again for example the top-left corner of the rectangle), but have it return that point as it would be in the main window?
Also - maybe there is a better way to do what I’m trying to do. I’m working on an interactive surface that has several different views. There is the view that is the main menu, and when you select something from that “menu”, a different view slides in from the right and pushes the main view off the screen. Now this new view also has some “buttons” that you can click. I am drawing the different views into Fbos and doing the sliding animation by changing where the Fbos are drawn to. Problem is, I need to find out if the mouse or touch is inside a given hot-zone to register the button press, but if i just use the Fbo coordinates, the program doesn’t take into consideration where the Fbo is actually drawn. (Let me know if I can explain that better.)
Does anyone have any idea of a better way to handle this?
Thanks for any help.
What you’re talking about is kind of a big topic but there are a few easy ways around it. The first would be just keeping a matrix that you can track your transformations.
ofTranslate(10, 10); // move over 10,10
ofRotate(45, 1, 0, 0); // 45 degrees on the X
m.rotate(45, 1, 0, 0);
fbo.end();// we lose our GL transformations but they're stored in our ofMatrix
then later you can use that to transform and rotate the points of your mouse position if you store it as a ofVec3f, like ofVec3f(mouseX, mouseY, 0);
Hope that points you in the right direction.
Thanks Josh, that does help. I think I kind of ended up doing something similar, I setup two ofRectangles for my button hotspots. One has the coordinates for being drawn in the Fbo, the other has the coordinates of where it is at in the main window. The first I can set and forget, the second I have to update every time I move the Fbo. I hadn’t thought about or really used the ofMatrix before, I’ll look into that.
Do you think it makes more sense to transform the mouse position or do what I’m doing with two separate sets of points and not have to transform the mouse points?
Thanks again for your help.
Very cool! If you’re not doing any rotation then what you’re doing makes perfect sense, but if you start rotating things you might try using a matrix since it represents scaling and rotation better.