Debian Codegraph @

examples/animations/animate_transform_by_code/code/gameviewmain.pas

raw
1 {
2 Copyright 2020-2023 Michalis Kamburelis.
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 { Main view, where most of the application logic takes place. }
16 unit GameViewMain;
17
18 interface
19
20 uses Classes,
21 CastleVectors, CastleComponentSerialize,
22 CastleUIControls, CastleControls, CastleKeysMouse, CastleScene, CastleTimeUtils,
23 X3DNodes;
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 MainScene: TCastleScene;
33 private
34 Time: TFloatTime;
35 TransformBox2: TTransformNode;
36 TransformBox3: TTransformNode;
37 TransformBox4: TTransformNode;
38 public
39 constructor Create(AOwner: TComponent); override;
40 procedure Start; override;
41 procedure Update(const SecondsPassed: Single; var HandleInput: Boolean); override;
42 end;
43
44 var
45 ViewMain: TViewMain;
46
47 implementation
48
49 uses SysUtils;
50
51 { TViewMain ----------------------------------------------------------------- }
52
53 constructor TViewMain.Create(AOwner: TComponent);
54 begin
55 inherited;
56 DesignUrl := 'castle-data:/gameviewmain.castle-user-interface';
57 end;
58
59 procedure TViewMain.Start;
60 begin
61 inherited;
62 TransformBox2 := MainScene.Node(TTransformNode, 'Box2Transform') as TTransformNode;
63 TransformBox3 := MainScene.Node(TTransformNode, 'Box3Transform') as TTransformNode;
64 TransformBox4 := MainScene.Node(TTransformNode, 'Box4Transform') as TTransformNode;
65 end;
66
67 procedure TViewMain.Update(const SecondsPassed: Single; var HandleInput: Boolean);
68 begin
69 inherited;
70 { This virtual method is executed every frame (many times per second). }
71 LabelFps.Caption := 'FPS: ' + Container.Fps.ToString;
72
73 Time := Time + Container.Fps.SecondsPassed;
74
75 { Change rotation angles (4th component of the vector),
76 leaving the rotation axis (XYZ components) unchanged. }
77 TransformBox2.Rotation := Vector4(TransformBox2.Rotation.XYZ, Time);
78 TransformBox3.Rotation := Vector4(TransformBox2.Rotation.XYZ, Time * 2);
79 TransformBox4.Rotation := Vector4(TransformBox2.Rotation.XYZ, Time * 4);
80 end;
81
82 end.