2
0

Unit1.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "GLBaseClasses"
  8. #pragma link "GLCadencer"
  9. #pragma link "GLCoordinates"
  10. #pragma link "GLCrossPlatform"
  11. #pragma link "GLObjects"
  12. #pragma link "GLScene"
  13. #pragma link "GLSimpleNavigation"
  14. #pragma link "GLWin32Viewer"
  15. #pragma resource "*.dfm"
  16. TForm1 *Form1;
  17. //---------------------------------------------------------------------------
  18. __fastcall TForm1::TForm1(TComponent* Owner)
  19. : TForm(Owner)
  20. {
  21. }
  22. const int
  23. cSize = 5;
  24. //---------------------------------------------------------------------------
  25. void __fastcall TForm1::FormCreate(TObject *Sender)
  26. {
  27. int x, y, z;
  28. TGLCube *cube;
  29. float factor, cubeSize;
  30. // bench only creation and 1st render (with lists builds, etc...)
  31. factor = 70 / (cSize * 2 + 1);
  32. cubeSize = 0.4 * factor;
  33. for (x = -cSize; x< cSize; x++)
  34. for (y = -cSize; y< cSize; y++)
  35. for (z = -cSize; z< cSize; z++)
  36. {
  37. cube = (TGLCube *) (DummyCube1->AddNewChild(__classid(TGLCube)));
  38. cube->Position->AsVector = PointMake(factor * x, factor * y, factor * z);
  39. cube->CubeWidth = cubeSize;
  40. cube->CubeHeight = cubeSize;
  41. cube->CubeDepth = cubeSize;
  42. cube->Material->FrontProperties->Diffuse->Color =
  43. VectorLerp(clrYellow, clrRed, (float)(x * x + y * y + z * z)/(cSize * cSize * 3));
  44. // uncomment following lines to stress OpenGL with more color changes calls
  45. //cube->Material->FrontProperties->Ambient->Color=VectorLerp(clrYellow, clrRed, (x*x+y*y+z*z)/(cSize*cSize*3));
  46. //cube->Material->FrontProperties->Emission->Color=VectorLerp(clrYellow, clrRed, (x*x+y*y+z*z)/(cSize*cSize*3));
  47. //cube->Material->FrontProperties->Specular->Color=VectorLerp(clrYellow, clrRed, (x*x+y*y+z*z)/(cSize*cSize*3));
  48. }
  49. }
  50. //---------------------------------------------------------------------------
  51. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  52. const double newTime)
  53. {
  54. DummyCube1->TurnAngle = 90 * newTime; // 90° per second
  55. }
  56. //---------------------------------------------------------------------------