ezEngine  Milestone 7
GeomUtils.h
1 #pragma once
2 
3 #include <CoreUtils/Basics.h>
4 #include <Foundation/Math/Vec3.h>
5 #include <Foundation/Math/Mat4.h>
6 #include <Foundation/Math/Color.h>
7 #include <Foundation/Containers/HybridArray.h>
8 #include <Foundation/Containers/Deque.h>
9 
16 class EZ_COREUTILS_DLL ezGeometry
17 {
18 public:
19 
21  struct Vertex
22  {
24 
25  ezVec3 m_vPosition;
26  ezVec3 m_vNormal;
27  ezVec2 m_vTexCoord;
28  ezColor m_Color;
29  ezInt32 m_iCustomIndex;
30  };
31 
33  struct Polygon
34  {
35  ezVec3 m_vNormal;
36  ezHybridArray<ezUInt32, 4> m_Vertices;
37  };
38 
40  struct Line
41  {
43 
44  ezUInt32 m_uiStartVertex;
45  ezUInt32 m_uiEndVertex;
46  };
47 
49  const ezDeque<Vertex>& GetVertices() const { return m_Vertices; }
50 
52  const ezDeque<Polygon>& GetPolygons() const { return m_Polygons; }
53 
55  const ezDeque<Line>& GetLines() const { return m_Lines; }
56 
58  void Clear();
59 
61  ezUInt32 AddVertex(const ezVec3& vPos, const ezVec3& vNormal, const ezVec2& vTexCoord, const ezColor& color, ezInt32 iCustomIndex = 0);
62 
64  ezUInt32 AddVertex(const ezVec3& vPos, const ezVec3& vNormal, const ezVec2& vTexCoord, const ezColor& color, ezInt32 iCustomIndex, const ezMat4& mTransform);
65 
67  void AddPolygon(const ezArrayPtr<ezUInt32>& Vertices);
68 
70  void AddLine(ezUInt32 uiStartVertex, ezUInt32 uiEndVertex);
71 
73  void ComputeFaceNormals();
74 
79  void ComputeSmoothVertexNormals();
80 
82  void SetAllVertexCustomIndex(ezInt32 iCustomIndex, ezUInt32 uiFirstVertex = 0);
83 
85  void SetAllVertexColor(const ezColor& color, ezUInt32 uiFirstVertex = 0);
86 
91  void Transform(const ezMat4& mTransform, bool bTransformPolyNormals);
92 
94  void Merge(const ezGeometry& other);
95 
98  void AddRectXY(const ezVec2& size, const ezColor& color, const ezMat4& mTransform = ezMat4::IdentityMatrix(), ezInt32 iCustomIndex = 0);
99 
101  void AddBox(const ezVec3& size, const ezColor& color, const ezMat4& mTransform = ezMat4::IdentityMatrix(), ezInt32 iCustomIndex = 0);
102 
104  void AddTexturedBox(const ezVec3& size, const ezColor& color, const ezMat4& mTransform = ezMat4::IdentityMatrix(), ezInt32 iCustomIndex = 0);
105 
109  void AddPyramid(const ezVec3& size, bool bCap, const ezColor& color, const ezMat4& mTransform = ezMat4::IdentityMatrix(), ezInt32 iCustomIndex = 0);
110 
121  void AddGeodesicSphere(float fRadius, ezUInt8 uiSubDivisions, const ezColor& color, const ezMat4& mTransform = ezMat4::IdentityMatrix(), ezInt32 iCustomIndex = 0);
122 
128  void AddCylinder(float fRadiusTop, float fRadiusBottom, float fHeight, bool bCapTop, bool bCapBottom, ezUInt16 uiSegments, const ezColor& color, const ezMat4& mTransform = ezMat4::IdentityMatrix(), ezInt32 iCustomIndex = 0, ezAngle fraction = ezAngle::Degree(360.0f));
129 
133  void AddCone(float fRadius, float fHeight, bool bCap, ezUInt16 uiSegments, const ezColor& color, const ezMat4& mTransform = ezMat4::IdentityMatrix(), ezInt32 iCustomIndex = 0);
134 
139  void AddSphere(float fRadius, ezUInt16 uiSegments, ezUInt16 uiStacks, const ezColor& color, const ezMat4& mTransform = ezMat4::IdentityMatrix(), ezInt32 iCustomIndex = 0);
140 
146  void AddHalfSphere(float fRadius, ezUInt16 uiSegments, ezUInt16 uiStacks, bool bCap, const ezColor& color, const ezMat4& mTransform = ezMat4::IdentityMatrix(), ezInt32 iCustomIndex = 0);
147 
154  void AddCapsule(float fRadius, float fHeight, ezUInt16 uiSegments, ezUInt16 uiStacks, const ezColor& color, const ezMat4& mTransform = ezMat4::IdentityMatrix(), ezInt32 iCustomIndex = 0);
155 
163  void AddTorus(float fInnerRadius, float fOuterRadius, ezUInt16 uiSegments, ezUInt16 uiSegmentDetail, const ezColor& color, const ezMat4& mTransform = ezMat4::IdentityMatrix(), ezInt32 iCustomIndex = 0);
164 
166  // ThickLine
167  // Part of a Torus
168  // Arc
169  // Arch
170  // Circle
171  // Curved cone (spotlight)
172  // flat arc / circle (ie. UE4 gizmo)
173  // ....
174 
175  // Compounds:
176  // Arrow
177  // Cross ?
178  //
179 
180 
181 private:
182  void TransformVertices(const ezMat4& mTransform, ezUInt32 uiFirstVertex);
183 
184  ezDeque<Vertex> m_Vertices;
185  ezDeque<Polygon> m_Polygons;
186  ezDeque<Line> m_Lines;
187 };
188