fPickC.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <tchar.h>
  4. #pragma hdrstop
  5. #include "fPickC.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma link "GLS.BaseClasses"
  9. #pragma link "GLS.Coordinates"
  10. #pragma link "GLS.GeomObjects"
  11. #pragma link "GLS.Objects"
  12. #pragma link "GLS.Scene"
  13. #pragma link "GLS.SceneViewer"
  14. #pragma resource "*.dfm"
  15. TForm1 *Form1;
  16. //---------------------------------------------------------------------------
  17. __fastcall TForm1::TForm1(TComponent* Owner)
  18. : TForm(Owner)
  19. {
  20. }
  21. //---------------------------------------------------------------------------
  22. void __fastcall TForm1::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift,
  23. int X, int Y)
  24. {
  25. TGLCustomSceneObject *pick;
  26. // find what's under the mouse
  27. pick = (TGLCustomSceneObject *) GLSceneViewer1->Buffer->GetPickedObject(X, Y);
  28. // if it has changed since last MouseMove...
  29. if (pick != oldPick)
  30. {
  31. // ...turn to black previous "hot" object...
  32. if (oldPick)
  33. oldPick->Material->FrontProperties->Emission->Color = clrBlack;
  34. // ...and heat up the new selection...
  35. if (pick)
  36. pick->Material->FrontProperties->Emission->Color = clrRed;
  37. // ...and don't forget it !
  38. oldPick = pick;
  39. }
  40. }
  41. //---------------------------------------------------------------------------
  42. void __fastcall TForm1::GLSceneViewer1MouseDown(TObject *Sender, TMouseButton Button,
  43. TShiftState Shift, int X, int Y)
  44. {
  45. TGLCustomSceneObject *pick;
  46. // if an object is picked...
  47. pick = (TGLCustomSceneObject *) GLSceneViewer1->Buffer->GetPickedObject(X, Y);
  48. if (pick)
  49. // ...turn it to yellow and show its name
  50. pick->Material->FrontProperties->Emission->Color = clrYellow;
  51. ShowMessage("You clicked the "+pick->Name);
  52. }
  53. //---------------------------------------------------------------------------