J'ai tenté de faire une reprise du cube en combinant une partie de ton code et du mien pour me faire une machine à gaz qui me gère toutes les translations et rotations...

Je suis arrivé à ça :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
 
 
program Project1;
 
{$FRAME_WIDTH 1000}
{$FRAME_HEIGHT 600}
{$FRAME_RATE 25}
{$BACKGROUND $FFFFFF}
 
uses
  Flash8;
 
Type
 TMatrice = class
  procedure Produitmatriciel;
  procedure Translate(tx, ty, tz: number);
  procedure RotateX(ax: number);
  procedure RotateY(ay: number);
  procedure RotateZ(az: number);
  Constructor Create;
 end;
 
 TPoint3D = class
  x,y,z:number;
  Function Transform2d(P:TPoint3D):Point;
  procedure Transform;
  Constructor Create(xv,yv,zv:number);
 end;
 
 TFace=class(Movieclip)
  zorder:integer;
  size:number;
  p: array[1..5] of TPoint3D;
  procedure build(Rx,Ry:number);
  procedure Tracer(penw:integer;ColorFill:integer);
  constructor Create (parent:Movieclip;Depth,asize:integer);
  procedure position;
 end;
 
 TCube=class(Movieclip)
  Face:array[1..5] of TFace;
  procedure Reset;
  constructor Create(parent:Movieclip;Depth:integer);
  procedure onEnterFrame;override;
 end;
 
const carre:array[1..5,1..3]of double=((-100,-100,0),(100,-100,0),(100,100,0),(-100,100,0),(0,0,0));
      pi=3.141592654;
 
 
var  matrice:TMatrice;
     Values,Mi,V,id: array[0..3,0..3] of number;
 
Constructor TPoint3D.Create(xv,yv,zv:number);
begin
 x:=xv;
 y:=yv;
 z:=zv;
end;
 
procedure TPoint3D.Transform;
var x1,y1,z1:number;
begin
  x1 := x * Values[0,0] + y * Values[0,1] +z * Values[ 0,2] + Values[0,3];
  y1 := x * Values[1,0] + y * Values[1,1] +z * Values[ 1,2] + Values[1,3];
  z1 := x * Values[2,0] + y * Values[2,1] +z * Values[2,2]  + Values[2,3];
  x:=x1;
  y:=y1;
  z:=z1;
end;
 
Function TPoint3D.Transform2d(P:TPoint3D):Point;
begin
  result:=Point.Create(128 * P.x / (128 + P.z / 4),128 * P.y / (128 + P.z / 4));
end;
 
Constructor TMatrice.Create;
var  i,j: Integer;
begin
 id[0, 0] :=  1;    id[1, 0] :=  0;    id[2, 0] :=  0;    id[3, 0] :=  0;   //matrice identité
 id[0, 1] :=  0;    id[1, 1] :=  1;    id[2, 1] :=  0;    id[3, 1] :=  0;
 id[0, 2] :=  0;    id[1, 2] :=  0;    id[2, 2] :=  1;    id[3, 2] :=  0;
 id[0, 3] :=  0;    id[1, 3] :=  0;    id[2, 3] :=  0;    id[3, 3] :=  1;
 
 for i := 0 to 3 do   //initialisation des matrices à identité
   for j:=0 to 3 do
   begin
    Values[i,j] :=id[i,j];
    Mi[i,j]:=id[i,j];
   end;
end;
 
Procedure TMatrice.Produitmatriciel;
var
  i,j,k: Integer;
  p:number;
begin
 for i:=0 to 3 do
  for j := 0 to 3 do
  begin
    p := 0;
    for k := 0 to 3 do p := p + Mi[i, k] * values[k, j];
    V[i,j] := p;
  end;
 
 for i := 0 to 3 do
  for j := 0 to 3 do
   Values[i,j] := V[i,j];
end;
 
procedure TMatrice.Translate(tx, ty, tz: number);
begin
  Mi[0, 0] :=  1;    Mi[1, 0] :=  0;    Mi[2, 0] :=  0;    Mi[3, 0] :=  0;
  Mi[0, 1] :=  0;    Mi[1, 1] :=  1;    Mi[2, 1] :=  0;    Mi[3, 1] :=  0;
  Mi[0, 2] :=  0;    Mi[1, 2] :=  0;    Mi[2, 2] :=  1;    Mi[3, 2] :=  0;
  Mi[0, 3] :=  tx;   Mi[1, 3] :=  ty;   Mi[2, 3] :=  tz;   Mi[3, 3] :=  1;
  Produitmatriciel;
 
  //réinitialisation de Mi à matrice identité
  Mi[0, 3] :=  0;
  Mi[1, 3] :=  0;
  Mi[2, 3] :=  0;
end;
 
Procedure TMatrice.RotateX(ax: number);
var cax,sax:number;
begin
 if ax<>0 then
 begin
  cax:=cos(ax);
  sax:=sin(ax);
 
  Mi[0, 0] :=  1;     Mi[1, 0] :=  0;      Mi[2, 0] :=  0;      Mi[3, 0] :=  0;
  Mi[0, 1] :=  0;     Mi[1, 1] :=  cax;    Mi[2, 1] :=  -sax;   Mi[3, 1] :=  0;
  Mi[0, 2] :=  0;     Mi[1, 2] :=  sax;    Mi[2, 2] :=  cax;    Mi[3, 2] :=  0;
  Mi[0, 3] :=  0;     Mi[1, 3] :=  0;      Mi[2, 3] :=  0;      Mi[3, 3] :=  1;
  Produitmatriciel;
 
  //réinitialisation de Mi à matrice identité
  Mi[1, 1] :=  1;
  Mi[1, 2] :=  0;
  Mi[2, 1] :=  0;
  Mi[2, 2] :=  1;
 end;
end;
 
Procedure TMatrice.RotateY(ay: number);
var cay,say:number;
begin
 if ay<>0 then
 begin
  cay:=cos(ay);
  say:=sin(ay);
 
  Mi[0, 0] :=  cay;     Mi[1, 0] :=  0;     Mi[2, 0] :=  -say;  Mi[3, 0] :=  0;
  Mi[0, 1] :=  0;       Mi[1, 1] :=  1;     Mi[2, 1] :=  0;     Mi[3, 1] :=  0;
  Mi[0, 2] :=  say;     Mi[1, 2] :=  0;     Mi[2, 2] :=  cay;   Mi[3, 2] :=  0;
  Mi[0, 3] :=  0;       Mi[1, 3] :=  0;     Mi[2, 3] :=  0;     Mi[3, 3] :=  1;
  Produitmatriciel;
 
  //réinitialisation de Mi à matrice identité
  Mi[0, 0] :=  1;
  Mi[0, 2] :=  0;
  Mi[2, 0] :=  0;
  Mi[2, 2] :=  1;
 end;
end;
 
Procedure TMatrice.RotateZ(az: number);
var caz,saz:number;
begin
 if az<> 0 then
 begin
  caz:=cos(az);
  saz:=sin(az);
 
  Mi[0, 0] :=  caz;       Mi[1, 0] :=  -saz;    Mi[2, 0] :=  0;   Mi[3, 0] :=  0;
  Mi[0, 1] :=  saz;       Mi[1, 1] :=  caz;     Mi[2, 1] :=  0;   Mi[3, 1] :=  0;
  Mi[0, 2] :=  0;         Mi[1, 2] :=  0;       Mi[2, 2] :=  1;   Mi[3, 2] :=  0;
  Mi[0, 3] :=  0;         Mi[1, 3] :=  0;       Mi[2, 3] :=  0;   Mi[3, 3] :=  1;
  Produitmatriciel;
 
  //réinitialisation de Mi à matrice identité
  Mi[0, 0] :=  1;
  Mi[0, 1] :=  0;
  Mi[1, 0] :=  0;
  Mi[1, 1] :=  1;
 end;
end;
 
constructor TFace.Create (parent:Movieclip;Depth,asize:integer);
begin
  inherited Create(Parent, 'face' + IntToStr(Depth),Depth);
  Matrice:=TMatrice.Create;
  size:=asize;
  zorder:=Depth;
end;
 
procedure TFace.build(Rx,Ry:number);
var i:integer;
begin
  Matrice.Translate(0, 0,-size/2);
  Matrice.RotateX(Rx);
  Matrice.RotateY(Ry);
 
 for i:=1 to 4 do
 begin
  P[i]:=TPoint3D.Create(carre[i,1],carre[i,2],carre[i,3]);
  P[i].transform;
 end;
  P[5]:=TPoint3D.Create(0,0,-size/2);
end;
 
procedure TFace.Tracer(penw:integer;ColorFill:integer);
var i:integer;
begin
 clear;
 Linestyle(penw,clBlack);
 BeginFill(colorFill);
 moveto(P[1].Transform2D(P[1]).x,P[1].Transform2D(P[1]).y);
 for i:=2 to 4 do lineto(P[i].Transform2D(P[i]).x,P[i].Transform2D(P[i]).y);
 Lineto(P[1].Transform2D(P[1]).x,P[1].Transform2D(P[1]).y);
 p[5].Transform;
 //swapDepths(Zorder-Trunc(P[5].z)*6);
 swapDepths(-P[5].z);
end;
 
 
procedure TFace.position;
var i:integer;
begin
 for i:=1 to 4 do P[i].Transform;
end;
 
 
 
constructor TCube.Create(parent:Movieclip;Depth:integer);
var i,j:integer;
begin
  inherited Create(Parent, 'cube' + IntToStr(Depth),Depth);
  Face[1]:=TFace.Create(self,1,200);
  with Face[1] do
  begin
   build(0,0);
   Tracer(3,clred);
  end;
 
  Face[2]:=TFace.Create(self,2,200);
  with Face[2] do
  begin
   build(0,pi/2);
   Tracer(3,clblue);
   end;
 
  Face[3]:=TFace.Create(self,3,200);
  with Face[3] do
  begin
   build(0,pi);
   Tracer(3,clgreen);
  end;
 
  Face[4]:=TFace.Create(self,4,200);
  with Face[4] do
  begin
   build(0,3*pi/2);
   Tracer(3,claqua);
  end;
 
  Face[5]:=TFace.Create(self,5,200);
  with Face[5] do
  begin
   build(pi/2,0);
   Tracer(3,clyellow);
  end;
 
  Face[6]:=TFace.Create(self,6,200);
  with Face[6] do
  begin
   build(-pi/2,0);
   Tracer(3,$ff00ff);
  end;
 
  //_x:=stage.width/2;
  _y:=stage.height/2;
 
  Reset;
end;
 
procedure TCube.Reset;
var
  i,j: Integer;
begin
  for i := 0 to 3 do
   for j:=0 to 3 do
    Values[i,j] := id[i,j];
end;
 
procedure TCube.onEnterFrame;
begin
 //Matrice.rotatex(pi/180);
 //Matrice.rotateY(pi/180);
 //Matrice.rotateZ(pi/180);
 //Matrice.translate(0,0,5);
 //Matrice.translate(0,5,0);   //en y, l'axe est vertical vers le bas (normal, si z est rentrant (ijk) trièdre direct et y vers le bas).
   Matrice.translate(5,0,0);
 
 Face[1].position;
 Face[1].tracer(3,clred);
 
 
 Face[2].position;
 Face[2].tracer(3,clblue);
 
 
 Face[3].position;
 Face[3].tracer(3,clgreen);
 
 
 Face[4].position;
 Face[4].tracer(3,claqua);
 
 
 Face[5].position;
 Face[5].tracer(3,clyellow);
 
 
 Face[6].position;
 Face[6].tracer(3,$ff00ff);
 
 Reset;
end;
 
begin
 TCube.Create(_Root,0);
end.
J'ai mis volontairement un simple déplacement en x et je m'aperçois que j'ai des soucis avec la gestion de la priorités des faces...

De plus, on constate que la routine qui gère le passage 3D2D a ses limites...
(voir profondeur du cube lorsqu'il s'éloigne...)

Il va falloir approfondir les connaissances en infographie pour gérer efficacement la profondeur...

As-tu des solutions pour ces deux points ?