SO3Engine
SCOLTerrain.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// Scene Graph includes
41
42
43
53int SO3TerrainCreate(mmachine m)
54{
55#ifdef SO3_DEBUG
56 MMechostr(MSKDEBUG, "SO3TerrainCreate\n");
57#endif
58
59 int name = MMpull(m);
60 int s = MMget(m, 0);
61 if (s == NIL)
62 {
63 MMset(m, 0, NIL);
64 return 0;
65 }
66
67 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
68 if (scene == NULL)
69 {
70 MMset(m, 0, NIL);
71 return 0;
72 }
73
74 std::string sname(MMstartstr(m, MTOP(name)));
75 STerrain* terrain = 0;
76 try
77 {
78 terrain = scene->CreateTerrain(sname);
79 }
80 catch (Ogre::Exception &e)
81 {
82 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
83 MMset(m, 0, NIL);
84 return 0;
85 }
86
87 // remove last param
88 MMpull(m);
89 return createTerrain(m, terrain, scene);
90}
91
92
101int SO3TerrainDelete(mmachine m)
102{
103#ifdef SO3_DEBUG
104 MMechostr(MSKDEBUG, "SO3TerrainDelete\n");
105#endif
106
107 int s = MMget(m, 0);
108 if (s == NIL)
109 {
110 MMset(m, 0, NIL);
111 return 0;
112 }
113
114 OBJdelTM(m, SO3TERRAINTYPE, s);
115 MMset(m, 0, ITOM(1));
116 return 0;
117}
118
119
134{
135#ifdef SO3_DEBUG
136 MMechostr(MSKDEBUG, "SO3TerrainSetHeightMap\n");
137#endif
138
139 int maxbs = MTOI(MMpull(m));
140 int minbs = MTOI(MMpull(m));
141 float scale = MTOF(MMpull(m));
142 float size = MTOF(MMpull(m));
143 int file = MMpull(m);
144 int t = MMget(m, 0);
145
146 if ((t == NIL) || (file == NIL))
147 {
148 MMset(m, 0, NIL);
149 return 0;
150 }
151
152 string pathStd = MMstartstr(m, MTOP(file));
153 for (unsigned int i = 0; i < pathStd.length(); i++)
154 {
155 if (pathStd.substr(i, 1) == "\\")
156 pathStd.replace(i, 1, "/");
157 }
158
159 STerrain* terrain = MMgetPointer<STerrain*>(m, MTOP(t));
160 if (terrain == NULL)
161 {
162 MMset(m, 0, NIL);
163 return 0;
164 }
165
166 if (size <= 0.0f)
167 size = 100.0f;
168
169 if (scale <= 0.0f)
170 scale = 1.0f;
171
172 if (minbs <= 0)
173 minbs = 33;
174
175 if (maxbs <= minbs)
176 maxbs = minbs * 2 + 1;
177
178 if (!terrain->DefineHeightMap(pathStd, size, scale, minbs, maxbs))
179 MMset(m, 0, NIL);
180 else
181 MMset(m, 0, ITOM(1));
182
183 return 0;
184}
185
186
187NativeDefinition natSO3Terrain[] = {
188 { "SO3TerrainCreate", 2, "fun [SO3_SCENE S] SO3_TERRAIN", SO3TerrainCreate },
189 { "SO3TerrainDelete", 1, "fun [SO3_TERRAIN] I", SO3TerrainDelete },
190 { "SO3TerrainSetHeightMap", 6, "fun [SO3_TERRAIN P F F I I] I", SO3TerrainSetHeightMap }
191};
192
193
199int SCOLloadTerrain(mmachine m, cbmachine w)
200{
201 return PKhardpak2(m, "SO3Terrain.pkg", sizeof(natSO3Terrain) / sizeof(natSO3Terrain[0]), natSO3Terrain);
202}
203
204
210{
211 return 0;
212}
NativeDefinition natSO3Terrain[]
int SCOLloadTerrain(mmachine m, cbmachine w)
Load the SO3Engine Terrain function.
int SCOLfreeTerrain()
free the SO3Engine Terrain function
MMechostr(MSKDEBUG, " > Start loading Plugin SO3Engine dll\n")
SCOL_EXPORT int cbmachine w
Definition SO3SCOL.cpp:5150
int createTerrain(mmachine m, STerrain *terrain, SScene *curScene)
int SO3TERRAINTYPE
Definition SO3SCOL.cpp:91
int SO3TerrainSetHeightMap(mmachine m)
SO3TerrainSetHeightMap : Define a terrain height map and params Every terrain parameters must be a va...
int SO3TerrainCreate(mmachine m)
main include
int SO3TerrainDelete(mmachine m)
SO3TerrainDelete : destroy a terrain.