aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CCubeSceneNode.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CCubeSceneNode.cpp')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/CCubeSceneNode.cpp468
1 files changed, 234 insertions, 234 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CCubeSceneNode.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CCubeSceneNode.cpp
index 12e4153..f815b5b 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/CCubeSceneNode.cpp
+++ b/libraries/irrlicht-1.8/source/Irrlicht/CCubeSceneNode.cpp
@@ -1,234 +1,234 @@
1// Copyright (C) 2002-2012 Nikolaus Gebhardt 1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine". 2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h 3// For conditions of distribution and use, see copyright notice in irrlicht.h
4 4
5#include "CCubeSceneNode.h" 5#include "CCubeSceneNode.h"
6#include "IVideoDriver.h" 6#include "IVideoDriver.h"
7#include "ISceneManager.h" 7#include "ISceneManager.h"
8#include "S3DVertex.h" 8#include "S3DVertex.h"
9#include "SMeshBuffer.h" 9#include "SMeshBuffer.h"
10#include "os.h" 10#include "os.h"
11#include "CShadowVolumeSceneNode.h" 11#include "CShadowVolumeSceneNode.h"
12 12
13namespace irr 13namespace irr
14{ 14{
15namespace scene 15namespace scene
16{ 16{
17 17
18 /* 18 /*
19 011 111 19 011 111
20 /6,8------/5 y 20 /6,8------/5 y
21 / | / | ^ z 21 / | / | ^ z
22 / | / | | / 22 / | / | | /
23 010 3,9-------2 | |/ 23 010 3,9-------2 | |/
24 | 7- - -10,4 101 *---->x 24 | 7- - -10,4 101 *---->x
25 | / | / 25 | / | /
26 |/ | / 26 |/ | /
27 0------11,1/ 27 0------11,1/
28 000 100 28 000 100
29 */ 29 */
30 30
31//! constructor 31//! constructor
32CCubeSceneNode::CCubeSceneNode(f32 size, ISceneNode* parent, ISceneManager* mgr, 32CCubeSceneNode::CCubeSceneNode(f32 size, ISceneNode* parent, ISceneManager* mgr,
33 s32 id, const core::vector3df& position, 33 s32 id, const core::vector3df& position,
34 const core::vector3df& rotation, const core::vector3df& scale) 34 const core::vector3df& rotation, const core::vector3df& scale)
35 : IMeshSceneNode(parent, mgr, id, position, rotation, scale), 35 : IMeshSceneNode(parent, mgr, id, position, rotation, scale),
36 Mesh(0), Shadow(0), Size(size) 36 Mesh(0), Shadow(0), Size(size)
37{ 37{
38 #ifdef _DEBUG 38 #ifdef _DEBUG
39 setDebugName("CCubeSceneNode"); 39 setDebugName("CCubeSceneNode");
40 #endif 40 #endif
41 41
42 setSize(); 42 setSize();
43} 43}
44 44
45 45
46CCubeSceneNode::~CCubeSceneNode() 46CCubeSceneNode::~CCubeSceneNode()
47{ 47{
48 if (Shadow) 48 if (Shadow)
49 Shadow->drop(); 49 Shadow->drop();
50 if (Mesh) 50 if (Mesh)
51 Mesh->drop(); 51 Mesh->drop();
52} 52}
53 53
54 54
55void CCubeSceneNode::setSize() 55void CCubeSceneNode::setSize()
56{ 56{
57 if (Mesh) 57 if (Mesh)
58 Mesh->drop(); 58 Mesh->drop();
59 Mesh = SceneManager->getGeometryCreator()->createCubeMesh(core::vector3df(Size)); 59 Mesh = SceneManager->getGeometryCreator()->createCubeMesh(core::vector3df(Size));
60} 60}
61 61
62 62
63//! renders the node. 63//! renders the node.
64void CCubeSceneNode::render() 64void CCubeSceneNode::render()
65{ 65{
66 video::IVideoDriver* driver = SceneManager->getVideoDriver(); 66 video::IVideoDriver* driver = SceneManager->getVideoDriver();
67 driver->setTransform(video::ETS_WORLD, AbsoluteTransformation); 67 driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
68 68
69 if (Shadow) 69 if (Shadow)
70 Shadow->updateShadowVolumes(); 70 Shadow->updateShadowVolumes();
71 71
72 // for debug purposes only: 72 // for debug purposes only:
73 video::SMaterial mat = Mesh->getMeshBuffer(0)->getMaterial(); 73 video::SMaterial mat = Mesh->getMeshBuffer(0)->getMaterial();
74 74
75 // overwrite half transparency 75 // overwrite half transparency
76 if (DebugDataVisible & scene::EDS_HALF_TRANSPARENCY) 76 if (DebugDataVisible & scene::EDS_HALF_TRANSPARENCY)
77 mat.MaterialType = video::EMT_TRANSPARENT_ADD_COLOR; 77 mat.MaterialType = video::EMT_TRANSPARENT_ADD_COLOR;
78 driver->setMaterial(mat); 78 driver->setMaterial(mat);
79 driver->drawMeshBuffer(Mesh->getMeshBuffer(0)); 79 driver->drawMeshBuffer(Mesh->getMeshBuffer(0));
80 80
81 // for debug purposes only: 81 // for debug purposes only:
82 if (DebugDataVisible) 82 if (DebugDataVisible)
83 { 83 {
84 video::SMaterial m; 84 video::SMaterial m;
85 m.Lighting = false; 85 m.Lighting = false;
86 m.AntiAliasing=0; 86 m.AntiAliasing=0;
87 driver->setMaterial(m); 87 driver->setMaterial(m);
88 88
89 if (DebugDataVisible & scene::EDS_BBOX) 89 if (DebugDataVisible & scene::EDS_BBOX)
90 { 90 {
91 driver->draw3DBox(Mesh->getMeshBuffer(0)->getBoundingBox(), video::SColor(255,255,255,255)); 91 driver->draw3DBox(Mesh->getMeshBuffer(0)->getBoundingBox(), video::SColor(255,255,255,255));
92 } 92 }
93 if (DebugDataVisible & scene::EDS_BBOX_BUFFERS) 93 if (DebugDataVisible & scene::EDS_BBOX_BUFFERS)
94 { 94 {
95 driver->draw3DBox(Mesh->getMeshBuffer(0)->getBoundingBox(), 95 driver->draw3DBox(Mesh->getMeshBuffer(0)->getBoundingBox(),
96 video::SColor(255,190,128,128)); 96 video::SColor(255,190,128,128));
97 } 97 }
98 if (DebugDataVisible & scene::EDS_NORMALS) 98 if (DebugDataVisible & scene::EDS_NORMALS)
99 { 99 {
100 // draw normals 100 // draw normals
101 const f32 debugNormalLength = SceneManager->getParameters()->getAttributeAsFloat(DEBUG_NORMAL_LENGTH); 101 const f32 debugNormalLength = SceneManager->getParameters()->getAttributeAsFloat(DEBUG_NORMAL_LENGTH);
102 const video::SColor debugNormalColor = SceneManager->getParameters()->getAttributeAsColor(DEBUG_NORMAL_COLOR); 102 const video::SColor debugNormalColor = SceneManager->getParameters()->getAttributeAsColor(DEBUG_NORMAL_COLOR);
103 const u32 count = Mesh->getMeshBufferCount(); 103 const u32 count = Mesh->getMeshBufferCount();
104 104
105 for (u32 i=0; i != count; ++i) 105 for (u32 i=0; i != count; ++i)
106 { 106 {
107 driver->drawMeshBufferNormals(Mesh->getMeshBuffer(i), debugNormalLength, debugNormalColor); 107 driver->drawMeshBufferNormals(Mesh->getMeshBuffer(i), debugNormalLength, debugNormalColor);
108 } 108 }
109 } 109 }
110 110
111 // show mesh 111 // show mesh
112 if (DebugDataVisible & scene::EDS_MESH_WIRE_OVERLAY) 112 if (DebugDataVisible & scene::EDS_MESH_WIRE_OVERLAY)
113 { 113 {
114 m.Wireframe = true; 114 m.Wireframe = true;
115 driver->setMaterial(m); 115 driver->setMaterial(m);
116 116
117 driver->drawMeshBuffer(Mesh->getMeshBuffer(0)); 117 driver->drawMeshBuffer(Mesh->getMeshBuffer(0));
118 } 118 }
119 } 119 }
120} 120}
121 121
122 122
123//! returns the axis aligned bounding box of this node 123//! returns the axis aligned bounding box of this node
124const core::aabbox3d<f32>& CCubeSceneNode::getBoundingBox() const 124const core::aabbox3d<f32>& CCubeSceneNode::getBoundingBox() const
125{ 125{
126 return Mesh->getMeshBuffer(0)->getBoundingBox(); 126 return Mesh->getMeshBuffer(0)->getBoundingBox();
127} 127}
128 128
129 129
130//! Removes a child from this scene node. 130//! Removes a child from this scene node.
131//! Implemented here, to be able to remove the shadow properly, if there is one, 131//! Implemented here, to be able to remove the shadow properly, if there is one,
132//! or to remove attached childs. 132//! or to remove attached childs.
133bool CCubeSceneNode::removeChild(ISceneNode* child) 133bool CCubeSceneNode::removeChild(ISceneNode* child)
134{ 134{
135 if (child && Shadow == child) 135 if (child && Shadow == child)
136 { 136 {
137 Shadow->drop(); 137 Shadow->drop();
138 Shadow = 0; 138 Shadow = 0;
139 } 139 }
140 140
141 return ISceneNode::removeChild(child); 141 return ISceneNode::removeChild(child);
142} 142}
143 143
144 144
145//! Creates shadow volume scene node as child of this node 145//! Creates shadow volume scene node as child of this node
146//! and returns a pointer to it. 146//! and returns a pointer to it.
147IShadowVolumeSceneNode* CCubeSceneNode::addShadowVolumeSceneNode( 147IShadowVolumeSceneNode* CCubeSceneNode::addShadowVolumeSceneNode(
148 const IMesh* shadowMesh, s32 id, bool zfailmethod, f32 infinity) 148 const IMesh* shadowMesh, s32 id, bool zfailmethod, f32 infinity)
149{ 149{
150 if (!SceneManager->getVideoDriver()->queryFeature(video::EVDF_STENCIL_BUFFER)) 150 if (!SceneManager->getVideoDriver()->queryFeature(video::EVDF_STENCIL_BUFFER))
151 return 0; 151 return 0;
152 152
153 if (!shadowMesh) 153 if (!shadowMesh)
154 shadowMesh = Mesh; // if null is given, use the mesh of node 154 shadowMesh = Mesh; // if null is given, use the mesh of node
155 155
156 if (Shadow) 156 if (Shadow)
157 Shadow->drop(); 157 Shadow->drop();
158 158
159 Shadow = new CShadowVolumeSceneNode(shadowMesh, this, SceneManager, id, zfailmethod, infinity); 159 Shadow = new CShadowVolumeSceneNode(shadowMesh, this, SceneManager, id, zfailmethod, infinity);
160 return Shadow; 160 return Shadow;
161} 161}
162 162
163 163
164void CCubeSceneNode::OnRegisterSceneNode() 164void CCubeSceneNode::OnRegisterSceneNode()
165{ 165{
166 if (IsVisible) 166 if (IsVisible)
167 SceneManager->registerNodeForRendering(this); 167 SceneManager->registerNodeForRendering(this);
168 ISceneNode::OnRegisterSceneNode(); 168 ISceneNode::OnRegisterSceneNode();
169} 169}
170 170
171 171
172//! returns the material based on the zero based index i. 172//! returns the material based on the zero based index i.
173video::SMaterial& CCubeSceneNode::getMaterial(u32 i) 173video::SMaterial& CCubeSceneNode::getMaterial(u32 i)
174{ 174{
175 return Mesh->getMeshBuffer(0)->getMaterial(); 175 return Mesh->getMeshBuffer(0)->getMaterial();
176} 176}
177 177
178 178
179//! returns amount of materials used by this scene node. 179//! returns amount of materials used by this scene node.
180u32 CCubeSceneNode::getMaterialCount() const 180u32 CCubeSceneNode::getMaterialCount() const
181{ 181{
182 return 1; 182 return 1;
183} 183}
184 184
185 185
186//! Writes attributes of the scene node. 186//! Writes attributes of the scene node.
187void CCubeSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const 187void CCubeSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
188{ 188{
189 ISceneNode::serializeAttributes(out, options); 189 ISceneNode::serializeAttributes(out, options);
190 190
191 out->addFloat("Size", Size); 191 out->addFloat("Size", Size);
192} 192}
193 193
194 194
195//! Reads attributes of the scene node. 195//! Reads attributes of the scene node.
196void CCubeSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) 196void CCubeSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
197{ 197{
198 f32 newSize = in->getAttributeAsFloat("Size"); 198 f32 newSize = in->getAttributeAsFloat("Size");
199 newSize = core::max_(newSize, 0.0001f); 199 newSize = core::max_(newSize, 0.0001f);
200 if (newSize != Size) 200 if (newSize != Size)
201 { 201 {
202 Size = newSize; 202 Size = newSize;
203 setSize(); 203 setSize();
204 } 204 }
205 205
206 ISceneNode::deserializeAttributes(in, options); 206 ISceneNode::deserializeAttributes(in, options);
207} 207}
208 208
209 209
210//! Creates a clone of this scene node and its children. 210//! Creates a clone of this scene node and its children.
211ISceneNode* CCubeSceneNode::clone(ISceneNode* newParent, ISceneManager* newManager) 211ISceneNode* CCubeSceneNode::clone(ISceneNode* newParent, ISceneManager* newManager)
212{ 212{
213 if (!newParent) 213 if (!newParent)
214 newParent = Parent; 214 newParent = Parent;
215 if (!newManager) 215 if (!newManager)
216 newManager = SceneManager; 216 newManager = SceneManager;
217 217
218 CCubeSceneNode* nb = new CCubeSceneNode(Size, newParent, 218 CCubeSceneNode* nb = new CCubeSceneNode(Size, newParent,
219 newManager, ID, RelativeTranslation); 219 newManager, ID, RelativeTranslation);
220 220
221 nb->cloneMembers(this, newManager); 221 nb->cloneMembers(this, newManager);
222 nb->getMaterial(0) = getMaterial(0); 222 nb->getMaterial(0) = getMaterial(0);
223 nb->Shadow = Shadow; 223 nb->Shadow = Shadow;
224 nb->Shadow->grab(); 224 nb->Shadow->grab();
225 225
226 if ( newParent ) 226 if ( newParent )
227 nb->drop(); 227 nb->drop();
228 return nb; 228 return nb;
229} 229}
230 230
231 231
232} // end namespace scene 232} // end namespace scene
233} // end namespace irr 233} // end namespace irr
234 234