fDuckyC.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. TFileName Path = GetCurrentAssetPath();
  16. SetCurrentDir(Path + "\\model");
  17. // Load the nurbs data
  18. GLActor1->LoadFromFile("duck1.nurbs");
  19. GLActor1->AddDataFromFile("duck2.nurbs");
  20. GLActor1->AddDataFromFile("duck3.nurbs");
  21. // { Translate FreeForm based on the first mesh object's average
  22. // control point. Quick and dirty ... or maybe just dirty :P }
  23. TGLAffineVectorList *cp =
  24. ((TMOParametricSurface *) (GLActor1->MeshObjects->Items[0]))->ControlPoints;
  25. GLActor1->Position->Translate(VectorNegate(VectorScale(cp->Sum(),1.0/cp->Count)));
  26. }
  27. //---------------------------------------------------------------------------
  28. void __fastcall TForm1::GLSceneViewer1MouseDown(TObject * Sender,
  29. TMouseButton Button,
  30. TShiftState Shift, int X, int Y)
  31. {
  32. mx = X;
  33. my = Y;
  34. }
  35. //---------------------------------------------------------------------------
  36. void __fastcall TForm1::TrackBar1Change(TObject * Sender)
  37. {
  38. for(int i = 0; i < GLActor1->MeshObjects->Count; i++)
  39. ((TMOParametricSurface *) (GLActor1->MeshObjects->Items[i]))->
  40. Resolution = TrackBar1->Position;
  41. GLActor1->StructureChanged();
  42. }
  43. //---------------------------------------------------------------------------
  44. void __fastcall TForm1::CheckBox1Click(TObject * Sender)
  45. {
  46. if(CheckBox1->Checked)
  47. {
  48. GLActor1->Material->PolygonMode = pmLines;
  49. GLActor1->Material->FaceCulling = fcNoCull;
  50. }
  51. else
  52. {
  53. GLActor1->Material->PolygonMode = pmFill;
  54. GLActor1->Material->FaceCulling = fcBufferDefault;
  55. }
  56. }
  57. //---------------------------------------------------------------------------
  58. void __fastcall TForm1::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift,
  59. int X, int Y)
  60. {
  61. if(Shift.Contains(ssShift))
  62. {
  63. GLCamera1->MoveAroundTarget(my - Y, mx - X);
  64. mx = X;
  65. my = Y;
  66. }
  67. }
  68. //---------------------------------------------------------------------------