diff options
author | David Walter Seikel | 2013-01-13 18:54:10 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-01-13 18:54:10 +1000 |
commit | 959831f4ef5a3e797f576c3de08cd65032c997ad (patch) | |
tree | e7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/source/Irrlicht/CBillboardSceneNode.cpp | |
parent | Add info about changes to Irrlicht. (diff) | |
download | SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.zip SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.gz SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.bz2 SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.xz |
Remove damned ancient DOS line endings from Irrlicht. Hopefully I did not go overboard.
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CBillboardSceneNode.cpp')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/CBillboardSceneNode.cpp | 588 |
1 files changed, 294 insertions, 294 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CBillboardSceneNode.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CBillboardSceneNode.cpp index 22d41bd..dcdd6ba 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/CBillboardSceneNode.cpp +++ b/libraries/irrlicht-1.8/source/Irrlicht/CBillboardSceneNode.cpp | |||
@@ -1,294 +1,294 @@ | |||
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 "CBillboardSceneNode.h" | 5 | #include "CBillboardSceneNode.h" |
6 | #include "IVideoDriver.h" | 6 | #include "IVideoDriver.h" |
7 | #include "ISceneManager.h" | 7 | #include "ISceneManager.h" |
8 | #include "ICameraSceneNode.h" | 8 | #include "ICameraSceneNode.h" |
9 | #include "os.h" | 9 | #include "os.h" |
10 | 10 | ||
11 | namespace irr | 11 | namespace irr |
12 | { | 12 | { |
13 | namespace scene | 13 | namespace scene |
14 | { | 14 | { |
15 | 15 | ||
16 | //! constructor | 16 | //! constructor |
17 | CBillboardSceneNode::CBillboardSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id, | 17 | CBillboardSceneNode::CBillboardSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id, |
18 | const core::vector3df& position, const core::dimension2d<f32>& size, | 18 | const core::vector3df& position, const core::dimension2d<f32>& size, |
19 | video::SColor colorTop, video::SColor colorBottom) | 19 | video::SColor colorTop, video::SColor colorBottom) |
20 | : IBillboardSceneNode(parent, mgr, id, position) | 20 | : IBillboardSceneNode(parent, mgr, id, position) |
21 | { | 21 | { |
22 | #ifdef _DEBUG | 22 | #ifdef _DEBUG |
23 | setDebugName("CBillboardSceneNode"); | 23 | setDebugName("CBillboardSceneNode"); |
24 | #endif | 24 | #endif |
25 | 25 | ||
26 | setSize(size); | 26 | setSize(size); |
27 | 27 | ||
28 | indices[0] = 0; | 28 | indices[0] = 0; |
29 | indices[1] = 2; | 29 | indices[1] = 2; |
30 | indices[2] = 1; | 30 | indices[2] = 1; |
31 | indices[3] = 0; | 31 | indices[3] = 0; |
32 | indices[4] = 3; | 32 | indices[4] = 3; |
33 | indices[5] = 2; | 33 | indices[5] = 2; |
34 | 34 | ||
35 | vertices[0].TCoords.set(1.0f, 1.0f); | 35 | vertices[0].TCoords.set(1.0f, 1.0f); |
36 | vertices[0].Color = colorBottom; | 36 | vertices[0].Color = colorBottom; |
37 | 37 | ||
38 | vertices[1].TCoords.set(1.0f, 0.0f); | 38 | vertices[1].TCoords.set(1.0f, 0.0f); |
39 | vertices[1].Color = colorTop; | 39 | vertices[1].Color = colorTop; |
40 | 40 | ||
41 | vertices[2].TCoords.set(0.0f, 0.0f); | 41 | vertices[2].TCoords.set(0.0f, 0.0f); |
42 | vertices[2].Color = colorTop; | 42 | vertices[2].Color = colorTop; |
43 | 43 | ||
44 | vertices[3].TCoords.set(0.0f, 1.0f); | 44 | vertices[3].TCoords.set(0.0f, 1.0f); |
45 | vertices[3].Color = colorBottom; | 45 | vertices[3].Color = colorBottom; |
46 | } | 46 | } |
47 | 47 | ||
48 | 48 | ||
49 | //! pre render event | 49 | //! pre render event |
50 | void CBillboardSceneNode::OnRegisterSceneNode() | 50 | void CBillboardSceneNode::OnRegisterSceneNode() |
51 | { | 51 | { |
52 | if (IsVisible) | 52 | if (IsVisible) |
53 | SceneManager->registerNodeForRendering(this); | 53 | SceneManager->registerNodeForRendering(this); |
54 | 54 | ||
55 | ISceneNode::OnRegisterSceneNode(); | 55 | ISceneNode::OnRegisterSceneNode(); |
56 | } | 56 | } |
57 | 57 | ||
58 | 58 | ||
59 | //! render | 59 | //! render |
60 | void CBillboardSceneNode::render() | 60 | void CBillboardSceneNode::render() |
61 | { | 61 | { |
62 | video::IVideoDriver* driver = SceneManager->getVideoDriver(); | 62 | video::IVideoDriver* driver = SceneManager->getVideoDriver(); |
63 | ICameraSceneNode* camera = SceneManager->getActiveCamera(); | 63 | ICameraSceneNode* camera = SceneManager->getActiveCamera(); |
64 | 64 | ||
65 | if (!camera || !driver) | 65 | if (!camera || !driver) |
66 | return; | 66 | return; |
67 | 67 | ||
68 | // make billboard look to camera | 68 | // make billboard look to camera |
69 | 69 | ||
70 | core::vector3df pos = getAbsolutePosition(); | 70 | core::vector3df pos = getAbsolutePosition(); |
71 | 71 | ||
72 | core::vector3df campos = camera->getAbsolutePosition(); | 72 | core::vector3df campos = camera->getAbsolutePosition(); |
73 | core::vector3df target = camera->getTarget(); | 73 | core::vector3df target = camera->getTarget(); |
74 | core::vector3df up = camera->getUpVector(); | 74 | core::vector3df up = camera->getUpVector(); |
75 | core::vector3df view = target - campos; | 75 | core::vector3df view = target - campos; |
76 | view.normalize(); | 76 | view.normalize(); |
77 | 77 | ||
78 | core::vector3df horizontal = up.crossProduct(view); | 78 | core::vector3df horizontal = up.crossProduct(view); |
79 | if ( horizontal.getLength() == 0 ) | 79 | if ( horizontal.getLength() == 0 ) |
80 | { | 80 | { |
81 | horizontal.set(up.Y,up.X,up.Z); | 81 | horizontal.set(up.Y,up.X,up.Z); |
82 | } | 82 | } |
83 | horizontal.normalize(); | 83 | horizontal.normalize(); |
84 | core::vector3df topHorizontal = horizontal * 0.5f * TopEdgeWidth; | 84 | core::vector3df topHorizontal = horizontal * 0.5f * TopEdgeWidth; |
85 | horizontal *= 0.5f * Size.Width; | 85 | horizontal *= 0.5f * Size.Width; |
86 | 86 | ||
87 | // pointing down! | 87 | // pointing down! |
88 | core::vector3df vertical = horizontal.crossProduct(view); | 88 | core::vector3df vertical = horizontal.crossProduct(view); |
89 | vertical.normalize(); | 89 | vertical.normalize(); |
90 | vertical *= 0.5f * Size.Height; | 90 | vertical *= 0.5f * Size.Height; |
91 | 91 | ||
92 | view *= -1.0f; | 92 | view *= -1.0f; |
93 | 93 | ||
94 | for (s32 i=0; i<4; ++i) | 94 | for (s32 i=0; i<4; ++i) |
95 | vertices[i].Normal = view; | 95 | vertices[i].Normal = view; |
96 | 96 | ||
97 | /* Vertices are: | 97 | /* Vertices are: |
98 | 2--1 | 98 | 2--1 |
99 | |\ | | 99 | |\ | |
100 | | \| | 100 | | \| |
101 | 3--0 | 101 | 3--0 |
102 | */ | 102 | */ |
103 | vertices[0].Pos = pos + horizontal + vertical; | 103 | vertices[0].Pos = pos + horizontal + vertical; |
104 | vertices[1].Pos = pos + topHorizontal - vertical; | 104 | vertices[1].Pos = pos + topHorizontal - vertical; |
105 | vertices[2].Pos = pos - topHorizontal - vertical; | 105 | vertices[2].Pos = pos - topHorizontal - vertical; |
106 | vertices[3].Pos = pos - horizontal + vertical; | 106 | vertices[3].Pos = pos - horizontal + vertical; |
107 | 107 | ||
108 | // draw | 108 | // draw |
109 | 109 | ||
110 | if (DebugDataVisible & scene::EDS_BBOX) | 110 | if (DebugDataVisible & scene::EDS_BBOX) |
111 | { | 111 | { |
112 | driver->setTransform(video::ETS_WORLD, AbsoluteTransformation); | 112 | driver->setTransform(video::ETS_WORLD, AbsoluteTransformation); |
113 | video::SMaterial m; | 113 | video::SMaterial m; |
114 | m.Lighting = false; | 114 | m.Lighting = false; |
115 | driver->setMaterial(m); | 115 | driver->setMaterial(m); |
116 | driver->draw3DBox(BBox, video::SColor(0,208,195,152)); | 116 | driver->draw3DBox(BBox, video::SColor(0,208,195,152)); |
117 | } | 117 | } |
118 | 118 | ||
119 | driver->setTransform(video::ETS_WORLD, core::IdentityMatrix); | 119 | driver->setTransform(video::ETS_WORLD, core::IdentityMatrix); |
120 | 120 | ||
121 | driver->setMaterial(Material); | 121 | driver->setMaterial(Material); |
122 | 122 | ||
123 | driver->drawIndexedTriangleList(vertices, 4, indices, 2); | 123 | driver->drawIndexedTriangleList(vertices, 4, indices, 2); |
124 | } | 124 | } |
125 | 125 | ||
126 | 126 | ||
127 | //! returns the axis aligned bounding box of this node | 127 | //! returns the axis aligned bounding box of this node |
128 | const core::aabbox3d<f32>& CBillboardSceneNode::getBoundingBox() const | 128 | const core::aabbox3d<f32>& CBillboardSceneNode::getBoundingBox() const |
129 | { | 129 | { |
130 | return BBox; | 130 | return BBox; |
131 | } | 131 | } |
132 | 132 | ||
133 | 133 | ||
134 | //! sets the size of the billboard | 134 | //! sets the size of the billboard |
135 | void CBillboardSceneNode::setSize(const core::dimension2d<f32>& size) | 135 | void CBillboardSceneNode::setSize(const core::dimension2d<f32>& size) |
136 | { | 136 | { |
137 | Size = size; | 137 | Size = size; |
138 | 138 | ||
139 | if (core::equals(Size.Width, 0.0f)) | 139 | if (core::equals(Size.Width, 0.0f)) |
140 | Size.Width = 1.0f; | 140 | Size.Width = 1.0f; |
141 | TopEdgeWidth = Size.Width; | 141 | TopEdgeWidth = Size.Width; |
142 | 142 | ||
143 | if (core::equals(Size.Height, 0.0f)) | 143 | if (core::equals(Size.Height, 0.0f)) |
144 | Size.Height = 1.0f; | 144 | Size.Height = 1.0f; |
145 | 145 | ||
146 | const f32 avg = (Size.Width + Size.Height)/6; | 146 | const f32 avg = (Size.Width + Size.Height)/6; |
147 | BBox.MinEdge.set(-avg,-avg,-avg); | 147 | BBox.MinEdge.set(-avg,-avg,-avg); |
148 | BBox.MaxEdge.set(avg,avg,avg); | 148 | BBox.MaxEdge.set(avg,avg,avg); |
149 | } | 149 | } |
150 | 150 | ||
151 | 151 | ||
152 | void CBillboardSceneNode::setSize(f32 height, f32 bottomEdgeWidth, f32 topEdgeWidth) | 152 | void CBillboardSceneNode::setSize(f32 height, f32 bottomEdgeWidth, f32 topEdgeWidth) |
153 | { | 153 | { |
154 | Size.set(bottomEdgeWidth, height); | 154 | Size.set(bottomEdgeWidth, height); |
155 | TopEdgeWidth = topEdgeWidth; | 155 | TopEdgeWidth = topEdgeWidth; |
156 | 156 | ||
157 | if (core::equals(Size.Height, 0.0f)) | 157 | if (core::equals(Size.Height, 0.0f)) |
158 | Size.Height = 1.0f; | 158 | Size.Height = 1.0f; |
159 | 159 | ||
160 | if (core::equals(Size.Width, 0.f) && core::equals(TopEdgeWidth, 0.f)) | 160 | if (core::equals(Size.Width, 0.f) && core::equals(TopEdgeWidth, 0.f)) |
161 | { | 161 | { |
162 | Size.Width = 1.0f; | 162 | Size.Width = 1.0f; |
163 | TopEdgeWidth = 1.0f; | 163 | TopEdgeWidth = 1.0f; |
164 | } | 164 | } |
165 | 165 | ||
166 | const f32 avg = (core::max_(Size.Width,TopEdgeWidth) + Size.Height)/6; | 166 | const f32 avg = (core::max_(Size.Width,TopEdgeWidth) + Size.Height)/6; |
167 | BBox.MinEdge.set(-avg,-avg,-avg); | 167 | BBox.MinEdge.set(-avg,-avg,-avg); |
168 | BBox.MaxEdge.set(avg,avg,avg); | 168 | BBox.MaxEdge.set(avg,avg,avg); |
169 | } | 169 | } |
170 | 170 | ||
171 | 171 | ||
172 | video::SMaterial& CBillboardSceneNode::getMaterial(u32 i) | 172 | video::SMaterial& CBillboardSceneNode::getMaterial(u32 i) |
173 | { | 173 | { |
174 | return Material; | 174 | return Material; |
175 | } | 175 | } |
176 | 176 | ||
177 | 177 | ||
178 | //! returns amount of materials used by this scene node. | 178 | //! returns amount of materials used by this scene node. |
179 | u32 CBillboardSceneNode::getMaterialCount() const | 179 | u32 CBillboardSceneNode::getMaterialCount() const |
180 | { | 180 | { |
181 | return 1; | 181 | return 1; |
182 | } | 182 | } |
183 | 183 | ||
184 | 184 | ||
185 | //! gets the size of the billboard | 185 | //! gets the size of the billboard |
186 | const core::dimension2d<f32>& CBillboardSceneNode::getSize() const | 186 | const core::dimension2d<f32>& CBillboardSceneNode::getSize() const |
187 | { | 187 | { |
188 | return Size; | 188 | return Size; |
189 | } | 189 | } |
190 | 190 | ||
191 | 191 | ||
192 | //! Gets the widths of the top and bottom edges of the billboard. | 192 | //! Gets the widths of the top and bottom edges of the billboard. |
193 | void CBillboardSceneNode::getSize(f32& height, f32& bottomEdgeWidth, | 193 | void CBillboardSceneNode::getSize(f32& height, f32& bottomEdgeWidth, |
194 | f32& topEdgeWidth) const | 194 | f32& topEdgeWidth) const |
195 | { | 195 | { |
196 | height = Size.Height; | 196 | height = Size.Height; |
197 | bottomEdgeWidth = Size.Width; | 197 | bottomEdgeWidth = Size.Width; |
198 | topEdgeWidth = TopEdgeWidth; | 198 | topEdgeWidth = TopEdgeWidth; |
199 | } | 199 | } |
200 | 200 | ||
201 | 201 | ||
202 | //! Writes attributes of the scene node. | 202 | //! Writes attributes of the scene node. |
203 | void CBillboardSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const | 203 | void CBillboardSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const |
204 | { | 204 | { |
205 | IBillboardSceneNode::serializeAttributes(out, options); | 205 | IBillboardSceneNode::serializeAttributes(out, options); |
206 | 206 | ||
207 | out->addFloat("Width", Size.Width); | 207 | out->addFloat("Width", Size.Width); |
208 | out->addFloat("TopEdgeWidth", TopEdgeWidth); | 208 | out->addFloat("TopEdgeWidth", TopEdgeWidth); |
209 | out->addFloat("Height", Size.Height); | 209 | out->addFloat("Height", Size.Height); |
210 | out->addColor("Shade_Top", vertices[1].Color); | 210 | out->addColor("Shade_Top", vertices[1].Color); |
211 | out->addColor("Shade_Down", vertices[0].Color); | 211 | out->addColor("Shade_Down", vertices[0].Color); |
212 | } | 212 | } |
213 | 213 | ||
214 | 214 | ||
215 | //! Reads attributes of the scene node. | 215 | //! Reads attributes of the scene node. |
216 | void CBillboardSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) | 216 | void CBillboardSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) |
217 | { | 217 | { |
218 | IBillboardSceneNode::deserializeAttributes(in, options); | 218 | IBillboardSceneNode::deserializeAttributes(in, options); |
219 | 219 | ||
220 | Size.Width = in->getAttributeAsFloat("Width"); | 220 | Size.Width = in->getAttributeAsFloat("Width"); |
221 | Size.Height = in->getAttributeAsFloat("Height"); | 221 | Size.Height = in->getAttributeAsFloat("Height"); |
222 | 222 | ||
223 | if (in->existsAttribute("TopEdgeWidth")) | 223 | if (in->existsAttribute("TopEdgeWidth")) |
224 | { | 224 | { |
225 | TopEdgeWidth = in->getAttributeAsFloat("TopEdgeWidth"); | 225 | TopEdgeWidth = in->getAttributeAsFloat("TopEdgeWidth"); |
226 | if (Size.Width != TopEdgeWidth) | 226 | if (Size.Width != TopEdgeWidth) |
227 | setSize(Size.Height, Size.Width, TopEdgeWidth); | 227 | setSize(Size.Height, Size.Width, TopEdgeWidth); |
228 | } | 228 | } |
229 | else | 229 | else |
230 | setSize(Size); | 230 | setSize(Size); |
231 | vertices[1].Color = in->getAttributeAsColor("Shade_Top"); | 231 | vertices[1].Color = in->getAttributeAsColor("Shade_Top"); |
232 | vertices[0].Color = in->getAttributeAsColor("Shade_Down"); | 232 | vertices[0].Color = in->getAttributeAsColor("Shade_Down"); |
233 | vertices[2].Color = vertices[1].Color; | 233 | vertices[2].Color = vertices[1].Color; |
234 | vertices[3].Color = vertices[0].Color; | 234 | vertices[3].Color = vertices[0].Color; |
235 | } | 235 | } |
236 | 236 | ||
237 | 237 | ||
238 | //! Set the color of all vertices of the billboard | 238 | //! Set the color of all vertices of the billboard |
239 | //! \param overallColor: the color to set | 239 | //! \param overallColor: the color to set |
240 | void CBillboardSceneNode::setColor(const video::SColor& overallColor) | 240 | void CBillboardSceneNode::setColor(const video::SColor& overallColor) |
241 | { | 241 | { |
242 | for(u32 vertex = 0; vertex < 4; ++vertex) | 242 | for(u32 vertex = 0; vertex < 4; ++vertex) |
243 | vertices[vertex].Color = overallColor; | 243 | vertices[vertex].Color = overallColor; |
244 | } | 244 | } |
245 | 245 | ||
246 | 246 | ||
247 | //! Set the color of the top and bottom vertices of the billboard | 247 | //! Set the color of the top and bottom vertices of the billboard |
248 | //! \param topColor: the color to set the top vertices | 248 | //! \param topColor: the color to set the top vertices |
249 | //! \param bottomColor: the color to set the bottom vertices | 249 | //! \param bottomColor: the color to set the bottom vertices |
250 | void CBillboardSceneNode::setColor(const video::SColor& topColor, | 250 | void CBillboardSceneNode::setColor(const video::SColor& topColor, |
251 | const video::SColor& bottomColor) | 251 | const video::SColor& bottomColor) |
252 | { | 252 | { |
253 | vertices[0].Color = bottomColor; | 253 | vertices[0].Color = bottomColor; |
254 | vertices[1].Color = topColor; | 254 | vertices[1].Color = topColor; |
255 | vertices[2].Color = topColor; | 255 | vertices[2].Color = topColor; |
256 | vertices[3].Color = bottomColor; | 256 | vertices[3].Color = bottomColor; |
257 | } | 257 | } |
258 | 258 | ||
259 | 259 | ||
260 | //! Gets the color of the top and bottom vertices of the billboard | 260 | //! Gets the color of the top and bottom vertices of the billboard |
261 | //! \param[out] topColor: stores the color of the top vertices | 261 | //! \param[out] topColor: stores the color of the top vertices |
262 | //! \param[out] bottomColor: stores the color of the bottom vertices | 262 | //! \param[out] bottomColor: stores the color of the bottom vertices |
263 | void CBillboardSceneNode::getColor(video::SColor& topColor, | 263 | void CBillboardSceneNode::getColor(video::SColor& topColor, |
264 | video::SColor& bottomColor) const | 264 | video::SColor& bottomColor) const |
265 | { | 265 | { |
266 | bottomColor = vertices[0].Color; | 266 | bottomColor = vertices[0].Color; |
267 | topColor = vertices[1].Color; | 267 | topColor = vertices[1].Color; |
268 | } | 268 | } |
269 | 269 | ||
270 | 270 | ||
271 | //! Creates a clone of this scene node and its children. | 271 | //! Creates a clone of this scene node and its children. |
272 | ISceneNode* CBillboardSceneNode::clone(ISceneNode* newParent, ISceneManager* newManager) | 272 | ISceneNode* CBillboardSceneNode::clone(ISceneNode* newParent, ISceneManager* newManager) |
273 | { | 273 | { |
274 | if (!newParent) | 274 | if (!newParent) |
275 | newParent = Parent; | 275 | newParent = Parent; |
276 | if (!newManager) | 276 | if (!newManager) |
277 | newManager = SceneManager; | 277 | newManager = SceneManager; |
278 | 278 | ||
279 | CBillboardSceneNode* nb = new CBillboardSceneNode(newParent, | 279 | CBillboardSceneNode* nb = new CBillboardSceneNode(newParent, |
280 | newManager, ID, RelativeTranslation, Size); | 280 | newManager, ID, RelativeTranslation, Size); |
281 | 281 | ||
282 | nb->cloneMembers(this, newManager); | 282 | nb->cloneMembers(this, newManager); |
283 | nb->Material = Material; | 283 | nb->Material = Material; |
284 | nb->TopEdgeWidth = this->TopEdgeWidth; | 284 | nb->TopEdgeWidth = this->TopEdgeWidth; |
285 | 285 | ||
286 | if ( newParent ) | 286 | if ( newParent ) |
287 | nb->drop(); | 287 | nb->drop(); |
288 | return nb; | 288 | return nb; |
289 | } | 289 | } |
290 | 290 | ||
291 | 291 | ||
292 | } // end namespace scene | 292 | } // end namespace scene |
293 | } // end namespace irr | 293 | } // end namespace irr |
294 | 294 | ||