#include <pDomain.h>
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 |
pDomain * | copy () 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 |
Definition at line 367 of file pDomain.h.
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 }
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 }
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 }
pDomain* PDCone::copy | ( | ) | const [inline, virtual] |
float PDCone::len |
float PDCone::radOut |
float PDCone::radIn |
float PDCone::radOutSqr |
float PDCone::radInSqr |
float PDCone::radDif |
float PDCone::axisLenInvSqr |
bool PDCone::ThinShell |