Skip to content

Commit a1e3cec

Browse files
committed
Handle viewport top/bottom/etc. keys consistent with editor
1 parent 3ef5afd commit a1e3cec

File tree

2 files changed

+86
-32
lines changed

2 files changed

+86
-32
lines changed

code/v3dsceneviewpoints.pas

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -293,16 +293,15 @@ procedure TMenuViewpoints.Recalculate(Scene: TCastleSceneCore);
293293
Append(TMenuItem.Create('Default VRML 1.0 viewpoint', 51));
294294
Append(TMenuItem.Create('Default VRML 2.0 (and X3D) viewpoint', 52));
295295
Append(TMenuSeparator.Create);
296-
Append(TMenuItem.Create('Calculated viewpoint to see the scene (+Y up, -Z dir)', 53));
297-
Append(TMenuItem.Create('Calculated viewpoint to see the scene (+Y up, +Z dir)', 54));
298-
Append(TMenuItem.Create('Calculated viewpoint to see the scene (+Y up, -X dir)', 55));
299-
Append(TMenuItem.Create('Calculated viewpoint to see the scene (+Y up, +X dir)', 56));
300-
Append(TMenuSeparator.Create);
301-
Append(TMenuItem.Create('Calculated viewpoint to see the scene (+Z up, -X dir)', 57));
302-
Append(TMenuItem.Create('Calculated viewpoint to see the scene (+Z up, +X dir)', 58));
303-
Append(TMenuItem.Create('Calculated viewpoint to see the scene (+Z up, -Y dir)', 59));
304-
Append(TMenuItem.Create('Calculated viewpoint to see the scene (+Z up, +Y dir)', 60));
305-
296+
{ TODO: key shortcuts should handle both numpad and non-numpad key presses.
297+
TODO: key shortcuts should show Ctrl+XXX versions.
298+
For now we workaround both by handling more keys in Press. }
299+
Append(TMenuItem.Create('Top', 53, '7'));
300+
Append(TMenuItem.Create('Bottom', 54{ TODO: , Ctrl7}));
301+
Append(TMenuItem.Create('Front', 57, '1'));
302+
Append(TMenuItem.Create('Back', 58{ TODO: , Ctrl1}));
303+
Append(TMenuItem.Create('Right', 59, '3'));
304+
Append(TMenuItem.Create('Left', 60{ TODO: , Ctrl3}));
306305
MenuUpdateEnd;
307306
end;
308307

view3dscene.lpr

Lines changed: 77 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -753,8 +753,79 @@ procedure TV3DViewport.Render;
753753

754754
SOnlyWhenOctreeAvailable = 'This is not possible when octree is not generated. Turn on "Navigation -> Collision Detection" to make it available.';
755755

756+
procedure SetViewpointForWholeScene(
757+
const WantedDirection, WantedUp: Integer;
758+
const WantedDirectionPositive, WantedUpPositive: boolean);
759+
var
760+
Position, Direction, Up, GravityUp: TVector3;
761+
begin
762+
CameraViewpointForWholeScene(Scene.BoundingBox, WantedDirection, WantedUp,
763+
WantedDirectionPositive, WantedUpPositive,
764+
Position, Direction, Up, GravityUp);
765+
MainViewport.Camera.AnimateTo(Position, Direction, Up, CameraTransitionTime);
766+
MainViewport.Camera.GravityUp := GravityUp;
767+
end;
768+
769+
procedure SetViewpointTop;
770+
begin
771+
SetViewpointForWholeScene(1, 2, false, false);
772+
end;
773+
774+
procedure SetViewpointBottom;
775+
begin
776+
SetViewpointForWholeScene(1, 2, true , false);
777+
end;
778+
779+
procedure SetViewpointFront;
780+
begin
781+
SetViewpointForWholeScene(2, 1, false, true);
782+
end;
783+
784+
procedure SetViewpointBack;
785+
begin
786+
SetViewpointForWholeScene(2, 1, true , true);
787+
end;
788+
789+
procedure SetViewpointRight;
790+
begin
791+
SetViewpointForWholeScene(0, 1, false, true);
792+
end;
793+
794+
procedure SetViewpointLeft;
795+
begin
796+
SetViewpointForWholeScene(0, 1, true , true);
797+
end;
798+
756799
procedure Press(Container: TCastleContainer; const Event: TInputPressRelease);
757800
begin
801+
{ Although some of these shortcuts are also assigned to menu items,
802+
catching them here is more reliable -- allows to handle also Ctrl+number
803+
combinations, and capture both numpad and non-numpad versions. }
804+
if Event.IsKey(key7) or Event.IsKey(keyNumPad7) then
805+
begin
806+
if Event.ModifiersDown = [] then
807+
SetViewpointTop
808+
else
809+
if Event.ModifiersDown = [mkCtrl] then
810+
SetViewpointBottom;
811+
end;
812+
if Event.IsKey(key1) or Event.IsKey(keyNumPad1) then
813+
begin
814+
if Event.ModifiersDown = [] then
815+
SetViewpointFront
816+
else
817+
if Event.ModifiersDown = [mkCtrl] then
818+
SetViewpointBack;
819+
end;
820+
if Event.IsKey(key3) or Event.IsKey(keyNumPad3) then
821+
begin
822+
if Event.ModifiersDown = [] then
823+
SetViewpointRight
824+
else
825+
if Event.ModifiersDown = [mkCtrl] then
826+
SetViewpointLeft;
827+
end;
828+
758829
{ Support selecting item by ctrl + right button click. }
759830
if Event.IsMouseButton(buttonRight) and (mkCtrl in Window.Pressed.Modifiers) then
760831
begin
@@ -2001,19 +2072,6 @@ procedure MenuClick(Container: TCastleContainer; MenuItem: TMenuItem);
20012072
RenderContext.GlobalAmbient := C;
20022073
end;
20032074

2004-
procedure SetViewpointForWholeScene(
2005-
const WantedDirection, WantedUp: Integer;
2006-
const WantedDirectionPositive, WantedUpPositive: boolean);
2007-
var
2008-
Position, Direction, Up, GravityUp: TVector3;
2009-
begin
2010-
CameraViewpointForWholeScene(Scene.BoundingBox, WantedDirection, WantedUp,
2011-
WantedDirectionPositive, WantedUpPositive,
2012-
Position, Direction, Up, GravityUp);
2013-
MainViewport.Camera.AnimateTo(Position, Direction, Up, CameraTransitionTime);
2014-
MainViewport.Camera.GravityUp := GravityUp;
2015-
end;
2016-
20172075
procedure RemoveNodesWithMatchingName;
20182076
var
20192077
Wildcard: string;
@@ -2864,15 +2922,12 @@ procedure MenuClick(Container: TCastleContainer; MenuItem: TMenuItem);
28642922
MainViewport.Camera.GravityUp := DefaultX3DGravityUp;
28652923
end;
28662924

2867-
53: SetViewpointForWholeScene(2, 1, false, true);
2868-
54: SetViewpointForWholeScene(2, 1, true , true);
2869-
55: SetViewpointForWholeScene(0, 1, false, true);
2870-
56: SetViewpointForWholeScene(0, 1, true , true);
2871-
2872-
57: SetViewpointForWholeScene(0, 2, false, true);
2873-
58: SetViewpointForWholeScene(0, 2, true , true);
2874-
59: SetViewpointForWholeScene(1, 2, false, true);
2875-
60: SetViewpointForWholeScene(1, 2, true , true);
2925+
53: SetViewpointTop;
2926+
54: SetViewpointBottom;
2927+
57: SetViewpointFront;
2928+
58: SetViewpointBack;
2929+
59: SetViewpointRight;
2930+
60: SetViewpointLeft;
28762931

28772932
65: Viewpoints.Initial(MainViewport);
28782933
66: Viewpoints.Previous(MainViewport);

0 commit comments

Comments
 (0)