mirror of
https://github.com/tribes2/engine.git
synced 2026-04-21 04:15:24 +00:00
t2 engine svn checkout
This commit is contained in:
commit
ff569bd2ae
988 changed files with 394180 additions and 0 deletions
72
math/mSphere.h
Normal file
72
math/mSphere.h
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// V12 Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _MSPHERE_H_
|
||||
#define _MSPHERE_H_
|
||||
|
||||
//Includes
|
||||
#ifndef _MPOINT_H_
|
||||
#include "Math/mPoint.h"
|
||||
#endif
|
||||
|
||||
class SphereF
|
||||
{
|
||||
public:
|
||||
Point3F center;
|
||||
F32 radius;
|
||||
|
||||
public:
|
||||
SphereF() { }
|
||||
SphereF(const Point3F& in_rPosition,
|
||||
const F32 in_rRadius)
|
||||
: center(in_rPosition),
|
||||
radius(in_rRadius)
|
||||
{
|
||||
if (radius < 0.0f)
|
||||
radius = 0.0f;
|
||||
}
|
||||
|
||||
bool isContained(const Point3F& in_rContain) const;
|
||||
bool isContained(const SphereF& in_rContain) const;
|
||||
bool isIntersecting(const SphereF& in_rIntersect) const;
|
||||
};
|
||||
|
||||
//-------------------------------------- INLINES
|
||||
//
|
||||
inline bool
|
||||
SphereF::isContained(const Point3F& in_rContain) const
|
||||
{
|
||||
F32 distSq = (center - in_rContain).lenSquared();
|
||||
|
||||
return (distSq <= (radius * radius));
|
||||
}
|
||||
|
||||
inline bool
|
||||
SphereF::isContained(const SphereF& in_rContain) const
|
||||
{
|
||||
if (radius < in_rContain.radius)
|
||||
return false;
|
||||
|
||||
// Since our radius is guaranteed to be >= other's, we
|
||||
// can dodge the sqrt() here.
|
||||
//
|
||||
F32 dist = (in_rContain.center - center).lenSquared();
|
||||
|
||||
return (dist <= ((radius - in_rContain.radius) *
|
||||
(radius - in_rContain.radius)));
|
||||
}
|
||||
|
||||
inline bool
|
||||
SphereF::isIntersecting(const SphereF& in_rIntersect) const
|
||||
{
|
||||
F32 distSq = (in_rIntersect.center - center).lenSquared();
|
||||
|
||||
return (distSq <= ((in_rIntersect.radius + radius) *
|
||||
(in_rIntersect.radius + radius)));
|
||||
}
|
||||
|
||||
#endif //_SPHERE_H_
|
||||
Loading…
Add table
Add a link
Reference in a new issue