Debian Codegraph @

examples/viewport_and_scenes/bump_mapping/code/gameviewmain.pas

raw
1 {
2 Copyright 2017-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. }
16 unit GameViewMain;
17
18 interface
19
20 uses Classes,
21 CastleVectors, CastleUIControls, CastleControls, CastleKeysMouse,
22 CastleScene, CastleTimeUtils;
23
24 type
25 TViewMain = class(TCastleView)
26 published
27 { Components designed using CGE editor.
28 These fields will be automatically initialized at Start. }
29 LabelFps: TCastleLabel;
30 MainLight: TCastlePointLight;
31 private
32 Time: TFloatTime;
33 procedure UpdateMainLightLocation;
34 public
35 constructor Create(AOwner: TComponent); override;
36 procedure Start; override;
37 procedure Update(const SecondsPassed: Single; var HandleInput: Boolean); override;
38 end;
39
40 var
41 ViewMain: TViewMain;
42
43 implementation
44
45 uses Math,
46 CastleUtils { Delphi needs this to define Float };
47
48 constructor TViewMain.Create(AOwner: TComponent);
49 begin
50 inherited;
51 DesignUrl := 'castle-data:/gameviewmain.castle-user-interface';
52 end;
53
54 procedure TViewMain.Start;
55 begin
56 inherited;
57 Time := 0;
58 UpdateMainLightLocation;
59 end;
60
61 procedure TViewMain.UpdateMainLightLocation;
62 const
63 Radius = 2;
64 var
65 S, C: Float;
66 begin
67 SinCos(Time * 2, S, C);
68 MainLight.Translation := Vector3(S * Radius, C * Radius + 1, 2);
69 end;
70
71 procedure TViewMain.Update(const SecondsPassed: Single; var HandleInput: Boolean);
72 begin
73 inherited;
74 { This virtual method is executed every frame (many times per second). }
75 LabelFps.Caption := 'FPS: ' + Container.Fps.ToString;
76
77 Time := Time + Container.Fps.SecondsPassed;
78 UpdateMainLightLocation;
79 end;
80
81 end.