tzachshabtay / MonoAGS

AGS (Adventure Game Studio) reimagined in Mono
https://tzachshabtay.github.io/MonoAGS/
Artistic License 2.0
27 stars 8 forks source link

Viewport pivot feature not working as expected #264

Closed ghost closed 6 years ago

ghost commented 6 years ago

After updating games to changes from #260 scaling and rotating are completely broken. I cannot even tell what point it scales from or rotates around. From the looks of it, it lies far beyond the viewport itself.

The game room is very large, may that be related somehow?

UPD. While pivot is at 0,0 it definitely looks like it rotates and scales related to the bottom-left of the room. If I change it to 0.5,0.5, I am not so sure what happens. Maybe the center point becomes a point lying at a distance of half-viewport size from the room's corner (not certain).

Another problem is that if I change pivot to, for example (0.5, 0.5) the viewport is no longer centered to the camera target, the target appears in the bottom-left corner instead. Is this supposed to be like that?

tzachshabtay commented 6 years ago

I've made some fixes in this branch: https://github.com/tzachshabtay/MonoAGS/tree/ViewportFixes Can you test it and confirm it works as expected with that branch?

ghost commented 6 years ago

The camera target now stays in center with the pivot changed, but rotation still performed around a fixed room point rather than relative to viewport position.

I guess the target position on screen is only important for Camera class, because it is that class that determines where to position viewport. Viewport itself does not care about target.

So, it is all about coordinates viewport is positioning, scaling and rotating around.


I realized there is no definition for how viewport's X.Y properties relate to Pivot. I did not mention that in feature request either.

Maybe treat all viewport positioning in relation to pivot? I.e. if Pivot is (0,0), then Viewport.X/Y are also room coordinates that must be shown at viewport's (0,0) (bottom-left corner). If Pivot is (0.5,0.5) then Viewport.X/Y will mean room coordinates to show at viewport's center?

Not completely sure if that's a good idea myself, tbh. I mean, that sounds logical, but in a regular side-view adventure AGSers used to control viewport's corner coordinates, while may still want to rotate it around center.

ghost commented 6 years ago

I think of most importance is to write down an order of operations into engine and maybe interface documentation.

If there were only positionung and rotation, at first things seem kind of simple: first you position viewport to X,Y (aligned to bottom-left corner, or to pivot, it's technically equaly easy), then rotate around pivot.

With scaling added, I begin to wonder what "position" actually means. Does it mean the coordinates of viewport's corner before scaling, or after scaling?

Now, to think of it, from the user's perspective what is more convenient, to have Viewport's position mean coordinates before rotation or after rotation?

tzachshabtay commented 6 years ago

Maybe treat all viewport positioning in relation to pivot?

Yes, that's what I wanted to do in the beginning, actually, only messed up the signs. This way it will be consistent with how the pivot works for the objects. I'll do another commit today for this.

rotation still performed around a fixed room point rather than relative to viewport position.

Hmmm, it works fine in the demo game, you can see in Features -> Viewports, it has a viewport with (0.5, 0.5) pivot and it's rotated around the center as expected. I'll try to reproduce with "Last & Furious" (I assume that's where you saw this?).

ghost commented 6 years ago

I'll try to reproduce with "Last & Furious" (I assume that's where you saw this?).

Yes, I was testing this in racing game, because I have viewport rotation bound to key controls there already.

But I guess it could be more convenient to make a room x2 or x3 size of a game's virtual size and test it there, probably that would be easier to see what point it rotates around. Because in L&F I have to drive down to the bottom of the map to actually confirm that viewport rotates around some location in the corner.

tzachshabtay commented 6 years ago

Pushed fixes again (same branch), can you re-test? Thanks.

ghost commented 6 years ago

Ok, rotation works now, rotates around pivot.

But scaling always zooms in/out towards/from bottom-left corner of the viewport, or so it seems.

tzachshabtay commented 6 years ago

I'll need a repro for this, then, because I tested with Last & Furious (after changing the viewport pivot to 0.5,0.5 and the camera to adjust to that pivot), and both scaling and rotating were centered as expected.

ghost commented 6 years ago

I pushed a temporary branch: https://github.com/ivan-mogilko/MonoAGSGames/tree/fix--camerapivot

Removed viewport position clamping to room bounds from camera, because it made it harder to test.

Steps:

tzachshabtay commented 6 years ago

Thanks, should be fixed now, can you confirm on your side?

ghost commented 6 years ago

Ok, it works now!