]> git.jsancho.org Git - c-irrlicht.git/blob - src/ISceneManager.cpp
Booleans
[c-irrlicht.git] / src / ISceneManager.cpp
1 /* c-irrlicht --- C bindings for Irrlicht Engine
2
3    Copyright (C) 2019 Javier Sancho <jsf@jsancho.org>
4
5    This file is part of c-irrlicht.
6
7    c-irrlicht is free software; you can redistribute it and/or modify
8    it under the terms of the GNU Lesser General Public License as
9    published by the Free Software Foundation; either version 3 of the
10    License, or (at your option) any later version.
11
12    c-irrlicht is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    General Public License for more details.
16
17    You should have received a copy of the GNU Lesser General Public
18    License along with guile-irrlicht.  If not, see
19    <http://www.gnu.org/licenses/>.
20 */
21
22 #include <irrlicht/irrlicht.h>
23 #include "ISceneManager.h"
24
25 class CustomSceneNode : public irr::scene::ISceneNode
26 {
27   void (*Render)();
28   irr_core_aabbox3d_f32* (*GetBoundingBox)();
29   uint32_t (*GetMaterialCount)();
30   irr_video_SMaterial* (*GetMaterial)(unsigned int i);
31
32 public:
33   CustomSceneNode(irr::scene::ISceneNode* parent,
34                   irr::scene::ISceneManager* smgr,
35                   irr::s32 id,
36                   const irr::core::vector3df& position,
37                   const irr::core::vector3df& rotation,
38                   const irr::core::vector3df& scale,
39                   void (*render)(),
40                   irr_core_aabbox3d_f32* (*getBoundingBox)(),
41                   uint32_t (*getMaterialCount)(),
42                   irr_video_SMaterial* (*getMaterial)(unsigned int i))
43   : irr::scene::ISceneNode(parent, smgr, id, position, rotation, scale)
44   {
45     Render = render;
46     GetBoundingBox = getBoundingBox;
47     GetMaterialCount = getMaterialCount;
48     GetMaterial = getMaterial;
49   }
50
51   virtual void OnRegisterSceneNode()
52   {
53     if (IsVisible) {
54       SceneManager->registerNodeForRendering(this);
55     }
56
57     ISceneNode::OnRegisterSceneNode();
58   }
59
60   virtual void render()
61   {
62     Render();
63   }
64
65   virtual const irr::core::aabbox3d<irr::f32>& getBoundingBox() const
66   {
67     irr_core_aabbox3d_f32* box = GetBoundingBox();
68     irr::core::aabbox3d<irr::f32>* irrBox = new irr::core::aabbox3d<irr::f32>();
69     return *irrBox;
70   }
71
72   virtual irr::u32 getMaterialCount() const
73   {
74     return GetMaterialCount();
75   }
76
77   virtual irr::video::SMaterial& getMaterial(irr::u32 i)
78   {
79     irr_video_SMaterial* material = GetMaterial(i);
80     irr::video::SMaterial* irrMaterial = new irr::video::SMaterial();
81     irrMaterial->Wireframe = material->wireframe;
82     irrMaterial->Lighting = material->lighting;
83     return *irrMaterial;
84   }
85 };
86
87 extern "C" {
88   irr_scene_IAnimatedMeshSceneNode*
89   irr_scene_addAnimatedMeshSceneNode(irr_scene_ISceneManager* smgr,
90                                      irr_scene_IAnimatedMesh* mesh,
91                                      irr_scene_ISceneNode* parent,
92                                      int32_t id,
93                                      irr_core_vector3df* position,
94                                      irr_core_vector3df* rotation,
95                                      irr_core_vector3df* scale,
96                                      bool alsoAddIfMeshPointerZero)
97   {
98     const irr::core::vector3df iPosition =
99       position ?
100       irr::core::vector3df(position->x, position->y, position->z) :
101       irr::core::vector3df(0, 0, 0);
102
103     const irr::core::vector3df iRotation =
104       rotation ?
105       irr::core::vector3df(rotation->x, rotation->y, rotation->z) :
106       irr::core::vector3df(0, 0, 0);
107
108     const irr::core::vector3df& iScale =
109       scale ?
110       irr::core::vector3df(scale->x, scale->y, scale->z) :
111       irr::core::vector3df(1, 1, 1);
112
113     return (irr_scene_IAnimatedMeshSceneNode*)
114       ((irr::scene::ISceneManager*)smgr)
115       ->addAnimatedMeshSceneNode((irr::scene::IAnimatedMesh*)mesh,
116                                  (irr::scene::ISceneNode*)parent,
117                                  id,
118                                  iPosition,
119                                  iRotation,
120                                  iScale,
121                                  alsoAddIfMeshPointerZero);
122   }
123
124   irr_scene_ICameraSceneNode*
125   irr_scene_addCameraSceneNode(irr_scene_ISceneManager* smgr,
126                                irr_scene_ISceneNode* parent,
127                                irr_core_vector3df* position,
128                                irr_core_vector3df* lookat,
129                                int32_t id,
130                                bool makeActive)
131   {
132     const irr::core::vector3df& iPosition =
133       position ?
134       irr::core::vector3df(position->x, position->y, position->z) :
135       irr::core::vector3df(0, 0, 0);
136
137     const irr::core::vector3df& iLookat =
138       lookat ?
139       irr::core::vector3df(lookat->x, lookat->y, lookat->z) :
140       irr::core::vector3df(0, 0, 100);
141
142     return (irr_scene_ICameraSceneNode*)
143       ((irr::scene::ISceneManager*)smgr)
144       ->addCameraSceneNode((irr::scene::ISceneNode*)parent,
145                            iPosition,
146                            iLookat,
147                            id,
148                            makeActive);
149   }
150
151   irr_scene_ICameraSceneNode*
152   irr_scene_addCameraSceneNodeFPS(irr_scene_ISceneManager* smgr,
153                                   irr_scene_ISceneNode* parent,
154                                   float_t rotateSpeed,
155                                   float_t moveSpeed,
156                                   int32_t id,
157                                   irr_SkeyMap* keyMapArray,
158                                   int32_t keyMapSize,
159                                   bool noVerticalMovement,
160                                   float_t jumpSpeed,
161                                   bool invertMouse,
162                                   bool makeActive)
163   {
164     return ((irr::scene::ISceneManager*)smgr)
165       ->addCameraSceneNodeFPS((irr::scene::ISceneNode*)parent,
166                               rotateSpeed,
167                               moveSpeed,
168                               id,
169                               (irr::SKeyMap*)keyMapArray,
170                               keyMapSize,
171                               noVerticalMovement,
172                               jumpSpeed,
173                               invertMouse,
174                               makeActive);
175   }
176
177   irr_scene_ISceneNode*
178   irr_scene_addCustomSceneNode(irr_scene_ISceneManager* smgr,
179                                irr_scene_ISceneNode* parent,
180                                int32_t id,
181                                irr_core_vector3df* position,
182                                irr_core_vector3df* rotation,
183                                irr_core_vector3df* scale,
184                                void (*render)(),
185                                irr_core_aabbox3d_f32* (*getBoundingBox)(),
186                                uint32_t (*getMaterialCount)(),
187                                irr_video_SMaterial* (*getMaterial)(unsigned int i))
188   {
189     if (parent == NULL)
190       {
191         parent = irr_scene_getRootSceneNode(smgr);
192       }
193
194     const irr::core::vector3df iPosition =
195       position ?
196       irr::core::vector3df(position->x, position->y, position->z) :
197       irr::core::vector3df(0, 0, 0);
198
199     const irr::core::vector3df iRotation =
200       rotation ?
201       irr::core::vector3df(rotation->x, rotation->y, rotation->z) :
202       irr::core::vector3df(0, 0, 0);
203
204     const irr::core::vector3df& iScale =
205       scale ?
206       irr::core::vector3df(scale->x, scale->y, scale->z) :
207       irr::core::vector3df(1, 1, 1);
208
209     CustomSceneNode *node =
210       new CustomSceneNode((irr::scene::ISceneNode*)parent,
211                           (irr::scene::ISceneManager*)smgr,
212                           id,
213                           iPosition,
214                           iRotation,
215                           iScale,
216                           render,
217                           getBoundingBox,
218                           getMaterialCount,
219                           getMaterial);
220     return node;
221   }
222
223   irr_scene_IMeshSceneNode*
224   irr_scene_addOctreeSceneNode(irr_scene_ISceneManager* smgr,
225                                irr_scene_IAnimatedMesh* mesh,
226                                irr_scene_ISceneNode* parent,
227                                int32_t id,
228                                int32_t minimalPolysPerNode,
229                                bool alsoAddIfMeshPointerZero)
230   {
231     return ((irr::scene::ISceneManager*)smgr)
232       ->addOctreeSceneNode((irr::scene::IAnimatedMesh*)mesh,
233                            (irr::scene::ISceneNode*)parent,
234                            id,
235                            minimalPolysPerNode,
236                            alsoAddIfMeshPointerZero);
237   }
238
239   irr_scene_ISceneNodeAnimator*
240   irr_scene_createRotationAnimator(irr_scene_ISceneManager* smgr,
241                                    irr_core_vector3df* rotationSpeed)
242   {
243     const irr::core::vector3df& irrRotationSpeed =
244       irr::core::vector3df(rotationSpeed->x, rotationSpeed->y, rotationSpeed->z);
245
246     return ((irr::scene::ISceneManager*)smgr)
247       ->createRotationAnimator(irrRotationSpeed);
248   }
249
250   void
251   irr_scene_drawAll(irr_scene_ISceneManager* smgr)
252   {
253     ((irr::scene::ISceneManager*)smgr)->drawAll();
254   }
255
256
257   irr_scene_IAnimatedMesh*
258   irr_scene_getMesh(irr_scene_ISceneManager* smgr,
259                     const char* filename)
260   {
261     return (irr_scene_IAnimatedMesh*)
262       ((irr::scene::ISceneManager*)smgr)->getMesh(filename);
263   }
264
265   irr_scene_ISceneNode*
266   irr_scene_getRootSceneNode(irr_scene_ISceneManager* smgr)
267   {
268     return (irr_scene_ISceneNode*)
269       ((irr::scene::ISceneManager*)smgr)->getRootSceneNode();
270   }
271 }