1
Graphics / Re: View, Viewports and getting mouse location
« on: December 06, 2023, 06:56:53 pm »
I must be missing something.
From what I see, you can't convert screen coords to world coords until you set the View to a Window/RenderTarget. So I actually have to do graphics work in my Update function. Something like this:
Update Method:
Render Method:
And I don't see how I can avoid adjusting the view in the Render phase because the Update phase has left it in the wrong view state.
On top of it, the Update method is actually called several times for every Render method (accurate physics sometimes requires this), so it ends up being a lot of view switching. Hopefully its fast at least.
From what I see, you can't convert screen coords to world coords until you set the View to a Window/RenderTarget. So I actually have to do graphics work in my Update function. Something like this:
Update Method:
RenderWindow.SetView(new View( .. world view / viewport details) );
Vector2i mousecoordsWorld = RenderWindow.MapPixelToCoords(getMouseCoords());
// do world updates such as shoot bullets
RenderWindow.SetView(new View( .. HUD view / viewport details) );
Vector2i mousecoordsHud = RenderWindow.MapPixelToCoords(getMouseCoords());
// do hud updates such as updating button states and detecting clicks...
Vector2i mousecoordsWorld = RenderWindow.MapPixelToCoords(getMouseCoords());
// do world updates such as shoot bullets
RenderWindow.SetView(new View( .. HUD view / viewport details) );
Vector2i mousecoordsHud = RenderWindow.MapPixelToCoords(getMouseCoords());
// do hud updates such as updating button states and detecting clicks...
Render Method:
RenderWindow.SetView(new View( .. world view / viewport details) );
// render world
RenderWindow.SetView(new View( .. HUD view / viewport details) );
// render Hud
// render world
RenderWindow.SetView(new View( .. HUD view / viewport details) );
// render Hud
And I don't see how I can avoid adjusting the view in the Render phase because the Update phase has left it in the wrong view state.
On top of it, the Update method is actually called several times for every Render method (accurate physics sometimes requires this), so it ends up being a lot of view switching. Hopefully its fast at least.