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

游戏引擎

开发平台:

Visual C++

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