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

Composants VCL Delphi Discussion :

discussion sur essai asphyre 4.1


Sujet :

Composants VCL Delphi

Vue hybride

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

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 644
    Par défaut discussion sur essai asphyre 4.1
    j'ai tenté un essai d'animation dans le canvas avec asphyre dont voici le code :
    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
     
    unit Unit1;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,AsphyreDevices,AsphyreEvents,AsphyreTimer,Vectors2;
     
    type TEspacemath=record
         O:TPoint2;
         grd:single;//valeur des graduations
         end;
     
     
    type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      private
        { Déclarations privées }
      i:integer;
      theta,w,t:single;
      espace:Tespacemath;
      function x(val:single):single;
      function y(val:single):single;
      function convert(val:single):single;
      procedure configureDevice(sender:TAsphyreDevice;Tag:TObject;var config:TscreenConfig);
      procedure TimerEvent(sender:TObject);
      procedure ProcessEvent (sender:TObject);
      procedure RenderCallback(sender:TAsphyreDevice;Tag:TObject);
      public
        { Déclarations publiques }
      end;
     
     
    var
      Form1: TForm1;
     
    implementation
      Const R=10;
    {$R *.dfm}
     
    procedure TForm1.configureDevice(sender:TAsphyreDevice;Tag:TObject;var config:TscreenConfig);
    begin
    config.WindowHandle:=self.Handle;
    config.Width:=clientwidth;
    config.height:=clientheight;
    config.windowed:=true;
    config.bitdepth:=bd24bit;
    end;
     
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    width:=screen.Width;
    height:=screen.Height div 2;
    position:=poscreencenter;
    formstyle:=fsstayontop;
    if (not Devices.Initialize(Configuredevice,self)) then
    begin
      MessageDlg('asphyre n''a pas pu s''initialiser' ,mtError,[mbOk],0); 
      Close();
      Exit;
    end;
    timer.Enabled:=true;
    timer.OnTimer:=timerevent;
    timer.MaxFPS:=100; //freq des images
     
    with espace do begin
                   O:=point2(0,clientheight);
                   grd:=clientwidth/100;
    end;
    w:=40*pi/180; //vitesse angulaire 40°/s
    end;
     
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
    Devices.Finalize;
    end;
     
    procedure TForm1.RenderCallback(sender:TAsphyreDevice;Tag:TObject);
    var j:integer;
     
    begin
     
    with sender.Canvas do begin
    LineAntialias:=true;
    LineWidth:=1;
    for j := 0 to 50 do begin
                        lineex(point2(x(2*j),y(0)),point2(x(2*j),y(100)),$ffffffff);
                        lineex(point2(x(0),y(2*j)),point2(x(100),y(2*j)),$ffffffff);
    end;
    LineWidth:=5;
    lineex(point2(x(0),y(2)),point2(x(100),y(2)),$ff00ffff);
    LineWidth:=7;
    //ROUE
    circle(x(R*theta+R),y(R+2),convert(R),60,$ffff0000);
    LineWidth:=5;
    lineex(point2(x(R*theta+R),y(R+2)),point2(x(R*theta+R+R*cos(theta)),y(R+2+R*sin(-theta))),$ffff0000);
    lineex(point2(x(R*theta+R),y(R+2)),point2(x(R*theta+R+R*cos(theta+pi/2)),y(R+2+R*sin(-(theta+pi/2)))),$ffff0000);
    lineex(point2(x(R*theta+R),y(R+2)),point2(x(R*theta+R+R*cos(theta+3*pi/2)),y(R+2+R*sin(-(theta+3*pi/2)))),$ffff0000);
    lineex(point2(x(R*theta+R),y(R+2)),point2(x(R*theta+R+R*cos(theta+pi)),y(R+2+R*sin(-(theta+pi)))),$ffff0000);
    //
     
    end;
    end;
     
    procedure TForm1.TimerEvent(sender:TObject);
    begin
    caption:=floattostr(t)+' s';
    t:=t+1/timer.MaxFPS;
    If convert(R*THETA)>clientwidth then begin theta:=0; t:=0;end;
    theta:=w*t;
    DefDevice.Render(rendercallback,self,$ff000000);
    Timer.Process;
    end;
     
    procedure TForm1.ProcessEvent (sender:TObject);
    begin
    //rien
    end;
     
    function TForm1.x(val:single):single;
    begin
    result:=espace.O.X+espace.grd*val;
    end;
     
    function TForm1.y(val: Single):single;
    begin
    result:=espace.O.y-espace.grd*val;
    end;
     
    function Tform1.convert(val:single):single;
    begin
    result:=val*espace.grd;
    end;
     
    end.
    peu importe l'animation...c'était un essai...
    je suis passé en coordonnées mathématiques, c'est plus cool pour raisonner.

    Je gagne en fluidité, c'est certain lol
    mais le onpaint ? (comment ça marche ?-> Dessin qui se redessine difficilement après déplacement de la fiche en dehors de l'écran...De plus, le timer qui semble s'arrêter momentanément..

    Et en agrandissement(wsmaximised) la fenêtre, déformation du dessin alors que tout est fait en fonction de la largeur de l'écran ?

    donc distorsion du canvas...

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

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 644
    Par défaut
    Toutes les méthodes du canvas sont en single. Je sais que les jeux sont des sources gourmandes en nombres à virgule...
    Qui peut m'expliquer comment fonctionne le codage de la surface du canvas dans asphyre vu que l'on ne travaille pas directement sur des pixels...
    Et à part l'excellent tuto de pedro, on ne trouve aucune explication en français sur l'utilisation approfondie des méthodes des objets d'asphyre...

    Ce qui est couillon, c'est qu'en ajoutant un bouton sur tous les exemples fournis avec timer.enabled :=false sur le onclick; En sortant la fiche de l'écran --> pas de onpaint donc disparition de l'affichage.
    le timer doit tourner en permanence.
    C'est plutôt gênant quand on a besoin d'arrêter l'animation...

    La portabilité... Si directx9 n'est pas à jour, impossible de lancer une application. J'ai essayé sur mon vieux portable avec encore un xp pack 1 pour voir .
    manque la dll machin d3d9... je crois.
    Si je la mets dans un dossier avec mon executable,--> corruption etc...

    Il y a une solution ?

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

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 644
    Par défaut
    J'ai réglé le onpaint ( je pense... en tout cas ça fonctionne)
    J'ai tenté de régler le redimensionnent..
    mon quadrillage devrait partir du bas de la fiche en maximisant, ce n'est pas le cas.(il reste dans la même position.)


    ci-joint:
    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
     
    unit Unit1;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,AsphyreDevices,AsphyreEvents,AsphyreTimer,Vectors2,direct3d9;
     
    type TEspacemath=record
         O:TPoint2;
         grd:single;
         end;
     
     
    type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
        procedure FormResize(Sender: TObject);
        procedure FormPaint(Sender: TObject);
      private
        { Déclarations privées }
      theta,w,t:single;
      espace:Tespacemath;
      function x(val:single):single;
      function y(val:single):single;
      function convert(val:single):single;
      procedure configureDevice(sender:TAsphyreDevice;Tag:TObject;var config:TscreenConfig);
      procedure TimerEvent(sender:TObject);
      procedure ProcessEvent (sender:TObject);
      procedure RenderCallback(sender:TAsphyreDevice;Tag:TObject);
      procedure DeviceReset(Sender: TAsphyreDevice; Tag: TObject;
       var Params: TD3DPresentParameters);
      public
        { Déclarations publiques }
      end;
     
     
    var
      Form1: TForm1;
     
    implementation
      Const R=10;
    {$R *.dfm}
     
    procedure TForm1.configureDevice(sender:TAsphyreDevice;Tag:TObject;var config:TscreenConfig);
    begin
    config.WindowHandle:=self.Handle;
    config.Width:=clientwidth;
    config.height:=clientheight;
    config.windowed:=true;
    config.bitdepth:=bd24bit;
    end;
     
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    width:=screen.Width;
    height:=screen.Height div 2;
    position:=poscreencenter;
    formstyle:=fsstayontop;
    if (not Devices.Initialize(Configuredevice,self)) then
    begin
      MessageDlg('asphyre n''a pas pu s''initialiser' ,mtError,[mbOk],0);
      Close();
      Exit;
    end;
    timer.Enabled:=true;
    timer.OnTimer:=timerevent;
    timer.MaxFPS:=100; //freq des images
     
    with espace do begin
                   O:=point2(0,clientheight);
                   grd:=clientwidth/100;
    end;
    w:=40*pi/180; //vitesse angulaire 40°/s
    end;
     
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
    Devices.Finalize;
    end;
     
    procedure TForm1.FormPaint(Sender: TObject);
    begin
    DefDevice.Render(rendercallback,self,$ff000000);
    end;
     
    procedure TForm1.FormResize(Sender: TObject);
    begin
    DefDevice.Reset(DeviceReset, Self);
    end;
     
     
     
    //---------------------------------------------------------------------------
    procedure TForm1.DeviceReset(Sender: TAsphyreDevice; Tag: TObject;
     var Params: TD3DPresentParameters);
    begin
     Params.BackBufferWidth := ClientWidth;
     Params.BackBufferHeight:= ClientHeight;
    end;
     
    procedure TForm1.RenderCallback(sender:TAsphyreDevice;Tag:TObject);
    var j:integer;
     
    begin
     
    with sender.Canvas do begin
    LineAntialias:=true;
    LineWidth:=1;
    for j := 0 to 50 do begin
                        lineex(point2(x(2*j),y(0)),point2(x(2*j),y(100)),$ffffffff);
                        lineex(point2(x(0),y(2*j)),point2(x(100),y(2*j)),$ffffffff);
    end;
    LineWidth:=5;
    lineex(point2(x(0),y(2)),point2(x(100),y(2)),$ff00ffff);
    LineWidth:=7;
    //ROUE
    circle(x(R*theta+R),y(R+2),convert(R),60,$ffff0000);
    LineWidth:=5;
    lineex(point2(x(R*theta+R),y(R+2)),point2(x(R*theta+R+R*cos(theta)),y(R+2+R*sin(-theta))),$ffff0000);
    lineex(point2(x(R*theta+R),y(R+2)),point2(x(R*theta+R+R*cos(theta+pi/2)),y(R+2+R*sin(-(theta+pi/2)))),$ffff0000);
    lineex(point2(x(R*theta+R),y(R+2)),point2(x(R*theta+R+R*cos(theta+3*pi/2)),y(R+2+R*sin(-(theta+3*pi/2)))),$ffff0000);
    lineex(point2(x(R*theta+R),y(R+2)),point2(x(R*theta+R+R*cos(theta+pi)),y(R+2+R*sin(-(theta+pi)))),$ffff0000);
    //
     
    end;
    end;
     
    procedure TForm1.TimerEvent(sender:TObject);
    begin
    caption:=floattostrF(t,fffixed,4,2)+' s'+'      teta=  '+floattostrf(theta*180/pi,fffixed,4,1)+'  °  '+'Fréq :   '+inttostr(timer.FrameRate)+'  Hz';
    t:=t+1/timer.MaxFPS;
    If convert(R*THETA)>clientwidth then begin theta:=0; t:=0;end;
    theta:=w*t;
    DefDevice.Render(rendercallback,self,$ff000000);
    Timer.Process;
    end;
     
    procedure TForm1.ProcessEvent (sender:TObject);
    begin
    //rien
    end;
     
    function TForm1.x(val:single):single;
    begin
    result:=espace.O.X+espace.grd*val;
    end;
     
    function TForm1.y(val: Single):single;
    begin
    result:=espace.O.y-espace.grd*val;
    end;
     
    function Tform1.convert(val:single):single;
    begin
    result:=val*espace.grd;
    end;
     
    end.
    reste encore mes interrogations du post précédent non résolues.

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

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 644
    Par défaut
    J'ai résolu l'histoire de la dll...
    J'avais pris celle de mon répertoire system32 sous vista et non celle délivrée avec asphyre dans le dossier dll.

    Par contre, sur mon portable, la fréquence descend à 78 Hz avec le ventilo qui se met en route alors que je tourne à 105 hz en moyenne pour le framerate sur mon ordi le plus récent...

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. discussion sur .NET
    Par tut dans le forum MFC
    Réponses: 4
    Dernier message: 27/07/2005, 15h41
  2. Réponses: 6
    Dernier message: 30/01/2005, 23h48
  3. Discussions sur la (les) syntaxe(s)
    Par Laurent Dardenne dans le forum Sepi
    Réponses: 11
    Dernier message: 02/01/2005, 20h25

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