Преглед на файлове

a million random GLPoints are displayed in less than a second in GLSceenViewer advdemos

GLScene преди 4 години
родител
ревизия
731bf79430

+ 2 - 2
AdvDemos/Delphi/GLSViewer/GLSViewer.dproj

@@ -100,14 +100,14 @@
     </PropertyGroup>
     <PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
         <BT_BuildType>Debug</BT_BuildType>
-        <VerInfo_Build>93</VerInfo_Build>
+        <VerInfo_Build>115</VerInfo_Build>
         <AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
         <VerInfo_AutoIncVersion>true</VerInfo_AutoIncVersion>
         <VerInfo_MinorVer>8</VerInfo_MinorVer>
         <VerInfo_Debug>true</VerInfo_Debug>
         <VerInfo_Locale>1033</VerInfo_Locale>
         <Icon_MainIcon>Resource\GLSViewer.ico</Icon_MainIcon>
-        <VerInfo_Keys>CompanyName=;FileVersion=1.8.0.93;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductVersion=1.8.0.0;Comments=;ProgramID=com.embarcadero.$(MSBuildProjectName);FileDescription=$(MSBuildProjectName);ProductName=$(MSBuildProjectName)</VerInfo_Keys>
+        <VerInfo_Keys>CompanyName=;FileVersion=1.8.0.115;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductVersion=1.8.0.0;Comments=;ProgramID=com.embarcadero.$(MSBuildProjectName);FileDescription=$(MSBuildProjectName);ProductName=$(MSBuildProjectName)</VerInfo_Keys>
         <VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
     </PropertyGroup>
     <PropertyGroup Condition="'$(Cfg_2_Win64)'!=''">

+ 36 - 10
AdvDemos/Delphi/GLSViewer/Source/fMain.dfm

@@ -130,7 +130,6 @@ object MainForm: TMainForm
   ShowHint = True
   WindowState = wsMaximized
   OnCreate = FormCreate
-  OnMouseWheel = FormMouseWheel
   OnShow = FormShow
   PixelsPerInch = 96
   TextHeight = 13
@@ -173,7 +172,6 @@ object MainForm: TMainForm
     OnMouseLeave = snViewerMouseLeave
     Align = alClient
     OnMouseDown = snViewerMouseDown
-    OnMouseMove = snViewerMouseMove
     OnMouseUp = snViewerMouseUp
     TabOrder = 1
   end
@@ -1097,10 +1095,14 @@ object MainForm: TMainForm
           item
             Items = <
               item
-                Action = acObjects
-                Caption = 'O&bjects...'
+                Action = acPoints
+                Caption = '&Points'
                 ImageIndex = 21
               end
+              item
+                Action = acSpheres
+                Caption = 'Sph&eres'
+              end
               item
                 Caption = '-'
               end
@@ -1708,8 +1710,8 @@ object MainForm: TMainForm
             ShowCaption = False
           end
           item
-            Action = acObjects
-            Caption = 'O&bjects...'
+            Action = acPoints
+            Caption = '&Points'
             ImageIndex = 21
             ShowCaption = False
           end
@@ -2040,12 +2042,12 @@ object MainForm: TMainForm
       Caption = 'CSAA 16X'
       GroupIndex = 2
     end
-    object acObjects: TAction
+    object acPoints: TAction
       Category = 'View'
-      Caption = 'Objects...'
-      Hint = 'Objects'
+      Caption = 'Points'
+      Hint = 'Points'
       ImageIndex = 21
-      OnExecute = acObjectsExecute
+      OnExecute = acPointsExecute
     end
     object acNaviCube: TAction
       Category = 'View'
@@ -2061,6 +2063,10 @@ object MainForm: TMainForm
       ImageIndex = 22
       OnExecute = acToolsInfoExecute
     end
+    object acSpheres: TAction
+      Category = 'View'
+      Caption = 'Spheres'
+    end
   end
   object ImageListMenu: TImageList
     Left = 120
@@ -2870,4 +2876,24 @@ object MainForm: TMainForm
     Left = 240
     Top = 152
   end
+  object GLSimpleNavigation: TGLSimpleNavigation
+    Form = Owner
+    GLSceneViewer = snViewer
+    FormCaption = 'GLSViewer - %FPS'
+    KeyCombinations = <
+      item
+        ShiftState = [ssLeft, ssRight]
+        Action = snaZoom
+      end
+      item
+        ShiftState = [ssLeft]
+        Action = snaMoveAroundTarget
+      end
+      item
+        ShiftState = [ssRight]
+        Action = snaMoveAroundTarget
+      end>
+    Left = 328
+    Top = 96
+  end
 end

+ 24 - 18
AdvDemos/Delphi/GLSViewer/Source/fMain.pas

@@ -64,7 +64,8 @@ uses
   fGLAbout,
   fGLOptions,
   fGLDialog,
-  dGLSViewer;
+  dGLSViewer,
+  GLS.SimpleNavigation;
 
 type
   TMainForm = class(TGLForm)
@@ -132,13 +133,15 @@ type
     atbTools: TActionToolBar;
     atbView: TActionToolBar;
     atbFile: TActionToolBar;
-    acObjects: TAction;
+    acPoints: TAction;
     AsyncTimer: TGLAsyncTimer;
     dcWorld: TGLDummyCube;
     grdXYZ: TGLXYZGrid;
     acNaviCube: TAction;
     GLPoints: TGLPoints;
     acToolsInfo: TAction;
+    GLSimpleNavigation: TGLSimpleNavigation;
+    acSpheres: TAction;
     procedure FormCreate(Sender: TObject);
     procedure snViewerMouseDown(Sender: TObject; Button: TMouseButton;
       Shift: TShiftState; X, Y: Integer);
@@ -183,7 +186,7 @@ type
     procedure acViewResetExecute(Sender: TObject);
     procedure acViewZoomOutExecute(Sender: TObject);
     procedure acViewZoomInExecute(Sender: TObject);
-    procedure acObjectsExecute(Sender: TObject);
+    procedure acPointsExecute(Sender: TObject);
     procedure AsyncTimerTimer(Sender: TObject);
     procedure acNaviCubeExecute(Sender: TObject);
     procedure acToolsInfoExecute(Sender: TObject);
@@ -214,9 +217,6 @@ var
   MainForm: TMainForm;
   NaviCube: TGLNaviCube;
 
-const
-  NumObjects: Integer = 1000;
-
 //=======================================================================
 implementation
 //=======================================================================
@@ -943,24 +943,30 @@ begin
 end;
 
 // Show Base and Additional Objects
-procedure TMainForm.acObjectsExecute(Sender: TObject);
+procedure TMainForm.acPointsExecute(Sender: TObject);
 var
   i: Integer;
   Color : TVector3f;
-const
-  RandMax: Integer = 1000;
+  NumPoints: Integer;
+  X, Y, Z : Single;
+
 begin
-  for i := 0 to NumObjects - 1 do
+  NumPoints := 1000000;
+  GLPoints := TGLPoints(dcWorld.AddNewChild(TGLPoints));
+  GLPoints.Size := 5.0;
+  GLPoints.Style := psSmooth;
+  for i := 0 to NumPoints - 1 do
   begin
-    GLPoints := TGLPoints(dcWorld.AddNewChild(TGLPoints));
-    Color.X := Random(256)/256;
-    Color.Y := Random(256)/256;
-    Color.Z := Random(256)/256;
+    Color.X := Random();
+    Color.Y := Random();
+    Color.Z := Random();
+
+	  X := Random(50) - 25;
+	  Y := Random(50) - 25;
+	  Z := Random(50) - 25;
+
+    GLPoints.Positions.Add(X*0.05, Y*0.05, Z*0.05);  // Fill array of GLPoints
     GLPoints.Colors.AddPoint(Color);
-    GLPoints.Size := 5;
-	  GLPoints.Position.X := Random(10) - 5;
-	  GLPoints.Position.Y := Random(10) - 5;
-	  GLPoints.Position.Z := Random(10) - 5;
   end;
 end;
 

+ 5 - 5
Source/GLS.Coordinates.pas

@@ -27,9 +27,9 @@ type
      csUnknown : aucune contrainte *)
   TGLCoordinatesStyle = (csPoint2D, csPoint, csVector, csUnknown);
 
-  (* Stores and homogeneous vector.
+  (* Stores any homogeneous vector.
     This class is basicly a container for a TGLVector, allowing proper use of
-    delphi property editors and editing in the IDE. Vector/Coordinates
+    property editors and editing in the IDE. Vector/Coordinates
     manipulation methods are only minimal.
     Handles dynamic default values to save resource file space.  *)
   TGLCustomCoordinates = class(TGLUpdateAbleObject)
@@ -639,7 +639,7 @@ end;
 
 // ----------------- Conversions of coordinates --------------------
 
-// ----- Cylindrical_Cartesian ---------------------------------------------
+// ----------------- Cylindrical_Cartesian ----------------------
 
 procedure Cylindrical_Cartesian(const r, theta, z1: single; var x, y, z: single);
 
@@ -648,7 +648,7 @@ begin
   z := z1;
 end;
 
-// ----- Cylindrical_Cartesian -------------------------------------------------
+// ----- Cylindrical_Cartesian -------------------------------------
 (* Convert Cylindrical to Cartesian with no checks. Double version
   Ref: http://mathworld.wolfram.com/CylindricalCoordinates.html *)
 procedure Cylindrical_Cartesian(const r, theta, z1: double; var x, y, z: double);
@@ -658,7 +658,7 @@ begin
   z := z1;
 end;
 
-// ----- Cylindrical_Cartesian -------------------------------------------------
+// ------------------ Cylindrical_Cartesian -----------------------
 (* Convert Cylindrical to Cartesian with checks.
   ierr: [0] = ok,
   [1] = r out of bounds. Acceptable r: [0,inf)

+ 1 - 1
Source/GLS.Objects.pas

@@ -597,7 +597,7 @@ type
     property TopCap: TGLCapType read FTopCap write SetTopCap default ctNone;
   end;
 
-  (* Base class for objects based on a polygon. *)
+  (* Base class for objects based on a polygon *)
   TGLPolygonBase = class(TGLSceneObject)
   private
     FDivision: Integer;

+ 14 - 18
Source/GLS.VectorGeometry.pas

@@ -176,8 +176,6 @@ type
   TAffineExtMatrix = array [0 .. 2] of TAffineExtVector;
 
   // Some simplified names
-///  PGLMatrix = ^TGLMatrix;
-///  TGLMatrix = THomogeneousFltMatrix;
 
   TMatrixArray = array [0 .. MaxInt shr 7] of TGLMatrix;
   PMatrixArray = ^TMatrixArray;
@@ -250,6 +248,7 @@ const
   MinusXVector: TAffineVector = (X: - 1; Y: 0; Z: 0);
   MinusYVector: TAffineVector = (X: 0; Y: - 1; Z: 0);
   MinusZVector: TAffineVector = (X: 0; Y: 0; Z: - 1);
+
   // Standard homogeneous vectors
   XHmgVector: THomogeneousVector = (X: 1; Y: 0; Z: 0; W: 0);
   YHmgVector: THomogeneousVector = (X: 0; Y: 1; Z: 0; W: 0);
@@ -261,6 +260,7 @@ const
   XYZHmgVector: THomogeneousVector = (X: 1; Y: 1; Z: 1; W: 0);
   XYZWHmgVector: THomogeneousVector = (X: 1; Y: 1; Z: 1; W: 1);
   NullHmgVector: THomogeneousVector = (X: 0; Y: 0; Z: 0; W: 0);
+
   // Standard homogeneous points
   XHmgPoint: THomogeneousVector = (X: 1; Y: 0; Z: 0; W: 1);
   YHmgPoint: THomogeneousVector = (X: 0; Y: 1; Z: 0; W: 1);
@@ -512,7 +512,7 @@ procedure VectorSubtract(const V1: TGLVector; const V2: TAffineVector; var resul
 // Returns V1-V2
 function VectorSubtract(const V1, V2: TGLVector): TGLVector; overload; 
 // Subtracts V2 from V1 and return value in result
-procedure VectorSubtract(const V1, V2: TGLVector; var result: TGLVector); overload; 
+procedure VectorSubtract(const V1, V2: TGLVector; var result: TGLVector); overload;
 // Subtracts V2 from V1 and return value in result
 procedure VectorSubtract(const V1, V2: TGLVector; var result: TAffineVector); overload;
 function VectorSubtract(const V1: TAffineVector; delta: Single): TAffineVector; overload; inline;
@@ -2452,6 +2452,7 @@ function VectorNorm(const V: TAffineVector): Single;
 begin
   result := V.X * V.X + V.Y * V.Y + V.Z * V.Z;
 end;
+
 function VectorNorm(const V: TGLVector): Single;
 begin
   result := V.X * V.X + V.Y * V.Y + V.Z * V.Z;
@@ -5632,15 +5633,14 @@ end;
 
 function ConvertRotation(const Angles: TAffineVector): TGLVector;
 
-{ Rotation of the Angle t about the axis (X, Y, Z) is given by:
-
+(*
+  Rotation of the Angle t about the axis (X, Y, Z) is given by:
   | X^2 + (1-X^2) Cos(t),    XY(1-Cos(t))  +  Z Sin(t), XZ(1-Cos(t))-Y Sin(t) |
   M = | XY(1-Cos(t))-Z Sin(t), Y^2 + (1-Y^2) Cos(t),      YZ(1-Cos(t)) + X Sin(t) |
   | XZ(1-Cos(t)) + Y Sin(t), YZ(1-Cos(t))-X Sin(t),   Z^2 + (1-Z^2) Cos(t)    |
 
   Rotation about the three axes (Angles a1, a2, a3) can be represented as
   the product of the individual rotation matrices:
-
   | 1  0       0       | | Cos(a2) 0 -Sin(a2) | |  Cos(a3) Sin(a3) 0 |
   | 0  Cos(a1) Sin(a1) | * | 0       1  0       | * | -Sin(a3) Cos(a3) 0 |
   | 0 -Sin(a1) Cos(a1) | | Sin(a2) 0  Cos(a2) | |  0       0       1 |
@@ -5654,14 +5654,11 @@ function ConvertRotation(const Angles: TAffineVector): TGLVector;
   Z^2 + (1-Z^2) Cos(t) = M[2][2]
 
   Adding the three equations, we get:
-
   X^2  +  Y^2  +  Z^2 - (M[0][0]  +  M[1][1]  +  M[2][2]) =
   - (3 - X^2 - Y^2 - Z^2) Cos(t)
 
   Since (X^2  +  Y^2  +  Z^2) = 1, we can rewrite as:
-
   Cos(t) = (1 - (M[0][0]  +  M[1][1]  +  M[2][2])) / 2
-
   Solving for t, we get:
 
   t = Acos(((M[0][0]  +  M[1][1]  +  M[2][2]) - 1) / 2)
@@ -5669,11 +5666,10 @@ function ConvertRotation(const Angles: TAffineVector): TGLVector;
   We can substitute t into the equations for X^2, Y^2, and Z^2 above
   to get the values for X, Y, and Z.  To find the proper signs we note
   that:
-
   2 X Sin(t) = M[1][2] - M[2][1]
   2 Y Sin(t) = M[2][0] - M[0][2]
   2 Z Sin(t) = M[0][1] - M[1][0]
-}
+*)
 var
   Axis1, Axis2: TVector3f;
   M, m1, m2: TGLMatrix;
@@ -6655,7 +6651,7 @@ begin
   result := (u >= 0) and (V >= 0) and (u + V <= 1);
 end;
 
-{ ***************************************************************************** }
+//**********************************************************************
 
 function Vector2fMake(const X, Y: Single): TVector2f;
 begin
@@ -6687,7 +6683,7 @@ begin
   result.Y := Y;
 end;
 
-// **************
+//**********************************************************
 
 function Vector2fMake(const Vector: TVector3f): TVector2f;
 begin
@@ -6719,7 +6715,7 @@ begin
   result.Y := Vector.Y;
 end;
 
-// **********
+//*******************************************************
 
 function Vector2fMake(const Vector: TVector4f): TVector2f;
 begin
@@ -6751,7 +6747,7 @@ begin
   result.Y := Vector.Y;
 end;
 
-{ ***************************************************************************** }
+//***********************************************************************
 
 function Vector3fMake(const X, Y, Z: Single): TVector3f;
 begin
@@ -6858,7 +6854,7 @@ begin
   result.Z := Vector.Z;
 end;
 
-{ ***************************************************************************** }
+//***********************************************************************
 
 function Vector4fMake(const X, Y, Z, W: Single): TVector4f;
 begin
@@ -6985,7 +6981,7 @@ begin
   result.W := W;
 end;
 
-{ ***************************************************************************** }
+//***********************************************************************
 
 function VectorEquals(const Vector1, Vector2: TVector2f): Boolean;
 begin
@@ -7012,7 +7008,7 @@ begin
   result := (V1.X = V2.X) and (V1.Y = V2.Y);
 end;
 
-{ ***************************************************************************** }
+// ********************************************************************
 
 function VectorEquals(const V1, V2: TVector3i): Boolean;
 begin