Recent

Author Topic: CastleEngine Navigation setting  (Read 481 times)

Jake012345

  • Sr. Member
  • ****
  • Posts: 253
  • 'The knowledge is the key.'
    • FPCProjectShare
CastleEngine Navigation setting
« 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) :'(
Check my ProjectShare site and share your content: FPCShare

Eugene Loza

  • Hero Member
  • *****
  • Posts: 569
    • My "almost daily" development blog
Re: CastleEngine Navigation setting
« Reply #1 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
Lazarus 1.9 + FPC 3.1.1 Debian Jessie 64 bit.

My Free and Open Source games in Lazarus/FreePascal/CastleGameEngine:
https://decoherence.itch.io/
(and some ancient games in Turbo Pascal too)
Sources are here: https://github.com/eugeneloza?tab=repositories

michalis

  • Full Member
  • ***
  • Posts: 102
    • Homepage
Re: CastleEngine Navigation setting
« Reply #2 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".

Jake012345

  • Sr. Member
  • ****
  • Posts: 253
  • 'The knowledge is the key.'
    • FPCProjectShare
Re: CastleEngine Navigation setting
« Reply #3 on: April 17, 2020, 09:36:14 am »
I'm just wanted to optimalize the default navigation.
Check my ProjectShare site and share your content: FPCShare

 

TinyPortal © 2005-2018