19 mTuple({ 0.0f, 0.0f, 0.0f, 0.0f })
40 if (signedDistance <= -radius)
45 if (signedDistance >= radius)
72 float lengthSqr =
Dot(centerDiff, centerDiff);
73 float radiusDiff = radius1 - radius0;
74 float radiusDiffSqr = radiusDiff*radiusDiff;
76 if (radiusDiffSqr >= lengthSqr)
78 if (radiusDiff >= 0.0
f)
85 float length = sqrt(lengthSqr);
88 float coeff = (length + radiusDiff) / (2.0
f*length);
98 #if defined (GTE_USE_MAT_VEC) 110 float sum[3] = { 0.0f, 0.0f, 0.0f };
112 for (i = 0; i < numVertices; ++i)
114 float const* position = (
float const*)(data + i*vertexSize);
115 sum[0] += position[0];
116 sum[1] += position[1];
117 sum[2] += position[2];
119 float invNumVertices = 1.0f / (float)numVertices;
120 mTuple[0] = sum[0] * invNumVertices;
121 mTuple[1] = sum[1] * invNumVertices;
122 mTuple[2] = sum[2] * invNumVertices;
126 for (i = 0; i < numVertices; ++i)
128 float const* position = (
const float*)(data + i*vertexSize);
132 position[1] - mTuple[1],
133 position[2] - mTuple[2]
135 float radiusSqr = diff[0] * diff[0] + diff[1] * diff[1] + diff[2] * diff[2];
136 if (radiusSqr > mTuple[3])
138 mTuple[3] = radiusSqr;
153 "Invalid bound. Did you forget to call UpdateModelBound()?");
158 float const infinity = std::numeric_limits<float>::max();
162 if (tmin == -infinity)
164 LogAssert(tmax == infinity,
"tmax must be infinity for a line.");
167 diff = origin - center;
168 a0 =
Dot(diff, diff) - radius*radius;
169 a1 =
Dot(direction, diff);
171 return discr >= 0.0f;
174 if (tmax == infinity)
176 LogAssert(tmin == 0.0
f,
"tmin must be zero for a ray.");
179 diff = origin - center;
180 a0 =
Dot(diff, diff) - radius*radius;
188 a1 =
Dot(direction, diff);
199 return discr >= 0.0f;
202 LogAssert(tmax > tmin,
"tmin < tmax is required for a segment.");
205 float taverage = 0.5f*(tmin + tmax);
207 float segExtent = 0.5f * (tmax - tmin);
210 a0 =
Dot(diff, diff) - radius*radius;
217 a1 =
Dot(direction, diff);
218 discr = a1 * a1 - a0;
228 float absA1 = fabs(a1);
229 float tmp = segExtent - absA1;
230 return tmp * tmp <= discr || segExtent >= absA1;
239 "Invalid bound. Did you forget to call UpdateModelBound()?");
246 return Dot(diff, diff) <= rSum*rSum;
257 "Invalid bound. Did you forget to call UpdateModelBound()?");
264 float a =
Dot(relVelocity, relVelocity);
265 float c =
Dot(cenDiff, cenDiff);
267 float rSumSqr = rSum*rSum;
271 float b =
Dot(cenDiff, relVelocity);
276 return a*c - b*b <= a*rSumSqr;
280 return tmax*(tmax*a + 2.0f*
b) + c <= rSumSqr;
int WhichSide(CullingPlane const &plane) const
BoundingSphere & operator=(BoundingSphere const &sphere)
#define LogAssert(condition, message)
GLboolean GLboolean GLboolean GLboolean a
void SetRadius(float radius)
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
Vector4< float > GetCenter() const
#define LogWarning(message)
GLboolean GLboolean GLboolean b
GLuint GLsizei GLsizei * length
bool TestIntersection(Vector4< float > const &origin, Vector4< float > const &direction, float tmin, float tmax) const
void ComputeFromData(int numVertices, int vertexSize, char const *data)
GLuint GLenum GLenum transform
void GrowToContain(BoundingSphere const &sphere)
void TransformBy(Transform const &transform, BoundingSphere &sphere) const
float DistanceTo(Vector4< float > const &P) const
void SetCenter(Vector4< float > const ¢er)