Debian Codegraph @

examples/lazarus/load_model_and_camera_manually/mainf.pas

raw
1 {
2 Copyright 2014-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
16 { Main form. }
17 unit mainf;
18
19 {$mode objfpc}{$H+}
20
21 interface
22
23 uses
24 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
25 CastleControl, CastleCameras, CastleScene, CastleViewport;
26
27 type
28 TMainForm = class(TForm)
29 Control1: TCastleControl;
30 Label1: TLabel;
31 procedure FormCreate(Sender: TObject);
32 private
33 Viewport: TCastleViewport;
34 WalkNavigation: TCastleWalkNavigation;
35 Background: TCastleBackground;
36 Scene: TCastleScene;
37 public
38 { public declarations }
39 end;
40
41 var
42 MainForm: TMainForm;
43
44 implementation
45
46 {$R *.lfm}
47
48 uses CastleVectors, CastleColors;
49
50 procedure TMainForm.FormCreate(Sender: TObject);
51 begin
52 Viewport := TCastleViewport.Create(Self);
53 Viewport.FullSize := true;
54 Control1.Controls.InsertFront(Viewport);
55
56 Scene := TCastleScene.Create(Self);
57 Scene.Load('castle-data:/bridge_level/bridge_final.x3dv');
58 Scene.PreciseCollisions := true;
59
60 Viewport.Items.Add(Scene);
61
62 WalkNavigation := TCastleWalkNavigation.Create(Self);
63 WalkNavigation.PreferredHeight := 2;
64 WalkNavigation.Radius := 0.1;
65 WalkNavigation.MoveSpeed := 10.0; // default is 1
66 WalkNavigation.Gravity := true;
67 Viewport.InsertFront(WalkNavigation);
68
69 // Set camera vectors using Castle Game Engine.
70 Viewport.Camera.SetWorldView(
71 Vector3(-46.30, -4.49, 4.89), // position
72 Vector3(0.96, 0.03, -0.27), // direction
73 Vector3(-0.03, 1.00, 0.01) // up (current)
74 );
75 Viewport.Camera.ProjectionNear := WalkNavigation.Radius / 2;
76
77 Background := TCastleBackground.Create(Self);
78 Background.SkyTopColor := RedRGB;
79 Viewport.Background := Background;
80 end;
81
82 end.