Unit1.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "GLBitmapFont"
  8. #pragma link "GLCoordinates"
  9. #pragma link "GLCrossPlatform"
  10. #pragma link "GLHUDObjects"
  11. #pragma link "GLMaterial"
  12. #pragma link "GLObjects"
  13. #pragma link "GLScene"
  14. #pragma link "GLUserShader"
  15. #pragma link "GLVectorFileObjects"
  16. #pragma link "GLWin32Viewer"
  17. #pragma link "GLWindowsFont"
  18. #pragma resource "*.dfm"
  19. TForm1 *Form1;
  20. //---------------------------------------------------------------------------
  21. __fastcall TForm1::TForm1(TComponent* Owner)
  22. : TForm(Owner)
  23. {
  24. }
  25. //---------------------------------------------------------------------------
  26. void __fastcall TForm1::FormCreate(TObject *Sender)
  27. {
  28. TMeshObject *mo;
  29. TFGVertexIndexList *fgQuads, *fgTris;
  30. int i;
  31. TFileStream *str;
  32. // load our raw data
  33. str = new TFileStream("IntensityMesh.data", fmOpenRead);
  34. str->Read(0, 4);
  35. //-System::AnsiString::SetLength(DataNodes, i);
  36. str->Read(0, 4);
  37. /*
  38. Ex:
  39. DynamicArray<int> arrayOfInt;
  40. arrayOfInt.Length = 10;
  41. cout << "ArrayLength: " << arrayOfInt.Length << endl;
  42. SetLength(arrayOfInt, 10);
  43. */
  44. //-SetLength(DataPrimitives, i);
  45. //-str->Read(DataNodes[0], Length(DataNodes)*SizeOf(TDataNode));
  46. //-str->Read(DataPrimitives[0], Length(DataPrimitives)*SizeOf(TDataPrimitive));
  47. str->Free();
  48. // fill the freeform with our data
  49. // first create a mesh object
  50. mo = new TMeshObject(); //Delphi - mo = TMeshObject.CreateOwned(GLFreeForm.MeshObjects);
  51. mo = (TMeshObject *) (GLFreeForm->MeshObjects);
  52. mo->Mode = momFaceGroups;
  53. // Specify vertex and texcoords data (intensity is stored a texcoord)
  54. /*
  55. Ex:
  56. int TotalArray(const DynamicArray<int>& arrayOfInt)
  57. {
  58. int total=0;
  59. for (int i=arrayOfInt.Low; i<=arrayOfInt.High; i++)
  60. total += arrayOfInt[i];
  61. return total;
  62. }
  63. */
  64. //--------------------------------
  65. /*
  66. for (i=0; i<High(DataNodes);i++)
  67. {
  68. mo->Vertices->Add(DataNodes[i]->X, DataNodes[i]->Y, DataNodes[i]->Z);
  69. mo->TexCoords->Add(DataNodes[i]->Intensity*0.001, 0);
  70. }
  71. // Then create the facegroups that will hold our quads and triangles
  72. fgQuads = TFGVertexIndexList.CreateOwned(mo.FaceGroups);
  73. fgQuads->Mode = fgmmQuads;
  74. fgTris = TFGVertexIndexList.CreateOwned(mo.FaceGroups);
  75. fgTris->Mode = fgmmTriangles;
  76. // and fill them with our primitives
  77. for (i=1; i < High(DataPrimitives);i++)
  78. with DataPrimitives[i]-> do
  79. {
  80. if (Node4<>$FFFF)
  81. {
  82. fgQuads.VertexIndices.Add(Node1, Node2);
  83. fgQuads.VertexIndices.Add(Node4, Node3);
  84. }
  85. else
  86. fgTris->VertexIndices->Add(Node1, Node2, Node3);
  87. }
  88. */
  89. // auto center
  90. GLFreeForm->PerformAutoCentering();
  91. // and initialize scale
  92. TBScaleChange(this);
  93. }
  94. //---------------------------------------------------------------------------
  95. void __fastcall TForm1::GLSceneViewer1MouseDown(TObject *Sender, TMouseButton Button,
  96. TShiftState Shift, int X, int Y)
  97. {
  98. mx=X; my=Y;
  99. GLSceneViewer1->SetFocus();
  100. }
  101. //---------------------------------------------------------------------------
  102. void __fastcall TForm1::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift,
  103. int X, int Y)
  104. {
  105. if (Shift.Contains(ssLeft))
  106. GLCamera->MoveAroundTarget(my-Y, mx-X);
  107. if (Shift.Contains(ssRight)) {
  108. DCTarget->Position->AddScaledVector((mx-X)/30, GLCamera->AbsoluteRightVectorToTarget());
  109. DCTarget->Position->AddScaledVector((Y-my)/30, GLCamera->AbsoluteUpVectorToTarget());
  110. }
  111. mx=X; my=Y;
  112. }
  113. //---------------------------------------------------------------------------
  114. void __fastcall TForm1::TBScaleChange(TObject *Sender)
  115. {
  116. GLMaterialLibrary1->Materials->Items[0]->TextureScale->X = (float)TBScale->Position/100;
  117. HTPaletteRight->Text = FormatFloat("%d", (TBScale->Position*10));
  118. GLSceneViewer1->Invalidate();
  119. }
  120. //---------------------------------------------------------------------------