ofCamera.screenToWorld - when can I start using it?

Hi,

I defined a ofCamera in the setup portion and I’m using it for calculations in the update portion, to see which part of the world is actually being viewed (and of course later, in the draw portion, also using the same ofCamera to actually draw).

I noticed that in the first run of update, the ofCamera is returning invalid results in screenToWorld and worldToScreen because the viewport is not yet initialized. Is there a way to “force init” it in order for the calculations in update to be correct even on the first run? Or should I refactor my code to disregard results from first update?

Thanks,

Tal

that is actually a bug, the viewport is usually set before the draw call but the camera calculations depend on the viewport so it should be set before that. i’m going to look into it but you can probably fix it by calling ofViewport() in setup which will set the default viewport

Hi,

Thanks for the reply, Arturo.

Tried your workaround. Unfortunately, it does not work. Any more ideas?

Tal

i guess you need to also begin the camera at least once for it to apply the correct matrices,

Tried too, still no good.

I did begin() and end() in the setup.

Was that your meaning?