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 #ifdef MATH_URHO3D_INTEROP24 #include <Urho3D/Math/Sphere.h>25 #endif26 27 [MATH_BEGIN_NAMESPACE]28 29 30 class [Sphere]31 {32 public:33 34 vec [pos];35 36 37 float [r];38 39 40 41 42 43 [Sphere]() {}44 45 46 47 48 [Sphere](const vec ¢er, float radius);49 50 51 52 53 54 [Sphere](const vec &pointA, const vec &pointB);55 56 57 58 [Sphere](const vec &pointA, const vec &pointB, const vec &pointC);59 60 61 62 [Sphere](const vec &pointA, const vec &pointB, const vec &pointC, const vec &pointD);63 64 65 66 67 void [Translate](const vec &offset);68 69 70 71 void [Transform](const [float3x3] &transform);72 void [Transform](const [float3x4] &transform);73 void [Transform](const [float4x4] &transform);74 void [Transform](const [Quat] &transform);75 76 77 78 79 [AABB] [MinimalEnclosingAABB]() const;80 81 82 83 84 [AABB] [MaximalContainedAABB]() const;85 86 87 88 89 void [SetNegativeInfinity]();90 91 92 93 94 float [Volume]() const;95 96 97 98 99 float [SurfaceArea]() const;100 101 102 103 104 float [Diameter]() const { return 2.f * [r]; }105 106 107 108 109 vec [Centroid]() const { return [pos]; }110 111 112 vec [AnyPointFast]() const { return [pos]; }113 114 115 116 117 118 119 120 vec [ExtremePoint](const vec &direction) const;121 vec [ExtremePoint](const vec &direction, float &projectionDistance) const;122 123 124 125 126 127 128 129 130 void [ProjectToAxis](const vec &direction, float &outMin, float &outMax) const;131 132 133 134 135 136 137 bool [IsFinite]() const;138 139 140 141 142 bool [IsDegenerate]() const;143 144 145 146 void [SetDegenerate]();147 148 149 150 151 bool [Contains](const vec &point) const;152 bool [Contains](const vec &point, float [epsilon]) const;153 bool [Contains](const [LineSegment] &lineSegment) const;154 bool [Contains](const [Triangle] &triangle) const;155 bool [Contains](const [Polygon] &polygon) const;156 bool [Contains](const [AABB] &aabb) const;157 bool [Contains](const [OBB] &obb) const;158 bool [Contains](const [Frustum] &frustum) const;159 bool [Contains](const [Polyhedron] &polyhedron) const;160 bool [Contains](const [Sphere] &sphere) const;161 bool [Contains](const [Sphere] &sphere, float [epsilon]) const;162 bool [Contains](const [Capsule] &capsule) const;163 164 165 166 167 168 169 170 171 172 static [Sphere] [FastEnclosingSphere](const vec *pointArray, int numPoints);173 174 175 176 177 178 179 180 181 182 183 184 static [Sphere] [OptimalEnclosingSphere](const vec *pointArray, int numPoints);185 186 187 188 189 190 static [Sphere] [OptimalEnclosingSphere](const vec &a, const vec &b);191 192 193 194 195 static [Sphere] [OptimalEnclosingSphere](const vec &a, const vec &b, const vec &c);196 197 198 199 200 static [Sphere] [OptimalEnclosingSphere](const vec &a, const vec &b, const vec &c, const vec &[d]);201 202 203 204 205 206 207 208 209 210 static [Sphere] [OptimalEnclosingSphere](const vec &a, const vec &b, const vec &c, const vec &[d], const vec &[e],211 int &redundantPoint);212 213 214 215 216 217 218 static [Sphere] [FitThroughPoints](const vec &a, const vec &b) { return [OptimalEnclosingSphere](a, b); }219 220 221 222 223 224 225 226 227 228 static [Sphere] [FitThroughPoints](const vec &a, const vec &b, const vec &c);229 230 231 232 233 234 235 236 237 static [Sphere] [FitThroughPoints](const vec &a, const vec &b, const vec &c, const vec &[d]);238 239 240 241 242 243 244 float [Distance](const vec &point) const;245 float [Distance](const [Sphere] &sphere) const;246 float [Distance](const [Capsule] &capsule) const;247 float [Distance](const [AABB] &aabb) const;248 float [Distance](const [OBB] &obb) const;249 float [Distance](const [Plane] &plane) const;250 float [Distance](const [Triangle] &triangle) const;251 float [Distance](const [Ray] &ray) const;252 float [Distance](const [Line] &line) const;253 float [Distance](const [LineSegment] &lineSegment) const;254 255 256 257 float [MaxDistance](const vec &point) const;258 259 260 261 262 263 264 vec [ClosestPoint](const vec &point) const;265 266 267 268 269 270 271 272 273 274 275 276 int [Intersects](const [LineSegment] &lineSegment, vec *intersectionPoint = 0, vec *intersectionNormal = 0, float *[d] = 0, float *d2 = 0) const;277 int [Intersects](const [Line] &line, vec *intersectionPoint = 0, vec *intersectionNormal = 0, float *[d] = 0, float *d2 = 0) const;278 int [Intersects](const [Ray] &ray, vec *intersectionPoint = 0, vec *intersectionNormal = 0, float *[d] = 0, float *d2 = 0) const;279 bool [Intersects](const [Plane] &plane) const;280 bool [Intersects](const [AABB] &aabb, vec *closestPointOnAABB = 0) const;281 bool [Intersects](const [OBB] &obb, vec *closestPointOnOBB = 0) const;282 bool [Intersects](const [Triangle] &triangle, vec *closestPointOnTriangle = 0) const;283 bool [Intersects](const [Capsule] &capsule) const;284 bool [Intersects](const [Polygon] &polygon) const;285 bool [Intersects](const [Frustum] &frustum) const;286 bool [Intersects](const [Polyhedron] &polyhedron) const;287 bool [Intersects](const [Sphere] &sphere) const;288 289 290 291 292 293 294 295 296 297 void [Enclose](const vec &point, float [epsilon] = 1[e]-4f);298 void [Enclose](const vec *pointArray, int numPoints);299 void [Enclose](const [LineSegment] &lineSegment);300 void [Enclose](const [AABB] &aabb);301 void [Enclose](const [OBB] &obb);302 void [Enclose](const [Sphere] &sphere);303 void [Enclose](const [Triangle] &triangle);304 void [Enclose](const [Polygon] &polygon);305 void [Enclose](const [Polyhedron] &polyhedron);306 void [Enclose](const [Frustum] &frustum);307 void [Enclose](const [Capsule] &capsule);308 309 310 311 312 void [ExtendRadiusToContain](const vec &point, float [epsilon] = 1[e]-4f);313 void [ExtendRadiusToContain](const [Sphere] &sphere, float [epsilon] = 1[e]-4f);314 315 316 317 318 319 320 321 322 323 vec [RandomPointInside]([LCG] &lcg);324 static vec [RandomPointInside]([LCG] &lcg, const vec ¢er, float radius);325 326 327 328 329 330 331 332 333 vec [RandomPointOnSurface]([LCG] &lcg);334 static vec [RandomPointOnSurface]([LCG] &lcg, const vec ¢er, float radius);335 336 337 338 static vec [RandomUnitaryFloat3]([LCG] &lcg) { return [Sphere]([POINT_VEC](0,0,0), 1.f).RandomPointOnSurface(lcg); }339 340 341 342 343 344 345 346 int [Triangulate](vec *outPos, vec *outNormal, [float2] *outUV, int numVertices, bool ccwIsFrontFacing) const;347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 static int [IntersectLine](const vec &linePos, const vec &lineDir, const vec &sphereCenter,371 float sphereRadius, float &t1, float &t2);372 373 #ifdef MATH_ENABLE_STL_SUPPORT374 375 std::string [ToString]() const;376 std::string [SerializeToString]() const;377 378 379 std::string [SerializeToCodeString]() const;380 #endif381 382 static [Sphere] [FromString](const char *str, const char **outEndStr = 0);383 #ifdef MATH_ENABLE_STL_SUPPORT384 static [Sphere] [FromString](const std::string &str) { return [FromString](str.c_str()); }385 #endif386 387 #ifdef MATH_QT_INTEROP388 operator QString() const { return toString(); }389 QString toString() const { return QString::fromStdString([ToString]()); }390 #endif391 #ifdef MATH_GRAPHICSENGINE_INTEROP392 void [Triangulate](VertexBuffer &vb, int numVertices, bool ccwIsFrontFacing) const;393 #endif394 #ifdef MATH_URHO3D_INTEROP395 [Sphere](const Urho3D::Sphere &other) : [pos](other.center_), [r](other.radius_) {}396 operator Urho3D::Sphere() const { return Urho3D::Sphere([pos], [r]); }397 #endif398 399 bool [Equals](const [Sphere] &rhs, float [epsilon] = 1[e]-3f) const { return [pos].[Equals](rhs.[pos], [epsilon]) && [EqualAbs]([r], rhs.[r], [epsilon]); }400 401 402 403 bool [BitEquals](const [Sphere] &other) const;404 };405 406 #ifdef MATH_QT_INTEROP407 Q_DECLARE_METATYPE([Sphere])408 Q_DECLARE_METATYPE([Sphere]*)409 #endif410 411 [Sphere] [operator *](const [float3x3] &m, const [Sphere] &s);412 [Sphere] [operator *](const [float3x4] &m, const [Sphere] &s);413 [Sphere] [operator *](const [float4x4] &m, const [Sphere] &s);414 [Sphere] [operator *](const [Quat] &q, const [Sphere] &s);415 416 #ifdef MATH_ENABLE_STL_SUPPORT417 std::ostream &[operator <<](std::ostream &o, const [Sphere] &sphere);418 #endif419 420 [MATH_END_NAMESPACE] Go back to previous page