Debian Codegraph @

examples/physics/physics_test_scale_colliders/code/gameviewmain.pas

raw
1 {
2 Copyright 2022-2023 Michalis Kamburelis, Andrzej Kilijański.
3
4 This file is part of "Castle Game Engine".
5
6 "Castle Game Engine" is free software; see the file COPYING.txt,
7 included in this distribution, for details about the copyright.
8
9 "Castle Game Engine" is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 ----------------------------------------------------------------------------
14 }
15
16 { Main view, where most of the application logic takes place. }
17 unit GameViewMain;
18
19 interface
20
21 uses Classes,
22 CastleVectors, CastleComponentSerialize,
23 CastleUIControls, CastleControls, CastleKeysMouse, CastleTransform, CastleViewport;
24
25 type
26 { Main view, where most of the application logic takes place. }
27 TViewMain = class(TCastleView)
28 published
29 { Components designed using CGE editor.
30 These fields will be automatically initialized at Start. }
31 LabelFps: TCastleLabel;
32 ButtonScaleRedBox: TCastleButton;
33 ButtonLocalScaleRedBoxCollider: TCastleButton;
34 ButtonScaleGreenSphere: TCastleButton;
35 ButtonScaleAll: TCastleButton;
36 RedBox: TCastleTransform;
37 GreenSphere: TCastleTransform;
38 TransformAll: TCastleTransform;
39 Viewport: TCastleViewport;
40 private
41 procedure ClickScaleAll(Sender: TObject);
42 procedure ClickScaleGreenSphere(Sender: TObject);
43 procedure ClickScaleRedBox(Sender: TObject);
44 procedure ClickLocalScaleRedBoxCollider(Sender: TObject);
45 public
46 constructor Create(AOwner: TComponent); override;
47 procedure Start; override;
48 procedure Update(const SecondsPassed: Single; var HandleInput: Boolean); override;
49 function Press(const Event: TInputPressRelease): Boolean; override;
50 end;
51
52 var
53 ViewMain: TViewMain;
54
55 implementation
56
57 uses SysUtils;
58
59 { TViewMain ----------------------------------------------------------------- }
60
61 procedure TViewMain.ClickScaleAll(Sender: TObject);
62 begin
63 //TransformAll.Scale := Vector3(0.5, 0.5, 0.5);
64 TransformAll.Scale := Vector3(1.5, 1.5, 1.5);
65 end;
66
67 procedure TViewMain.ClickScaleGreenSphere(Sender: TObject);
68 begin
69 GreenSphere.Scale := Vector3(3,3,3);
70 end;
71
72 procedure TViewMain.ClickScaleRedBox(Sender: TObject);
73 begin
74 //RedBox.Scale := Vector3(0.9,0.3,0.4);
75 //RedBox.Scale := Vector3(3,3,3);
76 //RedBox.Scale := Vector3(0.6,0.3,0.3);
77 RedBox.Scale := Vector3(3,3,3);
78 //RedBox.Scale := Vector3(0.6,5.3,0.3);
79 end;
80
81 procedure TViewMain.ClickLocalScaleRedBoxCollider(Sender: TObject);
82 var
83 Collider: TCastleCollider;
84 begin
85 Collider := RedBox.FindBehavior(TCastleCollider) as TCastleCollider;
86 if Collider <> nil then
87 Collider.SizeScale := 0.5;
88 end;
89
90 constructor TViewMain.Create(AOwner: TComponent);
91 begin
92 inherited;
93 DesignUrl := 'castle-data:/gameviewmain.castle-user-interface';
94 end;
95
96 procedure TViewMain.Start;
97 begin
98 inherited;
99 ButtonScaleAll.OnClick := {$ifdef FPC}@{$endif}ClickScaleAll;
100 ButtonScaleGreenSphere.OnClick := {$ifdef FPC}@{$endif}ClickScaleGreenSphere;
101 ButtonScaleRedBox.OnClick := {$ifdef FPC}@{$endif}ClickScaleRedBox;
102 ButtonLocalScaleRedBoxCollider.OnClick := {$ifdef FPC}@{$endif}ClickLocalScaleRedBoxCollider;
103 end;
104
105 procedure TViewMain.Update(const SecondsPassed: Single; var HandleInput: Boolean);
106 begin
107 inherited;
108 { This virtual method is executed every frame (many times per second). }
109 LabelFps.Caption := 'FPS: ' + Container.Fps.ToString;
110 end;
111
112 function TViewMain.Press(const Event: TInputPressRelease): Boolean;
113 begin
114 Result := inherited;
115 if Result then Exit; // allow the ancestor to handle keys
116
117 { This virtual method is executed when user presses
118 a key, a mouse button, or touches a touch-screen.
119
120 Note that each UI control has also events like OnPress and OnClick.
121 These events can be used to handle the "press", if it should do something
122 specific when used in that UI control.
123 The TViewMain.Press method should be used to handle keys
124 not handled in children controls.
125 }
126
127 // Use this to handle keys:
128 {
129 if Event.IsKey(keyXxx) then
130 begin
131 // DoSomething;
132 Exit(true); // key was handled
133 end;
134 }
135 end;
136
137 end.