Huge Camera and Navigation Improvements – Thank You Patrons!

Posted on

Castle Game Engine editor with 3 viewports (scene managers)
Castle Game Engine editor with scene manager menu

To celebrate #ThankYouPatrons day in the weirdest and most-programmer-friendly way possible, today we merge into the “master” branch of Castle Game Engine a big refactor of the camera code! This is a huge work, started 4 months ago, and causing 110 new commits.

It includes a number of new inter-connected features:

  1. The API to control the camera (viewer position, direction, up, projection etc.) and navigation is now much simpler. Check out API docs about new TCastleAbstactViewport.Camera and TCastleAbstactViewport.Navigation.

  2. You can now configure both camera and navigation visually, using the CGE editor.

    When you select a viewport (most usually a TCastleSceneManager instance), or anything inside a viewport (like a TCastleScene), there will appear a new set of buttons on the toolbar. The “hamburger” button there contains a menu with useful operations to configure camera and navigation. The “initial” camera vectors will be stored in the design, as well as the chosen navigation component.

    (The buttons to translate/rotate/scale scenes are not yet handled — coming soon!)

  3. We split previous camera class into two concepts, TCastleCamera (“what is current viewer position/orientation and projection”) and TCastleNavigation (“how to handle user input to change the viewer position/orientation”).

    This caused a lot of work to make it right, and also to keep backward-compatibility as much as possible. I’ll list reasons for making it in another post — it’s a story in itself.

  4. We provide easy means to turn off “auto-detection” of camera and navigation. Just set AutoCamera and/or AutoNavigation to false.

    I recognize now that this “auto-detection” is sometimes undesired or even surprising. I would advise most games to set both AutoCamera and AutoNavigation to false right after creating TCastleSceneManager. CGE editor will do it by default too, soon.

  5. TCastle2DSceneManager is now deprecated, as it is useless. You can now easily request orthographic camera with TCastleSceneManager (call Setup2D method, or just set yourself Camera.ProjectionType = ptOrthographic and configure Camera.Orthographic properties). This makes things much simpler. We never needed any special class for 2D, our TCastleSceneManager is for both 2D and 3D — now it’s obvious šŸ™‚

  6. It is now configurable which camera (from which viewport) controls “central” features like headlight, X3D ProximitySensor, audio listener. Set TCastleSceneManager.MainCamera for this.

  7. CGE editor received a number of smaller improvements along the way. E.g. you can now duplicate (Ctrl + D) transformations/scenes too, assigning SceneManager.MainScene and other references works.

Start the discussion at Castle Game Engine Forum