Visualization Library 2.0.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
SceneManager.cpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
33 #include <vlGraphics/Actor.hpp>
34 #include <vlGraphics/Camera.hpp>
35 #include <vlGraphics/Effect.hpp>
36 #include <vlGraphics/Scissor.hpp>
37 #include <vlGraphics/Texture.hpp>
38 #include <vlCore/Image.hpp>
39 
40 using namespace vl;
41 
42 //-----------------------------------------------------------------------------
44 {
45  VL_DEBUG_SET_OBJECT_NAME()
46  // mActors = new ActorCollection;
47  mBoundsDirty = true;
48  mCullingEnabled = true;
49  mEnableMask = 0xFFFFFFFF;
50 }
51 //-----------------------------------------------------------------------------
53 {
54  ActorCollection actors;
55  extractActors(actors);
56 
57  AABB bbox;
58  bbox.setNull();
59  for(int i=0; i<actors.size(); ++i)
60  {
61  actors.at(i)->computeBounds();
62  bbox += actors.at(i)->boundingBox();
63  }
64  setBoundingBox(bbox);
65 
66  // better method
67  Sphere sphere;
68  real radius = real(-1.0);
69  for(int i=0; i<actors.size(); ++i)
70  {
71  if (actors.at(i)->boundingSphere().isNull())
72  continue;
73  real r = (actors.at(i)->boundingSphere().center() - boundingBox().center()).length() + actors.at(i)->boundingSphere().radius();
74  if (r > radius)
75  radius = r;
76  }
77  sphere.setCenter(boundingBox().center());
78  sphere.setRadius(radius);
79  setBoundingSphere(sphere);
80 
81  setBoundsDirty(false);
82 }
83 //-----------------------------------------------------------------------------
85 {
86  return a->isEnabled() && (a->enableMask() & enableMask()) != 0;
87 }
88 //-----------------------------------------------------------------------------
Associates a Renderable object to an Effect and Transform.
Definition: Actor.hpp:130
const T * at(int i) const
Definition: Collection.hpp:100
SceneManager()
Constructor.
bool isEnabled() const
Whether an Actor should be considered for rendering, picking, scene bounding box calculation etc...
Definition: Actor.hpp:277
unsigned int enableMask() const
The enable mask to be used by extractVisibleActors()
int size() const
Definition: Collection.hpp:82
const vec3 & center() const
Returns the center of the sphere.
Definition: Sphere.hpp:68
vec3 center() const
Returns the center of the AABB.
Definition: AABB.cpp:184
unsigned int mEnableMask
void setBoundingBox(const AABB &bbox)
Explicitly set the scene manager&#39;s bounding sphere. See also computeBounds().
void setNull()
Sets ths AABB as null, that is, empty.
Definition: AABB.hpp:57
const Sphere & boundingSphere() const
Returns the bounding sphere (not guaranteed to be up to date) that contains this Actor.
Definition: Actor.hpp:208
unsigned int enableMask() const
The enable mask of an Actor is usually used to defines whether the actor should be rendered or not de...
Definition: Actor.hpp:270
bool isEnabled(Actor *a) const
Returns true if "a->enableMask() & enableMask()) != 0".
Visualization Library main namespace.
real radius() const
Returns the radius of the sphere.
Definition: Sphere.hpp:74
void setBoundsDirty(bool dirty)
Flags a scene manager&#39;s bounding box and bounding sphere as dirty. The bounds will be recomputed usin...
const AABB & boundingBox() const
Returns the scene manager&#39;s bounding box.
The AABB class implements an axis-aligned bounding box using vl::real precision.
Definition: AABB.hpp:44
void setBoundingSphere(const Sphere &sphere)
Explicitly set the scene manager&#39;s bounding sphere. See also computeBounds().
void setRadius(real radius)
Sets the radius of the sphere.
Definition: Sphere.hpp:71
const AABB & boundingBox() const
Returns the bounding box (not guaranteed to be up to date) that contains this Actor.
Definition: Actor.hpp:205
The Sphere class defines a sphere using a center and a radius using vl::real precision.
Definition: Sphere.hpp:43
Defined as a simple subclass of Collection<Actor>, see Collection for more information.
Definition: Actor.hpp:479
virtual void extractActors(ActorCollection &list)=0
Appends all the Actors contained in the scene manager without performing frustum culling or checking ...
void computeBounds()
Computes the bounding box and bounding sphere of an Actor if boundsDirty().
Definition: Actor.cpp:95
T length(T v)
Definition: glsl_math.hpp:1084
virtual void computeBounds()
Computes the bounding box and bounding sphere of the scene manager and of all the Actors contained in...
bool isNull() const
Returns true if the sphere is null, ie, if radius is < 0.
Definition: Sphere.hpp:59
void setCenter(const vec3 &center)
Sets the center of the sphere.
Definition: Sphere.hpp:65