]> git.jsancho.org Git - guile-irrlicht.git/blob - src/scene-node.cpp
29d5214b208b418c417be8d2dfc22fc4d91c6b51
[guile-irrlicht.git] / src / scene-node.cpp
1 /* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine
2
3    Copyright (C) 2020 Javier Sancho <jsf@jsancho.org>
4
5    This file is part of guile-irrlicht.
6
7    guile-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    guile-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 <libguile.h>
24 #include "gsubr.h"
25 #include "material-flags.h"
26 #include "matrix4.h"
27 #include "scene-node.h"
28 #include "vector3d.h"
29
30 using namespace irr;
31
32 template <typename TSceneNode>
33 SCM
34 ISceneNode_addAnimator (SCM scene_node,
35                         SCM animator)
36 {
37   TSceneNode node = (TSceneNode) scm_to_pointer (scene_node);
38   node->addAnimator ((scene::ISceneNodeAnimator*) scm_to_pointer (animator));
39   return SCM_UNSPECIFIED;
40 }
41
42 template <typename TSceneNode>
43 SCM
44 ISceneNode_getAbsoluteTransformation (SCM scene_node)
45 {
46   TSceneNode node = (TSceneNode) scm_to_pointer (scene_node);
47   return scm_from_matrix4 (node->getAbsoluteTransformation ());
48 }
49
50 template <typename TSceneNode>
51 SCM
52 ISceneNode_getPosition (SCM scene_node)
53 {
54   TSceneNode node = (TSceneNode) scm_to_pointer (scene_node);
55   return scm_from_vector3df (node->getPosition ());
56 }
57
58 template <typename TSceneNode>
59 SCM
60 ISceneNode_setMaterialFlag (SCM scene_node,
61                             SCM flag,
62                             SCM newvalue)
63 {
64   TSceneNode node = (TSceneNode) scm_to_pointer (scene_node);
65   node->setMaterialFlag (scm_to_material_flag (flag), scm_to_bool (newvalue));
66   return SCM_UNSPECIFIED;
67 }
68
69 template <typename TSceneNode>
70 SCM
71 ISceneNode_setMaterialTexture (SCM scene_node,
72                                SCM texture_layer,
73                                SCM texture)
74 {
75   TSceneNode node = (TSceneNode) scm_to_pointer (scene_node);
76   node->setMaterialTexture (scm_to_uint32 (texture_layer),
77                             (video::ITexture*) scm_to_pointer (texture));
78   return SCM_UNSPECIFIED;
79 }
80
81 template <typename TSceneNode>
82 SCM
83 ISceneNode_setPosition (SCM scene_node,
84                         SCM position)
85 {
86   TSceneNode node = (TSceneNode) scm_to_pointer (scene_node);
87   node->setPosition (scm_to_vector3df (position));
88   return SCM_UNSPECIFIED;
89 }
90
91 template <typename TSceneNode>
92 SCM
93 ISceneNode_setRotation (SCM scene_node,
94                         SCM rotation)
95 {
96   TSceneNode node = (TSceneNode) scm_to_pointer (scene_node);
97   node->setRotation (scm_to_vector3df (rotation));
98   return SCM_UNSPECIFIED;
99 }
100
101 template <typename TSceneNode>
102 SCM
103 ISceneNode_setScale (SCM scene_node,
104                      SCM scale)
105 {
106   TSceneNode node = (TSceneNode) scm_to_pointer (scene_node);
107   node->setScale (scm_to_vector3df (scale));
108   return SCM_UNSPECIFIED;
109 }
110
111 void
112 init_scene_node (void)
113 {
114   DEFINE_GSUBR ("IAnimatedMeshSceneNode_addAnimator", 2, 0, 0,
115                 ISceneNode_addAnimator<scene::IAnimatedMeshSceneNode*>);
116   DEFINE_GSUBR ("IMeshSceneNode_addAnimator", 2, 0, 0,
117                 ISceneNode_addAnimator<scene::IMeshSceneNode*>);
118   DEFINE_GSUBR ("ISceneNode_addAnimator", 2, 0, 0,
119                 ISceneNode_addAnimator<scene::ISceneNode*>);
120
121   DEFINE_GSUBR ("ISceneNode_getAbsoluteTransformation", 1, 0, 0,
122                 ISceneNode_getAbsoluteTransformation<scene::ISceneNode*>);
123
124   DEFINE_GSUBR ("IMeshSceneNode_getPosition", 1, 0, 0,
125                 ISceneNode_getPosition<scene::IMeshSceneNode*>);
126   DEFINE_GSUBR ("ISceneNode_getPosition", 1, 0, 0,
127                 ISceneNode_getPosition<scene::ISceneNode*>);
128
129   DEFINE_GSUBR ("IAnimatedMeshSceneNode_setMaterialFlag", 3, 0, 0,
130                 ISceneNode_setMaterialFlag<scene::IAnimatedMeshSceneNode*>);
131   DEFINE_GSUBR ("IMeshSceneNode_setMaterialFlag", 3, 0, 0,
132                 ISceneNode_setMaterialFlag<scene::IMeshSceneNode*>);
133   DEFINE_GSUBR ("ISceneNode_setMaterialFlag", 3, 0, 0,
134                 ISceneNode_setMaterialFlag<scene::ISceneNode*>);
135
136   DEFINE_GSUBR ("IAnimatedMeshSceneNode_setMaterialTexture", 3, 0, 0,
137                 ISceneNode_setMaterialTexture<scene::IAnimatedMeshSceneNode*>);
138   DEFINE_GSUBR ("IMeshSceneNode_setMaterialTexture", 3, 0, 0,
139                 ISceneNode_setMaterialTexture<scene::IMeshSceneNode*>);
140   DEFINE_GSUBR ("ISceneNode_setMaterialTexture", 3, 0, 0,
141                 ISceneNode_setMaterialTexture<scene::ISceneNode*>);
142
143   DEFINE_GSUBR ("IMeshSceneNode_setPosition", 2, 0, 0,
144                 ISceneNode_setPosition<scene::IMeshSceneNode*>);
145   DEFINE_GSUBR ("ISceneNode_setPosition", 2, 0, 0,
146                 ISceneNode_setPosition<scene::ISceneNode*>);
147
148   DEFINE_GSUBR ("IAnimatedMeshSceneNode_setRotation", 2, 0, 0,
149                 ISceneNode_setRotation<scene::IAnimatedMeshSceneNode*>);
150   DEFINE_GSUBR ("ICameraSceneNode_setRotation", 2, 0, 0,
151                 ISceneNode_setRotation<scene::ICameraSceneNode*>);
152   DEFINE_GSUBR ("ISceneNode_setRotation", 2, 0, 0,
153                 ISceneNode_setRotation<scene::ISceneNode*>);
154
155   DEFINE_GSUBR ("IAnimatedMeshSceneNode_setScale", 2, 0, 0,
156                 ISceneNode_setScale<scene::IAnimatedMeshSceneNode*>);
157   DEFINE_GSUBR ("ISceneNode_setScale", 2, 0, 0,
158                 ISceneNode_setScale<scene::ISceneNode*>);
159 }