Skip to content

Commit

Permalink
Navigation just uses parent TCastleViewport, this simplifies a lot of…
Browse files Browse the repository at this point in the history
… things

- Deprecate TCastleViewport.Navigation, no longer need to get/set this

- Move automatic navigation to TCastleAutoNavigationViewport, it is a deprecated baggage not necessary in typical operations

- Add TCastleNavigation.CheckCollision
  • Loading branch information
michaliskambi committed May 6, 2022
1 parent 34981d0 commit 8145ad2
Show file tree
Hide file tree
Showing 10 changed files with 1,078 additions and 1,086 deletions.
10 changes: 9 additions & 1 deletion packages/castle_base.lpk
Expand Up @@ -74,7 +74,7 @@ This is the same license as used by Lazarus LCL and FPC RTL.
See https://castle-engine.io/license.php for details.
"/>
<Version Major="6" Minor="5"/>
<Files Count="974">
<Files Count="976">
<Item1>
<Filename Value="../src/audio/castleinternalabstractsoundbackend.pas"/>
<UnitName Value="CastleInternalAbstractSoundBackend"/>
Expand Down Expand Up @@ -4001,6 +4001,14 @@ See https://castle-engine.io/license.php for details.
<Filename Value="../src/scene/castleviewport_design_navigation.inc"/>
<Type Value="Include"/>
</Item974>
<Item975>
<Filename Value="../src/scene/castleviewport_autonavigation.inc"/>
<Type Value="Include"/>
</Item975>
<Item976>
<Filename Value="../src/scene/castleviewport_scenemanager.inc"/>
<Type Value="Include"/>
</Item976>
</Files>
<RequiredPkgs Count="3">
<Item1>
Expand Down
61 changes: 1 addition & 60 deletions src/scene/castlescenecore.pas
Expand Up @@ -1741,9 +1741,6 @@ TVisibilitySensors = class({$ifdef FPC}specialize{$endif} TDictionary<TVis
procedure RegisterCompiledScript(const HandlerName: string;
Handler: TCompiledScriptHandler);

{ TNavigationType value determined by current NavigationInfo node. }
function NavigationTypeFromNavigationInfo: TNavigationType;

{ Update TCastleNavigation properties based on currently bound NavigationInfo.
Bound NavigationInfo node is taken from
Expand Down Expand Up @@ -7463,62 +7460,6 @@ procedure TCastleSceneCore.ExecuteCompiledScript(const HandlerName: string;

{ camera ------------------------------------------------------------------ }

function TCastleSceneCore.NavigationTypeFromNavigationInfo: TNavigationType;

function StringToNavigationType(const S: string;
out NavigationType: TNavigationType): boolean;
begin
Result := false;
if S = 'WALK' then
begin
Result := true;
NavigationType := ntWalk;
end else
if S = 'FLY' then
begin
Result := true;
NavigationType := ntFly
end else
if S = 'NONE' then
begin
Result := true;
NavigationType := ntNone
end else
if (S = 'EXAMINE') or
(S = 'LOOKAT') then
begin
if S = 'LOOKAT' then
WritelnWarning('X3D', 'TODO: Navigation type "LOOKAT" is not yet supported, treating like "EXAMINE"');
Result := true;
NavigationType := ntExamine;
end else
if (S = 'ARCHITECTURE') or
(S = 'TURNTABLE') then
begin
Result := true;
NavigationType := ntTurntable
end else
if S = 'ANY' then
begin
{ Do nothing, also do not report this NavigationInfo.type as unknown. }
end else
WritelnWarning('X3D', 'Unknown NavigationInfo.type "%s"', [S]);
end;

var
I: Integer;
NavigationNode: TNavigationInfoNode;
begin
NavigationNode := NavigationInfoStack.Top;
if NavigationNode <> nil then
for I := 0 to NavigationNode.FdType.Count - 1 do
if StringToNavigationType(NavigationNode.FdType.Items[I], Result) then
Exit;

{ No recognized "type" found, so use default type EXAMINE. }
Result := ntExamine;
end;

function TCastleSceneCore.SensibleCameraRadius(const WorldBox: TBox3D;
out RadiusAutomaticallyDerivedFromBox: Boolean): Single;
var
Expand Down Expand Up @@ -8070,7 +8011,7 @@ procedure TCastleSceneCore.AddViewpointFromNavigation(
begin
if RootNode = nil then
raise Exception.Create('You have to initialize RootNode, usually just by loading some scene to TCastleSceneCore.Load, before adding viewpoints');
if Navigation.InternalViewport = nil then
if Navigation.Camera <> nil then
raise Exception.Create('Navigation must be part of some Viewport before using AddViewpointFromNavigation');

Navigation.Camera.GetWorldView(APosition, ADirection, AUp);
Expand Down

0 comments on commit 8145ad2

Please sign in to comment.