Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

pge::Sphere Class Reference

#include <Sphere.h>

Collaboration diagram for pge::Sphere:

Collaboration graph
[legend]

Public Member Functions

 Sphere (const Vector3f &center, float radius)
 Constructor given the center and the radius of the sphere.

 Sphere (AABB *aabb)
 Constructor that constructs a bounding sphere around the given AABB.

 ~Sphere (void)
 Destructor.

float getDistance (const Sphere &sphere)
 Returns the distance to another sphere.

float getSquaredDistance (const Sphere &sphere)
 Returns the squared distance to another sphere.

float getDistance (const Vector3f &point)
 Returns the distance to a point.

float getSquaredDistance (const Vector3f &point)
 Returns the squared distance between the sphere's center and the point.

bool isIntersecting (const Sphere &sphere)
 Returns 1 if this sphere intersects with a given sphere.

bool isPointInside (const Vector3f &point)
 Returns 1 if the given point is inside this sphere.


Data Fields

Vector3f m_center
float m_radius

Constructor & Destructor Documentation

pge::Sphere::Sphere const Vector3f center,
float  radius
 

Constructor given the center and the radius of the sphere.

Definition at line 20 of file Sphere.cpp.

References m_center, and m_radius.

00020                                                            {
00021                 m_center = center;
00022                 m_radius = radius;
00023         }

pge::Sphere::Sphere AABB aabb  ) 
 

Constructor that constructs a bounding sphere around the given AABB.

Definition at line 31 of file Sphere.cpp.

References m_center, pge::AABB::m_maxX, pge::AABB::m_maxY, pge::AABB::m_maxZ, pge::AABB::m_minX, pge::AABB::m_minY, pge::AABB::m_minZ, and m_radius.

00031                                  {
00032                 float middleX;
00033                 float middleY;
00034                 float middleZ;
00035                 float dx;
00036                 float dy;
00037                 float dz;
00038                 //float sqrtTwo = 1.4142135623730950488f;
00039 
00040                 dx = aabb->m_maxX - aabb->m_minX;
00041                 dy = aabb->m_maxY - aabb->m_minY;
00042                 dz = aabb->m_maxZ - aabb->m_minZ;
00043 
00044                 // Get the middle point of each edge
00045                 middleX = (dx / 2.0f) + aabb->m_minX;
00046                 middleY = (dy / 2.0f) + aabb->m_minY;
00047                 middleZ = (dz / 2.0f) + aabb->m_minZ;
00048 
00049                 // set the center
00050                 m_center = Vector3f(middleX, middleY, middleZ);
00051 
00052                 // now get the radius
00053 
00054                 // this approach will make a sphere too small, but else its too big
00055                 //dx = (dx * sqrtTwo) / 2.0f;
00056                 //dy = (dy * sqrtTwo) / 2.0f;
00057                 //dz = (dz * sqrtTwo) / 2.0f;
00058                 m_radius = dx;
00059                 if(dy > m_radius) {
00060                         m_radius = dy;
00061                 }
00062                 if(dz > m_radius) {
00063                         m_radius = dz;
00064                 }
00065         }

pge::Sphere::~Sphere void   ) 
 

Destructor.

Definition at line 73 of file Sphere.cpp.

00073                             {
00074         }


Member Function Documentation

float pge::Sphere::getDistance const Vector3f point  ) 
 

Returns the distance to a point.

This function returns the distance between the sphere's center and a point.

Definition at line 106 of file Sphere.cpp.

References m_center, pge::Vector3f::magnitude(), and pge::Vector3f::subtract().

00106                                                        {
00107                 Vector3f v;
00108                 v = m_center.subtract(point);
00109                 return v.magnitude();
00110         }

Here is the call graph for this function:

float pge::Sphere::getDistance const Sphere sphere  ) 
 

Returns the distance to another sphere.

This function returns the distance from this sphere's center to another sphere's center. Basically this calculates the vector between the two centers and returns the magnitude. if you only need to compare than use the sqrDistance(...) instead, it does not use any squareroot functions.

Definition at line 82 of file Sphere.cpp.

References m_center, pge::Vector3f::magnitude(), and pge::Vector3f::subtract().

00082                                                       {
00083                 Vector3f v;
00084                 v = m_center.subtract(sphere.m_center);
00085                 return v.magnitude();
00086         }

Here is the call graph for this function:

float pge::Sphere::getSquaredDistance const Vector3f point  ) 
 

Returns the squared distance between the sphere's center and the point.

This function works like the one above, except that it returns the squared distance.

Definition at line 118 of file Sphere.cpp.

References m_center, pge::Vector3f::sqrMagnitude(), and pge::Vector3f::subtract().

00118                                                               {
00119                 Vector3f v;
00120                 v = m_center.subtract(point);
00121                 return v.sqrMagnitude();
00122         }

Here is the call graph for this function:

float pge::Sphere::getSquaredDistance const Sphere sphere  ) 
 

Returns the squared distance to another sphere.

This function works exactly like the one above, except that it returns the the squared distance.

Definition at line 94 of file Sphere.cpp.

References m_center, pge::Vector3f::sqrMagnitude(), and pge::Vector3f::subtract().

Referenced by isIntersecting(), and isPointInside().

00094                                                              {
00095                 Vector3f v;
00096                 v = m_center.subtract(sphere.m_center);
00097                 return v.sqrMagnitude();
00098         }

Here is the call graph for this function:

bool pge::Sphere::isIntersecting const Sphere sphere  ) 
 

Returns 1 if this sphere intersects with a given sphere.

Definition at line 130 of file Sphere.cpp.

References getSquaredDistance(), and m_radius.

Referenced by pge::SingleTexturedMesh::render().

00130                                                         {
00131                 float d;
00132 
00133 
00134                 d = getSquaredDistance(sphere);
00135                 if((m_radius * m_radius) >= (d - (sphere.m_radius * sphere.m_radius))) {
00136                         return true;
00137                 }
00138                 return false;
00139         }

Here is the call graph for this function:

bool pge::Sphere::isPointInside const Vector3f point  ) 
 

Returns 1 if the given point is inside this sphere.

Definition at line 147 of file Sphere.cpp.

References getSquaredDistance(), and m_radius.

00147                                                         {
00148                 float d;
00149 
00150 
00151                 d = getSquaredDistance(point);
00152                 if((m_radius * m_radius) >= d) {
00153                         return true;
00154                 }
00155                 return false;
00156         }

Here is the call graph for this function:


Field Documentation

Vector3f pge::Sphere::m_center
 

Definition at line 92 of file Sphere.h.

Referenced by pge::Camera::applyCameraPosition(), pge::Camera::applyCameraView(), getDistance(), pge::Camera::getPosition(), getSquaredDistance(), pge::SingleTexturedMesh::render(), pge::Camera::revertCameraView(), pge::Camera::setPosition(), Sphere(), and pge::Camera::updatePhysics().

float pge::Sphere::m_radius
 

Definition at line 93 of file Sphere.h.

Referenced by isIntersecting(), isPointInside(), and Sphere().


The documentation for this class was generated from the following files:
Generated on Mon Oct 16 12:09:42 2006 for Phobosengine by doxygen 1.3.4