Project

General

Profile

SO3Engine
SCOLDynamicCubeMap.cpp
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
25
34#include "SCOLPack/SO3SCOL.h"
35
36// Material includes
38
39// Scene Graph includes
41
52{
53#ifdef SO3_DEBUG
54 MMechostr(MSKDEBUG, "SO3DynamicCubeMapCreate\n");
55#endif
56
57 int n = MMpull(m);
58 int s = MMget(m, 0);
59
60 // Checking parameters.
61 if((s==NIL)||(n==NIL))
62 {
63 MMset(m, 0, NIL);
64 return 0;
65 }
66
67 // Get the SScene pointer
68 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
69 if(scene==NULL)
70 {
71 MMset(m, 0, NIL);
72 return 0;
73 }
74
75 // Get the name
76 std::string tmpDynamicCubeMapName = MMstartstr(m, MTOP(n));
77
78 // Create the object
79 SDynamicCubeMap* dynamicCubeMap = 0;
80 try
81 {
82 dynamicCubeMap = scene->CreateDynamicCubeMap(tmpDynamicCubeMapName);
83 }
84 catch(Ogre::Exception &e)
85 {
86 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
87 MMset(m, 0, NIL);
88 return 0;
89 }
90
91 //get scene scol object
92 int p = OBJfindTH(m, SO3SCENETYPE, SCOL_PTR scene);
93 // push channel
94 MMset(m, 0, MMfetch(m, p, OFFOBJCHN));
95
96 if ((MMpushPointer(m, dynamicCubeMap) != 0))
97 {
98 scene->DeleteDynamicCubeMap(dynamicCubeMap);
99 MMset(m, 0, NIL);
100 return MERRMEM;
101 }
102
103 OBJcreate(m, SO3OBJTYPE, SCOL_PTR dynamicCubeMap, SO3SCENETYPE, SCOL_PTR scene);
104
105 return 0;
106}
107
121{
122#ifdef SO3_DEBUG
123 MMechostr(MSKDEBUG, "SO3DynamicCubeMapSetTargetMaterial\n");
124#endif
125
126 int textureUnit = MMpull(m);
127 int pass = MMpull(m);
128 int technique = MMpull(m);
129 int mat = MMpull(m);
130 int dcm = MMget(m, 0);
131
132 // Checking parameters.
133 if((dcm==NIL)||(mat==NIL)||(technique==NIL)||(pass==NIL)||(textureUnit==NIL))
134 {
135 MMset(m, 0, NIL);
136 return 0;
137 }
138
139 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
140 if(node == 0)
141 {
142 MMset(m, 0, NIL);
143 return 0;
144 }
145
146 if(node->GetNodeType() != SNode::DYNAMIC_CUBE_MAP_ID)
147 {
148 MMset(m, 0, NIL);
149 return 0;
150 }
151
152 SDynamicCubeMap* dynamicCubeMap = static_cast<SDynamicCubeMap*>(node);
153
154 // Get the targeted SMaterial pointer
155 SMaterial* material = MMgetPointer<SMaterial*>(m, MTOP(mat));
156 if(material == NULL)
157 {
158 MMset(m, 0, NIL);
159 return 0;
160 }
161
162 // Get other parameters
163 technique = MTOI(technique);
164 pass = MTOI(pass);
165 textureUnit = MTOI(textureUnit);
166
167 try
168 {
169 dynamicCubeMap->SetMaterial(material, technique, pass, textureUnit);
170 MMset(m, 0, ITOM(1));
171 }
172 catch(Ogre::Exception& e)
173 {
174 MMechostr(MSKRUNTIME, "An exception has occurred: %s\n", e.what());
175 MMset(m, 0, NIL);
176 }
177 return 0;
178}
179
189{
190#ifdef SO3_DEBUG
191 MMechostr(MSKDEBUG, "SO3DynamicCubeMapGetEnable\n");
192#endif
193
194 int dcm = MMget(m, 0);
195 if(dcm==NIL)
196 {
197 MMset(m,0,NIL);
198 return 0;
199 }
200
201 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
202 if(node == 0)
203 {
204 MMset(m, 0, NIL);
205 return 0;
206 }
207
208 if(node->GetNodeType()!=SNode::DYNAMIC_CUBE_MAP_ID)
209 {
210 MMset(m, 0, NIL);
211 return 0;
212 }
213
214 SDynamicCubeMap* dynamicCubeMap = static_cast<SDynamicCubeMap*>(node);
215
216 int val = 0;
217 if(dynamicCubeMap->GetEnable())
218 val = 1;
219
220 MMset(m, 0, ITOM(val));
221 return 0;
222}
223
234{
235#ifdef SO3_DEBUG
236 MMechostr(MSKDEBUG, "SO3DynamicCubeMapSetEnable\n");
237#endif
238
239 int b = MTOI(MMpull(m));
240 int dcm = MMget(m, 0);
241 if((dcm==NIL)||(b==NIL))
242 {
243 MMset(m, 0, NIL);
244 return 0;
245 }
246
247 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
248 if(node == 0)
249 {
250 MMset(m, 0, NIL);
251 return 0;
252 }
253
254 if(node->GetNodeType()!=SNode::DYNAMIC_CUBE_MAP_ID)
255 {
256 MMset(m, 0, NIL);
257 return 0;
258 }
259
260 SDynamicCubeMap* dynamicCubeMap = static_cast<SDynamicCubeMap*>(node);
261
262 if(b >= 1)
263 dynamicCubeMap->SetEnable(true);
264 else
265 dynamicCubeMap->SetEnable(false);
266
267 MMset(m, 0, ITOM(1));
268 return 0;
269}
270
280{
281#ifdef SO3_DEBUG
282 MMechostr(MSKDEBUG, "SO3DynamicCubeMapGetAutoUpdate\n");
283#endif
284
285 int dcm = MMget(m, 0);
286 if(dcm==NIL)
287 {
288 MMset(m,0,NIL);
289 return 0;
290 }
291
292 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
293 if(node == 0)
294 {
295 MMset(m, 0, NIL);
296 return 0;
297 }
298
299 if(node->GetNodeType()!=SNode::DYNAMIC_CUBE_MAP_ID)
300 {
301 MMset(m, 0, NIL);
302 return 0;
303 }
304
305 SDynamicCubeMap* dynamicCubeMap = static_cast<SDynamicCubeMap*>(node);
306
307 int val = 0;
308 if(dynamicCubeMap->GetAutoUpdate())
309 val = 1;
310
311 MMset(m, 0, ITOM(val));
312 return 0;
313}
314
325{
326#ifdef SO3_DEBUG
327 MMechostr(MSKDEBUG, "SO3DynamicCubeMapSetAutoUpdate\n");
328#endif
329
330 int b = MTOI(MMpull(m));
331 int dcm = MMget(m, 0);
332 if((dcm==NIL)||(b==NIL))
333 {
334 MMset(m, 0, NIL);
335 return 0;
336 }
337
338 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
339 if(node == 0)
340 {
341 MMset(m, 0, NIL);
342 return 0;
343 }
344
345 if(node->GetNodeType()!=SNode::DYNAMIC_CUBE_MAP_ID)
346 {
347 MMset(m, 0, NIL);
348 return 0;
349 }
350
351 SDynamicCubeMap* dynamicCubeMap = static_cast<SDynamicCubeMap*>(node);
352
353 if(b >= 1)
354 dynamicCubeMap->SetAutoUpdate(true);
355 else
356 dynamicCubeMap->SetAutoUpdate(false);
357
358 MMset(m, 0, ITOM(1));
359 return 0;
360}
361
362
372{
373#ifdef SO3_DEBUG
374 MMechostr(MSKDEBUG, "SO3DynamicCubeMapGetTextureSize\n");
375#endif
376
377 int dcm = MMget(m, 0);
378 if(dcm==NIL)
379 {
380 MMset(m,0,NIL);
381 return 0;
382 }
383
384 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
385 if(node == 0)
386 {
387 MMset(m, 0, NIL);
388 return 0;
389 }
390
391 if(node->GetNodeType()!=SNode::DYNAMIC_CUBE_MAP_ID)
392 {
393 MMset(m, 0, NIL);
394 return 0;
395 }
396
397 SDynamicCubeMap* dynamicCubeMap = static_cast<SDynamicCubeMap*>(node);
398 MMset(m, 0, ITOM(dynamicCubeMap->GetSize()));
399 return 0;
400}
401
412{
413#ifdef SO3_DEBUG
414 MMechostr(MSKDEBUG, "SO3DynamicCubeMapSetTextureSize\n");
415#endif
416
417 int b = MMpull(m);
418 int dcm = MMget(m, 0);
419 if((dcm==NIL)||(b==NIL))
420 {
421 MMset(m, 0, NIL);
422 return 0;
423 }
424
425 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
426 if(node == 0)
427 {
428 MMset(m, 0, NIL);
429 return 0;
430 }
431
432 if(node->GetNodeType()!=SNode::DYNAMIC_CUBE_MAP_ID)
433 {
434 MMset(m, 0, NIL);
435 return 0;
436 }
437
438 SDynamicCubeMap* dynamicCubeMap = static_cast<SDynamicCubeMap*>(node);
439
440 try
441 {
442 dynamicCubeMap->SetSize(MTOI(b));
443 MMset(m, 0, ITOM(1));
444 }
445 catch(Ogre::Exception& e)
446 {
447 MMechostr(MSKRUNTIME, "An exception has occurred: %s\n", e.what());
448 MMset(m, 0, NIL);
449 }
450 return 0;
451}
452
462{
463#ifdef SO3_DEBUG
464 MMechostr(MSKDEBUG, "SO3DynamicCubeMapUpdate\n");
465#endif
466
467 int dcm = MMget(m, 0);
468 if(dcm==NIL)
469 {
470 MMset(m,0,NIL);
471 return 0;
472 }
473
474 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
475 if(node == 0)
476 {
477 MMset(m, 0, NIL);
478 return 0;
479 }
480
481 if(node->GetNodeType()!=SNode::DYNAMIC_CUBE_MAP_ID)
482 {
483 MMset(m, 0, NIL);
484 return 0;
485 }
486
487 SDynamicCubeMap* dynamicCubeMap = static_cast<SDynamicCubeMap*>(node);
488
489 dynamicCubeMap->Update();
490 MMset(m, 0, ITOM(1));
491 return 0;
492}
493
494
495NativeDefinition natSO3CubeMap[] = {
496 { "SO3DynamicCubeMapCreate", 2, "fun [SO3_SCENE S] SO3_OBJECT", SO3DynamicCubeMapCreate },
497 { "SO3DynamicCubeMapSetTargetMaterial", 5, "fun [SO3_OBJECT SO3_MATERIAL I I I] SO3_OBJECT", SO3DynamicCubeMapSetTargetMaterial },
498 { "SO3DynamicCubeMapGetEnable", 1, "fun [SO3_OBJECT] I", SO3DynamicCubeMapGetEnable },
499 { "SO3DynamicCubeMapSetEnable", 2, "fun [SO3_OBJECT I] I", SO3DynamicCubeMapSetEnable },
500 { "SO3DynamicCubeMapGetTextureSize", 1, "fun [SO3_OBJECT] I", SO3DynamicCubeMapGetTextureSize },
501 { "SO3DynamicCubeMapSetTextureSize", 2, "fun [SO3_OBJECT I] I", SO3DynamicCubeMapSetTextureSize },
502 { "SO3DynamicCubeMapGetAutoUpdate", 1, "fun [SO3_OBJECT] I", SO3DynamicCubeMapGetAutoUpdate },
503 { "SO3DynamicCubeMapSetAutoUpdate", 2, "fun [SO3_OBJECT I] I", SO3DynamicCubeMapSetAutoUpdate },
504 { "SO3DynamicCubeMapUpdate", 1, "fun [SO3_OBJECT] I", SO3DynamicCubeMapUpdate }
505};
506
507
513int SCOLloadDynamicCubeMap(mmachine m,cbmachine w)
514{
515 return PKhardpak2(m, "SO3CubeMap.pkg", sizeof(natSO3CubeMap) / sizeof(natSO3CubeMap[0]), natSO3CubeMap);
516}
517
523{
524 return 0;
525}
int SCOLloadDynamicCubeMap(mmachine m, cbmachine w)
Load the SO3Engine DynamicCubeMap function.
int SCOLfreeDynamicCubeMap()
free the SO3Engine DynamicCubeMap function
NativeDefinition natSO3CubeMap[]
MMechostr(MSKDEBUG, " > Start loading Plugin SO3Engine dll\n")
SCOL_EXPORT int cbmachine w
Definition SO3SCOL.cpp:5150
int SO3SCENETYPE
Definition SO3SCOL.cpp:88
int SO3OBJTYPE
Definition SO3SCOL.cpp:90
int SO3DynamicCubeMapSetTargetMaterial(mmachine m)
SO3DynamicCubeMapSetTargetMaterial : Set the material on wich the rendered texture will be setted....
int SO3DynamicCubeMapUpdate(mmachine m)
SO3DynamicCubeMapUpdate : manually update a dynamic cube map (in case autoUpdate is set to false);.
int SO3DynamicCubeMapGetAutoUpdate(mmachine m)
SO3DynamicCubeMapGetAutoUpdate : Get the auto update state (is the cube map update each frame?...
int SO3DynamicCubeMapGetTextureSize(mmachine m)
SO3DynamicCubeMapGetTextureSize : Get the size of the dynamic cube map texture.
int SO3DynamicCubeMapCreate(mmachine m)
main include
int SO3DynamicCubeMapSetEnable(mmachine m)
SO3DynamicCubeMapSetEnable : Set the Enable state for dynamic cube map.
int SO3DynamicCubeMapSetTextureSize(mmachine m)
SO3DynamicCubeMapSetTextureSize : Set the size of the dynamic cube map texture.
int SO3DynamicCubeMapSetAutoUpdate(mmachine m)
SO3DynamicCubeMapSetAutoUpdate : Set the AutoUpdate state (refresh every frame) for dynamic cube map.
int SO3DynamicCubeMapGetEnable(mmachine m)
SO3DynamicCubeMapGetEnable : Get the enable state for the dynamic cube map.