fFeedbackC.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fFeedbackC.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "GLS.BaseClasses"
  8. #pragma link "GLS.Coordinates"
  9. #pragma link "GLS.Feedback"
  10. #pragma link "GLS.Objects"
  11. #pragma link "GLS.GeomObjects"
  12. #pragma link "GLS.Scene"
  13. #pragma link "GLS.VectorFileObjects"
  14. #pragma link "GLS.SceneViewer"
  15. #pragma link "GLS.Mesh"
  16. #pragma link "GLS.Feedback"
  17. #pragma resource "*.dfm"
  18. TForm1 *Form1;
  19. //---------------------------------------------------------------------------
  20. __fastcall TForm1::TForm1(TComponent* Owner)
  21. : TForm(Owner)
  22. {
  23. }
  24. //---------------------------------------------------------------------------
  25. void __fastcall TForm1::Button1Click(TObject *Sender)
  26. {
  27. TMeshObject *mo;
  28. TFGIndexTexCoordList *fg;
  29. // Clear our freeform of any meshes
  30. GLFreeForm1->MeshObjects->Clear();
  31. // Set feedback to active, will feedback render child
  32. // objects into it's buffer
  33. GLFeedback1->Active = true;
  34. // Process the first mesh object (GLCube and GLDodecahedron)
  35. // Make the objects visible that we want to buffer
  36. MeshObject1->Visible = true;
  37. // Render the feedback object to buffer it's child object
  38. // that are visible
  39. GLSceneViewer1->Buffer->Render(GLFeedback1);
  40. // Hide the child objects we rendered
  41. MeshObject1->Visible = false;
  42. // Create a new mesh object in our freeform
  43. // Delphi - mo := TMeshObject.CreateOwned(GLFreeForm1.MeshObjects);
  44. mo = new TMeshObject;
  45. mo = (TMeshObject *) (GLFreeForm1->MeshObjects);
  46. mo->Mode = momTriangles;
  47. // Process the feedback buffer for polygon data
  48. // and build a mesh (normals are recalculated
  49. // since feedback only yields position and
  50. // texcoords)
  51. GLFeedback1->BuildMeshFromBuffer(
  52. mo->Vertices, mo->Normals, mo->Colors, mo->TexCoords, NULL);
  53. // Process the second mesh object (GLSphere)
  54. // (comments from first mesh object apply here also)
  55. MeshObject2->Visible = true;
  56. GLSceneViewer1->Buffer->Render(GLFeedback1);
  57. MeshObject2->Visible = false;
  58. // Vertex indices are required for smooth normals
  59. // Delphi - mo := TMeshObject.CreateOwned(GLFreeForm1.MeshObjects);
  60. GLFreeForm1->MeshObjects->Add(Mesh);
  61. mo = new TMeshObject;
  62. mo = GLFreeForm1->MeshObjects->Items[0];
  63. mo->Mode = momFaceGroups;
  64. //Delphi - fg := TFGIndexTexCoordList.CreateOwned(mo.FaceGroups);
  65. fg = new TFGIndexTexCoordList;
  66. fg->Mode = fgmmTriangles;
  67. GLS.Feedback1->BuildMeshFromBuffer(
  68. mo->Vertices, mo->Normals, NULL, fg->TexCoords, fg->VertexIndices);
  69. // Deactivate the feedback object
  70. GLS.Feedback1->Active = false;
  71. GLFreeForm1->StructureChanged();
  72. }
  73. //---------------------------------------------------------------------------
  74. void __fastcall TForm1::GLSceneViewer1MouseDown(TObject *Sender, TMouseButton Button,
  75. TShiftState Shift, int X, int Y)
  76. {
  77. mx = X;
  78. my = Y;
  79. }
  80. //---------------------------------------------------------------------------
  81. void __fastcall TForm1::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift,
  82. int X, int Y)
  83. {
  84. if (Shift.Contains(ssLeft))
  85. GLCamera1->MoveAroundTarget(my - Y, mx - X);
  86. mx = X;
  87. my = Y;
  88. }
  89. //---------------------------------------------------------------------------