1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
// Copyright (C) 2007-2012 Dean Wadsworth
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CVolumeLightSceneNode.h"
#include "IVideoDriver.h"
#include "ISceneManager.h"
#include "S3DVertex.h"
#include "os.h"
namespace irr
{
namespace scene
{
//! constructor
CVolumeLightSceneNode::CVolumeLightSceneNode(ISceneNode* parent, ISceneManager* mgr,
s32 id, const u32 subdivU, const u32 subdivV,
const video::SColor foot,
const video::SColor tail,
const core::vector3df& position,
const core::vector3df& rotation, const core::vector3df& scale)
: IVolumeLightSceneNode(parent, mgr, id, position, rotation, scale),
Mesh(0), LPDistance(8.0f),
SubdivideU(subdivU), SubdivideV(subdivV),
FootColor(foot), TailColor(tail),
LightDimensions(core::vector3df(1.0f, 1.2f, 1.0f))
{
#ifdef _DEBUG
setDebugName("CVolumeLightSceneNode");
#endif
constructLight();
}
CVolumeLightSceneNode::~CVolumeLightSceneNode()
{
if (Mesh)
Mesh->drop();
}
void CVolumeLightSceneNode::constructLight()
{
if (Mesh)
Mesh->drop();
Mesh = SceneManager->getGeometryCreator()->createVolumeLightMesh(SubdivideU, SubdivideV, FootColor, TailColor, LPDistance, LightDimensions);
}
//! renders the node.
void CVolumeLightSceneNode::render()
{
if (!Mesh)
return;
video::IVideoDriver* driver = SceneManager->getVideoDriver();
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
driver->setMaterial(Mesh->getMeshBuffer(0)->getMaterial());
driver->drawMeshBuffer(Mesh->getMeshBuffer(0));
}
//! returns the axis aligned bounding box of this node
const core::aabbox3d<f32>& CVolumeLightSceneNode::getBoundingBox() const
{
return Mesh->getBoundingBox();
}
void CVolumeLightSceneNode::OnRegisterSceneNode()
{
if (IsVisible)
{
SceneManager->registerNodeForRendering(this, ESNRP_TRANSPARENT);
}
ISceneNode::OnRegisterSceneNode();
}
//! returns the material based on the zero based index i. To get the amount
//! of materials used by this scene node, use getMaterialCount().
//! This function is needed for inserting the node into the scene hirachy on a
//! optimal position for minimizing renderstate changes, but can also be used
//! to directly modify the material of a scene node.
video::SMaterial& CVolumeLightSceneNode::getMaterial(u32 i)
{
return Mesh->getMeshBuffer(i)->getMaterial();
}
//! returns amount of materials used by this scene node.
u32 CVolumeLightSceneNode::getMaterialCount() const
{
return 1;
}
void CVolumeLightSceneNode::setSubDivideU (const u32 inU)
{
if (inU != SubdivideU)
{
SubdivideU = inU;
constructLight();
}
}
void CVolumeLightSceneNode::setSubDivideV (const u32 inV)
{
if (inV != SubdivideV)
{
SubdivideV = inV;
constructLight();
}
}
void CVolumeLightSceneNode::setFootColor(const video::SColor inColor)
{
if (inColor != FootColor)
{
FootColor = inColor;
constructLight();
}
}
void CVolumeLightSceneNode::setTailColor(const video::SColor inColor)
{
if (inColor != TailColor)
{
TailColor = inColor;
constructLight();
}
}
//! Writes attributes of the scene node.
void CVolumeLightSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
{
ISceneNode::serializeAttributes(out, options);
out->addFloat("lpDistance", LPDistance);
out->addInt("subDivideU", SubdivideU);
out->addInt("subDivideV", SubdivideV);
out->addColor("footColor", FootColor);
out->addColor("tailColor", TailColor);
out->addVector3d("lightDimension", LightDimensions);
}
//! Reads attributes of the scene node.
void CVolumeLightSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
{
LPDistance = in->getAttributeAsFloat("lpDistance");
LPDistance = core::max_(LPDistance, 8.0f);
SubdivideU = in->getAttributeAsInt("subDivideU");
SubdivideU = core::max_(SubdivideU, 1u);
SubdivideV = in->getAttributeAsInt("subDivideV");
SubdivideV = core::max_(SubdivideV, 1u);
FootColor = in->getAttributeAsColor("footColor");
TailColor = in->getAttributeAsColor("tailColor");
LightDimensions = in->getAttributeAsVector3d("lightDimension");
constructLight();
ISceneNode::deserializeAttributes(in, options);
}
//! Creates a clone of this scene node and its children.
ISceneNode* CVolumeLightSceneNode::clone(ISceneNode* newParent, ISceneManager* newManager)
{
if (!newParent)
newParent = Parent;
if (!newManager)
newManager = SceneManager;
CVolumeLightSceneNode* nb = new CVolumeLightSceneNode(newParent,
newManager, ID, SubdivideU, SubdivideV, FootColor, TailColor, RelativeTranslation);
nb->cloneMembers(this, newManager);
nb->getMaterial(0) = Mesh->getMeshBuffer(0)->getMaterial();
if ( newParent )
nb->drop();
return nb;
}
} // end namespace scene
} // end namespace irr
|