Project

General

Profile

SO3Engine
SCOLDynamicReflectionMap.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
53{
54#ifdef SO3_DEBUG
55 MMechostr(MSKDEBUG, "SO3DynamicReflectionMapCreate\n");
56#endif
57
58 int n = MMpull(m);
59 int vp = MMpull(m);
60 int s = MMget(m, 0);
61
62 // Checking parameters.
63 if((s==NIL)||(n==NIL)||(vp==NIL))
64 {
65 MMset(m, 0, NIL);
66 return 0;
67 }
68
69 // Get the SScene pointer
70 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
71 if(scene==NULL)
72 {
73 MMset(m, 0, NIL);
74 return 0;
75 }
76
77 //get the viewport
78 SViewPort* viewport = MMgetPointer<SViewPort*>(m, MTOP(vp));
79 if(viewport==NULL)
80 {
81 MMset(m, 0, NIL);
82 return 0;
83 }
84
85 // Get the name
86 std::string tmpDynamicReflectionMapName = MMstartstr(m, MTOP(n));
87
88 // Create the object
89 SDynamicReflectionMap* dynamicReflectionMap = 0;
90 try
91 {
92 dynamicReflectionMap = scene->CreateDynamicReflectionMap(viewport, tmpDynamicReflectionMapName);
93 }
94 catch(Ogre::Exception &e)
95 {
96 MMechostr(MSKDEBUG,"An exception has occurred: %s\n",e.what());
97 MMset(m,0,NIL);
98 return 0;
99 }
100
101 //get scene scol object
102 int p = OBJfindTH(m, SO3SCENETYPE, SCOL_PTR scene);
103 // push channel
104 MMset(m, 0, MMfetch(m, p, OFFOBJCHN));
105
106 if ((MMpushPointer(m, dynamicReflectionMap) != 0))
107 {
108 scene->DeleteDynamicReflectionMap(dynamicReflectionMap);
109 MMset(m, 0, NIL);
110 return MERRMEM;
111 }
112
113 OBJcreate(m, SO3OBJTYPE, SCOL_PTR dynamicReflectionMap, SO3SCENETYPE, SCOL_PTR scene);
114
115 return 0;
116}
117
131{
132#ifdef SO3_DEBUG
133 MMechostr(MSKDEBUG, "SO3DynamicReflectionMapSetTargetMaterial\n");
134#endif
135
136 int textureUnit = MMpull(m);
137 int pass = MMpull(m);
138 int technique = MMpull(m);
139 int mat = MMpull(m);
140 int dcm = MMget(m, 0);
141
142 // Checking parameters.
143 if((dcm==NIL)||(mat==NIL)||(technique==NIL)||(pass==NIL)||(textureUnit==NIL))
144 {
145 MMset(m, 0, NIL);
146 return 0;
147 }
148
149 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
150 if(node == 0)
151 {
152 MMset(m, 0, NIL);
153 return 0;
154 }
155
156 if(node->GetNodeType()!=SNode::DYNAMIC_REFLECTION_MAP_ID)
157 {
158 MMset(m, 0, NIL);
159 return 0;
160 }
161
162 SDynamicReflectionMap* dynamicReflectionMap = static_cast<SDynamicReflectionMap*>(node);
163
164 // Get the targeted SMaterial pointer
165 SMaterial* material = MMgetPointer<SMaterial*>(m, MTOP(mat));
166 if(material == NULL)
167 {
168 MMset(m, 0, NIL);
169 return 0;
170 }
171
172 // Get other parameters
173 technique = MTOI(technique);
174 pass = MTOI(pass);
175 textureUnit = MTOI(textureUnit);
176
177 try
178 {
179 dynamicReflectionMap->SetMaterial(material, technique, pass, textureUnit);
180 MMset(m, 0, ITOM(1));
181 }
182 catch(Ogre::Exception& e)
183 {
184 MMechostr(MSKRUNTIME, "An exception has occurred: %s\n", e.what());
185 MMset(m, 0, NIL);
186 }
187 return 0;
188}
189
199{
200#ifdef SO3_DEBUG
201 MMechostr(MSKDEBUG, "SO3DynamicReflectionMapGetEnable\n");
202#endif
203
204 int dcm = MMget(m, 0);
205 if(dcm==NIL)
206 {
207 MMset(m,0,NIL);
208 return 0;
209 }
210
211 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
212 if(node == 0)
213 {
214 MMset(m, 0, NIL);
215 return 0;
216 }
217
218 if(node->GetNodeType()!=SNode::DYNAMIC_REFLECTION_MAP_ID)
219 {
220 MMset(m, 0, NIL);
221 return 0;
222 }
223
224 SDynamicReflectionMap* dynamicReflectionMap = static_cast<SDynamicReflectionMap*>(node);
225
226 int val = 0;
227 if(dynamicReflectionMap->GetEnable())
228 val = 1;
229
230 MMset(m, 0, ITOM(val));
231 return 0;
232}
233
244{
245#ifdef SO3_DEBUG
246 MMechostr(MSKDEBUG, "SO3DynamicReflectionMapSetEnable\n");
247#endif
248
249 int b = MTOI(MMpull(m));
250 int dcm = MMget(m, 0);
251 if((dcm==NIL)||(b==NIL))
252 {
253 MMset(m, 0, NIL);
254 return 0;
255 }
256
257 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
258 if(node == 0)
259 {
260 MMset(m, 0, NIL);
261 return 0;
262 }
263
264 if(node->GetNodeType()!=SNode::DYNAMIC_REFLECTION_MAP_ID)
265 {
266 MMset(m, 0, NIL);
267 return 0;
268 }
269
270 SDynamicReflectionMap* dynamicReflectionMap = static_cast<SDynamicReflectionMap*>(node);
271
272 if(b >= 1)
273 dynamicReflectionMap->SetEnable(true);
274 else
275 dynamicReflectionMap->SetEnable(false);
276
277 MMset(m, 0, ITOM(1));
278 return 0;
279}
280
290{
291#ifdef SO3_DEBUG
292 MMechostr(MSKDEBUG, "SO3DynamicReflectionMapGetRevertClipPlane\n");
293#endif
294
295 int dcm = MMget(m, 0);
296 if(dcm==NIL)
297 {
298 MMset(m,0,NIL);
299 return 0;
300 }
301
302 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
303 if(node == 0)
304 {
305 MMset(m, 0, NIL);
306 return 0;
307 }
308
309 if(node->GetNodeType()!=SNode::DYNAMIC_REFLECTION_MAP_ID)
310 {
311 MMset(m, 0, NIL);
312 return 0;
313 }
314
315 SDynamicReflectionMap* dynamicReflectionMap = static_cast<SDynamicReflectionMap*>(node);
316
317 int val = 0;
318 if(dynamicReflectionMap->GetRevertClipPlane())
319 val = 1;
320
321 MMset(m, 0, ITOM(val));
322 return 0;
323}
324
335{
336#ifdef SO3_DEBUG
337 MMechostr(MSKDEBUG, "SO3DynamicReflectionMapSetRevertClipPlane\n");
338#endif
339
340 int b = MTOI(MMpull(m));
341 int dcm = MMget(m, 0);
342 if(dcm==NIL)
343 {
344 MMset(m, 0, NIL);
345 return 0;
346 }
347
348 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
349 if(node == 0)
350 {
351 MMset(m, 0, NIL);
352 return 0;
353 }
354
355 if(node->GetNodeType()!=SNode::DYNAMIC_REFLECTION_MAP_ID)
356 {
357 MMset(m, 0, NIL);
358 return 0;
359 }
360
361 SDynamicReflectionMap* dynamicReflectionMap = static_cast<SDynamicReflectionMap*>(node);
362
363 if(b >= 1)
364 dynamicReflectionMap->SetRevertClipPlane(true);
365 else
366 dynamicReflectionMap->SetRevertClipPlane(false);
367
368 MMset(m, 0, ITOM(1));
369 return 0;
370}
371
372
382{
383#ifdef SO3_DEBUG
384 MMechostr(MSKDEBUG, "SO3DynamicReflectionMapGetTextureSize\n");
385#endif
386
387 int dcm = MMget(m, 0);
388 if(dcm==NIL)
389 {
390 MMset(m,0,NIL);
391 return 0;
392 }
393
394 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
395 if(node == 0)
396 {
397 MMset(m, 0, NIL);
398 return 0;
399 }
400
401 if(node->GetNodeType()!=SNode::DYNAMIC_REFLECTION_MAP_ID)
402 {
403 MMset(m, 0, NIL);
404 return 0;
405 }
406
407 SDynamicReflectionMap* dynamicReflectionMap = static_cast<SDynamicReflectionMap*>(node);
408 MMset(m, 0, ITOM(dynamicReflectionMap->GetSize()));
409 return 0;
410}
411
422{
423#ifdef SO3_DEBUG
424 MMechostr(MSKDEBUG, "SO3DynamicReflectionMapSetTextureSize\n");
425#endif
426
427 int b = MMpull(m);
428 int dcm = MMget(m, 0);
429 if((dcm==NIL)||(b==NIL))
430 {
431 MMset(m, 0, NIL);
432 return 0;
433 }
434
435 SNode* node = MMgetPointer<SNode*>(m, MTOP(dcm));
436 if(node == 0)
437 {
438 MMset(m, 0, NIL);
439 return 0;
440 }
441
442 if(node->GetNodeType()!=SNode::DYNAMIC_REFLECTION_MAP_ID)
443 {
444 MMset(m, 0, NIL);
445 return 0;
446 }
447
448 SDynamicReflectionMap* dynamicReflectionMap = static_cast<SDynamicReflectionMap*>(node);
449
450 try
451 {
452 dynamicReflectionMap->SetSize(MTOI(b));
453 MMset(m, 0, ITOM(1));
454 }
455 catch(Ogre::Exception& e)
456 {
457 MMechostr(MSKRUNTIME, "An exception has occurred: %s\n", e.what());
458 MMset(m, 0, NIL);
459 }
460 return 0;
461}
462
463
464NativeDefinition natSO3RefMap[] = {
465 { "SO3DynamicReflectionMapCreate", 3, "fun [SO3_SCENE SO3_VIEWPORT S] SO3_OBJECT", SO3DynamicReflectionMapCreate, },
466 { "SO3DynamicReflectionMapSetTargetMaterial", 5, "fun [SO3_OBJECT SO3_MATERIAL I I I] SO3_OBJECT", SO3DynamicReflectionMapSetTargetMaterial, },
467 { "SO3DynamicReflectionMapGetEnable", 1, "fun [SO3_OBJECT] I", SO3DynamicReflectionMapGetEnable, },
468 { "SO3DynamicReflectionMapSetEnable", 2, "fun [SO3_OBJECT I] I", SO3DynamicReflectionMapSetEnable, },
469 { "SO3DynamicReflectionMapGetTextureSize", 1, "fun [SO3_OBJECT] I", SO3DynamicReflectionMapGetTextureSize, },
470 { "SO3DynamicReflectionMapSetTextureSize", 2, "fun [SO3_OBJECT I] I", SO3DynamicReflectionMapSetTextureSize, },
471 { "SO3DynamicReflectionMapGetRevertClipPlane", 1, "fun [SO3_OBJECT] I", SO3DynamicReflectionMapGetRevertClipPlane, },
472 { "SO3DynamicReflectionMapSetRevertClipPlane", 2, "fun [SO3_OBJECT I] I", SO3DynamicReflectionMapSetRevertClipPlane, }
473};
474
475
481int SCOLloadDynamicReflectionMap(mmachine m,cbmachine w)
482{
483 return PKhardpak2(m, "SO3RefMap.pkg", sizeof(natSO3RefMap) / sizeof(natSO3RefMap[0]), natSO3RefMap);
484}
485
491{
492 return 0;
493}
int SCOLfreeDynamicReflectionMap()
free the SO3Engine DynamicReflectionMap function
NativeDefinition natSO3RefMap[]
int SCOLloadDynamicReflectionMap(mmachine m, cbmachine w)
Load the SO3Engine DynamicReflectionMap function.
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 SO3DynamicReflectionMapSetTextureSize(mmachine m)
SO3DynamicReflectionMapSetTextureSize : Set the size of the dynamic reflection map texture.
int SO3DynamicReflectionMapSetTargetMaterial(mmachine m)
SO3DynamicReflectionMapSetTargetMaterial : Set the material on wich the rendered texture will be sett...
int SO3DynamicReflectionMapGetTextureSize(mmachine m)
SO3DynamicReflectionMapGetTextureSize : Get the size of the dynamic reflection map texture.
int SO3DynamicReflectionMapSetRevertClipPlane(mmachine m)
SO3DynamicReflectionMapSetRevertClipPlane : Set the revert clip plane state for dynamic reflection ma...
int SO3DynamicReflectionMapSetEnable(mmachine m)
SO3DynamicReflectionMapSetEnable : Set the Enable state for dynamic reflection map.
int SO3DynamicReflectionMapGetEnable(mmachine m)
SO3DynamicReflectionMapGetEnable : Get the enable state for the dynamic reflection map.
int SO3DynamicReflectionMapGetRevertClipPlane(mmachine m)
SO3DynamicReflectionMapGetRevertClipPlane : Get the revert clip plane state (is the camera clip plane...
int SO3DynamicReflectionMapCreate(mmachine m)
main include