Skip to content

Commit 6cf5174

Browse files
committed
Corrections et améliorations diverses
- amélioration du TGBEJoystick; - les mouvements des TGBEClouds et TGBEPlaneExtend peuvent être réalisés via TTask; - amélioration du TGBEPlayerPosition pour détection des collisions; - modification uGBEUtils3D pour la détection des collisions et réactivité avec interaction composants 2D; - adaptation de la démo JoystickPlayer.
1 parent 8454e80 commit 6cf5174

File tree

14 files changed

+172
-66
lines changed

14 files changed

+172
-66
lines changed

GBEClouds.pas

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ interface
44

55
uses
66
System.SysUtils, System.Classes, FMX.Types, FMX.Types3D, FMX.Controls3D, FMX.Objects3D, Generics.Collections,
7-
System.Math.Vectors, FMX.MaterialSources;
7+
System.Math.Vectors, FMX.MaterialSources, System.Threading;
88

99
type
1010
TGBEClouds = class(TDummy)
@@ -13,7 +13,7 @@ TGBEClouds = class(TDummy)
1313
fListClouds : TList<TPlane>;
1414
fNbClouds, fLimits : integer;
1515
fWindSpeed : single;
16-
fActiveWind : boolean;
16+
fActiveWind, fUseTasks : boolean;
1717
fTexturesClouds: TList<TTextureMaterialSource>;
1818
function getNbClouds: integer;
1919
function getWindSpeed: single;
@@ -23,6 +23,7 @@ TGBEClouds = class(TDummy)
2323
procedure setLimits(const Value: integer);
2424
function getActiveWind: boolean;
2525
procedure setActiveWind(const Value: boolean);
26+
procedure deplacementNuages;
2627
protected
2728
{ Déclarations protégées }
2829
public
@@ -40,6 +41,7 @@ TGBEClouds = class(TDummy)
4041
property Limits : integer read getLimits write setLimits;
4142
property NbClouds : integer read getNbClouds write setNbClouds;
4243
property WindSpeed : single read getWindSpeed write setWindSpeed;
44+
property UseTasks : boolean read fUseTasks write fUseTasks;
4345
end;
4446

4547
procedure Register;
@@ -68,6 +70,7 @@ constructor TGBEClouds.Create(AOwner: TComponent);
6870
fActiveWind := false;
6971
fListClouds := TList<TPlane>.Create;
7072
fTexturesClouds := TList<TTextureMaterialSource>.create;
73+
fUseTasks := true;
7174
end;
7275

7376
procedure TGBEClouds.deleteTexturesClouds;
@@ -105,24 +108,39 @@ function TGBEClouds.getWindSpeed: single;
105108
end;
106109

107110
procedure TGBEClouds.moveClouds;
111+
begin
112+
if (fActiveWind) and (NbClouds > 0) then
113+
begin
114+
if fUseTasks then
115+
begin
116+
TTask.Create(procedure
117+
begin
118+
deplacementNuages;
119+
end).start;
120+
end
121+
else
122+
begin
123+
deplacementNuages;
124+
end;
125+
end;
126+
end;
127+
128+
procedure TGBEClouds.deplacementNuages;
108129
var
109130
s:TPlane;
110131
P:TFmxObject; // Va servir d'itérateur pour parcourir tous les objets enfants du dmyNuages
111132
begin
112-
if fActiveWind then
133+
for P in self.Children do // Parcours des objets enfants du dmyNuages
113134
begin
114-
for P in self.Children do // Parcours des objets enfants du dmyNuages
135+
if P is TPlane then // Si l'objet est un TPlane
115136
begin
116-
if P is TPlane then // Si l'objet est un TPlane
137+
s := TPlane(P); // On va travailler sur ce TPlane
138+
s.position.x := s.position.x + fWindSpeed / ( s.Position.z);
139+
if (s.position.x > fLimits) or
140+
(s.Position.X < -fLimits) then // Si la position en X du nuage > 1000, alors on repositionne le nuage à la position x = -1000 et Y et Z valeurs aléatoires
117141
begin
118-
s := TPlane(P); // On va travailler sur ce TPlane
119-
s.position.x := s.position.x + fWindSpeed / ( s.Position.z);
120-
if (s.position.x > fLimits) or
121-
(s.Position.X < -fLimits) then // Si la position en X du nuage > 1000, alors on repositionne le nuage à la position x = -1000 et Y et Z valeurs aléatoires
122-
begin
123-
s.Position.point := Point3D(-fLimits, random-0.5, random*fLimits * (0.5-random));
124-
s.Opacity := random;
125-
end;
142+
s.Position.point := Point3D(-fLimits, random-0.5, random*fLimits * (0.5-random));
143+
s.Opacity := random;
126144
end;
127145
end;
128146
end;
@@ -184,6 +202,7 @@ procedure TGBEClouds.generateClouds;
184202
s.Opaque := false;
185203
s.ZWrite := false; // pour éviter que le rectangle "cadre" du TPlane soit visible => mais du coup la profondeur n'est plus gérée : le Soleil passe devant les nuages...
186204
s.HitTest := false; // pour ne pas pouvoir cliquer dessus
205+
s.tag := self.Tag;
187206
s.Position.Point:=Point3D(random*fLimits * (0.5-random), random - 0.5, random*fLimits * (0.5-random)); // On positionne le nuage arbitrairement et aléatoirement partout au dessus de notre monde
188207
s.RotationAngle.Z := random * 360; // Orientation aléatoire du nuage
189208
end;

GBEJoystick.pas

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ interface
44

55
uses
66
System.SysUtils, System.Classes, FMX.Types, FMX.Controls, FMX.Layouts, GBEPlayerPosition, System.Math.Vectors, system.types,
7-
FMX.Viewport3D, System.UITypes, FMX.Dialogs, FMX.Objects, FMX.Graphics, FMX.Ani;
7+
FMX.Viewport3D, System.UITypes, FMX.Dialogs, FMX.Objects, FMX.Graphics, FMX.Ani, uGBEUtils3D;
88

99
type
1010
TGBEJoystickType = (jtOrientation, jtDeplacement);
@@ -166,13 +166,17 @@ procedure TGBEJoystick.DoMouseLeave;
166166
procedure TGBEJoystick.MouseMove(Shift: TShiftState; X, Y: Single);
167167
begin
168168
inherited;
169+
169170
if ssLeft in shift then
170171
begin
171-
if fJoystickType = jtOrientation then angleDeVue := PointF(X,Y);
172-
if fJoystickType = jtDeplacement then fPosDepartCurseur := PointF(X,Y);
172+
if (Viewport3D <> nil) and (PlayerPosition <> nil) then
173+
begin
174+
if fJoystickType = jtOrientation then angleDeVue := PointF(X,Y);
173175

174-
fCircle2.Position.X := x - offset.x;
175-
fCircle2.Position.y := Y - offset.y;
176+
fCircle2.Position.X := x - offset.x;
177+
fCircle2.Position.y := Y - offset.y;
178+
interactionIHM(Viewport3D);
179+
end;
176180
end;
177181
end;
178182

@@ -191,8 +195,11 @@ procedure TGBEJoystick.Paint;
191195
begin
192196
if fJoystickType = jtDeplacement then
193197
begin
194-
fAcceleration := ( fPosDepartCurseur.Y - self.height/2) / (sensitivity * 10000);
195-
fPlayerPosition.RotationAngle.Y := fPlayerPosition.RotationAngle.Y + (fPosDepartCurseur.x - self.Width /2)/(sensitivity * 5);
198+
if assigned(fPlayerPosition) then
199+
begin
200+
FAcceleration := FAcceleration + ((fCircle.Height - fCircle2.Height)*0.5 + fCircle2.position.Y) / Sensitivity;
201+
fPlayerPosition.RotationAngle.Y := fPlayerPosition.RotationAngle.Y - ((fCircle.Width - fCircle2.Width)*0.5 - fCircle2.Position.X) / Sensitivity;
202+
end;
196203
end;
197204
end;
198205
end;
@@ -202,8 +209,8 @@ procedure TGBEJoystick.Resize;
202209
inherited;
203210
fCircle2.width := fCircle.Width -20;
204211
fCircle2.height := fCircle.height -20;
205-
fCircle2.position.X := (fCircle.Width - fCircle2.Width)/2 ;
206-
fCircle2.position.Y := (fCircle.Height - fCircle2.Height)/2;
212+
fCircle2.position.X := (fCircle.Width - fCircle2.Width)*0.5;
213+
fCircle2.position.Y := (fCircle.Height - fCircle2.Height)*0.5;
207214
end;
208215

209216
procedure TGBEJoystick.setJoystickType(const Value: TGBEJoystickType);

GBEPlaneExtend.pas

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ TGBEPlaneExtend = class(TPlane)
1717
fTime, fAmplitude, fLongueur, fVitesse : single;
1818
fOrigine, fCenter : TPoint3D;
1919
fNbMesh : integer;
20-
fActiveWaves, fShowlines : boolean;
20+
fActiveWaves, fShowlines, fUseTasks : boolean;
2121
fMaterialLignes: TColorMaterialSource;
2222
{ Déclarations privées }
2323
procedure CalcWaves(D : TPoint3D);
@@ -36,6 +36,7 @@ TGBEPlaneExtend = class(TPlane)
3636
property Longueur : single read fLongueur write fLongueur;
3737
property Vitesse : single read fVitesse write fVitesse;
3838
property ShowLines: boolean read fShowlines write fShowLines;
39+
property UseTasks : boolean read fUseTasks write fUseTasks;
3940
property MaterialLines : TColorMaterialSource read fMaterialLignes write fMaterialLignes;
4041
end;
4142

@@ -97,6 +98,7 @@ constructor TGBEPlaneExtend.Create(AOwner: TComponent);
9798
fOrigine := Point3D(self.SubdivisionsWidth / self.Width, self.SubdivisionsHeight / self.Height, 2);
9899
fNbMesh:=(SubdivisionsWidth + 1) * (SubdivisionsHeight + 1);
99100
fCenter := Point3D(SubdivisionsWidth / self.Width, SubdivisionsHeight / self.Height, 0);
101+
fUseTasks := true;
100102
end;
101103

102104
destructor TGBEPlaneExtend.Destroy;
@@ -109,10 +111,17 @@ procedure TGBEPlaneExtend.Render;
109111
inherited;
110112
if fActiveWaves then
111113
begin
112-
TTask.Create( procedure
113-
begin
114-
CalcWaves(Point3D(fAmplitude, fLongueur, fVitesse));
115-
end).start;
114+
if fUseTasks then
115+
begin
116+
TTask.Create( procedure
117+
begin
118+
CalcWaves(Point3D(fAmplitude, fLongueur, fVitesse));
119+
end).start;
120+
end
121+
else
122+
begin
123+
CalcWaves(Point3D(fAmplitude, fLongueur, fVitesse));
124+
end;
116125
end;
117126
if ShowLines then
118127
Context.DrawLines(self.Data.VertexBuffer, self.Data.IndexBuffer, TMaterialSource.ValidMaterial(fMaterialLignes),1);

GBEPlayerPosition.pas

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@ TGBEPlayerPosition = class(TDummy)
1313
fDummyOrientation, fNextPosition, fPositionDirection : TDummy;
1414
fCamera : TCamera;
1515
fTypePosition : TGBETypePosition;
16+
fWidth: single;
17+
fDepth: single;
18+
fHeight: single;
1619
function getPositionCamera: TPoint3D;
1720
procedure setPositionCamera(const Value: TPoint3D);
1821
function getAngleOfView: single;
1922
procedure setAngleOfView(const Value: single);
2023
procedure setTypePosition(const Value: TGBETypePosition);
24+
procedure setWidth(const Value: single);
25+
procedure setDepth(const Value: single);
26+
procedure setHeight(const Value: single);
2127
protected
2228
{ Déclarations protégées }
2329
public
@@ -35,6 +41,9 @@ TGBEPlayerPosition = class(TDummy)
3541
property TypePosition : TGBETypePosition read fTypePosition write setTypePosition;
3642
property NextPosition : TDummy read fNextPosition write fNextPosition;
3743
property HitTest default False;
44+
property Width : single read fWidth write setWidth;
45+
property Height : single read fHeight write setHeight;
46+
property Depth : single read fDepth write setDepth;
3847
end;
3948

4049
procedure Register;
@@ -54,22 +63,31 @@ constructor TGBEPlayerPosition.Create(AOwner: TComponent);
5463
fDummyOrientation := TDummy.Create(self);
5564
fDummyOrientation.Locked := true;
5665
fDummyOrientation.Stored := false;
66+
fDummyOrientation.Width := self.Width;
67+
fDummyOrientation.height := self.height;
68+
fDummyOrientation.Depth := self.Depth;
5769
AddObject(fDummyOrientation);
5870
fCamera := TCamera.Create(self);
5971
fCamera.Parent := fDummyOrientation;
6072

6173
fNextPosition := TDummy.Create(self);
6274
fNextPosition.Locked := true;
6375
fNextPosition.Stored := false;
76+
fNextPosition.Width := self.Width;
77+
fNextPosition.height := self.height;
78+
fNextPosition.Depth := self.Depth;
6479

6580
fPositionDirection := TDummy.Create(self);
6681
fPositionDirection.Locked := true;
6782
fPositionDirection.Stored := false;
83+
fPositionDirection.Width := self.Width;
84+
fPositionDirection.height := self.height;
85+
fPositionDirection.Depth := self.Depth;
6886
fPositionDirection.Parent := fDummyOrientation;
6987

7088
fPositionDirection.position.X := 0;
7189
fPositionDirection.position.Y := 0;
72-
fPositionDirection.position.Z := -0.1;
90+
fPositionDirection.position.Z := -0.01;
7391

7492
fTypePosition := TGBETypePosition.thirdPerson;
7593
end;
@@ -110,6 +128,22 @@ procedure TGBEPlayerPosition.setAngleOfView(const Value: single);
110128
fCamera.AngleOfView := value;
111129
end;
112130

131+
procedure TGBEPlayerPosition.setDepth(const Value: single);
132+
begin
133+
fDepth := Value;
134+
fDummyOrientation.Depth := Value;
135+
fNextPosition.Depth := Value;
136+
fPositionDirection.Depth := Value;
137+
end;
138+
139+
procedure TGBEPlayerPosition.setHeight(const Value: single);
140+
begin
141+
fHeight := Value;
142+
fDummyOrientation.Height := Value;
143+
fNextPosition.Height := Value;
144+
fPositionDirection.Height := Value;
145+
end;
146+
113147
procedure TGBEPlayerPosition.setPositionCamera(const Value: TPoint3D);
114148
begin
115149
fCamera.Position.Point := value;
@@ -133,4 +167,12 @@ procedure TGBEPlayerPosition.setTypePosition(const Value: TGBETypePosition);
133167
end;
134168
end;
135169

170+
procedure TGBEPlayerPosition.setWidth(const Value: single);
171+
begin
172+
fWidth := Value;
173+
fDummyOrientation.Width := Value;
174+
fNextPosition.Width := Value;
175+
fPositionDirection.Width := Value;
176+
end;
177+
136178
end.

GBEViewport3D.pas

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ procedure TGBEViewport3D.Paint;
135135
begin
136136
for I := 0 to FMyRenderingList.Count -1 do
137137
begin
138-
if FMyRenderingList[i].Visible or
138+
if FMyRenderingList[i].Visible or (FMyRenderingList[i].Tag <> 2) or
139139
(not FMyRenderingList[i].Visible and (csDesigning in ComponentState)
140140
and not FMyRenderingList[i].Locked) then
141141
begin
@@ -173,7 +173,10 @@ procedure TGBEViewport3D.RebuildRenderingList;
173173
FMyRenderingList.Clear;
174174
for i := 0 to Children.Count-1 do
175175
begin
176-
if children[i] is TControl3D then FMyRenderingList.Add((children[i] as TControl3d));
176+
if children[i] is TControl3D then
177+
begin
178+
FMyRenderingList.Add((children[i] as TControl3d));
179+
end;
177180
end;
178181
end;
179182
end;

demos/Clouds/demo_clouds.res

58.1 KB
Binary file not shown.

demos/Cubemap/demo_cubemap.res

58.1 KB
Binary file not shown.

demos/GenererBruit/genererbruit.res

58.1 KB
Binary file not shown.

demos/Grass/demo_grass.res

58.1 KB
Binary file not shown.

demos/JoystickPlayer/Unit1.fmx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ object form1: Tform1
204204
JoystickType = jtDeplacement
205205
Viewport3D = GBEViewport
206206
ShowIntegrateJoystick = True
207-
Sensitivity = 30
207+
Sensitivity = 180
208208
object Image2: TImage
209209
MultiResBitmap = <
210210
item

demos/JoystickPlayer/Unit1.pas

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface
66
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
77
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
88
System.Math.Vectors, FMX.Controls3D, FMX.Objects3D, FMX.Viewport3D,
9-
GBEViewport3D, GBEHeightmap, uHeightmap, FMX.MaterialSources, FMX.Ani,
9+
GBEViewport3D, GBEHeightmap, FMX.MaterialSources, FMX.Ani,
1010
GBEPlayerPosition, GBEJoystick, FMX.Layouts, FMX.Controls.Presentation,
1111
FMX.StdCtrls, uGBEUtils3D, FMX.ListBox, FMX.Objects, FMX.Types3D;
1212

@@ -54,6 +54,7 @@ Tform1 = class(TForm)
5454

5555
const
5656
tailleJoueur = 0.7; // Taille du joueur pour la vue FirstPerson
57+
vitesseMax = 0.1; // Vitesse maxi de déplacement
5758

5859
var
5960
form1: Tform1;
@@ -72,23 +73,26 @@ procedure Tform1.ComboBox1Change(Sender: TObject);
7273

7374
procedure Tform1.FloatAnimation1Process(Sender: TObject);
7475
begin
75-
vitesse := vitesse + GBEJoystick2.Acceleration;
76-
77-
GBEPlayerPosition1.NextPosition.Position.point := GBEPlayerPosition1.Position.Point - GBEJoystick2.direction * vitesse;
78-
GBEPlayerPosition1.NextPosition.position.Y := GBEHeightmap1.GetHeight(GBEPlayerPosition1.Position.Point);
79-
80-
if GBEPlayerPosition1.TypePosition = TGBETypePosition.firstPerson then
81-
GBEPlayerPosition1.NextPosition.position.Y := GBEPlayerPosition1.NextPosition.position.Y + tailleJoueur;
82-
83-
// On controle que la prochaine position est dans l'aire de jeu
84-
if (GBEPlayerPosition1.NextPosition.position.Point.x < GBEHeightmap1.Depth*0.5) and
85-
(GBEPlayerPosition1.NextPosition.position.Point.x > -GBEHeightmap1.Depth*0.5) and
86-
(GBEPlayerPosition1.NextPosition.position.Point.z < GBEHeightmap1.width*0.5) and
87-
(GBEPlayerPosition1.NextPosition.position.Point.z > -GBEHeightmap1.Depth*0.5) then
88-
begin
89-
GBEPlayerPosition1.Position.point := GBEPlayerPosition1.NextPosition.position.Point; // Si c'est le cas, on peut affecter la position à la procahine calculée
90-
end
91-
else vitesse := 0; // sinon on ne déplace pas le joueur et on réinitialise sa vitesse de déplacement
76+
if GBEJoystick2.Acceleration = 0 then vitesse := 0
77+
else begin
78+
if abs(vitesse) <= vitesseMax then vitesse := vitesse + GBEJoystick2.Acceleration/5000;
79+
80+
GBEPlayerPosition1.NextPosition.Position.point := GBEPlayerPosition1.Position.Point - GBEJoystick2.direction * vitesse;
81+
GBEPlayerPosition1.NextPosition.position.Y := GBEHeightmap1.GetHeight(GBEPlayerPosition1.Position.Point);
82+
83+
if GBEPlayerPosition1.TypePosition = TGBETypePosition.firstPerson then
84+
GBEPlayerPosition1.NextPosition.position.Y := GBEPlayerPosition1.NextPosition.position.Y + tailleJoueur;
85+
86+
// On controle que la prochaine position est dans l'aire de jeu
87+
if (GBEPlayerPosition1.NextPosition.position.Point.x < GBEHeightmap1.Depth*0.5) and
88+
(GBEPlayerPosition1.NextPosition.position.Point.x > -GBEHeightmap1.Depth*0.5) and
89+
(GBEPlayerPosition1.NextPosition.position.Point.z < GBEHeightmap1.width*0.5) and
90+
(GBEPlayerPosition1.NextPosition.position.Point.z > -GBEHeightmap1.Depth*0.5) then
91+
begin
92+
GBEPlayerPosition1.Position.point := GBEPlayerPosition1.NextPosition.position.Point; // Si c'est le cas, on peut affecter la position à la procahine calculée
93+
end
94+
else vitesse := 0; // sinon on ne déplace pas le joueur et on réinitialise sa vitesse de déplacement
95+
end;
9296
end;
9397

9498
procedure Tform1.FormCreate(Sender: TObject);
58.1 KB
Binary file not shown.

demos/Water/demowater.res

58.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)