fDuckyC.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fDuckyC.h"
  5. #include "GLS.ParametricSurfaces.hpp"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma link "GLS.FileNURBS"
  9. #pragma resource "*.dfm"
  10. TForm1 *Form1;
  11. int mx, my;
  12. //---------------------------------------------------------------------------
  13. __fastcall TForm1::TForm1(TComponent * Owner):TForm(Owner)
  14. {
  15. SetGLSceneMediaDir();
  16. // Load the nurbs data
  17. GLActor1->LoadFromFile("duck1.nurbs");
  18. GLActor1->AddDataFromFile("duck2.nurbs");
  19. GLActor1->AddDataFromFile("duck3.nurbs");
  20. // { Translate FreeForm based on the first mesh object's average
  21. // control point. Quick and dirty ... or maybe just dirty :P }
  22. TAffineVectorList *cp =
  23. ((TMOParametricSurface *) (GLActor1->MeshObjects->Items[0]))->ControlPoints;
  24. GLActor1->Position->Translate(VectorNegate(VectorScale(cp->Sum(),1.0/cp->Count)));
  25. }
  26. //---------------------------------------------------------------------------
  27. void __fastcall TForm1::GLSceneViewer1MouseDown(TObject * Sender,
  28. TMouseButton Button,
  29. TShiftState Shift, int X, int Y)
  30. {
  31. mx = X;
  32. my = Y;
  33. }
  34. //---------------------------------------------------------------------------
  35. void __fastcall TForm1::TrackBar1Change(TObject * Sender)
  36. {
  37. for(int i = 0; i < GLActor1->MeshObjects->Count; i++)
  38. ((TMOParametricSurface *) (GLActor1->MeshObjects->Items[i]))->
  39. Resolution = TrackBar1->Position;
  40. GLActor1->StructureChanged();
  41. }
  42. //---------------------------------------------------------------------------
  43. void __fastcall TForm1::CheckBox1Click(TObject * Sender)
  44. {
  45. if(CheckBox1->Checked)
  46. {
  47. GLActor1->Material->PolygonMode = pmLines;
  48. GLActor1->Material->FaceCulling = fcNoCull;
  49. }
  50. else
  51. {
  52. GLActor1->Material->PolygonMode = pmFill;
  53. GLActor1->Material->FaceCulling = fcBufferDefault;
  54. }
  55. }
  56. //---------------------------------------------------------------------------
  57. void __fastcall TForm1::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift,
  58. int X, int Y)
  59. {
  60. if(Shift.Contains(ssShift))
  61. {
  62. GLCamera1->MoveAroundTarget(my - Y, mx - X);
  63. mx = X;
  64. my = Y;
  65. }
  66. }
  67. //---------------------------------------------------------------------------