SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLAABBox Class Reference

Defines an axis aligned bounding box. More...

#include <SLAABBox.h>

Public Member Functions

 SLAABBox ()
 Default constructor with default zero vector initialization. More...
 
void minWS (const SLVec3f &minC)
 
void maxWS (const SLVec3f &maxC)
 
void minOS (const SLVec3f &minC)
 
void maxOS (const SLVec3f &maxC)
 
void isVisible (SLbool visible)
 
void sqrViewDist (SLfloat sqrVD)
 
SLVec3f minWS ()
 
SLVec3f maxWS ()
 
SLVec3f centerWS ()
 
SLfloat radiusWS ()
 
SLVec3f minOS ()
 
SLVec3f maxOS ()
 
SLVec3f centerOS ()
 
SLfloat radiusOS ()
 
SLbool isVisible ()
 
SLfloat sqrViewDist ()
 
SLRectfrectSS ()
 
void reset ()
 Resets initial state without contents. More...
 
void fromOStoWS (const SLVec3f &minOS, const SLVec3f &maxOS, const SLMat4f &wm)
 Recalculate min and max after transformation in world coords. More...
 
void fromWStoOS (const SLVec3f &minWS, const SLVec3f &maxWS, const SLMat4f &wmI)
 Recalculate min and max before transformation in object coords. More...
 
void updateAxisWS (const SLMat4f &wm)
 Updates the axis of the owning node. More...
 
void updateBoneWS (const SLMat4f &parentWM, SLbool isRoot, const SLMat4f &nodeWM)
 Updates joints axis and the bone line from the parent to us. More...
 
void mergeWS (SLAABBox &bb)
 Merges the bounding box bb to this one by extending this one axis aligned. More...
 
void drawWS (const SLCol4f &color)
 Draws the AABB in world space with lines in a color. More...
 
void drawAxisWS ()
 Draws the axis in world space with lines in a color. More...
 
void drawBoneWS ()
 Draws the joint axis and the parent bone in world space. More...
 
void setCenterAndRadiusWS ()
 Calculates center & radius of the bounding sphere around the AABB. More...
 
void generateVAO ()
 Generates the vertex buffer for the line visualization. More...
 
SLbool isHitInOS (SLRay *ray)
 SLAABBox::isHitInWS: Ray - AABB Intersection Test in object space. More...
 
SLbool isHitInWS (SLRay *ray)
 SLAABBox::isHitInWS: Ray - AABB Intersection Test in world space. More...
 
void calculateRectSS ()
 Calculates the AABBs min. and max. corners in screen space. More...
 
SLfloat rectCoverageInSS ()
 Calculates the bounding rectangle in screen space and returns coverage in SS. More...
 

Private Attributes

SLVec3f _minWS
 Min. corner in world space. More...
 
SLVec3f _minOS
 Min. corner in object space. More...
 
SLVec3f _maxWS
 Max. corner in world space. More...
 
SLVec3f _maxOS
 Max. corner in object space. More...
 
SLVec3f _centerWS
 Center of AABB in world space. More...
 
SLVec3f _centerOS
 Center of AABB in object space. More...
 
SLfloat _radiusWS
 Radius of sphere around AABB in WS. More...
 
SLfloat _radiusOS
 Radius of sphere around AABB in OS. More...
 
SLfloat _sqrViewDist
 Squared dist. from center to viewpoint. More...
 
SLVec3f _axis0WS
 World space axis center point. More...
 
SLVec3f _axisXWS
 World space x-axis vector. More...
 
SLVec3f _axisYWS
 World space y-axis vector. More...
 
SLVec3f _axisZWS
 World space z-axis vector. More...
 
SLbool _boneIsOffset
 Flag if the connection parent to us is a bone or an offset. More...
 
SLVec3f _parent0WS
 World space vector to the parent position. More...
 
SLbool _isVisible
 Flag if AABB is in the view frustum. More...
 
SLRectf _rectSS
 Bounding rectangle in screen space. More...
 
SLGLVertexArrayExt _vao
 Vertex array object for rendering. More...
 

Detailed Description

Defines an axis aligned bounding box.

The SLAABBox class defines an axis aligned bounding box with a minimal and maximal point. Each node (SLNode) will have an AABB the will be calculated in buildAABB. A mesh (SLMesh) will implement buildAABB and calculate the minimal and maximal coordinates in object space (stored in _minOS and _maxOS). For a fast ray-AABB intersection in world space we transform _minOS and _maxOS into world space (with the shapes world matrix) and store it in _minWS and _maxWS. For an even faster intersection test with the plane of the view frustum we calculate in addition the bounding sphere around the AABB. The radius and the center point are stored in _radiusOS/_centerOS and _radiusWS/_centerWS.

Definition at line 33 of file SLAABBox.h.

Constructor & Destructor Documentation

◆ SLAABBox()

SLAABBox::SLAABBox ( )

Default constructor with default zero vector initialization.

Definition at line 17 of file SLAABBox.cpp.

18 {
19  reset();
20 }
void reset()
Resets initial state without contents.
Definition: SLAABBox.cpp:23

Member Function Documentation

◆ calculateRectSS()

void SLAABBox::calculateRectSS ( )

Calculates the AABBs min. and max. corners in screen space.

Definition at line 400 of file SLAABBox.cpp.

401 {
402  SLVec3f corners[8];
403 
404  // Back corners in world space
405  corners[0] = _minWS;
406  corners[1] = SLVec3f(_maxWS.x, _minWS.y, _minWS.z);
407  corners[2] = SLVec3f(_minWS.x, _maxWS.y, _minWS.z);
408  corners[3] = SLVec3f(_maxWS.x, _maxWS.y, _minWS.z);
409 
410  // Front corners in world space
411  corners[4] = SLVec3f(_minWS.x, _minWS.y, _maxWS.z);
412  corners[5] = SLVec3f(_maxWS.x, _minWS.y, _maxWS.z);
413  corners[6] = SLVec3f(_minWS.x, _maxWS.y, _maxWS.z);
414  corners[7] = _maxWS;
415 
416  // build view-projection-viewport matrix
417  SLGLState* stateGL = SLGLState::instance();
418  SLMat4f vpvpMat = stateGL->viewportMatrix() *
419  stateGL->projectionMatrix *
420  stateGL->viewMatrix;
421 
422  // transform corners from world to screen space
423  for (SLint i = 0; i < 8; ++i)
424  corners[i] = vpvpMat.multVec(corners[i]);
425 
426  // Build min. and max. in screen space
427  SLVec2f minSS(FLT_MAX, FLT_MAX);
428  SLVec2f maxSS(FLT_MIN, FLT_MIN);
429 
430  for (SLint i = 0; i < 8; ++i)
431  {
432  minSS.x = std::min(minSS.x, corners[i].x);
433  minSS.y = std::min(minSS.y, corners[i].y);
434  maxSS.x = std::max(maxSS.x, corners[i].x);
435  maxSS.y = std::max(maxSS.y, corners[i].y);
436  }
437 
438  _rectSS.set(minSS.x,
439  minSS.y,
440  maxSS.x - minSS.x,
441  maxSS.y - minSS.y);
442  //_rectSS.print("_rectSS: ");
443 }
int SLint
Definition: SL.h:170
SLVec3< SLfloat > SLVec3f
Definition: SLVec3.h:318
SLRectf _rectSS
Bounding rectangle in screen space.
Definition: SLAABBox.h:100
SLVec3f _maxWS
Max. corner in world space.
Definition: SLAABBox.h:86
SLVec3f _minWS
Min. corner in world space.
Definition: SLAABBox.h:84
Singleton class holding all OpenGL states.
Definition: SLGLState.h:71
static SLGLState * instance()
Public static instance getter for singleton pattern.
Definition: SLGLState.h:74
SLMat4f viewMatrix
matrix for the active cameras view transform
Definition: SLGLState.h:91
SLMat4f viewportMatrix()
Definition: SLGLState.h:143
SLMat4f projectionMatrix
matrix for projection transform
Definition: SLGLState.h:90
SLVec3< T > multVec(SLVec3< T > v) const
Definition: SLMat4.h:576
void set(const T X, const T Y, const T WIDTH, const T HEIGHT)
Definition: SLRect.h:42
T y
Definition: SLVec3.h:43
T x
Definition: SLVec3.h:43
T z
Definition: SLVec3.h:43

◆ centerOS()

SLVec3f SLAABBox::centerOS ( )
inline

Definition at line 54 of file SLAABBox.h.

54 { return _centerOS; }
SLVec3f _centerOS
Center of AABB in object space.
Definition: SLAABBox.h:89

◆ centerWS()

SLVec3f SLAABBox::centerWS ( )
inline

Definition at line 50 of file SLAABBox.h.

50 { return _centerWS; }
SLVec3f _centerWS
Center of AABB in world space.
Definition: SLAABBox.h:88

◆ drawAxisWS()

void SLAABBox::drawAxisWS ( )

Draws the axis in world space with lines in a color.

Definition at line 271 of file SLAABBox.cpp.

272 {
273  if (!_vao.vaoID()) generateVAO();
275  SLCol4f::RED,
276  2.0f,
277  24,
278  2);
281  2.0f,
282  26,
283  2);
286  2.0f,
287  28,
288  2);
289 }
@ PT_lines
Definition: SLGLEnums.h:32
SLGLVertexArrayExt _vao
Vertex array object for rendering.
Definition: SLAABBox.h:101
void generateVAO()
Generates the vertex buffer for the line visualization.
Definition: SLAABBox.cpp:212
void drawArrayAsColored(SLGLPrimitiveType primitiveType, SLCol4f color, SLfloat lineOrPointSize=1.0f, SLuint indexFirstVertex=0, SLuint countVertices=0)
Draws the array as the specified primitive with the color.
SLuint vaoID() const
Returns either the VAO id or the VBO id.
static SLVec4 GREEN
Definition: SLVec4.h:217
static SLVec4 RED
Definition: SLVec4.h:216
static SLVec4 BLUE
Definition: SLVec4.h:218

◆ drawBoneWS()

void SLAABBox::drawBoneWS ( )

Draws the joint axis and the parent bone in world space.

The joints x-axis is drawn in red, the y-axis in green and the z-axis in blue. If the parent displacement is a bone it is drawn in yellow, if it is a an offset displacement in magenta. See also SLAABBox::updateBoneWS.

Definition at line 296 of file SLAABBox.cpp.

297 {
298  if (!_vao.vaoID()) generateVAO();
300  SLCol4f::RED,
301  2.0f,
302  24,
303  2);
306  2.0f,
307  26,
308  2);
311  2.0f,
312  28,
313  2);
314 
315  // draw either an offset line or a bone line as the parent
316  if (!_boneIsOffset)
319  1.0f,
320  30,
321  2);
322  else
325  1.0f,
326  30,
327  2);
328 }
SLbool _boneIsOffset
Flag if the connection parent to us is a bone or an offset.
Definition: SLAABBox.h:97
static SLVec4 YELLOW
Definition: SLVec4.h:219
static SLVec4 MAGENTA
Definition: SLVec4.h:221

◆ drawWS()

void SLAABBox::drawWS ( const SLCol4f color)

Draws the AABB in world space with lines in a color.

Definition at line 260 of file SLAABBox.cpp.

261 {
262  if (!_vao.vaoID()) generateVAO();
264  color,
265  1.0f,
266  0,
267  24);
268 }

◆ fromOStoWS()

void SLAABBox::fromOStoWS ( const SLVec3f minOS,
const SLVec3f maxOS,
const SLMat4f wm 
)

Recalculate min and max after transformation in world coords.

Definition at line 46 of file SLAABBox.cpp.

49 {
50  // Do not transform empty AABB (such as from the camera)
52  return;
53 
54  _minOS.set(minOS);
55  _maxOS.set(maxOS);
56  _minWS.set(minOS);
57  _maxWS.set(maxOS);
58 
59  // we need to transform all 8 corners for a non-optimal bounding box
60  SLVec3f vCorner[8];
61  SLint i;
62 
63  vCorner[0].set(_minWS);
64  vCorner[1].set(_maxWS.x, _minWS.y, _minWS.z);
65  vCorner[2].set(_maxWS.x, _minWS.y, _maxWS.z);
66  vCorner[3].set(_minWS.x, _minWS.y, _maxWS.z);
67  vCorner[4].set(_maxWS.x, _maxWS.y, _minWS.z);
68  vCorner[5].set(_minWS.x, _maxWS.y, _minWS.z);
69  vCorner[6].set(_minWS.x, _maxWS.y, _maxWS.z);
70  vCorner[7].set(_maxWS);
71 
72  // apply world transform
73  for (i = 0; i < 8; ++i)
74  vCorner[i] = wm.multVec(vCorner[i]);
75 
76  // sets the minimum and maximum of the vertex components of the 8 corners
77  _minWS.set(vCorner[0]);
78  _maxWS.set(vCorner[0]);
79  for (i = 1; i < 8; ++i)
80  {
81  _minWS.setMin(vCorner[i]);
82  _maxWS.setMax(vCorner[i]);
83  }
84 
85  // set coordinate axis in world space
90 
91  // Delete OpenGL vertex array
92  if (_vao.vaoID()) _vao.clearAttribs();
93 }
SLVec3f _minOS
Min. corner in object space.
Definition: SLAABBox.h:85
SLVec3f _axisZWS
World space z-axis vector.
Definition: SLAABBox.h:96
SLVec3f _axisXWS
World space x-axis vector.
Definition: SLAABBox.h:94
SLVec3f _maxOS
Max. corner in object space.
Definition: SLAABBox.h:87
SLVec3f _axisYWS
World space y-axis vector.
Definition: SLAABBox.h:95
SLVec3f _axis0WS
World space axis center point.
Definition: SLAABBox.h:93
SLVec3f maxOS()
Definition: SLAABBox.h:53
SLVec3f minOS()
Definition: SLAABBox.h:52
void clearAttribs()
Clears the attribute definition.
void setMax(const SLVec3 &v)
Definition: SLVec3.h:147
static SLVec3 AXISY
Definition: SLVec3.h:298
static SLVec3 AXISX
Definition: SLVec3.h:297
void set(const T X, const T Y, const T Z)
Definition: SLVec3.h:59
void setMin(const SLVec3 &v)
Definition: SLVec3.h:144
static SLVec3 AXISZ
Definition: SLVec3.h:299
static SLVec3 ZERO
Definition: SLVec3.h:285

◆ fromWStoOS()

void SLAABBox::fromWStoOS ( const SLVec3f minWS,
const SLVec3f maxWS,
const SLMat4f wmI 
)

Recalculate min and max before transformation in object coords.

Definition at line 96 of file SLAABBox.cpp.

99 {
100  _minOS.set(minWS);
101  _maxOS.set(maxWS);
102  _minWS.set(minWS);
103  _maxWS.set(maxWS);
104 
105  // we need to transform all 8 corners for a non-optimal bounding box
106  SLVec3f vCorner[8];
107  SLint i;
108 
109  vCorner[0].set(_minOS);
110  vCorner[1].set(_maxOS.x, _minOS.y, _minOS.z);
111  vCorner[2].set(_maxOS.x, _minOS.y, _maxOS.z);
112  vCorner[3].set(_minOS.x, _minOS.y, _maxOS.z);
113  vCorner[4].set(_maxOS.x, _maxOS.y, _minOS.z);
114  vCorner[5].set(_minOS.x, _maxOS.y, _minOS.z);
115  vCorner[6].set(_minOS.x, _maxOS.y, _maxOS.z);
116  vCorner[7].set(_maxOS);
117 
118  // apply world transform
119  for (i = 0; i < 8; ++i)
120  vCorner[i] = wmI.multVec(vCorner[i]);
121 
122  // sets the minimum and maximum of the vertex components of the 8 corners
123  _minOS.set(vCorner[0]);
124  _maxOS.set(vCorner[0]);
125  for (i = 1; i < 8; ++i)
126  {
127  _minOS.setMin(vCorner[i]);
128  _maxOS.setMax(vCorner[i]);
129  }
130 
131  // Delete OpenGL vertex array
132  if (_vao.vaoID()) _vao.clearAttribs();
133 
134  // Set center & radius of the bounding sphere around the AABB
135  _centerOS.set((_minOS + _maxOS) * 0.5f);
136  SLVec3f extent(_maxOS - _centerOS);
137  _radiusOS = extent.length();
138 }
SLVec3f minWS()
Definition: SLAABBox.h:48
SLfloat _radiusOS
Radius of sphere around AABB in OS.
Definition: SLAABBox.h:91
SLVec3f maxWS()
Definition: SLAABBox.h:49

◆ generateVAO()

void SLAABBox::generateVAO ( )

Generates the vertex buffer for the line visualization.

Definition at line 212 of file SLAABBox.cpp.

213 {
214  SLVVec3f P; // vertex positions
215 
216  // Bounding box lines in world space
217  P.push_back(SLVec3f(_minWS.x, _minWS.y, _minWS.z)); // lower rect
218  P.push_back(SLVec3f(_maxWS.x, _minWS.y, _minWS.z));
219  P.push_back(SLVec3f(_maxWS.x, _minWS.y, _minWS.z));
220  P.push_back(SLVec3f(_maxWS.x, _minWS.y, _maxWS.z));
221  P.push_back(SLVec3f(_maxWS.x, _minWS.y, _maxWS.z));
222  P.push_back(SLVec3f(_minWS.x, _minWS.y, _maxWS.z));
223  P.push_back(SLVec3f(_minWS.x, _minWS.y, _maxWS.z));
224  P.push_back(SLVec3f(_minWS.x, _minWS.y, _minWS.z));
225 
226  P.push_back(SLVec3f(_minWS.x, _maxWS.y, _minWS.z)); // upper rect
227  P.push_back(SLVec3f(_maxWS.x, _maxWS.y, _minWS.z));
228  P.push_back(SLVec3f(_maxWS.x, _maxWS.y, _minWS.z));
229  P.push_back(SLVec3f(_maxWS.x, _maxWS.y, _maxWS.z));
230  P.push_back(SLVec3f(_maxWS.x, _maxWS.y, _maxWS.z));
231  P.push_back(SLVec3f(_minWS.x, _maxWS.y, _maxWS.z));
232  P.push_back(SLVec3f(_minWS.x, _maxWS.y, _maxWS.z));
233 
234  P.push_back(SLVec3f(_minWS.x, _maxWS.y, _minWS.z)); // vertical lines
235  P.push_back(SLVec3f(_minWS.x, _minWS.y, _minWS.z));
236  P.push_back(SLVec3f(_minWS.x, _maxWS.y, _minWS.z));
237  P.push_back(SLVec3f(_maxWS.x, _minWS.y, _minWS.z));
238  P.push_back(SLVec3f(_maxWS.x, _maxWS.y, _minWS.z));
239  P.push_back(SLVec3f(_maxWS.x, _minWS.y, _maxWS.z));
240  P.push_back(SLVec3f(_maxWS.x, _maxWS.y, _maxWS.z));
241  P.push_back(SLVec3f(_minWS.x, _minWS.y, _maxWS.z));
242  P.push_back(SLVec3f(_minWS.x, _maxWS.y, _maxWS.z)); // 24
243 
244  // Axis lines in world space
245  P.push_back(SLVec3f(_axis0WS.x, _axis0WS.y, _axis0WS.z)); // x-axis
246  P.push_back(SLVec3f(_axisXWS.x, _axisXWS.y, _axisXWS.z));
247  P.push_back(SLVec3f(_axis0WS.x, _axis0WS.y, _axis0WS.z)); // y-axis
248  P.push_back(SLVec3f(_axisYWS.x, _axisYWS.y, _axisYWS.z));
249  P.push_back(SLVec3f(_axis0WS.x, _axis0WS.y, _axis0WS.z)); // z-axis
250  P.push_back(SLVec3f(_axisZWS.x, _axisZWS.y, _axisZWS.z)); // 30
251 
252  // Bone points in world space
253  P.push_back(SLVec3f(_parent0WS.x, _parent0WS.y, _parent0WS.z));
254  P.push_back(SLVec3f(_axis0WS.x, _axis0WS.y, _axis0WS.z));
255 
257 }
vector< SLVec3f > SLVVec3f
Definition: SLVec3.h:325
SLVec3f _parent0WS
World space vector to the parent position.
Definition: SLAABBox.h:98
void generateVertexPos(SLVVec2f *p)
Adds or updates & generates a position vertex attribute for colored line or point drawing.

◆ isHitInOS()

SLbool SLAABBox::isHitInOS ( SLRay ray)

SLAABBox::isHitInWS: Ray - AABB Intersection Test in object space.

Definition at line 331 of file SLAABBox.cpp.

332 {
333  // See: "An Efficient and Robust Ray Box Intersection Algorithm"
334  // by Amy L. Williams, Steve Barrus, R. Keith Morley, Peter Shirley
335  // This test is about 10% faster than the test from Woo
336  // It need the pre computed values invDir and sign in SLRay
337 
338  SLVec3f params[2] = {_minOS, _maxOS};
339  SLfloat tymin, tymax, tzmin, tzmax;
340 
341  ray->tmin = (params[ray->signOS[0]].x - ray->originOS.x) * ray->invDirOS.x;
342  ray->tmax = (params[1 - ray->signOS[0]].x - ray->originOS.x) * ray->invDirOS.x;
343  tymin = (params[ray->signOS[1]].y - ray->originOS.y) * ray->invDirOS.y;
344  tymax = (params[1 - ray->signOS[1]].y - ray->originOS.y) * ray->invDirOS.y;
345 
346  if ((ray->tmin > tymax) || (tymin > ray->tmax)) return false;
347  if (tymin > ray->tmin) ray->tmin = tymin;
348  if (tymax < ray->tmax) ray->tmax = tymax;
349 
350  tzmin = (params[ray->signOS[2]].z - ray->originOS.z) * ray->invDirOS.z;
351  tzmax = (params[1 - ray->signOS[2]].z - ray->originOS.z) * ray->invDirOS.z;
352 
353  if ((ray->tmin > tzmax) || (tzmin > ray->tmax)) return false;
354  if (tzmin > ray->tmin) ray->tmin = tzmin;
355  if (tzmax < ray->tmax) ray->tmax = tzmax;
356 
357  return ((ray->tmin < ray->length) && (ray->tmax > 0));
358 }
float SLfloat
Definition: SL.h:173
SLfloat tmax
max. dist. of last AABB intersection
Definition: SLRay.h:121
SLVec3f invDirOS
Inverse ray dir for fast AABB hit in OS.
Definition: SLRay.h:117
SLfloat tmin
min. dist. of last AABB intersection
Definition: SLRay.h:120
SLfloat length
length from origin to an intersection
Definition: SLRay.h:77
SLint signOS[3]
Sign of invDir for fast AABB hit in OS.
Definition: SLRay.h:119
SLVec3f originOS
Vector to the origin of ray in OS.
Definition: SLRay.h:80

◆ isHitInWS()

SLbool SLAABBox::isHitInWS ( SLRay ray)

SLAABBox::isHitInWS: Ray - AABB Intersection Test in world space.

Definition at line 361 of file SLAABBox.cpp.

362 {
363  // See: "An Efficient and Robust Ray Box Intersection Algorithm"
364  // by Amy L. Williams, Steve Barrus, R. Keith Morley, Peter Shirley
365  // This test is about 10% faster than the test from Woo
366  // It needs the pre-computed values invDir and sign in SLRay
367  SLVec3f params[2] = {_minWS, _maxWS};
368  SLfloat tymin, tymax, tzmin, tzmax;
369 
370  ray->tmin = (params[ray->sign[0]].x - ray->origin.x) * ray->invDir.x;
371  ray->tmax = (params[1 - ray->sign[0]].x - ray->origin.x) * ray->invDir.x;
372  tymin = (params[ray->sign[1]].y - ray->origin.y) * ray->invDir.y;
373  tymax = (params[1 - ray->sign[1]].y - ray->origin.y) * ray->invDir.y;
374 
375  if ((ray->tmin > tymax) || (tymin > ray->tmax)) return false;
376  if (tymin > ray->tmin) ray->tmin = tymin;
377  if (tymax < ray->tmax) ray->tmax = tymax;
378 
379  tzmin = (params[ray->sign[2]].z - ray->origin.z) * ray->invDir.z;
380  tzmax = (params[1 - ray->sign[2]].z - ray->origin.z) * ray->invDir.z;
381 
382  if ((ray->tmin > tzmax) || (tzmin > ray->tmax)) return false;
383  if (tzmin > ray->tmin) ray->tmin = tzmin;
384  if (tzmax < ray->tmax) ray->tmax = tzmax;
385 
386  return ((ray->tmin < ray->length) && (ray->tmax > 0));
387 }
SLint sign[3]
Sign of invDir for fast AABB hit in WS.
Definition: SLRay.h:118
SLVec3f origin
Vector to the origin of ray in WS.
Definition: SLRay.h:75
SLVec3f invDir
Inverse ray dir for fast AABB hit in WS.
Definition: SLRay.h:116

◆ isVisible() [1/2]

SLbool SLAABBox::isVisible ( )
inline

Definition at line 56 of file SLAABBox.h.

56 { return _isVisible; }
SLbool _isVisible
Flag if AABB is in the view frustum.
Definition: SLAABBox.h:99

◆ isVisible() [2/2]

void SLAABBox::isVisible ( SLbool  visible)
inline

Definition at line 44 of file SLAABBox.h.

44 { _isVisible = visible; }

◆ maxOS() [1/2]

SLVec3f SLAABBox::maxOS ( )
inline

Definition at line 53 of file SLAABBox.h.

53 { return _maxOS; }

◆ maxOS() [2/2]

void SLAABBox::maxOS ( const SLVec3f maxC)
inline

Definition at line 42 of file SLAABBox.h.

42 { _maxOS = maxC; }

◆ maxWS() [1/2]

SLVec3f SLAABBox::maxWS ( )
inline

Definition at line 49 of file SLAABBox.h.

49 { return _maxWS; }

◆ maxWS() [2/2]

void SLAABBox::maxWS ( const SLVec3f maxC)
inline

Definition at line 40 of file SLAABBox.h.

40 { _maxWS = maxC; }

◆ mergeWS()

void SLAABBox::mergeWS ( SLAABBox bb)

Merges the bounding box bb to this one by extending this one axis aligned.

Definition at line 390 of file SLAABBox.cpp.

391 {
392  if (bb.minWS() != SLVec3f::ZERO && bb.maxWS() != SLVec3f::ZERO)
393  {
394  _minWS.setMin(bb.minWS());
395  _maxWS.setMax(bb.maxWS());
396  }
397 }
void minWS(const SLVec3f &minC)
Definition: SLAABBox.h:39
void maxWS(const SLVec3f &maxC)
Definition: SLAABBox.h:40

◆ minOS() [1/2]

SLVec3f SLAABBox::minOS ( )
inline

Definition at line 52 of file SLAABBox.h.

52 { return _minOS; }

◆ minOS() [2/2]

void SLAABBox::minOS ( const SLVec3f minC)
inline

Definition at line 41 of file SLAABBox.h.

41 { _minOS = minC; }

◆ minWS() [1/2]

SLVec3f SLAABBox::minWS ( )
inline

Definition at line 48 of file SLAABBox.h.

48 { return _minWS; }

◆ minWS() [2/2]

void SLAABBox::minWS ( const SLVec3f minC)
inline

Definition at line 39 of file SLAABBox.h.

39 { _minWS = minC; }

◆ radiusOS()

SLfloat SLAABBox::radiusOS ( )
inline

Definition at line 55 of file SLAABBox.h.

55 { return _radiusOS; }

◆ radiusWS()

SLfloat SLAABBox::radiusWS ( )
inline

Definition at line 51 of file SLAABBox.h.

51 { return _radiusWS; }
SLfloat _radiusWS
Radius of sphere around AABB in WS.
Definition: SLAABBox.h:90

◆ rectCoverageInSS()

SLfloat SLAABBox::rectCoverageInSS ( )

Calculates the bounding rectangle in screen space and returns coverage in SS.

Definition at line 446 of file SLAABBox.cpp.

447 {
448  calculateRectSS();
449 
450  SLGLState* stateGL = SLGLState::instance();
451  SLfloat areaSS = _rectSS.width * _rectSS.height;
452  SLVec4i vp = stateGL->viewport();
453  SLfloat areaFullScreen = (float)vp.z * (float)vp.w;
454  SLfloat coverage = areaSS / areaFullScreen;
455  return coverage;
456 }
void calculateRectSS()
Calculates the AABBs min. and max. corners in screen space.
Definition: SLAABBox.cpp:400
void viewport(SLint x, SLint y, SLsizei width, SLsizei height)
Definition: SLGLState.cpp:378
T width
Definition: SLRect.h:29
T height
Definition: SLRect.h:29
T w
Definition: SLVec4.h:32
T z
Definition: SLVec4.h:32

◆ rectSS()

SLRectf& SLAABBox::rectSS ( )
inline

Definition at line 58 of file SLAABBox.h.

58 { return _rectSS; }

◆ reset()

void SLAABBox::reset ( )

Resets initial state without contents.

Definition at line 23 of file SLAABBox.cpp.

24 {
28  _radiusWS = 0;
29 
33  _radiusOS = 0;
34 
35  _sqrViewDist = 0;
40  _isVisible = true;
41 
42  _rectSS.setZero();
43 }
SLfloat _sqrViewDist
Squared dist. from center to viewpoint.
Definition: SLAABBox.h:92
void setZero()
Definition: SLRect.h:49

◆ setCenterAndRadiusWS()

void SLAABBox::setCenterAndRadiusWS ( )

Calculates center & radius of the bounding sphere around the AABB.

Definition at line 204 of file SLAABBox.cpp.

205 {
206  _centerWS.set((_minWS + _maxWS) * 0.5f);
207  SLVec3f ext(_maxWS - _centerWS);
208  _radiusWS = ext.length();
209 }

◆ sqrViewDist() [1/2]

SLfloat SLAABBox::sqrViewDist ( )
inline

Definition at line 57 of file SLAABBox.h.

57 { return _sqrViewDist; }

◆ sqrViewDist() [2/2]

void SLAABBox::sqrViewDist ( SLfloat  sqrVD)
inline

Definition at line 45 of file SLAABBox.h.

45 { _sqrViewDist = sqrVD; }

◆ updateAxisWS()

void SLAABBox::updateAxisWS ( const SLMat4f wm)

Updates the axis of the owning node.

Definition at line 141 of file SLAABBox.cpp.

142 {
143  // set coordinate axis in world space
148 
149  // Delete OpenGL vertex array
150  if (_vao.vaoID()) _vao.clearAttribs();
151 }

◆ updateBoneWS()

void SLAABBox::updateBoneWS ( const SLMat4f parentWM,
SLbool  isRoot,
const SLMat4f nodeWM 
)

Updates joints axis and the bone line from the parent to us.

If the node has a skeleton assigned the method updates the axis and bone visualization lines of the joint. Note that joints bone line is drawn by its children. So the bone line in here is the bone from the parent to us. If this parent bone direction is not along the parents Y axis we interpret the connection not as a bone but as an offset displacement. Bones will be drawn in SLAABBox::drawBoneWS in yellow and displacements in magenta. If the joint has no parent (the root) no line is drawn.

Definition at line 162 of file SLAABBox.cpp.

165 {
166  // set coordinate axis centre point
167  _axis0WS = nodeWM.multVec(SLVec3f::ZERO);
168 
169  // set scale factor for coordinate axis
170  SLfloat axisScaleFactor = 0.03f;
171 
172  if (!isRoot)
173  {
174  // build the parent pos in WM
175  _parent0WS = parentWM.multVec(SLVec3f::ZERO);
176 
177  // set the axis scale factor depending on the length of the parent bone
178  SLVec3f parentToMe = _axis0WS - _parent0WS;
179  axisScaleFactor = std::max(parentToMe.length() / 10.0f, axisScaleFactor);
180 
181  // check if the parent to me direction is parallel to the parents actual y-axis
182  parentToMe.normalize();
183  SLVec3f parentY = parentWM.axisY();
184  parentY.normalize();
185  _boneIsOffset = parentToMe.dot(parentY) < (1.0f - FLT_EPSILON);
186  }
187  else
188  {
189  // for the root node don't draw a parent bone
191  _boneIsOffset = false;
192  }
193 
194  // set coordinate axis end points
195  _axisXWS = nodeWM.multVec(SLVec3f::AXISX * axisScaleFactor);
196  _axisYWS = nodeWM.multVec(SLVec3f::AXISY * axisScaleFactor);
197  _axisZWS = nodeWM.multVec(SLVec3f::AXISZ * axisScaleFactor);
198 
199  // Delete OpenGL vertex array
200  if (_vao.vaoID()) _vao.clearAttribs();
201 }
SLVec3< T > axisY() const
Definition: SLMat4.h:186
SLVec3 & normalize()
Definition: SLVec3.h:124
T length() const
Definition: SLVec3.h:122
T dot(const SLVec3 &v) const
Definition: SLVec3.h:117

Member Data Documentation

◆ _axis0WS

SLVec3f SLAABBox::_axis0WS
private

World space axis center point.

Definition at line 93 of file SLAABBox.h.

◆ _axisXWS

SLVec3f SLAABBox::_axisXWS
private

World space x-axis vector.

Definition at line 94 of file SLAABBox.h.

◆ _axisYWS

SLVec3f SLAABBox::_axisYWS
private

World space y-axis vector.

Definition at line 95 of file SLAABBox.h.

◆ _axisZWS

SLVec3f SLAABBox::_axisZWS
private

World space z-axis vector.

Definition at line 96 of file SLAABBox.h.

◆ _boneIsOffset

SLbool SLAABBox::_boneIsOffset
private

Flag if the connection parent to us is a bone or an offset.

Definition at line 97 of file SLAABBox.h.

◆ _centerOS

SLVec3f SLAABBox::_centerOS
private

Center of AABB in object space.

Definition at line 89 of file SLAABBox.h.

◆ _centerWS

SLVec3f SLAABBox::_centerWS
private

Center of AABB in world space.

Definition at line 88 of file SLAABBox.h.

◆ _isVisible

SLbool SLAABBox::_isVisible
private

Flag if AABB is in the view frustum.

Definition at line 99 of file SLAABBox.h.

◆ _maxOS

SLVec3f SLAABBox::_maxOS
private

Max. corner in object space.

Definition at line 87 of file SLAABBox.h.

◆ _maxWS

SLVec3f SLAABBox::_maxWS
private

Max. corner in world space.

Definition at line 86 of file SLAABBox.h.

◆ _minOS

SLVec3f SLAABBox::_minOS
private

Min. corner in object space.

Definition at line 85 of file SLAABBox.h.

◆ _minWS

SLVec3f SLAABBox::_minWS
private

Min. corner in world space.

Definition at line 84 of file SLAABBox.h.

◆ _parent0WS

SLVec3f SLAABBox::_parent0WS
private

World space vector to the parent position.

Definition at line 98 of file SLAABBox.h.

◆ _radiusOS

SLfloat SLAABBox::_radiusOS
private

Radius of sphere around AABB in OS.

Definition at line 91 of file SLAABBox.h.

◆ _radiusWS

SLfloat SLAABBox::_radiusWS
private

Radius of sphere around AABB in WS.

Definition at line 90 of file SLAABBox.h.

◆ _rectSS

SLRectf SLAABBox::_rectSS
private

Bounding rectangle in screen space.

Definition at line 100 of file SLAABBox.h.

◆ _sqrViewDist

SLfloat SLAABBox::_sqrViewDist
private

Squared dist. from center to viewpoint.

Definition at line 92 of file SLAABBox.h.

◆ _vao

SLGLVertexArrayExt SLAABBox::_vao
private

Vertex array object for rendering.

Definition at line 101 of file SLAABBox.h.


The documentation for this class was generated from the following files: