Lazarus

Programming => Graphics and Multimedia => Games => Topic started by: Jake012345 on April 16, 2020, 07:59:13 pm

Title: CastleEngine Navigation setting
Post by: Jake012345 on April 16, 2020, 07:59:13 pm
How can I set the navigation?
I downloaded some navigation file what I can open with "view3scene" and working,
but I cant use these in my project.
And I want to make my own navigation style.
But... How?

(I'm just learning CastleEngine's basics and I read the info on web, but that's the result) :'(
Title: Re: CastleEngine Navigation setting
Post by: Eugene Loza on April 16, 2020, 09:44:16 pm
Hi, Jake!
Quote
And I want to make my own navigation style.
Depends on what are you trying to achieve by your own navigation style. Tell what do you want your project to do so that I or someone else can help you more specifically.

Note that there are two things that may be called "navigation":

First one is the TNavigationInfoNode node (see https://castle-engine.io/apidoc-unstable/html/X3DNodes.TNavigationInfoNode.html) often found inside of the X3D file, generated by Blender.

Or there is a new feature of the latest 6.5 version of Castle Game Engine, called TCastleNavigation (see https://castle-engine.io/apidoc-unstable/html/CastleCameras.TCastleNavigation.html) which improves the recent behavior of the TCamera.
For most tasks you should be perfectly enough with 2 presets inside the Castle Game Engine: TCastleWalkNavigation for FPS-like movement in the scene, or TCastleExamineNavigation suitable for most other purposes.

If you really need to create "your own navigation style", you can simply override one of those, e.g. like here https://gitlab.com/EugeneLoza/eliteminus/-/blob/master/gameinitialize.pas#L43
Title: Re: CastleEngine Navigation setting
Post by: michalis on April 16, 2020, 10:09:51 pm
To easily set the navigation, you can set TCastleViewport.NavigationType to ntWalk, ntFly, ntExamine, or ntNone. See https://castle-engine.io/apidoc-unstable/html/CastleViewport.TCastleViewport.html#NavigationType .

To control the navigation more, create an instance of TCastleExamineNavigation or TCastleWalkNavigation, or your custom descendant  of TCastleNavigation, and assign it to TCastleViewport.Navigation. This way you can control every aspect of the navigation. It can be as simple as this:

Code: [Select]
  Navigation := TCastleWalkNavigation.Create(Application);
  Navigation.MouseLook := true;
  Navigation.PreferredHeight := 1;
  Navigation.MoveHorizontalSpeed := 10;
  Navigation.Radius := 0.1;
  Viewport.Navigation := Navigation;

(Example from examples/3d_rendering_processing/build_3d_tunnel.lpr in CGE sources)


You can also just leave TCastleViewport.Navigation at nil, and control camera from any other place in your code. You can call, at any time (e.g. in some OnUpdate) TCastleViewport.SetView method to set position, direction and up vector of the camera.

More information is in the manual: Chapter "Loading, displaying a scene (simple loading of 3D models)" has a section "3. Set the camera and navigation" (https://castle-engine.io/manual_load_3d.php).
Title: Re: CastleEngine Navigation setting
Post by: Jake012345 on April 17, 2020, 09:36:14 am
I'm just wanted to optimalize the default navigation.
TinyPortal © 2005-2018