CHAI3D  3.0.0
CWorld.h
Go to the documentation of this file.
1 //==============================================================================
2 /*
3  Software License Agreement (BSD License)
4  Copyright (c) 2003-2015, CHAI3D.
5  (www.chai3d.org)
6 
7  All rights reserved.
8 
9  Redistribution and use in source and binary forms, with or without
10  modification, are permitted provided that the following conditions
11  are met:
12 
13  * Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15 
16  * Redistributions in binary form must reproduce the above
17  copyright notice, this list of conditions and the following
18  disclaimer in the documentation and/or other materials provided
19  with the distribution.
20 
21  * Neither the name of CHAI3D nor the names of its contributors may
22  be used to endorse or promote products derived from this software
23  without specific prior written permission.
24 
25  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  POSSIBILITY OF SUCH DAMAGE.
37 
38  \author <http://www.chai3d.org>
39  \author Francois Conti
40  \version 3.0.0 $Rev: 1656 $
41 */
42 //==============================================================================
43 
44 //------------------------------------------------------------------------------
45 #ifndef CWorldH
46 #define CWorldH
47 //------------------------------------------------------------------------------
48 #include "display/CCamera.h"
49 #include "graphics/CColor.h"
51 #include "graphics/CFog.h"
52 #include "materials/CTexture2d.h"
53 #include "world/CGenericObject.h"
54 //------------------------------------------------------------------------------
55 #include <vector>
56 //------------------------------------------------------------------------------
57 
58 //------------------------------------------------------------------------------
59 namespace chai3d {
60 //------------------------------------------------------------------------------
61 
62 //------------------------------------------------------------------------------
63 class cGenericLight;
64 class cShadowMap;
65 //------------------------------------------------------------------------------
67 #define C_MAXIMUM_OPENGL_LIGHT_COUNT 8
68 //------------------------------------------------------------------------------
69 
70 //==============================================================================
77 //==============================================================================
78 
79 //==============================================================================
91 //==============================================================================
92 class cWorld : public cGenericObject
93 {
94  friend class cGenericLight;
95 
96  //--------------------------------------------------------------------------
97  // CONSTRUCTOR & DESTRUCTOR:
98  //--------------------------------------------------------------------------
99 
100 public:
101 
103  cWorld();
104 
106  virtual ~cWorld();
107 
108 
109  //--------------------------------------------------------------------------
110  // PUBLIC METHODS - BACKGROUND PROPERTIES
111  //--------------------------------------------------------------------------
112 
113 public:
114 
116  void setBackgroundColor(const GLfloat a_red,
117  const GLfloat a_green,
118  const GLfloat a_blue);
119 
121  void setBackgroundColor(const cColorf& a_color);
122 
125 
126 
127  //-----------------------------------------------------------------------
128  // PUBLIC METHODS - LIGHT SOURCES:
129  //-----------------------------------------------------------------------
130 
131 public:
132 
134  void enableLightSourceRendering(bool enable) { m_renderLightSources = enable; }
135 
137  virtual cGenericLight* getLightSource(int index);
138 
139 
140  //-----------------------------------------------------------------------
141  // PUBLIC METHODS - COLLISION / INTERACTION:
142  //-----------------------------------------------------------------------
143 
144 public:
145 
147  virtual bool computeCollisionDetection(const cVector3d& a_segmentPointA,
148  const cVector3d& a_segmentPointB,
149  cCollisionRecorder& a_recorder,
150  cCollisionSettings& a_settings);
151 
153  virtual void computeLocalInteraction(const cVector3d& a_toolPos,
154  const cVector3d& a_toolVel,
155  const unsigned int a_IDN);
156 
157 
158  //-----------------------------------------------------------------------
159  // PUBLIC METHODS - SHADOW CASTING:
160  //-----------------------------------------------------------------------
161 
162 public:
163 
165  void setUseShadowCasting(bool a_enabled) { m_useShadowCasting = a_enabled; }
166 
169 
171  void setShadowIntensity(double a_intensity) { m_shadowIntensity = cClamp01(a_intensity); }
172 
173  // This method returns the shadow intensity.
174  double getShadowIntensity() { return (m_shadowIntensity); }
175 
177  virtual bool updateShadowMaps(const bool a_mirrorX = false,
178  const bool a_mirrorY = false,
179  const int a_displayContext = 0);
180 
181 
182  //--------------------------------------------------------------------------
183  // PUBLIC MEMBERS:
184  //--------------------------------------------------------------------------
185 
186 public:
187 
190 
193 
195  std::vector<cGenericLight*> m_lights;
196 
198  std::list<cShadowMap*> m_shadowMaps;
199 
201  double m_worldModelView[16];
202 
203 
204  //-----------------------------------------------------------------------
205  // VIRTUAL PROTECTED METHODS:
206  //-----------------------------------------------------------------------
207 
208 protected:
209 
211  virtual void render(cRenderOptions& a_options);
212 
213 
214  //--------------------------------------------------------------------------
215  // PROTECTED METHODS:
216  //--------------------------------------------------------------------------
217 
218 protected:
219 
221  bool addLightSource(cGenericLight* a_light);
222 
224  bool removeLightSource(cGenericLight* a_light);
225 
228 
229 
230  //--------------------------------------------------------------------------
231  // PROTECTED MEMBERS:
232  //--------------------------------------------------------------------------
233 
234 protected:
235 
238 
241 
244 };
245 
246 //------------------------------------------------------------------------------
247 } // namespace chai3d
248 //------------------------------------------------------------------------------
249 
250 //------------------------------------------------------------------------------
251 #endif
252 //------------------------------------------------------------------------------
253 
This class implements a 3D vector.
Definition: CVector3d.h:85
double m_worldModelView[16]
It's useful to store the world's modelview matrix, for rendering stuff in "global" coordinates...
Definition: CWorld.h:201
Implements arrays of 3D triangles.
cColorf getBackgroundColor() const
This method returns the background color of this world.
Definition: CWorld.h:124
This structures provide a containers for storing rendering options that are passed through the sceneg...
Definition: CRenderOptions.h:82
bool getUseShadowCastring()
This method returns true if shadow casting is enabled, false otherwise.
Definition: CWorld.h:168
Implementation of a camera.
cColorf m_backgroundColor
Background color of the world.
Definition: CWorld.h:189
double m_shadowIntensity
Shadow intensity. Values ranges between 0.0 and 1.0 (0.0 = no shadow - full light. 1.0 = full shadow - no light).
Definition: CWorld.h:240
virtual cGenericLight * getLightSource(int index)
This method returns a pointer to a particular light source (between 0 and MAXIMUM_OPENGL_LIGHT_COUNT-...
Definition: CWorld.cpp:229
bool m_useShadowCasting
If true then shadow maps are used.
Definition: CWorld.h:243
bool addLightSource(cGenericLight *a_light)
This method adds a light source to this world.
Definition: CWorld.cpp:134
void enableLightSourceRendering(bool enable)
This method enables or disables the rendering of this world's light sources.
Definition: CWorld.h:134
This class implements a base class for modeling light sources.
Definition: CGenericLight.h:79
This class implements a virtual world.
Definition: CWorld.h:92
Implements graphic fog capabilities.
This class implements a base class for all 2D or 3D objects in CHAI3D.
Definition: CGenericObject.h:112
This class implements a collision detection recorder that stores all collision events that are report...
Definition: CCollisionBasics.h:185
virtual ~cWorld()
Destructor of cWorld.
Definition: CWorld.cpp:87
This structure stores the collision settings that are passed to a collision detector when querying fo...
Definition: CCollisionBasics.h:242
Implements a base class for all objects.
This class implements fog inside the world.
Definition: CFog.h:81
virtual void render(cRenderOptions &a_options)
This method renders all light sources of this world.
Definition: CWorld.cpp:347
void setUseShadowCasting(bool a_enabled)
This method enables or disables shadow casting.
Definition: CWorld.h:165
This class defines a color using a GLfloat representation for each component.
Definition: CColor.h:138
Implements color properties.
void setBackgroundColor(const GLfloat a_red, const GLfloat a_green, const GLfloat a_blue)
This method sets the background color of this world.
Definition: CWorld.cpp:103
virtual void computeLocalInteraction(const cVector3d &a_toolPos, const cVector3d &a_toolVel, const unsigned int a_IDN)
This method updates the geometric relationship between the tool and this world.
Definition: CWorld.cpp:445
cFog * m_fog
Fog property.
Definition: CWorld.h:192
std::list< cShadowMap * > m_shadowMaps
List of active shadow maps.
Definition: CWorld.h:198
double cClamp01(const double &a_value)
This function clamps a value to a value ranged between 0.0 and 1.0.
Definition: CMaths.h:404
void setShadowIntensity(double a_intensity)
This method sets the shadow Intensity. (0.0 = no shadow - full light. 1.0 = full shadow - no light) ...
Definition: CWorld.h:171
Definition: CAudioBuffer.cpp:56
bool m_renderLightSources
If true then light sources should be used.
Definition: CWorld.h:237
Implements 2D textures.
bool isShadowCastingSupported()
This method returns true if shadow casting is supported on this hardware, false otherwise.
Definition: CWorld.cpp:317
std::vector< cGenericLight * > m_lights
List of light sources.
Definition: CWorld.h:195
double getShadowIntensity()
Definition: CWorld.h:174
virtual bool updateShadowMaps(const bool a_mirrorX=false, const bool a_mirrorY=false, const int a_displayContext=0)
This method updates all shadow maps.
Definition: CWorld.cpp:253
virtual bool computeCollisionDetection(const cVector3d &a_segmentPointA, const cVector3d &a_segmentPointB, cCollisionRecorder &a_recorder, cCollisionSettings &a_settings)
This method computes any collision between a segment and all objects in this world.
Definition: CWorld.cpp:413
bool removeLightSource(cGenericLight *a_light)
This method removed a light source from this world.
Definition: CWorld.cpp:195
cWorld()
Constructor of cWorld.
Definition: CWorld.cpp:59

CHAI3D 3.0.0 documentation
Please address any questions to support@chai3d.org
(C) 2003-2015 - CHAI3D
All Rights Reserved.