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