Shape.cpp
上传用户:gb3593
上传日期:2022-01-07
资源大小:3028k
文件大小:3k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. #pragma once
  2. #include "stdafx.h"
  3. #include "Vector.cpp"
  4. #include "Matrix.cpp"
  5. #include "ShapeType.cpp"
  6. #include "XForm.cpp"
  7. using namespace System::Collections::Generic;
  8. namespace Box2D
  9. {
  10. namespace Net
  11. {
  12. ref class Body;
  13. public ref class Shape
  14. {
  15. internal:
  16. b2Shape *shape;
  17. Shape(b2Shape *shapeRef) : shape(shapeRef) { }
  18. public:
  19. bool TestPoint(XForm^ xf, Vector^ p)
  20. {
  21. return shape->TestPoint(xf->getXForm(), p->getVec2());
  22. }
  23. property ShapeType ShapeType
  24. {
  25. Box2D::Net::ShapeType get()
  26. {
  27. return (Box2D::Net::ShapeType)shape->GetType();
  28. }
  29. }
  30. /// <summary>
  31. /// Get the parent body of this shape.
  32. /// </summary>
  33. property Body^ Body
  34. {
  35. Box2D::Net::Body^ get();
  36. }
  37. /*
  38. /// <summary>
  39. /// Get the world position.
  40. /// </summary>
  41. property Vector^ Position
  42. {
  43. Vector^ get()
  44. {
  45. return gcnew Vector(shape->Get->GetPosition());
  46. }
  47. }
  48. */
  49. /*
  50. property Matrix^ Rotation
  51. {
  52. Matrix^ get()
  53. {
  54. return gcnew Matrix(shape->GetRotationMatrix());
  55. }
  56. }
  57. */
  58. //TODO:
  59. //void* GetUserData();
  60. //
  61. // Remove and then add proxy from the broad-phase.
  62. // This is used to refresh the collision filters.
  63. //virtual void ResetProxy(b2BroadPhase* broadPhase) = 0;
  64. /// <summary>
  65. /// Get the next shape in the parent body's shape list.
  66. /// </summary>
  67. Shape^ GetNext()
  68. {
  69. return gcnew Shape(shape->GetNext());
  70. }
  71. };
  72. public ref class CircleShape : public Shape
  73. {
  74. internal:
  75. b2CircleShape *circleShape;
  76. CircleShape(b2CircleShape *shapeRef) : Shape(shapeRef), circleShape(shapeRef) { }
  77. public:
  78. CircleShape(Shape^ shape) : Shape(shape->shape), circleShape(0)
  79. {
  80. if(shape->ShapeType == Box2D::Net::ShapeType::e_circleShape &&
  81. reinterpret_cast<b2CircleShape *>(shape->shape))
  82. {
  83. circleShape = reinterpret_cast<b2CircleShape*>(shape->shape);
  84. }
  85. else
  86. {
  87. throw gcnew System::Exception("Attempting to convert a Shape to a CircleShape,"
  88.   "but the Shape is not a circle shape.");
  89. }
  90. }
  91. //TODO: this is not technically part of the "public" interface for CircleShape
  92. property float32 Radius
  93. {
  94. float32 get()
  95. {
  96. return circleShape->m_radius;
  97. }
  98. void set(float32 value)
  99. {
  100. circleShape->m_radius = value;
  101. }
  102. }
  103. };
  104. public ref class PolyShape : public Shape
  105. {
  106. internal:
  107. b2PolygonShape *polyShape;
  108. PolyShape(b2PolygonShape *shapeRef) : Shape(shapeRef), polyShape(shapeRef) { }
  109. public:
  110. PolyShape(Shape^ shape) : Shape(shape->shape), polyShape(0)
  111. {
  112. if(shape->ShapeType == Box2D::Net::ShapeType::e_polygonShape &&
  113. reinterpret_cast<b2PolygonShape *>(shape->shape))
  114. {
  115. polyShape = reinterpret_cast<b2PolygonShape*>(shape->shape);
  116. }
  117. else
  118. {
  119. throw gcnew System::Exception("Attempting to convert a Shape to a PolyShape,"
  120.   "but the Shape is not a poly shape.");
  121. }
  122. }
  123. property IList<Vector^>^ Vertices
  124. {
  125. IList<Vector^>^ get()
  126. {
  127. List<Vector^>^ list = gcnew List<Vector^>();
  128. for(int x = 0; x < polyShape->m_vertexCount; ++x)
  129. list->Add(gcnew Vector(polyShape->m_vertices[x]));
  130. return list;
  131. }
  132. }
  133. };
  134. }
  135. }