1 /* c-irrlicht --- C bindings for Irrlicht Engine
3 Copyright (C) 2019 Javier Sancho <jsf@jsancho.org>
5 This file is part of c-irrlicht.
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.
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.
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/>.
22 #include <irrlicht/irrlicht.h>
23 #include "ISceneManager.h"
25 class CustomSceneNode : public irr::scene::ISceneNode
28 irr_core_aabbox3d_f32* (*GetBoundingBox)();
29 uint32_t (*GetMaterialCount)();
30 irr_video_SMaterial* (*GetMaterial)(unsigned int i);
33 CustomSceneNode(irr::scene::ISceneNode* parent,
34 irr::scene::ISceneManager* smgr,
36 const irr::core::vector3df& position,
37 const irr::core::vector3df& rotation,
38 const irr::core::vector3df& scale,
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)
46 GetBoundingBox = getBoundingBox;
47 GetMaterialCount = getMaterialCount;
48 GetMaterial = getMaterial;
51 virtual void OnRegisterSceneNode()
54 SceneManager->registerNodeForRendering(this);
57 ISceneNode::OnRegisterSceneNode();
65 virtual const irr::core::aabbox3d<irr::f32>& getBoundingBox() const
67 irr_core_aabbox3d_f32* box = GetBoundingBox();
68 irr::core::aabbox3d<irr::f32>* irrBox = new irr::core::aabbox3d<irr::f32>();
72 virtual irr::u32 getMaterialCount() const
74 return GetMaterialCount();
77 virtual irr::video::SMaterial& getMaterial(irr::u32 i)
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;
88 irr_scene_IAnimatedMeshSceneNode*
89 irr_scene_addAnimatedMeshSceneNode(irr_scene_ISceneManager* smgr,
90 irr_scene_IAnimatedMesh* mesh,
91 irr_scene_ISceneNode* parent,
93 irr_core_vector3df* position,
94 irr_core_vector3df* rotation,
95 irr_core_vector3df* scale,
96 bool alsoAddIfMeshPointerZero)
98 const irr::core::vector3df iPosition =
100 irr::core::vector3df(position->x, position->y, position->z) :
101 irr::core::vector3df(0, 0, 0);
103 const irr::core::vector3df iRotation =
105 irr::core::vector3df(rotation->x, rotation->y, rotation->z) :
106 irr::core::vector3df(0, 0, 0);
108 const irr::core::vector3df& iScale =
110 irr::core::vector3df(scale->x, scale->y, scale->z) :
111 irr::core::vector3df(1, 1, 1);
113 return (irr_scene_IAnimatedMeshSceneNode*)
114 ((irr::scene::ISceneManager*)smgr)
115 ->addAnimatedMeshSceneNode((irr::scene::IAnimatedMesh*)mesh,
116 (irr::scene::ISceneNode*)parent,
121 alsoAddIfMeshPointerZero);
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,
132 const irr::core::vector3df& iPosition =
134 irr::core::vector3df(position->x, position->y, position->z) :
135 irr::core::vector3df(0, 0, 0);
137 const irr::core::vector3df& iLookat =
139 irr::core::vector3df(lookat->x, lookat->y, lookat->z) :
140 irr::core::vector3df(0, 0, 100);
142 return (irr_scene_ICameraSceneNode*)
143 ((irr::scene::ISceneManager*)smgr)
144 ->addCameraSceneNode((irr::scene::ISceneNode*)parent,
151 irr_scene_ICameraSceneNode*
152 irr_scene_addCameraSceneNodeFPS(irr_scene_ISceneManager* smgr,
153 irr_scene_ISceneNode* parent,
157 irr_SkeyMap* keyMapArray,
159 bool noVerticalMovement,
164 return ((irr::scene::ISceneManager*)smgr)
165 ->addCameraSceneNodeFPS((irr::scene::ISceneNode*)parent,
169 (irr::SKeyMap*)keyMapArray,
177 irr_scene_ISceneNode*
178 irr_scene_addCustomSceneNode(irr_scene_ISceneManager* smgr,
179 irr_scene_ISceneNode* parent,
181 irr_core_vector3df* position,
182 irr_core_vector3df* rotation,
183 irr_core_vector3df* scale,
185 irr_core_aabbox3d_f32* (*getBoundingBox)(),
186 uint32_t (*getMaterialCount)(),
187 irr_video_SMaterial* (*getMaterial)(unsigned int i))
191 parent = irr_scene_getRootSceneNode(smgr);
194 const irr::core::vector3df iPosition =
196 irr::core::vector3df(position->x, position->y, position->z) :
197 irr::core::vector3df(0, 0, 0);
199 const irr::core::vector3df iRotation =
201 irr::core::vector3df(rotation->x, rotation->y, rotation->z) :
202 irr::core::vector3df(0, 0, 0);
204 const irr::core::vector3df& iScale =
206 irr::core::vector3df(scale->x, scale->y, scale->z) :
207 irr::core::vector3df(1, 1, 1);
209 CustomSceneNode *node =
210 new CustomSceneNode((irr::scene::ISceneNode*)parent,
211 (irr::scene::ISceneManager*)smgr,
223 irr_scene_IMeshSceneNode*
224 irr_scene_addOctreeSceneNode(irr_scene_ISceneManager* smgr,
225 irr_scene_IAnimatedMesh* mesh,
226 irr_scene_ISceneNode* parent,
228 int32_t minimalPolysPerNode,
229 bool alsoAddIfMeshPointerZero)
231 return ((irr::scene::ISceneManager*)smgr)
232 ->addOctreeSceneNode((irr::scene::IAnimatedMesh*)mesh,
233 (irr::scene::ISceneNode*)parent,
236 alsoAddIfMeshPointerZero);
239 irr_scene_ISceneNodeAnimator*
240 irr_scene_createRotationAnimator(irr_scene_ISceneManager* smgr,
241 irr_core_vector3df* rotationSpeed)
243 const irr::core::vector3df& irrRotationSpeed =
244 irr::core::vector3df(rotationSpeed->x, rotationSpeed->y, rotationSpeed->z);
246 return ((irr::scene::ISceneManager*)smgr)
247 ->createRotationAnimator(irrRotationSpeed);
251 irr_scene_drawAll(irr_scene_ISceneManager* smgr)
253 ((irr::scene::ISceneManager*)smgr)->drawAll();
257 irr_scene_IAnimatedMesh*
258 irr_scene_getMesh(irr_scene_ISceneManager* smgr,
259 const char* filename)
261 return (irr_scene_IAnimatedMesh*)
262 ((irr::scene::ISceneManager*)smgr)->getMesh(filename);
265 irr_scene_ISceneNode*
266 irr_scene_getRootSceneNode(irr_scene_ISceneManager* smgr)
268 return (irr_scene_ISceneNode*)
269 ((irr::scene::ISceneManager*)smgr)->getRootSceneNode();