Unit1.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <tchar.h>
  4. #pragma hdrstop
  5. #include "Unit1.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma link "GLBaseClasses"
  9. #pragma link "GLCoordinates"
  10. #pragma link "GLCrossPlatform"
  11. #pragma link "GLGeomObjects"
  12. #pragma link "GLObjects"
  13. #pragma link "GLScene"
  14. #pragma link "GLWin32Viewer"
  15. #pragma resource "*.dfm"
  16. TForm1 *Form1;
  17. //---------------------------------------------------------------------------
  18. __fastcall TForm1::TForm1(TComponent* Owner)
  19. : TForm(Owner)
  20. {
  21. }
  22. //---------------------------------------------------------------------------
  23. void __fastcall TForm1::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift,
  24. int X, int Y)
  25. {
  26. TIPickTimer->Enabled = true;
  27. }
  28. //---------------------------------------------------------------------------
  29. void __fastcall TForm1::TIPickTimerTimer(TObject *Sender)
  30. {
  31. TPoint cp;
  32. // get what is under the mouse
  33. GetCursorPos(&cp);
  34. cp = GLSceneViewer1->ScreenToClient(cp);
  35. currentPick = (TGLCustomSceneObject *) (GLSceneViewer1->Buffer->GetPickedObject(cp.X, cp.Y));
  36. TIPickTimer->Enabled = false;
  37. }
  38. //---------------------------------------------------------------------------
  39. void __fastcall TForm1::GLSceneViewer1MouseDown(TObject *Sender, TMouseButton Button,
  40. TShiftState Shift, int X, int Y)
  41. {
  42. TGLCustomSceneObject *pick;
  43. // if an object is picked...
  44. pick = (TGLCustomSceneObject *) (GLSceneViewer1->Buffer->GetPickedObject(X, Y));
  45. if (pick)
  46. {
  47. // ...turn it to yellow and show its name
  48. pick->Material->FrontProperties->Emission->Color = clrYellow;
  49. ShowMessage("You clicked the "+pick->Name);
  50. }
  51. }
  52. //---------------------------------------------------------------------------
  53. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  54. {
  55. // trigger progression (we don't use time in this sample)
  56. GLScene1->Progress(0, 0);
  57. }
  58. //---------------------------------------------------------------------------
  59. void __fastcall TForm1::SphereProgress(TObject *Sender, const double deltaTime, const double newTime)
  60. {
  61. TColorVector targetColor;
  62. // with Sender as TGLCustomSceneObject do begin
  63. // if we are picked, target color is red, else it is black (no emission)
  64. if (Sender=currentPick)
  65. targetColor = clrRed;
  66. else
  67. targetColor = clrBlack;
  68. // Set new color at 66% between current and target color
  69. Sphere->Material->FrontProperties->Emission->
  70. Color = VectorLerp(targetColor, Sphere->Material->FrontProperties->Emission->
  71. Color, 0.66);
  72. }
  73. //---------------------------------------------------------------------------