1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #pragma once19 20 #include "../MathGeoLibFwd.h"21 #include "../Math/float3.h"22 23 [MATH_BEGIN_NAMESPACE]24 25 26 27 class [Triangle]28 {29 public:30 31 vec [a];32 33 34 vec [b];35 36 37 38 39 40 vec [c];41 42 43 44 45 46 [Triangle]() {}47 48 49 50 51 52 [Triangle](const vec &[a], const vec &[b], const vec &[c]);53 54 [FORCE_INLINE] static int [NumFaces]() { return 1; }55 [FORCE_INLINE] static int [NumEdges]() { return 3; }56 [FORCE_INLINE] static int [NumVertices]() { return 3; }57 58 59 60 61 void [Translate](const vec &offset);62 63 64 65 void [Transform](const [float3x3] &transform);66 void [Transform](const [float3x4] &transform);67 void [Transform](const [float4x4] &transform);68 void [Transform](const [Quat] &transform);69 70 71 72 73 74 75 76 77 78 79 [float3] [BarycentricUVW](const vec &point) const;80 81 82 83 84 85 86 87 88 89 90 [float2] [BarycentricUV](const vec &point) const;91 92 93 94 95 96 97 98 99 static bool [BarycentricInsideTriangle](const [float3] &uvw);100 101 102 103 104 105 106 vec [Point](const [float3] &uvw) const;107 vec [Point](float u, float v, float w) const;108 109 110 111 112 113 114 115 vec [Point](const [float2] &uv) const;116 vec [Point](float u, float v) const;117 118 119 120 vec [Centroid]() const;121 122 123 vec [CenterPoint]() const { return [Centroid](); }124 125 126 127 128 float [Area]() const;129 130 131 132 133 float [Perimeter]() const;134 135 136 vec *[VertexArrayPtr]() { return &[a]; }137 const vec *[VertexArrayPtr]() const { return &[a]; }138 139 140 141 142 143 144 vec [Vertex](int i) const;145 vec [CornerPoint](int i) const { return [Vertex](i); } 146 147 148 149 150 151 152 153 [LineSegment] [Edge](int i) const;154 155 156 157 158 [Plane] [PlaneCCW]() const;159 160 161 162 163 164 [Plane] [PlaneCW]() const;165 166 167 168 169 170 vec [NormalCCW]() const;171 172 173 174 175 176 vec [NormalCW]() const;177 178 179 vec [UnnormalizedNormalCCW]() const;180 181 182 183 184 185 vec [UnnormalizedNormalCW]() const;186 187 188 inline vec [AnyPointFast]() const { return [a]; }189 190 191 192 193 194 195 196 197 198 vec [ExtremePoint](const vec &direction) const;199 vec [ExtremePoint](const vec &direction, float &projectionDistance) const;200 201 202 203 204 205 [Polygon] [ToPolygon]() const;206 207 208 209 210 211 212 [Polyhedron] [ToPolyhedron]() const;213 214 215 [AABB] [BoundingAABB]() const;216 217 218 219 220 221 static float [Area2D](const [float2] &p1, const [float2] &p2, const [float2] &p3);222 223 224 225 226 227 228 static float [SignedArea](const vec &point, const vec &[a], const vec &[b], const vec &[c]);229 230 231 232 233 234 235 bool [IsFinite]() const;236 237 238 239 240 241 242 243 bool [IsDegenerate](float [epsilon] = 1[e]-3f) const;244 245 246 static bool [IsDegenerate](const vec &p1, const vec &p2, const vec &p3, float [epsilon] = 1[e]-3f);247 248 249 250 251 252 253 bool [Contains](const vec &point, float triangleThicknessSq = 1[e]-5f) const;254 bool [Contains](const [LineSegment] &lineSegment, float triangleThickness = 1[e]-3f) const;255 bool [Contains](const [Triangle] &triangle, float triangleThickness = 1[e]-3f) const;256 257 258 259 260 261 262 float [Distance](const vec &point) const;263 float [Distance](const [Sphere] &sphere) const;264 float [Distance](const [Capsule] &capsule) const;265 266 float [DistanceSq](const vec &point) const;267 268 269 270 271 272 273 274 275 276 277 278 279 bool [Intersects](const [LineSegment] &lineSegment, float *[d] = 0, vec *intersectionPoint = 0) const;280 bool [Intersects](const [Line] &line, float *[d] = 0, vec *intersectionPoint = 0) const;281 bool [Intersects](const [Ray] &ray, float *[d] = 0, vec *intersectionPoint = 0) const;282 bool [Intersects](const [Plane] &plane) const;283 284 285 286 bool [Intersects](const [Sphere] &sphere, vec *closestPointOnTriangle) const;287 bool [Intersects](const [Sphere] &sphere) const;288 289 290 291 bool [Intersects](const [Triangle] &triangle, [LineSegment] *outLine = 0) const;292 bool [Intersects](const [AABB] &aabb) const;293 bool [Intersects](const [OBB] &obb) const;294 bool [Intersects](const [Polygon] &polygon) const;295 bool [Intersects](const [Frustum] &frustum) const;296 bool [Intersects](const [Polyhedron] &polyhedron) const;297 bool [Intersects](const [Capsule] &capsule) const;298 299 300 static float [IntersectLineTri](const vec &linePos, const vec &lineDir,301 const vec &v0, const vec &v1, const vec &v2,302 float &u, float &v);303 304 305 306 307 308 309 310 void [ProjectToAxis](const vec &axis, float &dMin, float &dMax) const;311 312 int [UniqueFaceNormals](vec *out) const;313 int [UniqueEdgeDirections](vec *out) const;314 315 316 317 318 319 vec [ClosestPoint](const vec &point) const;320 321 322 vec [ClosestPoint](const [LineSegment] &lineSegment, vec *otherPt = 0) const;323 324 325 326 327 328 329 330 331 vec [ClosestPoint](const [Line] &line, vec *otherPt = 0) const;332 vec [ClosestPoint](const [Triangle] &triangle, vec *otherPt = 0) const;333 334 335 336 337 338 339 340 341 342 343 vec [ClosestPointToTriangleEdge](const [Line] &line, float *outU, float *outV, float *outD) const;344 vec [ClosestPointToTriangleEdge](const [LineSegment] &lineSegment, float *outU, float *outV, float *outD) const;345 346 347 348 349 350 351 352 353 vec [RandomPointInside]([LCG] &rng) const;354 355 356 357 358 359 vec [RandomVertex]([LCG] &rng) const;360 361 362 363 364 365 366 367 vec [RandomPointOnEdge]([LCG] &rng) const;368 369 #ifdef MATH_ENABLE_STL_SUPPORT370 371 std::string [ToString]() const;372 std::string [SerializeToString]() const;373 374 375 std::string [SerializeToCodeString]() const;376 #endif377 378 static [Triangle] [FromString](const char *str, const char **outEndStr = 0);379 #ifdef MATH_ENABLE_STL_SUPPORT380 static [Triangle] [FromString](const std::string &str) { return [FromString](str.c_str()); }381 #endif382 383 #ifdef MATH_QT_INTEROP384 operator QString() const { return toString(); }385 QString toString() const { return QString::fromStdString([ToString]()); }386 #endif387 388 bool [Equals](const [Triangle] &rhs, float [epsilon] = 1[e]-3f) const { return [a].[Equals](rhs.[a], [epsilon]) && [b].[Equals](rhs.[b], [epsilon]) && [c].[Equals](rhs.[c], [epsilon]); }389 390 391 392 bool [BitEquals](const [Triangle] &other) const { return [a].[BitEquals](other.[a]) && [b].[BitEquals](other.[b]) && [c].[BitEquals](other.[c]); }393 };394 395 [Triangle] [operator *](const [float3x3] &transform, const [Triangle] &t);396 [Triangle] [operator *](const [float3x4] &transform, const [Triangle] &t);397 [Triangle] [operator *](const [float4x4] &transform, const [Triangle] &t);398 [Triangle] [operator *](const [Quat] &transform, const [Triangle] &t);399 400 struct [Triangle_storage]401 {402 [vec_storage] [v0], [v1], [v2];403 [Triangle_storage](const [Triangle] &rhs)404 {405 *reinterpret_cast<[Triangle]*>(this) = rhs;406 }407 operator [Triangle]() const { return *reinterpret_cast<const [Triangle]*>(this); }408 };409 #define TRIANGLE(x) (*(Triangle*)&x)410 411 #ifdef MATH_QT_INTEROP412 Q_DECLARE_METATYPE([Triangle])413 Q_DECLARE_METATYPE([Triangle]*)414 #endif415 416 #ifdef MATH_ENABLE_STL_SUPPORT417 std::ostream &[operator <<](std::ostream &o, const [Triangle] &triangle);418 #endif419 420 bool [LineSegment2DLineSegment2DIntersect](const [float2] &p0, const [float2] &dir0, const [float2] &p1, const [float2] &dir1, float &s, float &t);421 422 [MATH_END_NAMESPACE] Go back to previous page