PDCone Class Reference

#include <pDomain.h>

Inheritance diagram for PDCone:

Inheritance graph
[legend]
Collaboration diagram for PDCone:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 PDCone (const pVec &e0, const pVec &e1, const float radOut0, const float radIn0=0.0f)
 ~PDCone ()
bool Within (const pVec &pos) const
pVec Generate () const
pDomaincopy () const

Public Attributes

pVec apex
pVec axis
pVec u
pVec v
float len
float radOut
float radIn
float radOutSqr
float radInSqr
float radDif
float axisLenInvSqr
bool ThinShell


Detailed Description

Definition at line 367 of file pDomain.h.


Constructor & Destructor Documentation

PDCone::PDCone ( const pVec e0,
const pVec e1,
const float  radOut0,
const float  radIn0 = 0.0f 
) [inline]

Definition at line 375 of file pDomain.h.

References apex, axis, axisLenInvSqr, fabsf(), fsqr(), pVec::length2(), pVec::normalize(), radDif, radIn, radInSqr, radOut, radOutSqr, sqrtf(), ThinShell, u, and v.

Referenced by copy().

00376     {
00377         apex = e0;
00378         axis = e1 - e0;
00379 
00380         if(radOut0 < radIn0) {
00381             radOut = radIn0; radIn = radOut0;
00382         } else {
00383             radOut = radOut0; radIn = radIn0;
00384         }
00385         radOutSqr = fsqr(radOut);
00386         radInSqr = fsqr(radIn);
00387 
00388         ThinShell = (radIn == radOut);
00389         radDif = radOut - radIn;
00390 
00391         // Given an arbitrary nonzero vector n, make two orthonormal
00392         // vectors u and v forming a frame [u,v,n.normalize()].
00393         pVec n = axis;
00394         float axisLenSqr = axis.length2();
00395         axisLenInvSqr = axisLenSqr ? 1.0f / axisLenSqr : 0.0f;
00396         n *= sqrtf(axisLenInvSqr);
00397 
00398         // Find a vector orthogonal to n.
00399         pVec basis(1.0f, 0.0f, 0.0f);
00400         if (fabsf(basis * n) > 0.999f)
00401             basis = pVec(0.0f, 1.0f, 0.0f);
00402 
00403         // Project away N component, normalize and cross to get
00404         // second orthonormal vector.
00405         u = basis - n * (basis * n);
00406         u.normalize();
00407         v = Cross(n, u);
00408     }

Here is the call graph for this function:

Here is the caller graph for this function:

PDCone::~PDCone (  )  [inline]

Definition at line 410 of file pDomain.h.

00411     {
00412     }


Member Function Documentation

bool PDCone::Within ( const pVec pos  )  const [inline, virtual]

Implements pDomain.

Definition at line 414 of file pDomain.h.

References apex, axis, axisLenInvSqr, fsqr(), pVec::length2(), radIn, radOut, and x.

00415     {
00416         // This is painful and slow. Might be better to do quick
00417         // accept/reject tests.
00418         // Let axis = vector from base to tip of the cylinder
00419         // x = vector from base to test point
00420         //         x . axis
00421         // dist = ---------- = projected distance of x along the axis
00422         //        axis. axis   ranging from 0 (base) to 1 (tip)
00423         //
00424         // rad = x - dist * axis = projected vector of x along the base
00425 
00426         pVec x = pos - apex;
00427 
00428         // Check axial distance
00429         // axisLenInvSqr stores 1 / (axis.axis)
00430         float dist = (axis * x) * axisLenInvSqr;
00431         if(dist < 0.0f || dist > 1.0f)
00432             return false;
00433 
00434         // Check radial distance; scale radius along axis for cones
00435         pVec xrad = x - axis * dist; // Radial component of x
00436         float rSqr = xrad.length2();
00437 
00438         return (rSqr <= fsqr(dist * radIn) && rSqr >= fsqr(dist * radOut));
00439     }

Here is the call graph for this function:

pVec PDCone::Generate (  )  const [inline, virtual]

Implements pDomain.

Definition at line 441 of file pDomain.h.

References apex, axis, cosf(), M_PI, pos, pRandf, radDif, radIn, sinf(), u, v, and x.

00442     {
00443         float dist = pRandf(); // Distance between base and tip
00444         float theta = pRandf() * 2.0f * float(M_PI); // Angle around axis
00445         // Distance from axis
00446         float r = radIn + pRandf() * radDif;
00447 
00448         // Another way to do this is to choose a random point in a square and keep it if it's in the circle.
00449         float x = r * cosf(theta);
00450         float y = r * sinf(theta);
00451 
00452         // Scale radius along axis for cones
00453         x *= dist;
00454         y *= dist;
00455 
00456         pVec pos = apex + axis * dist + u * x + v * y;
00457         return pos;
00458     }

Here is the call graph for this function:

pDomain* PDCone::copy (  )  const [inline, virtual]

Implements pDomain.

Definition at line 460 of file pDomain.h.

References PDCone().

00461     {
00462         PDCone *P = new PDCone(*this);
00463         return P;
00464     }

Here is the call graph for this function:


Member Data Documentation

pVec PDCone::apex

Definition at line 370 of file pDomain.h.

Referenced by Generate(), PDCone(), and Within().

pVec PDCone::axis

Definition at line 370 of file pDomain.h.

Referenced by Generate(), PDCone(), and Within().

pVec PDCone::u

Definition at line 370 of file pDomain.h.

Referenced by Generate(), and PDCone().

pVec PDCone::v

Definition at line 370 of file pDomain.h.

Referenced by Generate(), and PDCone().

float PDCone::len

Definition at line 371 of file pDomain.h.

float PDCone::radOut

Definition at line 371 of file pDomain.h.

Referenced by PDCone(), and Within().

float PDCone::radIn

Definition at line 371 of file pDomain.h.

Referenced by Generate(), PDCone(), and Within().

float PDCone::radOutSqr

Definition at line 371 of file pDomain.h.

Referenced by PDCone().

float PDCone::radInSqr

Definition at line 371 of file pDomain.h.

Referenced by PDCone().

float PDCone::radDif

Definition at line 371 of file pDomain.h.

Referenced by Generate(), and PDCone().

float PDCone::axisLenInvSqr

Definition at line 371 of file pDomain.h.

Referenced by PDCone(), and Within().

bool PDCone::ThinShell

Definition at line 372 of file pDomain.h.

Referenced by PDCone().


The documentation for this class was generated from the following file:
Generated on Sat Mar 15 23:51:42 2008 for Armagetron Advanced by  doxygen 1.5.4