Unit1.cpp 2.5 KB

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