IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Flash Pascal Discussion :

Priorité des faces et 3D2D


Sujet :

Flash Pascal

  1. #1
    Membre chevronné
    Avatar de Archimède
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2005
    Messages
    1 644
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 644
    Points : 1 975
    Points
    1 975
    Par défaut Priorité des faces et 3D2D
    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 ?

  2. #2
    Expert éminent sénior
    Avatar de Paul TOTH
    Homme Profil pro
    Freelance
    Inscrit en
    Novembre 2002
    Messages
    8 964
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2002
    Messages : 8 964
    Points : 28 430
    Points
    28 430
    Par défaut
    Bon alors, voici quelques modifications

    1) utilisation d'un variable toint pour éviter de calculer 2 fois Transform2D pour chaque point

    2) ramener le point origine au milieu de l'écran pour éviter les déformations lors de la projection (utilisation d'une translation pour placer le cube à droite)

    3) je n'ai pas bien compris pourquoi, mais dans ce cas il faut utiliser -ZOrder, avec +ZOrder les faces sont mal ordonnées.

    c'est lié à l'ordre de définition des faces. En fait le but est d'avoir toujours un Depth unique. Dans le cas de ce cube 4 des faces ont le même Z, il faut donc définir leur priorité autrement. L'ordre de dessin c'est bleu, vert, aqua, jaune...et c'est bien dans cet ordre qu'elles se superposent. Si on inverse ZOrder

    hum...le problème c'est que si j'applique une rotation de telle sorte que l'ordre des faces n'est plus bon, je retrouve un défaut d'affichage

    va falloir que je revoie ma copie...il faudra gérer les faces cachées, c'est à dire que les faces arrières ne doivent pas être dessinées. Pour cela il faut que leur vecteur normal pointe vers l'arrière. Il suffit de lui appliquer la rotation de la matrice (transformation sans tenir compte de Values[i, 3]) et de regarder sa valeur Z.

    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
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
     
    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;
     t: Point;
    begin
     clear;
     Linestyle(penw,clBlack);
     BeginFill(colorFill);
     // éviter le double calcule de la transformation
     t := P[1].Transform2D(P[1]);
     moveto(t.x,t.y);
     for i:=2 to 4 do
       // peut se faire aussi avec un with
       with P[i].Transform2D(P[i]) do
        lineto(x, y);
     // on réutilise le premier calcul
     Lineto(t.x, t.y);
     p[5].Transform;
     swapDepths(-Trunc(P[5].z)*6 - ZOrder);
     //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;
     
      Reset;
     
      // ne pas déplacer le centre de la transformation
      // pour éviter une déformation de la vue 3d
      Matrice.RotateX(Math.PI/4);
      Matrice.Translate(-500,0,0);
      _x:=stage.width/2;
      _y:=stage.height/2;
     
    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.
    Developpez.com: Mes articles, forum FlashPascal
    Entreprise: Execute SARL
    Le Store Excute Store

  3. #3
    Membre chevronné
    Avatar de Archimède
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2005
    Messages
    1 644
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 644
    Points : 1 975
    Points
    1 975
    Par défaut
    Merci pour ta correction sur le recentrage et ton optimisation pertinente avec P[1] (je n'avais pas remarqué sur le coup...)

    C'est passionnant comme truc mais ce n'est pas simple...Il faut se faire la main... Reste à trouver un swapDepths qui tienne la route...

  4. #4
    Membre chevronné
    Avatar de Archimède
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2005
    Messages
    1 644
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 644
    Points : 1 975
    Points
    1 975
    Par défaut
    Un autre truc que je viens de voir... Inutile de refaire systématiquement les transformations sur matrice dans le onEnterFrame si elles se répètent à l'identique à chaque frame...

    Donc si même transformation à chaque fois, mettre à la fin du constructor create translate, rotate... et values sera fixée une fois pour toute...

    Retirer de même le Reset à la fin du onEnterFrame.
    Garder position et tracer...

    J'avais fait comme ça dans le but de changer mes transformations en cours d'animation avec des conditions dans le onEnterFrame.

  5. #5
    Expert éminent sénior
    Avatar de Paul TOTH
    Homme Profil pro
    Freelance
    Inscrit en
    Novembre 2002
    Messages
    8 964
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2002
    Messages : 8 964
    Points : 28 430
    Points
    28 430
    Par défaut
    oui et cette notation est surprenante P[1].Transform2D(P[1]) ... le paramètre ne sert pas à grand chose
    Developpez.com: Mes articles, forum FlashPascal
    Entreprise: Execute SARL
    Le Store Excute Store

  6. #6
    Membre chevronné
    Avatar de Archimède
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2005
    Messages
    1 644
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 644
    Points : 1 975
    Points
    1 975
    Par défaut
    Citation Envoyé par Paul TOTH Voir le message
    oui et cette notation est surprenante P[1].Transform2D(P[1]) ... le paramètre ne sert pas à grand chose
    En effet, c'est pour les sourds d'oreilles, au cas où ils n'auraient pas compris...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    Function TPoint3D.Transform2d:Point;
    begin
      result:=Point.Create(128 * x / (128 + z / 4),128 * y / (128 + z / 4));
    end;
    ça m'apprendra à ne pas regarder la classe à laquelle appartient ma fonction...

    Autant pour moi

    merci

  7. #7
    Membre chevronné
    Avatar de Archimède
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2005
    Messages
    1 644
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 644
    Points : 1 975
    Points
    1 975
    Par défaut
    // ne pas déplacer le centre de la transformation
    // pour éviter une déformation de la vue 3d
    Ce qui veut dire qu'il faut refaire toutes les transformations de matrices à l'inverse pour retrouver le repère initial ?

    J'ai tenté le coup, ça ne marche pas et puis un produit de matrices est en général non commutatif, ce n'est pas simple...

  8. #8
    Membre chevronné
    Avatar de Archimède
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2005
    Messages
    1 644
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 644
    Points : 1 975
    Points
    1 975
    Par défaut
    Dans Procedure TFace.Build, faire la modif :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
     P[5]:=TPoint3D.Create(0,0,-size/2);
    par :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
     P[5]:=TPoint3D.Create(0,0,0);
    il subit transform après...

    la preuve, si je fais une structure cubique à faces centrées :

    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
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
     
    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: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;
      procedure circle(O:Point;Radius:number);
     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;
         cube1,cube2,cube3:TCube;
     
    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:Point;
    begin
      result:=Point.Create(128 * x / (128 + z / 4),128 * y / (128 + 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,0);
    end;
     
    procedure TFace.Tracer(penw:integer;ColorFill:integer);
    var i:integer;
    begin
     clear;
     Linestyle(penw,clBlack);
     BeginFill(colorFill);
     Circle(P[1].Transform2D,60);
     Circle(P[2].Transform2D,60);
     Circle(P[3].Transform2D,60);
     Circle(P[4].Transform2D,60);
     p[5].Transform;
     swapDepths(Zorder-Trunc(P[5].z)*6);
    // swapDepths(-P[5].z);
     Circle(P[5].Transform2D,60);
     
    end;
     
     
    procedure TFace.position;
    var i:integer;
    begin
     for i:=1 to 4 do P[i].Transform;
    end;
     
    Procedure TFace.circle(O:Point;Radius:number);
    var a,b,R,cx,cy: number;
    begin
      R:=Radius;
      cx:=O.x;
      cy:=O.y;
      a:= R * 0.414213562;
      b:= R * 0.707106781;
      moveTo(Cx+R,Cy);
      CurveTo(Cx+ R, Cy+-a, Cx+b,Cy -b);
      CurveTo(Cx+ a,Cy-R,Cx,Cy -r);
      CurveTo(Cx-a,Cy -R,Cx-b,Cy -b);
      CurveTo(Cx-R, Cy-a,Cx-R,Cy);
      CurveTo(Cx-R,Cy+a,Cx-b,Cy+b);
      CurveTo(Cx-a,Cy +R,Cx,Cy+r);
      CurveTo(Cx+a,Cy +R,Cx+b,Cy+b);
      CurveTo(Cx+R,Cy+a,Cx+R,Cy);
    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,clgray);
      end;
     
      Face[2]:=TFace.Create(self,2,200);
      with Face[2] do
      begin
       build(0,pi/2);
       Tracer(3,clgray);
       end;
     
      Face[3]:=TFace.Create(self,3,200);
      with Face[3] do
      begin
       build(0,pi);
       Tracer(3,clgray);
      end;
     
      Face[4]:=TFace.Create(self,4,200);
      with Face[4] do
      begin
       build(0,3*pi/2);
       Tracer(3,clgray);
      end;
     
      Face[5]:=TFace.Create(self,5,200);
      with Face[5] do
      begin
       build(pi/2,0);
       Tracer(3,clgray);
      end;
     
      Face[6]:=TFace.Create(self,6,200);
      with Face[6] do
      begin
       build(-pi/2,0);
       Tracer(3,clgray);
      end;
     
      _x:=stage.width/2;
      _y:=stage.height/2;
     
      Reset;
     
     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);
     
    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
     
     
     Face[1].position;
     Face[1].tracer(3,clgray);
     
     
     Face[2].position;
     Face[2].tracer(3,clgray);
     
     
     Face[3].position;
     Face[3].tracer(3,clgray);
     
     
     Face[4].position;
     Face[4].tracer(3,clgray);
     
     
     Face[5].position;
     Face[5].tracer(3,clgray);
     
     
     Face[6].position;
     Face[6].tracer(3,clgray);
     
    end;
     
    begin
     cube1:=TCube.Create(_Root,0);
    end.
    Ici, la méthode n'est pas appropriée puisque je ne pourrais pas gérer la priorité des atomes en les plaçant sur des faces...

    Il faut ici créer des movieclips pour chaque atome afin de gérer les superpositions...

    Et puis je ne gère pas l'effet de profondeur des rayons des sphères.

    C'était un essai pour le point P[5]...

  9. #9
    Membre chevronné
    Avatar de Archimède
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2005
    Messages
    1 644
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 644
    Points : 1 975
    Points
    1 975
    Par défaut
    Je viens de faire la structure cubique faces centrées pour m'amuser :
    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
     
    program Project1;
     
    {$FRAME_WIDTH 1000}
    {$FRAME_HEIGHT 600}
    {$FRAME_RATE 25}
    {$BACKGROUND $e0e0e0}
     
    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:Point;
      procedure Transform;
      Constructor Create(xv,yv,zv:number);
     end;
     
     TAtome=class(Movieclip)
      zorder:integer;
      size:number;
      p: TPoint3D;
      procedure build(tx,ty,tz:number);
      procedure Render(penw,ColorFill:integer);
      constructor Create (parent:Movieclip;Depth:integer);
      procedure FrameMove;
      procedure circle(O:Point;Radius:number);
     end;
     
     TCube=class(Movieclip)
      Atome:array[1..14] of TAtome;
      procedure Reset;
      constructor Create(parent:Movieclip;Depth:integer);
      procedure onEnterFrame;override;
     end;
     
     const
          pi=3.141592654;
          dsc=30;
     
    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:Point;
    begin
      result:=Point.Create(128 * x / (128 + z / 4),128 * y / (128 + 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 TAtome.Create (parent:Movieclip;Depth:integer);
    begin
      inherited Create(Parent, 'atome' + IntToStr(Depth),Depth);
      zorder:=Depth;
    end;
     
    procedure TAtome.build(tx,ty,tz:number);
    var i:integer;
    begin
      Matrice.Translate(tx, ty, tz);
      P:=TPoint3D.Create(0,0,0);
      P.Transform;
    end;
     
    procedure TAtome.Render(penw,ColorFill:integer);
    var i,sc:integer;
    begin
     clear;
     Linestyle(penw,clBlack);
     BeginFill(colorFill);
     Circle(P.Transform2D,75);
     swapDepths(-P.z+zorder);
     sc :=Trunc(100-dsc *(100+P.z)/200);//le scale en fonction de z  un delta scale de 30 soit sc=100% en avant et 70% en arrière
     _xscale := sc;
     _yscale := sc;
    end;
     
     
    procedure TAtome.FrameMove;
    begin
     P.Transform;
    end;
     
    Procedure TAtome.circle(O:Point;Radius:number);
    var a,b,R,cx,cy: number;
    begin
      R:=Radius;
      cx:=O.x;
      cy:=O.y;
      a:= R * 0.414213562;
      b:= R * 0.707106781;
      moveTo(Cx+R,Cy);
      CurveTo(Cx+ R, Cy+-a, Cx+b,Cy -b);
      CurveTo(Cx+ a,Cy-R,Cx,Cy -r);
      CurveTo(Cx-a,Cy -R,Cx-b,Cy -b);
      CurveTo(Cx-R, Cy-a,Cx-R,Cy);
      CurveTo(Cx-R,Cy+a,Cx-b,Cy+b);
      CurveTo(Cx-a,Cy +R,Cx,Cy+r);
      CurveTo(Cx+a,Cy +R,Cx+b,Cy+b);
      CurveTo(Cx+R,Cy+a,Cx+R,Cy);
    end;
     
     
    constructor TCube.Create(parent:Movieclip;Depth:integer);
    var i:integer;
    begin
      inherited Create(Parent, 'cube' + IntToStr(Depth),Depth);
      Matrice:=TMatrice.Create;
     
      for i:=1 to 14 do  Atome[i]:=TAtome.Create(self,i);
     
      Atome[1].build(-100,-100,-100);
      Atome[2].build(0,200,0);
      Atome[3].build(200,0,0);
      Atome[4].build(0,-200,0);
      Atome[5].build(-100,100,0);
      Atome[6].build(0,0,200);
      Atome[7].build(-100,-100,0);
      Atome[8].build(0,200,0);
      Atome[9].build(200,0,0);
      Atome[10].build(0,-200,0);
      Atome[11].build(0,100,-100); 
      Atome[12].build(-200,0,0);
      Atome[13].build(100,-100,0);
      Atome[14].build(0,200,0);
     
     
      _x:=stage.width/2;
      _y:=stage.height/2;
     
      Reset;
     
    // Matrice.rotatex(pi/180);
      Matrice.rotateY(pi/90);
    // 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);
     
    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;
    var i:integer;
    begin
    // exit;
     for i:=1 to 14 do
     with atome[i] do
     begin
      Framemove; //calcul de position
      Render(1,clwhite);  //rendu écran
     end;
    end;
     
    begin
     TCube.Create(_Root,0);
    end.
    ça me permet de voir ce qui se passe sur une unique translation en x. c'est plus parlant avec des sphères...

    Sinon, en retrouvant la formule du motif et en faisant un tableau, on peut faire un cristal... Avec une translation en z en avant, on pourrait d'ailleurs se balader à l'intérieur du cristal...faire des rotate ...dans un onkeydown avec les flèches..

  10. #10
    Membre chevronné
    Avatar de Archimède
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2005
    Messages
    1 644
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 644
    Points : 1 975
    Points
    1 975
    Par défaut
    J'ai fait ça aussi, si ça intéresse : structure du sel

    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
    336
     
    program PNaCl;
     
    {$FRAME_WIDTH 600}
    {$FRAME_HEIGHT 600}
    {$FRAME_RATE 25}
    {$BACKGROUND $303030}
     
    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:Point;
      procedure Transform;
      Constructor Create(xv,yv,zv:number);
     end;
     
     TIon=class(Movieclip)
      zorder:integer;
      size:number;
      p: TPoint3D;
      procedure build(tx,ty,tz:number);
      procedure Render(penw,ColorFill,R:integer);
      constructor Create (parent:Movieclip;Depth:integer);
      procedure FrameMove;
      procedure circle(O:Point;Radius:number);
     end;
     
     TCube=class(Movieclip)
      Chlorure:array[1..14] of TIon;
      sodium:array[15..27] of TIon;
      procedure Reset;
      constructor Create(parent:Movieclip;Depth:integer);
      procedure onEnterFrame;override;
     end;
     
     const
          pi=3.141592654;
          dsc=20;
     
     
    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:Point;
    begin
      result:=Point.Create(128 * x / (128 + z / 4),128 * y / (128 + 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 TIon.Create (parent:Movieclip;Depth:integer);
    begin
      inherited Create(Parent, 'atome' + IntToStr(Depth),Depth);
      zorder:=Depth;
    end;
     
    procedure TIon
    .build(tx,ty,tz:number);
    var i:integer;
    begin
      Matrice.Translate(tx, ty, tz);
      P:=TPoint3D.Create(0,0,0);
      P.Transform;
    end;
     
    procedure TIon.Render(penw,ColorFill,R:integer);
    var i,sc:integer;
    begin
     clear;
     Linestyle(penw,clBlack);
     BeginFill(colorFill);
     Circle(P.Transform2D,R);
     endFill();
     swapDepths(-P.z+zorder);
     sc :=Trunc(100-dsc *(100+P.z)/200);
     _xscale := sc;
     _yscale := sc;
    end;
     
     
    procedure TIon.FrameMove;
    begin
     P.Transform;
    end;
     
    Procedure TIon.circle(O:Point;Radius:number);
    var a,b,R,cx,cy: number;
    begin
      R:=Radius;
      cx:=O.x;
      cy:=O.y;
      a:= R * 0.414213562;
      b:= R * 0.707106781;
      moveTo(Cx+R,Cy);
      CurveTo(Cx+ R, Cy+-a, Cx+b,Cy -b);
      CurveTo(Cx+ a,Cy-R,Cx,Cy -r);
      CurveTo(Cx-a,Cy -R,Cx-b,Cy -b);
      CurveTo(Cx-R, Cy-a,Cx-R,Cy);
      CurveTo(Cx-R,Cy+a,Cx-b,Cy+b);
      CurveTo(Cx-a,Cy +R,Cx,Cy+r);
      CurveTo(Cx+a,Cy +R,Cx+b,Cy+b);
      CurveTo(Cx+R,Cy+a,Cx+R,Cy);
    end;
     
     
    constructor TCube.Create(parent:Movieclip;Depth:integer);
    var i:integer;
    begin
      inherited Create(Parent, 'cube' + IntToStr(Depth),Depth);
     
      beginFill(clwhite);
      Moveto(-stage.width/2,-stage.height/2);
      lineto(stage.width/2,-stage.height/2);
      lineto(stage.width/2,stage.height/2);
      lineto(-stage.width/2,stage.height/2);
      lineto(-stage.width/2,-stage.height/2);
     
      Matrice:=TMatrice.Create;
     
      for i:=1 to 14 do Chlorure[i]:=TIon.Create(self,i);
     
      Chlorure[1].build(-100,-100,-100);
      Chlorure[2].build(0,200,0);
      Chlorure[3].build(200,0,0);
      Chlorure[4].build(0,-200,0);
      Chlorure[5].build(-100,100,0);
      Chlorure[6].build(0,0,200);
      Chlorure[7].build(-100,-100,0);
      Chlorure[8].build(0,200,0);
      Chlorure[9].build(200,0,0);
      Chlorure[10].build(0,-200,0);
      Chlorure[11].build(0,100,-100);
      Chlorure[12].build(-200,0,0);
      Chlorure[13].build(100,-100,0);
      Chlorure[14].build(0,200,0);
     
      for i:=15 to 27 do sodium[i]:=TIon.Create(self,i);
     
      sodium[15].build(0,0,-100);
      sodium[16].build(-100,-100,0);
      sodium[17].build(100,-100,0);
      sodium[18].build(100,100,0);
      sodium[19].build(0,-100,100);
      sodium[20].build(0,100,100);
      sodium[21].build(0,100,-100);
      sodium[22].build(-100,0,100);
      sodium[23].build(-100,-100,0);
      sodium[24].build(100,-100,0);
      sodium[25].build(-100,0,-100);
      sodium[26].build(0,200,0);
      sodium[27].build(100,-100,0);
     
      _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;
    var i:integer;
    begin
      Matrice.rotateY(-pi*_xmouse/(180*40));
      Matrice.rotateX(-pi*_ymouse/(180*40));
     
     for i:=1 to 14 do
     with Chlorure[i] do
     begin
      Framemove;
      Render(1,$77CA9C,50);
     end;
     
     For i:=15 to 27 do
     with sodium[i] do
     begin
      Framemove;
      Render(1,$CDD2D5,30);
     end;
     
     reset;
    end;
     
    begin
     TCube.Create(_Root,0);
    end.

  11. #11
    Expert éminent sénior
    Avatar de Paul TOTH
    Homme Profil pro
    Freelance
    Inscrit en
    Novembre 2002
    Messages
    8 964
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2002
    Messages : 8 964
    Points : 28 430
    Points
    28 430
    Par défaut
    c'est pas mal du tout

    ceci dit, j'ai deux remarques:

    1) pour afficher des sphères comme ça tu peux t'inspirer de l'exemple ZoneFlash.fpr, les cercles sont dessinés une seule fois puis on joue sur _scalex et _scaley pour en changer les dimensions.

    2) en fait il n'est pas nécessaire d'utiliser plusieurs clips, on peut simplement séparer les polygones par un endFill()...il faut juste les dessiner dans le bon ordre: du plus éloigné au plus proche (algorithme du peintre)

    j'ai fait une démo qui fonctionne mais j'ai un soucis que je n'ai pas résolu sur la détermination des faces cachées, idéalement je ne voudrais dessiner que les faces visibles, mais je m'y perd un peu sur ce point, du coup je dessine deux fois trop de faces (la moitié d'entre elles étant cachées)
    CubeMan3D.swf

    au passage j'ai fait une dizaine de corrections sur le compilateur au fil des erreurs de compilation que j'ai rencontré, rien de très sévère mais tout de même du coup pas la peine que je vous donne le source de l'exemple en PJ car il ne compile pas sur la version officielle
    Developpez.com: Mes articles, forum FlashPascal
    Entreprise: Execute SARL
    Le Store Excute Store

  12. #12
    Membre chevronné
    Avatar de Archimède
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2005
    Messages
    1 644
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 644
    Points : 1 975
    Points
    1 975
    Par défaut
    En effet, tes remarques sont judicieuses, je n'y ai pas pensé sur le coup...J'étais resté dans la notion de movieclips indépendants...

    Génial le nouveau cube man, encore plus fort

    Il faudrait que tu nous dises comment faire la série de positions pour faire une décomposition de mouvement. C'est bien agencé...

    On peut ajouter dans les transformations, la rotation autour d'un axe quelconque...

    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
     
    Procedure TMatrice.Rotate(a,ux,uy,uz:number);
    var ca,sa,n :number;
        i,j:integer;
    begin
      ca:=cos(a);
      sa:=sin(a);
      n:=sqrt(ux*ux+uy*uy+uz*uz);
      ux:=ux/n;
      uy:=uy/n;
      uz:=uz/n;
     
      Mi[0, 0] :=ux*ux+(1-ux*ux)*ca;    Mi[1, 0] :=ux*uy*(1-ca)-uz*sa;    Mi[2, 0] :=ux*uz*(1-ca)+uy*sa;    Mi[3, 0] :=  0;
      Mi[0, 1] :=ux*uy*(1-ca)+uz*sa;    Mi[1, 1] :=uy*uy+(1-uy*uy)*ca;    Mi[2, 1] :=uy*uz*(1-ca)-ux*sa;    Mi[3, 1] :=  0;
      Mi[0, 2] :=ux*uz*(1-ca)-uy*sa;    Mi[1, 2] :=uy*uz*(1-ca)+ux*sa;    Mi[2, 2] :=uz*uz+(1-uz*uz)*ca;    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é
     For i:=0 to 2 do
      For j:=0 to 2 do Mi[i,j]:=Id[i,j];
    end;

  13. #13
    Membre chevronné
    Avatar de Archimède
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2005
    Messages
    1 644
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 644
    Points : 1 975
    Points
    1 975
    Par défaut
    En ajoutant matrix pour les dégradés, on a plus rien à envier de OpenGl
    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
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
     
    program PNaCl;
     
    {$FRAME_WIDTH 600}
    {$FRAME_HEIGHT 600}
    {$FRAME_RATE 25}
    {$BACKGROUND $dcdcdc}
     
    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:Point;
      procedure Transform;
      Constructor Create(xv,yv,zv:number);
     end;
     
     TIon=class(Movieclip)
      zorder:integer;
      size:number;
      p: TPoint3D;
      procedure build(tx,ty,tz:number);
      procedure Render(ColorFill,R:integer);
      constructor Create (parent:Movieclip;Depth:integer);
      procedure FrameMove;
     end;
     
     TCube=class(Movieclip)
      Chlorure:array[1..14] of TIon;
      sodium:array[15..27] of TIon;
      procedure Reset;
      constructor Create(parent:Movieclip;Depth:integer);
      procedure onEnterFrame;override;
     end;
     
     const
          pi=3.141592654;
          dsc=20;
     
     
    var  matrice:TMatrice;
         Values,Mi,V,id: array[0..3,0..3] of number;
     
    Procedure circle(O:Point;Radius:number;mc:movieclip);
    var a,b,R,cx,cy: number;
    begin
      R:=Radius;
      cx:=O.x;
      cy:=O.y;
      a:= R * 0.414213562;
      b:= R * 0.707106781;
      with mc do
      begin
       moveTo(Cx+R,Cy);
       CurveTo(Cx+ R, Cy+-a, Cx+b,Cy -b);
       CurveTo(Cx+ a,Cy-R,Cx,Cy -r);
       CurveTo(Cx-a,Cy -R,Cx-b,Cy -b);
       CurveTo(Cx-R, Cy-a,Cx-R,Cy);
       CurveTo(Cx-R,Cy+a,Cx-b,Cy+b);
       CurveTo(Cx-a,Cy +R,Cx,Cy+r);
       CurveTo(Cx+a,Cy +R,Cx+b,Cy+b);
       CurveTo(Cx+R,Cy+a,Cx+R,Cy);
      end;
    end;
     
    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:Point;
    begin
      result:=Point.Create(128 * x / (128 + z / 4),128 * y / (128 + 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 TIon.Create (parent:Movieclip;Depth:integer);
    begin
      inherited Create(Parent, 'atome' + IntToStr(Depth),Depth);
      zorder:=Depth;
    end;
     
    procedure TIon.build(tx,ty,tz:number);
    var i:integer;
    begin
      Matrice.Translate(tx, ty, tz);
      P:=TPoint3D.Create(0,0,0);
      P.Transform;
    end;
     
    procedure TIon.Render(ColorFill,R:integer);
    var i,sc:integer;
        matrix: Flash8.Matrix;
    begin
     clear;
     
     matrix := Flash8.Matrix.Create();
     matrix.createBox(1,1,0,10+P.Transform2D.x,14+P.Transform2D.y);
     beginGradientFill('radial',[colorFill,clgray],[100,100],[0,15],matrix);
     Circle(P.Transform2D,R,self);
     endFill();
     swapDepths(-P.z+zorder);
     sc :=Trunc(100-dsc *(100+P.z)/200);
     _xscale := sc;
     _yscale := sc;
    end;
     
     
    procedure TIon.FrameMove;
    begin
     P.Transform;
    end;
     
     
     
     
    constructor TCube.Create(parent:Movieclip;Depth:integer);
    var i:integer;
        matrix: Flash8.Matrix;
    begin
      inherited Create(Parent, 'cube' + IntToStr(Depth),Depth);
     
      beginFill(0);
      Moveto(-stage.width/2,-stage.height/2);
      lineto(stage.width/2,-stage.height/2);
      lineto(stage.width/2,stage.height/2);
      lineto(-stage.width/2,stage.height/2);
      lineto(-stage.width/2,-stage.height/2);
      endFill();
     
      Matrice:=TMatrice.Create;
     
      for i:=1 to 14 do Chlorure[i]:=TIon.Create(self,i);
     
      Chlorure[1].build(-100,-100,-100);
      Chlorure[2].build(0,200,0);
      Chlorure[3].build(200,0,0);
      Chlorure[4].build(0,-200,0);
      Chlorure[5].build(-100,100,0);
      Chlorure[6].build(0,0,200);
      Chlorure[7].build(-100,-100,0);
      Chlorure[8].build(0,200,0);
      Chlorure[9].build(200,0,0);
      Chlorure[10].build(0,-200,0);
      Chlorure[11].build(0,100,-100);
      Chlorure[12].build(-200,0,0);
      Chlorure[13].build(100,-100,0);
      Chlorure[14].build(0,200,0);
     
      for i:=15 to 27 do sodium[i]:=TIon.Create(self,i);
     
      sodium[15].build(0,0,-100);
      sodium[16].build(-100,-100,0);
      sodium[17].build(100,-100,0);
      sodium[18].build(100,100,0);
      sodium[19].build(0,-100,100);
      sodium[20].build(0,100,100);
      sodium[21].build(0,100,-100);
      sodium[22].build(-100,0,100);
      sodium[23].build(-100,-100,0);
      sodium[24].build(100,-100,0);
      sodium[25].build(-100,0,-100);
      sodium[26].build(0,200,0);
      sodium[27].build(100,-100,0);
     
      _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;
    var i:integer;
    begin
      Matrice.rotateY(-pi*_xmouse/(180*40));
      Matrice.rotateX(-pi*_ymouse/(180*40));
     
     for i:=1 to 14 do
     with Chlorure[i] do
     begin
      Framemove;
      Render($9FC198,50);
     end;
     
     For i:=15 to 27 do
     with sodium[i] do
     begin
      Framemove;
      Render($D4DDD1,30);
     end;
     
     reset;
    end;
     
    begin
     TCube.Create(_Root,0);
    end.
    Je n'ai pas modifié avec l'algo du peintre...C'est dommage de se priver de
    swapDepths qui est le gros point positif de flash.

  14. #14
    Expert éminent sénior
    Avatar de Paul TOTH
    Homme Profil pro
    Freelance
    Inscrit en
    Novembre 2002
    Messages
    8 964
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2002
    Messages : 8 964
    Points : 28 430
    Points
    28 430
    Par défaut
    très joli
    Developpez.com: Mes articles, forum FlashPascal
    Entreprise: Execute SARL
    Le Store Excute Store

Discussions similaires

  1. [C#] Configuration du niveau de priorite des processus
    Par stephdiplo150 dans le forum Windows Forms
    Réponses: 6
    Dernier message: 22/04/2007, 23h29
  2. [Postgres 8]Problème de priorité des requètes
    Par julienOriano dans le forum PostgreSQL
    Réponses: 1
    Dernier message: 28/12/2005, 12h36
  3. priorité des onload avec des iframes
    Par pekka77 dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 25/11/2005, 13h22
  4. [CSS2] Souci d'héritage et de priorité des styles.
    Par ARRG dans le forum Mise en page CSS
    Réponses: 5
    Dernier message: 12/07/2005, 09h03
  5. Priorité des AND/OR
    Par Mut dans le forum Langage SQL
    Réponses: 3
    Dernier message: 02/05/2005, 11h24

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo