indigo icon indicating copy to clipboard operation
indigo copied to clipboard

Add a `Camera` that centers on the given point, but will never display contents outside of a given bounding box.

Open Sintrastes opened this issue 3 years ago • 2 comments

A lot of top-down RPGs have a camera style where the camera is always centered on the current player, unless the player is near the edge of the current map, in which case the camera is fixed at the boundary of the map, following the character as closely as possible.

It would be convenient if Indigo had this as a built-in camera type, perhaps a Camera.BoundedLookAt(target: Point, zoom: Zoom, boundary: Rectangle) (rotation has been removed here, as it makes it harder to see what the behavior of such a camera should be).

Additionally, it would be nice if Indigo allowed users to create their own custom cameras like this somehow, in case there are more exotic use-cases that we may not necessarily want to have in the core Indigo library. This is not currently possible (as far as I can tell), as Camera is a sealed trait.

Sintrastes avatar Jan 10 '22 22:01 Sintrastes

Let me take those separately:

Constrained to a box

I really like the idea of being able to constrain the camera to some specific bounds - probably just a Rectangle I imagine. Could this just be an Option[Rectangle] on the current camera types that defaults to a None?

Otherwise yes I agree it could be a different camera type if you think there's value in that?

You're quite right that rotation does muddy the water, but if one was prepared to roll up ones sleeves and do the maths, it is doable. Similar things are done in/by the BoundaryLocator to figure out the bounds of rotated screen entities.

image

Custom camera

There are choices here.

Following what I've done everywhere else, we could just remove the sealed as you said. The only catch is that we currently need to know whether the camera is 'fixed' or 'look at' when we create the view matrix.

https://github.com/PurpleKingdomGames/indigo/blob/2674fc306070e98372af428642bbded3f68a845a/indigo/indigo/src/main/scala/indigo/platform/renderer/shared/CameraHelper.scala#L8

At the moment we can just magically know things because there's only two types and they formed an exhaustive ADT. If we open it up, we'd need to change that relationship and expose something on the camera instances that the user doesn't care about, but that helps the renderer. That might not be a big deal.

Another solution is to start using typeclasses, so you can take any A where you have a given IsCamera[A] or something, but I'm reluctant to go that route, purely for consistency reasons.

davesmith00000 avatar Jan 11 '22 00:01 davesmith00000

@davesmith00000 I think we can probably handle allowing custom defined cameras elsewhere -- I was just throwing out ideas. In terms of constraining the camera to a box, I like the idea of just adding an Option[Rectangle] parameter to the existing cameras.

Sintrastes avatar Jan 16 '22 00:01 Sintrastes