g3n / engine

Go 3D Game Engine (http://g3n.rocks)
https://discord.gg/NfaeVr8zDg
BSD 2-Clause "Simplified" License
2.8k stars 295 forks source link

camera.FlyControl for highly configurable FPS or flight-sim style camera control #266

Open quillaja opened 2 years ago

quillaja commented 2 years ago

Finally following up to #124 on my ancient promises of an alternative camera control to Orbit. I see there is also PR #196 and #262 for something similar.

I used a series of maps to allow the user to configure the keys, mouse, speeds, and constraints. Translation, Yaw, Pitch, Roll, FoV Zoom are available, and pitching is not restricted to [-90, 90] from world up.

I tried to describe the use of FlyControl as succinctly as possible in its documentation:

    FlyControl provides a camera controller that allows looking at the scene
    from a first person style view. It allows for translation in the
    Forward/Backward, Right/Left, and Up/Down directions, and rotation in the
    Yaw/Pitch/Roll directions from the camera's point of view. The camera's
    field of view can also be modified to allow ZoomOut/ZoomIn.

    For maximum flexibility, the FlyControl is very configurable, but two main
    modes of operation exist: "manual" and "automatic".

    "Manual" mode requires the user to directly make adjustments to the
    FlyControl's position and orientation by using the Forward(), Right(),
    Yaw(), Pitch() and other similar methods. Manual mode does not subscribe to
    key or mouse events, nor does it use the FlyControl's member maps "Speeds",
    "Keys", or "Mouse" ("Constraints" is used). A FlyControl created (eg with
    NewFlyControl()) with no options defaults to "manual" mode.

    "Automatic" mode subscribes to key and mouse events, and handles position
    and orientation adjustments according to parameters specified in the "Keys",
    "Mouse", "Speed", and "Constraint" maps. Generally, methods such as
    Forward() will not be used. Some preconfigured options are available with
    FPSStyle() and FlightSimStyle(), and can be further configured by the
    With*() options, and by modifying the FlyControl's Keys (etc) maps directly.
quillaja commented 2 years ago

One thing to add would be a way to use the constraints to restrict translational movement to a plane (eg XY).