My Project
Loading...
Searching...
No Matches
CWorld.h
Go to the documentation of this file.
1//==============================================================================
2/*
3 Software License Agreement (BSD License)
4 Copyright (c) 2003-2024, 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.3.0
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"
54//------------------------------------------------------------------------------
55#include <vector>
56//------------------------------------------------------------------------------
57
58//------------------------------------------------------------------------------
59namespace chai3d {
60//------------------------------------------------------------------------------
61
62//------------------------------------------------------------------------------
63class cGenericLight;
64class cShadowMap;
65//------------------------------------------------------------------------------
67#define C_MAXIMUM_OPENGL_LIGHT_COUNT 8
68//------------------------------------------------------------------------------
69
70//==============================================================================
77//==============================================================================
78
79//==============================================================================
91//==============================================================================
92class cWorld : public cGenericObject
93{
94 friend class cGenericLight;
95
96 //--------------------------------------------------------------------------
97 // CONSTRUCTOR & DESTRUCTOR:
98 //--------------------------------------------------------------------------
99
100public:
101
103 cWorld();
104
106 virtual ~cWorld();
107
108
109 //--------------------------------------------------------------------------
110 // PUBLIC METHODS - GENERAL:
111 //--------------------------------------------------------------------------
112
113public:
114
116 virtual std::string getClassName() { return ("World"); }
117
118
119 //--------------------------------------------------------------------------
120 // PUBLIC METHODS - BACKGROUND PROPERTIES
121 //--------------------------------------------------------------------------
122
123public:
124
126 void setBackgroundColor(const GLfloat a_red,
127 const GLfloat a_green,
128 const GLfloat a_blue);
129
131 void setBackgroundColor(const cColorf& a_color);
132
135
136
137 //-----------------------------------------------------------------------
138 // PUBLIC METHODS - LIGHT SOURCES:
139 //-----------------------------------------------------------------------
140
141public:
142
144 void enableLightSourceRendering(bool enable) { m_renderLightSources = enable; }
145
147 virtual cGenericLight* getLightSource(int index);
148
149
150 //-----------------------------------------------------------------------
151 // PUBLIC METHODS - COLLISION / INTERACTION:
152 //-----------------------------------------------------------------------
153
154public:
155
156 /*
158 virtual bool computeCollisionDetection(const cVector3d& a_segmentPointA,
159 const cVector3d& a_segmentPointB,
160 cCollisionRecorder& a_recorder,
161 cCollisionSettings& a_settings);
162 */
163
165 virtual void computeLocalInteraction(const cVector3d& a_toolPos,
166 const cVector3d& a_toolVel,
167 const unsigned int a_IDN);
168
169
170 //-----------------------------------------------------------------------
171 // PUBLIC METHODS - SHADOW CASTING:
172 //-----------------------------------------------------------------------
173
174public:
175
177 void setUseShadowCasting(bool a_enabled) { m_useShadowCasting = a_enabled; }
178
181
183 void setShadowIntensity(double a_intensity) { m_shadowIntensity = cClamp01(a_intensity); }
184
185 // This method returns the shadow intensity.
187
189 virtual bool updateShadowMaps(const bool a_mirrorX = false,
190 const bool a_mirrorY = false);
191
192
193 //--------------------------------------------------------------------------
194 // PUBLIC MEMBERS:
195 //--------------------------------------------------------------------------
196
197public:
198
201
204
206 std::vector<cGenericLight*> m_lights;
207
209 std::list<cShadowMap*> m_shadowMaps;
210
213
214
215 //-----------------------------------------------------------------------
216 // VIRTUAL PROTECTED METHODS:
217 //-----------------------------------------------------------------------
218
219protected:
220
222 virtual void render(cRenderOptions& a_options);
223
224
225 //--------------------------------------------------------------------------
226 // PROTECTED METHODS:
227 //--------------------------------------------------------------------------
228
229protected:
230
232 bool addLightSource(cGenericLight* a_light);
233
235 bool removeLightSource(cGenericLight* a_light);
236
239
240
241 //--------------------------------------------------------------------------
242 // PROTECTED MEMBERS:
243 //--------------------------------------------------------------------------
244
245protected:
246
249
252
255};
256
257//------------------------------------------------------------------------------
258} // namespace chai3d
259//------------------------------------------------------------------------------
260
261//------------------------------------------------------------------------------
262#endif
263//------------------------------------------------------------------------------
264
Implementation of a camera.
Implements color properties.
Implements graphic fog capabilities.
Implements a base class for all objects.
Implements 2D textures.
Implements arrays of 3D triangles.
This class implements fog inside the world.
Definition CFog.h:82
This class implements a base class for modeling light sources.
Definition CGenericLight.h:80
This class implements a base class for all 2D or 3D objects in CHAI3D.
Definition CGenericObject.h:113
This class implements a virtual world.
Definition CWorld.h:93
std::list< cShadowMap * > m_shadowMaps
List of active shadow maps.
Definition CWorld.h:209
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:101
virtual bool updateShadowMaps(const bool a_mirrorX=false, const bool a_mirrorY=false)
This method updates all shadow maps.
Definition CWorld.cpp:250
cColorf m_backgroundColor
Background color of the world.
Definition CWorld.h:200
bool m_renderLightSources
If true then light sources should be used.
Definition CWorld.h:248
double getShadowIntensity()
Definition CWorld.h:186
double m_worldModelView[16]
It's useful to store the world's modelview matrix, for rendering stuff in "global" coordinates.
Definition CWorld.h:212
cColorf getBackgroundColor() const
This method returns the background color of this world.
Definition CWorld.h:134
virtual ~cWorld()
Destructor of cWorld.
Definition CWorld.cpp:86
bool addLightSource(cGenericLight *a_light)
This method adds a light source to this world.
Definition CWorld.cpp:132
virtual std::string getClassName()
This method returns the name of the object class.
Definition CWorld.h:116
bool getUseShadowCastring()
This method returns true if shadow casting is enabled, false otherwise.
Definition CWorld.h:180
void setUseShadowCasting(bool a_enabled)
This method enables or disables shadow casting.
Definition CWorld.h:177
cWorld()
Constructor of cWorld.
Definition CWorld.cpp:59
double m_shadowIntensity
Shadow intensity. Values ranges between 0.0 and 1.0 (0.0 = no shadow - full light....
Definition CWorld.h:251
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:227
void enableLightSourceRendering(bool enable)
This method enables or disables the rendering of this world's light sources.
Definition CWorld.h:144
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:183
cFog * m_fog
Fog property.
Definition CWorld.h:203
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:414
bool removeLightSource(cGenericLight *a_light)
This method removed a light source from this world.
Definition CWorld.cpp:193
std::vector< cGenericLight * > m_lights
List of light sources.
Definition CWorld.h:206
virtual void render(cRenderOptions &a_options)
This method renders all light sources of this world.
Definition CWorld.cpp:358
bool isShadowCastingSupported()
This method returns true if shadow casting is supported on this hardware, false otherwise.
Definition CWorld.cpp:328
bool m_useShadowCasting
If true then shadow maps are used.
Definition CWorld.h:254
Definition CAudioBuffer.cpp:57
double cClamp01(const double &a_value)
This function clamps a value to a value ranged between 0.0 and 1.0.
Definition CMaths.h:431
This class defines a color using a GLfloat representation for each component.
Definition CColor.h:139
This structures provide a containers for storing rendering options that are passed through the sceneg...
Definition CRenderOptions.h:83
This class implements a 3D vector.
Definition CVector3d.h:89