aboutsummaryrefslogtreecommitdiff
path: root/dep/include/g3dlite/G3D/Sphere.h
blob: 122e4d41f65bb94f251fe8a06482d6a39d28265b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
 @file Sphere.h

 Sphere class

 @maintainer Morgan McGuire, matrix@graphics3d.com

 @created 2001-06-02
 @edited  2004-07-05
 */

#ifndef G3D_SPHERE_H
#define G3D_SPHERE_H

#include "G3D/platform.h"
#include "G3D/Vector3.h"
#include "G3D/Array.h"
#include "G3D/Sphere.h"

namespace G3D {

/**
 Sphere.
 */
class Sphere {
private:

    static int32     dummy;

public:
    Vector3          center;
    float            radius;

    Sphere() {
        center = Vector3::zero();
        radius = 0;
    }

    Sphere(
        const Vector3&  center,
        float           radius) {

        this->center = center;
        this->radius = radius;
    }

    virtual ~Sphere() {}

    bool operator==(const Sphere& other) const {
        return (center == other.center) && (radius == other.radius);
    }

    bool operator!=(const Sphere& other) const {
        return !((center == other.center) && (radius == other.radius));
    }

    /**
     Returns true if point is less than or equal to radius away from
     the center.
     */
    bool contains(const Vector3& point) const;

/**
     @deprecated Use culledBy(Array<Plane>&)
     */
    bool culledBy(
        const class Plane*  plane,
        int                 numPlanes,
        int32&              cullingPlaneIndex,
        const uint32        testMask,
        uint32&             childMask) const;

    /**
     @deprecated Use culledBy(Array<Plane>&)
     */
    bool culledBy(
        const class Plane*  plane,
        int                 numPlanes,
        int32&              cullingPlaneIndex = dummy,
        const uint32        testMask = -1) const;

    /**
      See AABox::culledBy
     */
    bool culledBy(
        const Array<Plane>&     plane,
        int32&                  cullingPlaneIndex,
        const uint32            testMask,
        uint32&                 childMask) const;

    /**
     Conservative culling test that does not produce a mask for children.
     */
    bool culledBy(
        const Array<Plane>&     plane,
        int32&                  cullingPlaneIndex = dummy,
        const uint32            testMask          = -1) const;
    virtual std::string toString() const;

    float volume() const;

    /** @deprecated */
    float surfaceArea() const;

    inline float area() const {
        return surfaceArea();
    }

    /**
     Uniformly distributed on the surface.
     */
    Vector3 randomSurfacePoint() const;

    /**
     Uniformly distributed on the interior (includes surface)
     */
    Vector3 randomInteriorPoint() const;

    void getBounds(class AABox& out) const;
};

} // namespace

inline unsigned int hashCode(const G3D::Sphere& sphere) {
    return (unsigned int)(hashCode(sphere.center) + (sphere.radius * 13));
}

#endif