2015-10-15 18:21:32 +00:00
|
|
|
#ifndef SPHERE_H
|
|
|
|
#define SPHERE_H
|
|
|
|
|
|
|
|
#include "basics_global.h"
|
|
|
|
|
|
|
|
#include "Vector3.h"
|
|
|
|
|
|
|
|
namespace paysages {
|
|
|
|
namespace basics {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Geometric sphere.
|
|
|
|
*/
|
2015-11-09 21:30:46 +00:00
|
|
|
class BASICSSHARED_EXPORT Sphere {
|
|
|
|
public:
|
2015-11-09 23:15:30 +00:00
|
|
|
Sphere() = default;
|
2015-10-15 18:21:32 +00:00
|
|
|
Sphere(const Vector3 ¢er, double radius);
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
inline const Vector3 &getCenter() const {
|
|
|
|
return center;
|
|
|
|
}
|
|
|
|
inline const double &getRadius() const {
|
|
|
|
return radius;
|
|
|
|
}
|
2015-10-15 18:21:32 +00:00
|
|
|
|
|
|
|
/**
|
2015-11-10 00:12:14 +00:00
|
|
|
* Check for intersections between the sphere and an infinite ray.
|
|
|
|
*
|
|
|
|
* Returns the number of intersections (0, 1 or 2).
|
|
|
|
*/
|
|
|
|
int checkRayIntersection(const InfiniteRay &ray) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the intersections between the sphere and an infinite ray.
|
2015-10-15 18:21:32 +00:00
|
|
|
*
|
|
|
|
* Returns the number of intersections (0, 1 or 2) and fill the intersection points.
|
|
|
|
*/
|
2015-11-10 00:12:14 +00:00
|
|
|
int findRayIntersection(const InfiniteRay &ray, Vector3 *first_intersection, Vector3 *second_intersection) const;
|
2015-10-15 18:21:32 +00:00
|
|
|
|
|
|
|
void save(PackStream *stream) const;
|
|
|
|
void load(PackStream *stream);
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
private:
|
2015-10-15 18:21:32 +00:00
|
|
|
Vector3 center;
|
|
|
|
double radius;
|
|
|
|
double radius2;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // SPHERE_H
|