Plonq / bevy_panorbit_camera

A simple pan and orbit camera for the Bevy game engine
Apache License 2.0
186 stars 36 forks source link

Add 'roll' controls and custom 'up' vector support #45

Closed Plonq closed 9 months ago

Plonq commented 9 months ago

closes #41

Adds the ability to control the 3rd rotational axis (roll), in addition to yaw/tilt (alpha/beta). Adding the 3rd axis can make things weird, in that it changes what the camera treats as 'up' (the up vector). And once the up vector has changed, it's practically impossible to reset it back to default with just the camera controls. You have to reset it programmatically. For this reason, roll is disabled by default in both mouse/kb controls and touch controls. Also, the concept of being 'upside down' makes no sense when you can change what 'up' means, and so allow_upside_down should typically be set to true when enabling roll or changing the up vector.

The roll control is implemented by introducing a 'base transform' upon which all other transformations are applied. By default, when roll is disabled, this base transform is identical to the world transform, i.e. Transform::IDENTITY. Changing the rotation of the base transform changes the 'up' vector. Changing the translation of it is not supported but theoretically it will effectively just change what 'zero pan' means, so isn't that useful. (Transform is used instead of a rotation like Quat or Mat3 because it provides useful methods.)

This PR also introduces a touch_enabled property which can be used to disable touch controls entirely (it's true by default). Disabling this may result in slightly better performance, but I haven't tested and I suspect the difference would be negligible in most cases.

Roll with keyboard controls:

https://github.com/Plonq/bevy_panorbit_camera/assets/7709415/b939f4e5-8e71-4b38-a179-8a5ef35ec2f5

Roll with touch controls:

https://github.com/Plonq/bevy_panorbit_camera/assets/7709415/9ebccc96-26c5-4a47-86d7-dd4f3c71ed34