Menu

How optimize scene rotation?

Help
Roman
2017-01-11
2017-01-26
  • Roman

    Roman - 2017-01-11

    Help me please.
    Can the scene be optimized, after creating all objects. So it will not lag when you move it.

    Source: https://yadi.sk/d/TNHucANY38Rqib
    Exe: https://yadi.sk/d/O_uMktwK38Rqkq

    unit Unit1;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, GLScene, GLObjects, GLCoordinates,
      GLWin32Viewer, GLCrossPlatform, GLBaseClasses, GLBitmapFont, Vcl.ExtCtrls;
    
    type
      TForm1 = class(TForm)
        GLScene1: TGLScene;
        GLSceneViewer1: TGLSceneViewer;
        GLCamera1: TGLCamera;
        World: TGLDummyCube;
        FRoom: TGLDummyCube;
        Timer1: TTimer;
        procedure GLSceneViewer1MouseWheel(Sender: TObject; Shift: TShiftState;
          WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
        procedure GLSceneViewer1MouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
        procedure GLSceneViewer1MouseMove(Sender: TObject; Shift: TShiftState; X,
          Y: Integer);
        procedure Timer1Timer(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
      mx,my:integer;
      GLCube:array[0..100000] of TGLCube;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.GLSceneViewer1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      mx:=x;
      my:=y;
    end;
    
    procedure TForm1.GLSceneViewer1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
      if ssLeft in shift then
      begin
        FRoom.TurnAngle :=FRoom.TurnAngle -(mx-x)/8;
        World.PitchAngle:=World.PitchAngle+(my-y)/8;
        if World.PitchAngle<0   then World.PitchAngle:=0  ;
        if World.PitchAngle>170 then World.PitchAngle:=170;
      end;
    
      mx:=x; my:=y;
    end;
    
    procedure TForm1.GLSceneViewer1MouseWheel(Sender: TObject; Shift: TShiftState;
      WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
    begin
      GLCamera1.Position.y:=GLCamera1.Position.y-(GLCamera1.Position.y/(WheelDelta/8));
    end;
    
    procedure TForm1.Timer1Timer(Sender: TObject);
    var n, ix,iy,iz, size :integer;
    begin
      Timer1.Enabled:=False;
      Form1.Caption:='Loading';
      n :=0;
      size:=20;
    
      World.PitchAngle:=90;
    
      for iy:=-size to size do
      begin
        for ix:=-size to size do
        for iz:=-size to size do
        begin
          GLCube[n]:=TGLCube.Create(Form1);
          GLCube[n].Parent:=FRoom;
          GLCube[n].Position.SetPoint(2*ix,2*iy,2*iz);
          GLCube[n].Material.FrontProperties.Diffuse.SetColor(random(100)/100,random(100)/100,random(100)/100);
          inc(n);
        end;
        Form1.Caption:=Format('Loading ( %d / %d )',[iy+size,size*2]);
        Application.ProcessMessages;
      end;
      Form1.Caption:='Done';
      ShowMessage('How optimize scene rotation? (Mouse Move)');
    end;
    
    end.
    
     

    Last edit: Roman 2017-01-11
  • Roman

    Roman - 2017-01-26

    Hi.

    Can I use Geometry Instancing in GLSsene?

    P.s.
    Use TGLProxyObject :)

     

    Last edit: Roman 2017-01-26
  • Roman

    Roman - 2017-01-26

    Fast:

    Source: https://yadi.sk/d/2o02umki3B85ty
    Exe: https://yadi.sk/d/Mi5wkwEx3B85uJ

    unit Unit1;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, GLScene, GLObjects, GLCoordinates, GLFileSTL,
      GLWin32Viewer, GLCrossPlatform, GLBaseClasses, GLBitmapFont, Vcl.ExtCtrls,
      GLVectorFileObjects, GLParticles, GLProxyObjects;
    
    type
      TForm1 = class(TForm)
        GLScene1: TGLScene;
        GLSceneViewer1: TGLSceneViewer;
        GLCamera1: TGLCamera;
        World: TGLDummyCube;
        Timer1: TTimer;
        GLLightSource1: TGLLightSource;
        FRoom: TGLParticles;
        procedure GLSceneViewer1MouseWheel(Sender: TObject; Shift: TShiftState;
          WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
        procedure GLSceneViewer1MouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
        procedure GLSceneViewer1MouseMove(Sender: TObject; Shift: TShiftState; X,
          Y: Integer);
        procedure Timer1Timer(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
      mx,my:integer;
      MasterObj:TGLFreeForm;
      ProxyObj:TGLColorProxy;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.GLSceneViewer1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      mx:=x;
      my:=y;
    end;
    
    procedure TForm1.GLSceneViewer1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
      if ssLeft in shift then
      begin
        FRoom.TurnAngle :=FRoom.TurnAngle -(mx-x)/8;
        World.PitchAngle:=World.PitchAngle+(my-y)/8;
        if World.PitchAngle<0   then World.PitchAngle:=0  ;
        if World.PitchAngle>170 then World.PitchAngle:=170;
      end;
    
      mx:=x; my:=y;
    end;
    
    procedure TForm1.GLSceneViewer1MouseWheel(Sender: TObject; Shift: TShiftState;
      WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
    begin
      GLCamera1.Position.y:=GLCamera1.Position.y-(GLCamera1.Position.y/(WheelDelta/8));
    end;
    
    procedure TForm1.Timer1Timer(Sender: TObject);
    var n, ix,iy,iz, size :integer;
    begin
      Timer1.Enabled:=False;
      Form1.Caption:='Loading';
      GLSceneViewer1.Buffer.Lighting:=False;
      n:=0;
      size:=20;
      World.PitchAngle:=90;
      MasterOBJ:=TGLFreeForm.Create(Form1);
      MasterOBJ.UseMeshMaterials:=False;
      MasterOBJ.LoadFromFile('Cyl.STL');
      MasterOBJ.Visible:=False;
      ProxyObj:=TGLColorProxy.Create(Form1);
      ProxyObj.Parent:=FRoom;
      ProxyObj.MasterObject:=MasterOBJ;
    
      for iy:=-size to size do
      begin
        for ix:=-size to size do
        for iz:=-size to size do
        with TGLColorProxy(FRoom.CreateParticle) do
        begin
          Position.SetPoint(2*ix,2*iy,2*iz);
          Scale.SetVector(random(50)/100+0.5,random(50)/100+0.5,random(50)/100+0.5);
          Direction.SetVector(random(100)/100,random(100)/100,random(100)/100);
          FrontColor.Diffuse.SetColor(random(100)/100,random(100)/100,random(100)/100);
          inc(n);
        end;
        Form1.Caption:=Format('Loading ( %d / %d )',[iy+size,size*2]);
        Application.ProcessMessages;
      end;
      Form1.Caption:='Done';
    end;
    
    end.
    
     

    Last edit: Roman 2017-01-27

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.