Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Frustum Class Reference

#include <frustum.h>

Collaboration diagram for Frustum:

Collaboration graph
List of all members.

Public Types

enum  {
  Bottom = 0, Top = 1, Left = 2, Right = 3,
  Near = 4, Far = 5
}
enum  Aspect { Outside = 0, Inside = 1, Intersect = 2 }

Public Member Functions

 Frustum (float fov, float aspectRatio, float nearDist, float farDist)
 Frustum (float fov, float aspectRatio, float nearDist)
Planef getPlane (int) const
Aspect test (const Point3f &) const
Aspect testSphere (const Point3d &center, double radius) const
Aspect testSphere (const Point3f &center, float radius) const
void transform (const Mat4f &)
void transform (const Mat3f &)

Private Member Functions

void init (float, float, float, float)

Private Attributes

bool infinite
Planef planes [6]

Member Enumeration Documentation

anonymous enum
 

Enumeration values:
Bottom 
Top 
Left 
Right 
Near 
Far 

Definition at line 27 of file frustum.h.

00027          {
00028         Bottom    = 0,
00029         Top       = 1,
00030         Left      = 2,
00031         Right     = 3,
00032         Near      = 4,
00033         Far       = 5,
00034     };

enum Frustum::Aspect
 

Enumeration values:
Outside 
Inside 
Intersect 

Definition at line 36 of file frustum.h.

00036                 {
00037         Outside   = 0,
00038         Inside    = 1,
00039         Intersect = 2,
00040     };


Constructor & Destructor Documentation

Frustum::Frustum float  fov,
float  aspectRatio,
float  nearDist
 

Definition at line 13 of file frustum.cpp.

References init().

00013                                                       :
00014     infinite(true)
00015 {
00016     init(fov, aspectRatio, n, n);
00017 }

Frustum::Frustum float  fov,
float  aspectRatio,
float  nearDist,
float  farDist
 

Definition at line 20 of file frustum.cpp.

References init().

00020                                                                :
00021     infinite(false)
00022 {
00023     init(fov, aspectRatio, n, f);
00024 }


Member Function Documentation

Planef Frustum::getPlane int   )  const [inline]
 

Definition at line 53 of file frustum.h.

References planes.

00054 {
00055     return planes[which];
00056 }

void Frustum::init float  ,
float  ,
float  ,
float 
[private]
 

Definition at line 27 of file frustum.cpp.

References Bottom, Far, Left, Near, Vector3< T >::normalize(), planes, Right, and Top.

Referenced by Frustum().

00028 {
00029     float h = (float) tan(fov / 2.0f);
00030     float w = h * aspectRatio;
00031 
00032     Vec3f normals[4];
00033     normals[Bottom] = Vec3f(0, 1, -h);
00034     normals[Top]    = Vec3f(0, -1, -h);
00035     normals[Left]   = Vec3f(1, 0, -w);
00036     normals[Right]  = Vec3f(-1, 0, -w);
00037     for (int i = 0; i < 4; i++)
00038     {
00039         normals[i].normalize();
00040         planes[i] = Planef(normals[i], Point3f(0, 0, 0));
00041     }
00042 
00043     planes[Near] = Planef(Vec3f(0, 0, -1), -n);
00044     planes[Far] = Planef(Vec3f(0, 0, 1), f);
00045 }

Frustum::Aspect Frustum::test const Point3f  )  const
 

Definition at line 48 of file frustum.cpp.

References testSphere().

00049 {
00050     return testSphere(p, 0);
00051 }

Frustum::Aspect Frustum::testSphere const Point3d center,
double  radius
const
 

Definition at line 72 of file frustum.cpp.

References Plane< T >::d, infinite, Inside, Intersect, Plane< T >::normal, Outside, planes, Vector3< T >::x, Vector3< T >::y, and Vector3< T >::z.

00073 {
00074     int nPlanes = infinite ? 5 : 6;
00075     int intersections = 0;
00076 
00077     for (int i = 0; i < nPlanes; i++)
00078     {
00079         //TODO: Celestia should incorporate some casting operators overloading to accomodate all this kind of stuff:
00080         Vec3f plNormal       = planes[i].normal;
00081         Vec3d plNormalDbl(plNormal.x, plNormal.y, plNormal.z); 
00082          
00083         double distanceToPlane = plNormalDbl.x * center.x + plNormalDbl.y * center.y + plNormalDbl.z * center.z + planes[i].d;        
00084         if (distanceToPlane < -radius)
00085             return Outside;
00086         else if (distanceToPlane <= radius)
00087             intersections |= (1 << i);
00088     }
00089 
00090     return (intersections == 0) ? Inside : Intersect;
00091 }

Frustum::Aspect Frustum::testSphere const Point3f center,
float  radius
const
 

Definition at line 54 of file frustum.cpp.

References Plane< T >::distanceTo(), infinite, Inside, Intersect, Outside, and planes.

Referenced by DSORenderer::process(), Renderer::render(), and test().

00055 {
00056     int nPlanes = infinite ? 5 : 6;
00057     int intersections = 0;
00058 
00059     for (int i = 0; i < nPlanes; i++)
00060     {
00061         float distanceToPlane = planes[i].distanceTo(center);
00062         if (distanceToPlane < -radius)
00063             return Outside;
00064         else if (distanceToPlane <= radius)
00065             intersections |= (1 << i);
00066     }
00067 
00068     return (intersections == 0) ? Inside : Intersect;
00069 }

void Frustum::transform const Mat4f  ) 
 

Definition at line 109 of file frustum.cpp.

References Plane< T >::d, infinite, Vector3< T >::length(), Plane< T >::normal, and planes.

00110 {
00111     int nPlanes = infinite ? 5 : 6;
00112     Mat4f invTranspose = m.inverse().transpose();
00113 
00114     for (int i = 0; i < nPlanes; i++)
00115     {
00116         planes[i] = planes[i] * invTranspose;
00117         float s = 1.0f / planes[i].normal.length();
00118         planes[i].normal = planes[i].normal * s;
00119         planes[i].d *= s;
00120     }
00121 }

void Frustum::transform const Mat3f  ) 
 

Definition at line 104 of file frustum.cpp.

Referenced by Renderer::renderObject().

00105 {
00106 }


Member Data Documentation

bool Frustum::infinite [private]
 

Definition at line 50 of file frustum.h.

Referenced by testSphere(), and transform().

Planef Frustum::planes[6] [private]
 

Definition at line 49 of file frustum.h.

Referenced by getPlane(), init(), testSphere(), and transform().


The documentation for this class was generated from the following files:
Generated on Sat Jan 14 22:33:20 2006 for Celestia by  doxygen 1.4.1