aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CSkyBoxSceneNode.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/CSkyBoxSceneNode.cpp526
1 files changed, 263 insertions, 263 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CSkyBoxSceneNode.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CSkyBoxSceneNode.cpp
index 756fab9..d357906 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/CSkyBoxSceneNode.cpp
+++ b/libraries/irrlicht-1.8/source/Irrlicht/CSkyBoxSceneNode.cpp
@@ -1,263 +1,263 @@
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 "CSkyBoxSceneNode.h" 5#include "CSkyBoxSceneNode.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 "S3DVertex.h" 9#include "S3DVertex.h"
10#include "os.h" 10#include "os.h"
11 11
12namespace irr 12namespace irr
13{ 13{
14namespace scene 14namespace scene
15{ 15{
16 16
17//! constructor 17//! constructor
18CSkyBoxSceneNode::CSkyBoxSceneNode(video::ITexture* top, video::ITexture* bottom, video::ITexture* left, 18CSkyBoxSceneNode::CSkyBoxSceneNode(video::ITexture* top, video::ITexture* bottom, video::ITexture* left,
19 video::ITexture* right, video::ITexture* front, video::ITexture* back, ISceneNode* parent, ISceneManager* mgr, s32 id) 19 video::ITexture* right, video::ITexture* front, video::ITexture* back, ISceneNode* parent, ISceneManager* mgr, s32 id)
20: ISceneNode(parent, mgr, id) 20: ISceneNode(parent, mgr, id)
21{ 21{
22 #ifdef _DEBUG 22 #ifdef _DEBUG
23 setDebugName("CSkyBoxSceneNode"); 23 setDebugName("CSkyBoxSceneNode");
24 #endif 24 #endif
25 25
26 setAutomaticCulling(scene::EAC_OFF); 26 setAutomaticCulling(scene::EAC_OFF);
27 Box.MaxEdge.set(0,0,0); 27 Box.MaxEdge.set(0,0,0);
28 Box.MinEdge.set(0,0,0); 28 Box.MinEdge.set(0,0,0);
29 29
30 // create indices 30 // create indices
31 31
32 Indices[0] = 0; 32 Indices[0] = 0;
33 Indices[1] = 1; 33 Indices[1] = 1;
34 Indices[2] = 2; 34 Indices[2] = 2;
35 Indices[3] = 3; 35 Indices[3] = 3;
36 36
37 // create material 37 // create material
38 38
39 video::SMaterial mat; 39 video::SMaterial mat;
40 mat.Lighting = false; 40 mat.Lighting = false;
41 mat.ZBuffer = video::ECFN_NEVER; 41 mat.ZBuffer = video::ECFN_NEVER;
42 mat.ZWriteEnable = false; 42 mat.ZWriteEnable = false;
43 mat.AntiAliasing=0; 43 mat.AntiAliasing=0;
44 mat.TextureLayer[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE; 44 mat.TextureLayer[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
45 mat.TextureLayer[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE; 45 mat.TextureLayer[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
46 46
47 /* Hey, I am no artist, but look at that 47 /* Hey, I am no artist, but look at that
48 cool ASCII art I made! ;) 48 cool ASCII art I made! ;)
49 49
50 -111 111 50 -111 111
51 /6--------/5 y 51 /6--------/5 y
52 / | / | ^ z 52 / | / | ^ z
53 / | 11-1 | | / 53 / | 11-1 | | /
54 -11-1 3---------2 | |/ 54 -11-1 3---------2 | |/
55 | 7- - -| -4 1-11 *---->x 55 | 7- - -| -4 1-11 *---->x
56 | -1-11 | / 3-------|2 56 | -1-11 | / 3-------|2
57 |/ | / | //| 57 |/ | / | //|
58 0---------1/ | // | 58 0---------1/ | // |
59 -1-1-1 1-1-1 |// | 59 -1-1-1 1-1-1 |// |
60 0--------1 60 0--------1
61 */ 61 */
62 62
63 video::ITexture* tex = front; 63 video::ITexture* tex = front;
64 if (!tex) tex = left; 64 if (!tex) tex = left;
65 if (!tex) tex = back; 65 if (!tex) tex = back;
66 if (!tex) tex = right; 66 if (!tex) tex = right;
67 if (!tex) tex = top; 67 if (!tex) tex = top;
68 if (!tex) tex = bottom; 68 if (!tex) tex = bottom;
69 69
70 const f32 onepixel = tex?(1.0f / (tex->getSize().Width * 1.5f)) : 0.0f; 70 const f32 onepixel = tex?(1.0f / (tex->getSize().Width * 1.5f)) : 0.0f;
71 const f32 t = 1.0f - onepixel; 71 const f32 t = 1.0f - onepixel;
72 const f32 o = 0.0f + onepixel; 72 const f32 o = 0.0f + onepixel;
73 73
74 // create front side 74 // create front side
75 75
76 Material[0] = mat; 76 Material[0] = mat;
77 Material[0].setTexture(0, front); 77 Material[0].setTexture(0, front);
78 Vertices[0] = video::S3DVertex(-1,-1,-1, 0,0,1, video::SColor(255,255,255,255), t, t); 78 Vertices[0] = video::S3DVertex(-1,-1,-1, 0,0,1, video::SColor(255,255,255,255), t, t);
79 Vertices[1] = video::S3DVertex( 1,-1,-1, 0,0,1, video::SColor(255,255,255,255), o, t); 79 Vertices[1] = video::S3DVertex( 1,-1,-1, 0,0,1, video::SColor(255,255,255,255), o, t);
80 Vertices[2] = video::S3DVertex( 1, 1,-1, 0,0,1, video::SColor(255,255,255,255), o, o); 80 Vertices[2] = video::S3DVertex( 1, 1,-1, 0,0,1, video::SColor(255,255,255,255), o, o);
81 Vertices[3] = video::S3DVertex(-1, 1,-1, 0,0,1, video::SColor(255,255,255,255), t, o); 81 Vertices[3] = video::S3DVertex(-1, 1,-1, 0,0,1, video::SColor(255,255,255,255), t, o);
82 82
83 // create left side 83 // create left side
84 84
85 Material[1] = mat; 85 Material[1] = mat;
86 Material[1].setTexture(0, left); 86 Material[1].setTexture(0, left);
87 Vertices[4] = video::S3DVertex( 1,-1,-1, -1,0,0, video::SColor(255,255,255,255), t, t); 87 Vertices[4] = video::S3DVertex( 1,-1,-1, -1,0,0, video::SColor(255,255,255,255), t, t);
88 Vertices[5] = video::S3DVertex( 1,-1, 1, -1,0,0, video::SColor(255,255,255,255), o, t); 88 Vertices[5] = video::S3DVertex( 1,-1, 1, -1,0,0, video::SColor(255,255,255,255), o, t);
89 Vertices[6] = video::S3DVertex( 1, 1, 1, -1,0,0, video::SColor(255,255,255,255), o, o); 89 Vertices[6] = video::S3DVertex( 1, 1, 1, -1,0,0, video::SColor(255,255,255,255), o, o);
90 Vertices[7] = video::S3DVertex( 1, 1,-1, -1,0,0, video::SColor(255,255,255,255), t, o); 90 Vertices[7] = video::S3DVertex( 1, 1,-1, -1,0,0, video::SColor(255,255,255,255), t, o);
91 91
92 // create back side 92 // create back side
93 93
94 Material[2] = mat; 94 Material[2] = mat;
95 Material[2].setTexture(0, back); 95 Material[2].setTexture(0, back);
96 Vertices[8] = video::S3DVertex( 1,-1, 1, 0,0,-1, video::SColor(255,255,255,255), t, t); 96 Vertices[8] = video::S3DVertex( 1,-1, 1, 0,0,-1, video::SColor(255,255,255,255), t, t);
97 Vertices[9] = video::S3DVertex(-1,-1, 1, 0,0,-1, video::SColor(255,255,255,255), o, t); 97 Vertices[9] = video::S3DVertex(-1,-1, 1, 0,0,-1, video::SColor(255,255,255,255), o, t);
98 Vertices[10] = video::S3DVertex(-1, 1, 1, 0,0,-1, video::SColor(255,255,255,255), o, o); 98 Vertices[10] = video::S3DVertex(-1, 1, 1, 0,0,-1, video::SColor(255,255,255,255), o, o);
99 Vertices[11] = video::S3DVertex( 1, 1, 1, 0,0,-1, video::SColor(255,255,255,255), t, o); 99 Vertices[11] = video::S3DVertex( 1, 1, 1, 0,0,-1, video::SColor(255,255,255,255), t, o);
100 100
101 // create right side 101 // create right side
102 102
103 Material[3] = mat; 103 Material[3] = mat;
104 Material[3].setTexture(0, right); 104 Material[3].setTexture(0, right);
105 Vertices[12] = video::S3DVertex(-1,-1, 1, 1,0,0, video::SColor(255,255,255,255), t, t); 105 Vertices[12] = video::S3DVertex(-1,-1, 1, 1,0,0, video::SColor(255,255,255,255), t, t);
106 Vertices[13] = video::S3DVertex(-1,-1,-1, 1,0,0, video::SColor(255,255,255,255), o, t); 106 Vertices[13] = video::S3DVertex(-1,-1,-1, 1,0,0, video::SColor(255,255,255,255), o, t);
107 Vertices[14] = video::S3DVertex(-1, 1,-1, 1,0,0, video::SColor(255,255,255,255), o, o); 107 Vertices[14] = video::S3DVertex(-1, 1,-1, 1,0,0, video::SColor(255,255,255,255), o, o);
108 Vertices[15] = video::S3DVertex(-1, 1, 1, 1,0,0, video::SColor(255,255,255,255), t, o); 108 Vertices[15] = video::S3DVertex(-1, 1, 1, 1,0,0, video::SColor(255,255,255,255), t, o);
109 109
110 // create top side 110 // create top side
111 111
112 Material[4] = mat; 112 Material[4] = mat;
113 Material[4].setTexture(0, top); 113 Material[4].setTexture(0, top);
114 Vertices[16] = video::S3DVertex( 1, 1,-1, 0,-1,0, video::SColor(255,255,255,255), t, t); 114 Vertices[16] = video::S3DVertex( 1, 1,-1, 0,-1,0, video::SColor(255,255,255,255), t, t);
115 Vertices[17] = video::S3DVertex( 1, 1, 1, 0,-1,0, video::SColor(255,255,255,255), o, t); 115 Vertices[17] = video::S3DVertex( 1, 1, 1, 0,-1,0, video::SColor(255,255,255,255), o, t);
116 Vertices[18] = video::S3DVertex(-1, 1, 1, 0,-1,0, video::SColor(255,255,255,255), o, o); 116 Vertices[18] = video::S3DVertex(-1, 1, 1, 0,-1,0, video::SColor(255,255,255,255), o, o);
117 Vertices[19] = video::S3DVertex(-1, 1,-1, 0,-1,0, video::SColor(255,255,255,255), t, o); 117 Vertices[19] = video::S3DVertex(-1, 1,-1, 0,-1,0, video::SColor(255,255,255,255), t, o);
118 118
119 // create bottom side 119 // create bottom side
120 120
121 Material[5] = mat; 121 Material[5] = mat;
122 Material[5].setTexture(0, bottom); 122 Material[5].setTexture(0, bottom);
123 Vertices[20] = video::S3DVertex( 1,-1, 1, 0,1,0, video::SColor(255,255,255,255), o, o); 123 Vertices[20] = video::S3DVertex( 1,-1, 1, 0,1,0, video::SColor(255,255,255,255), o, o);
124 Vertices[21] = video::S3DVertex( 1,-1,-1, 0,1,0, video::SColor(255,255,255,255), t, o); 124 Vertices[21] = video::S3DVertex( 1,-1,-1, 0,1,0, video::SColor(255,255,255,255), t, o);
125 Vertices[22] = video::S3DVertex(-1,-1,-1, 0,1,0, video::SColor(255,255,255,255), t, t); 125 Vertices[22] = video::S3DVertex(-1,-1,-1, 0,1,0, video::SColor(255,255,255,255), t, t);
126 Vertices[23] = video::S3DVertex(-1,-1, 1, 0,1,0, video::SColor(255,255,255,255), o, t); 126 Vertices[23] = video::S3DVertex(-1,-1, 1, 0,1,0, video::SColor(255,255,255,255), o, t);
127} 127}
128 128
129 129
130//! renders the node. 130//! renders the node.
131void CSkyBoxSceneNode::render() 131void CSkyBoxSceneNode::render()
132{ 132{
133 video::IVideoDriver* driver = SceneManager->getVideoDriver(); 133 video::IVideoDriver* driver = SceneManager->getVideoDriver();
134 scene::ICameraSceneNode* camera = SceneManager->getActiveCamera(); 134 scene::ICameraSceneNode* camera = SceneManager->getActiveCamera();
135 135
136 if (!camera || !driver) 136 if (!camera || !driver)
137 return; 137 return;
138 138
139 if ( !camera->isOrthogonal() ) 139 if ( !camera->isOrthogonal() )
140 { 140 {
141 // draw perspective skybox 141 // draw perspective skybox
142 142
143 core::matrix4 translate(AbsoluteTransformation); 143 core::matrix4 translate(AbsoluteTransformation);
144 translate.setTranslation(camera->getAbsolutePosition()); 144 translate.setTranslation(camera->getAbsolutePosition());
145 145
146 // Draw the sky box between the near and far clip plane 146 // Draw the sky box between the near and far clip plane
147 const f32 viewDistance = (camera->getNearValue() + camera->getFarValue()) * 0.5f; 147 const f32 viewDistance = (camera->getNearValue() + camera->getFarValue()) * 0.5f;
148 core::matrix4 scale; 148 core::matrix4 scale;
149 scale.setScale(core::vector3df(viewDistance, viewDistance, viewDistance)); 149 scale.setScale(core::vector3df(viewDistance, viewDistance, viewDistance));
150 150
151 driver->setTransform(video::ETS_WORLD, translate * scale); 151 driver->setTransform(video::ETS_WORLD, translate * scale);
152 152
153 for (s32 i=0; i<6; ++i) 153 for (s32 i=0; i<6; ++i)
154 { 154 {
155 driver->setMaterial(Material[i]); 155 driver->setMaterial(Material[i]);
156 driver->drawIndexedTriangleFan(&Vertices[i*4], 4, Indices, 2); 156 driver->drawIndexedTriangleFan(&Vertices[i*4], 4, Indices, 2);
157 } 157 }
158 } 158 }
159 else 159 else
160 { 160 {
161 // draw orthogonal skybox, 161 // draw orthogonal skybox,
162 // simply choose one texture and draw it as 2d picture. 162 // simply choose one texture and draw it as 2d picture.
163 // there could be better ways to do this, but currently I think this is ok. 163 // there could be better ways to do this, but currently I think this is ok.
164 164
165 core::vector3df lookVect = camera->getTarget() - camera->getAbsolutePosition(); 165 core::vector3df lookVect = camera->getTarget() - camera->getAbsolutePosition();
166 lookVect.normalize(); 166 lookVect.normalize();
167 core::vector3df absVect( core::abs_(lookVect.X), 167 core::vector3df absVect( core::abs_(lookVect.X),
168 core::abs_(lookVect.Y), 168 core::abs_(lookVect.Y),
169 core::abs_(lookVect.Z)); 169 core::abs_(lookVect.Z));
170 170
171 int idx = 0; 171 int idx = 0;
172 172
173 if ( absVect.X >= absVect.Y && absVect.X >= absVect.Z ) 173 if ( absVect.X >= absVect.Y && absVect.X >= absVect.Z )
174 { 174 {
175 // x direction 175 // x direction
176 idx = lookVect.X > 0 ? 0 : 2; 176 idx = lookVect.X > 0 ? 0 : 2;
177 } 177 }
178 else 178 else
179 if ( absVect.Y >= absVect.X && absVect.Y >= absVect.Z ) 179 if ( absVect.Y >= absVect.X && absVect.Y >= absVect.Z )
180 { 180 {
181 // y direction 181 // y direction
182 idx = lookVect.Y > 0 ? 4 : 5; 182 idx = lookVect.Y > 0 ? 4 : 5;
183 } 183 }
184 else 184 else
185 if ( absVect.Z >= absVect.X && absVect.Z >= absVect.Y ) 185 if ( absVect.Z >= absVect.X && absVect.Z >= absVect.Y )
186 { 186 {
187 // z direction 187 // z direction
188 idx = lookVect.Z > 0 ? 1 : 3; 188 idx = lookVect.Z > 0 ? 1 : 3;
189 } 189 }
190 190
191 video::ITexture* tex = Material[idx].getTexture(0); 191 video::ITexture* tex = Material[idx].getTexture(0);
192 192
193 if ( tex ) 193 if ( tex )
194 { 194 {
195 core::rect<s32> rctDest(core::position2d<s32>(-1,0), 195 core::rect<s32> rctDest(core::position2d<s32>(-1,0),
196 core::dimension2di(driver->getCurrentRenderTargetSize())); 196 core::dimension2di(driver->getCurrentRenderTargetSize()));
197 core::rect<s32> rctSrc(core::position2d<s32>(0,0), 197 core::rect<s32> rctSrc(core::position2d<s32>(0,0),
198 core::dimension2di(tex->getSize())); 198 core::dimension2di(tex->getSize()));
199 199
200 driver->draw2DImage(tex, rctDest, rctSrc); 200 driver->draw2DImage(tex, rctDest, rctSrc);
201 } 201 }
202 } 202 }
203} 203}
204 204
205 205
206 206
207//! returns the axis aligned bounding box of this node 207//! returns the axis aligned bounding box of this node
208const core::aabbox3d<f32>& CSkyBoxSceneNode::getBoundingBox() const 208const core::aabbox3d<f32>& CSkyBoxSceneNode::getBoundingBox() const
209{ 209{
210 return Box; 210 return Box;
211} 211}
212 212
213 213
214void CSkyBoxSceneNode::OnRegisterSceneNode() 214void CSkyBoxSceneNode::OnRegisterSceneNode()
215{ 215{
216 if (IsVisible) 216 if (IsVisible)
217 SceneManager->registerNodeForRendering(this, ESNRP_SKY_BOX); 217 SceneManager->registerNodeForRendering(this, ESNRP_SKY_BOX);
218 218
219 ISceneNode::OnRegisterSceneNode(); 219 ISceneNode::OnRegisterSceneNode();
220} 220}
221 221
222 222
223//! returns the material based on the zero based index i. To get the amount 223//! returns the material based on the zero based index i. To get the amount
224//! of materials used by this scene node, use getMaterialCount(). 224//! of materials used by this scene node, use getMaterialCount().
225//! This function is needed for inserting the node into the scene hirachy on a 225//! This function is needed for inserting the node into the scene hirachy on a
226//! optimal position for minimizing renderstate changes, but can also be used 226//! optimal position for minimizing renderstate changes, but can also be used
227//! to directly modify the material of a scene node. 227//! to directly modify the material of a scene node.
228video::SMaterial& CSkyBoxSceneNode::getMaterial(u32 i) 228video::SMaterial& CSkyBoxSceneNode::getMaterial(u32 i)
229{ 229{
230 return Material[i]; 230 return Material[i];
231} 231}
232 232
233 233
234//! returns amount of materials used by this scene node. 234//! returns amount of materials used by this scene node.
235u32 CSkyBoxSceneNode::getMaterialCount() const 235u32 CSkyBoxSceneNode::getMaterialCount() const
236{ 236{
237 return 6; 237 return 6;
238} 238}
239 239
240 240
241//! Creates a clone of this scene node and its children. 241//! Creates a clone of this scene node and its children.
242ISceneNode* CSkyBoxSceneNode::clone(ISceneNode* newParent, ISceneManager* newManager) 242ISceneNode* CSkyBoxSceneNode::clone(ISceneNode* newParent, ISceneManager* newManager)
243{ 243{
244 if (!newParent) newParent = Parent; 244 if (!newParent) newParent = Parent;
245 if (!newManager) newManager = SceneManager; 245 if (!newManager) newManager = SceneManager;
246 246
247 CSkyBoxSceneNode* nb = new CSkyBoxSceneNode(0,0,0,0,0,0, newParent, 247 CSkyBoxSceneNode* nb = new CSkyBoxSceneNode(0,0,0,0,0,0, newParent,
248 newManager, ID); 248 newManager, ID);
249 249
250 nb->cloneMembers(this, newManager); 250 nb->cloneMembers(this, newManager);
251 251
252 for (u32 i=0; i<6; ++i) 252 for (u32 i=0; i<6; ++i)
253 nb->Material[i] = Material[i]; 253 nb->Material[i] = Material[i];
254 254
255 if ( newParent ) 255 if ( newParent )
256 nb->drop(); 256 nb->drop();
257 return nb; 257 return nb;
258} 258}
259 259
260 260
261} // end namespace scene 261} // end namespace scene
262} // end namespace irr 262} // end namespace irr
263 263