]> git.jsancho.org Git - c-irrlicht.git/commitdiff
Custom scene node
authorJavier Sancho <jsf@jsancho.org>
Tue, 26 Nov 2019 17:06:09 +0000 (18:06 +0100)
committerJavier Sancho <jsf@jsancho.org>
Tue, 26 Nov 2019 17:06:09 +0000 (18:06 +0100)
Makefile.am
include/ICustomSceneNode.h [new file with mode: 0644]
include/ISceneManager.h
include/SMaterial.h [new file with mode: 0644]
include/aabbox3d.h [new file with mode: 0644]
include/cirrlicht.h
src/ISceneManager.cpp

index 771cf4e4091de89f36678df9c4404e7747cf0592..b8dce54613e80dde49137ad3cc8f72cd5f171f68 100644 (file)
@@ -13,6 +13,7 @@ libCIrrlicht_la_SOURCES = \
 libCIrrlicht_la_CPPFLAGS = -I$(top_srcdir)/include
 libCIrrlicht_la_LDFLAGS = -version-info 0:1
 pkginclude_HEADERS = \
+  include/aabbox3d.h \
   include/cirrlicht.h \
   include/dimension2d.h \
   include/EDriverTypes.h \
@@ -22,6 +23,7 @@ pkginclude_HEADERS = \
   include/IAnimatedMeshSceneNode.h \
   include/ICameraSceneNode.h \
   include/ICursorControl.h \
+  include/ICustomSceneNode.h \
   include/IFileArchive.h \
   include/IFileSystem.h \
   include/IGUIElement.h \
@@ -38,4 +40,5 @@ pkginclude_HEADERS = \
   include/SColor.h \
   include/SExposedVideoData.h \
   include/SKeyMap.h \
+  include/SMaterial.h \
   include/vector3d.h
diff --git a/include/ICustomSceneNode.h b/include/ICustomSceneNode.h
new file mode 100644 (file)
index 0000000..17dbeac
--- /dev/null
@@ -0,0 +1,27 @@
+/* c-irrlicht --- C bindings for Irrlicht Engine
+
+   Copyright (C) 2019 Javier Sancho <jsf@jsancho.org>
+
+   This file is part of c-irrlicht.
+
+   c-irrlicht is free software; you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 3 of the
+   License, or (at your option) any later version.
+
+   c-irrlicht is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with guile-irrlicht.  If not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __C_I_CUSTOM_SCENE_NODE_H_INCLUDED__
+#define __C_I_CUSTOM_SCENE_NODE_H_INCLUDED__
+
+typedef void irr_scene_ICustomSceneNode;
+
+#endif
index 5700bb08bafccb2aead24519339710680060fc11..ff1ed12a4da237213e358a724bfd27fe18a8de79 100644 (file)
 #ifndef __C_I_SCENE_MANAGER_H_INCLUDED__
 #define __C_I_SCENE_MANAGER_H_INCLUDED__
 
+#include "aabbox3d.h"
 #include "IAnimatedMesh.h"
 #include "IAnimatedMeshSceneNode.h"
 #include "ICameraSceneNode.h"
+#include "ICustomSceneNode.h"
 #include "IMeshSceneNode.h"
 #include "ISceneNode.h"
 #include "SKeyMap.h"
+#include "SMaterial.h"
 #include "vector3d.h"
 
 typedef void irr_scene_ISceneManager;
@@ -67,6 +70,18 @@ extern "C" {
                                   int invertMouse,
                                   int makeActive);
 
+  irr_scene_ICustomSceneNode*
+  irr_scene_addCustomSceneNode(irr_scene_ISceneManager* smgr,
+                               irr_scene_ISceneNode* parent,
+                               int id,
+                               irr_core_vector3df* position,
+                               irr_core_vector3df* rotation,
+                               irr_core_vector3df* scale,
+                               void (*render)(),
+                               irr_core_aabbox3d_f32* (*getBoundingBox)(),
+                               int (*getMaterialCount)(),
+                               irr_video_SMaterial* (*getMaterial)(unsigned int i));
+
   irr_scene_IMeshSceneNode*
   irr_scene_addOctreeSceneNodeAM(irr_scene_ISceneManager* smgr,
                                  irr_scene_IAnimatedMesh* mesh,
diff --git a/include/SMaterial.h b/include/SMaterial.h
new file mode 100644 (file)
index 0000000..6004657
--- /dev/null
@@ -0,0 +1,31 @@
+/* c-irrlicht --- C bindings for Irrlicht Engine
+
+   Copyright (C) 2019 Javier Sancho <jsf@jsancho.org>
+
+   This file is part of c-irrlicht.
+
+   c-irrlicht is free software; you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 3 of the
+   License, or (at your option) any later version.
+
+   c-irrlicht is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with guile-irrlicht.  If not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __C_IRR_S_MATERIAL_H_INCLUDED__
+#define __C_IRR_S_MATERIAL_H_INCLUDED__
+
+typedef struct
+{
+  int wireframe;
+  int lighting;
+} irr_video_SMaterial;
+
+#endif
diff --git a/include/aabbox3d.h b/include/aabbox3d.h
new file mode 100644 (file)
index 0000000..f31fadb
--- /dev/null
@@ -0,0 +1,28 @@
+/* c-irrlicht --- C bindings for Irrlicht Engine
+
+   Copyright (C) 2019 Javier Sancho <jsf@jsancho.org>
+
+   This file is part of c-irrlicht.
+
+   c-irrlicht is free software; you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 3 of the
+   License, or (at your option) any later version.
+
+   c-irrlicht is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with guile-irrlicht.  If not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __C_IRR_AABBOX_3D_H_INCLUDED__
+#define __C_IRR_AABBOX_3D_H_INCLUDED__
+
+typedef struct{
+} irr_core_aabbox3d_f32;
+
+#endif
index 48d96f2e4ef324fb4449bced017be80f483e20f8..f00e28c28aa1ec96762e53eb7e229d5808a58acd 100644 (file)
@@ -22,6 +22,7 @@
 #ifndef __C_IRRLICHT_H_INCLUDED__
 #define __C_IRRLICHT_H_INCLUDED__
 
+#include "aabbox3d.h"
 #include "dimension2d.h"
 #include "EDriverTypes.h"
 #include "EMaterialFlags.h"
@@ -29,6 +30,7 @@
 #include "IAnimatedMeshSceneNode.h"
 #include "ICameraSceneNode.h"
 #include "ICursorControl.h"
+#include "ICustomSceneNode.h"
 #include "IFileArchive.h"
 #include "IFileSystem.h"
 #include "IGUIEnvironment.h"
@@ -45,6 +47,7 @@
 #include "SColor.h"
 #include "SExposedVideoData.h"
 #include "SKeyMap.h"
+#include "SMaterial.h"
 #include "vector3d.h"
 
 #ifdef __cplusplus
index b682499927e47706d5c7319e7b6fb1f3a0a210cd..905ad4996ef8b8f2cb688e534b0fd635176b698c 100644 (file)
 #include <irrlicht/irrlicht.h>
 #include "ISceneManager.h"
 
+class CustomSceneNode : public irr::scene::ISceneNode
+{
+  void (*Render)();
+  irr_core_aabbox3d_f32* (*GetBoundingBox)();
+  int (*GetMaterialCount)();
+  irr_video_SMaterial* (*GetMaterial)(unsigned int i);
+
+public:
+  CustomSceneNode(irr::scene::ISceneNode* parent,
+                  irr::scene::ISceneManager* smgr,
+                  irr::s32 id,
+                  const irr::core::vector3df& position,
+                  const irr::core::vector3df& rotation,
+                  const irr::core::vector3df& scale,
+                  void (*render)(),
+                  irr_core_aabbox3d_f32* (*getBoundingBox)(),
+                  int (*getMaterialCount)(),
+                  irr_video_SMaterial* (*getMaterial)(unsigned int i))
+  : irr::scene::ISceneNode(parent, smgr, id, position, rotation, scale)
+  {
+    Render = render;
+    GetBoundingBox = getBoundingBox;
+    GetMaterialCount = getMaterialCount;
+    GetMaterial = getMaterial;
+  }
+
+  virtual void OnRegisterSceneNode()
+  {
+    if (IsVisible) {
+      SceneManager->registerNodeForRendering(this);
+    }
+
+    ISceneNode::OnRegisterSceneNode();
+  }
+
+  virtual void render()
+  {
+    Render();
+  }
+
+  virtual const irr::core::aabbox3d<irr::f32>& getBoundingBox() const
+  {
+    irr_core_aabbox3d_f32* box = GetBoundingBox();
+    irr::core::aabbox3d<irr::f32>* irrBox = new irr::core::aabbox3d<irr::f32>();
+    return *irrBox;
+  }
+
+  virtual irr::u32 getMaterialCount() const
+  {
+    return GetMaterialCount();
+  }
+
+  virtual irr::video::SMaterial& getMaterial(irr::u32 i)
+  {
+    irr_video_SMaterial* material = GetMaterial(i);
+    irr::video::SMaterial* irrMaterial = new irr::video::SMaterial();
+    irrMaterial->Wireframe = material->wireframe;
+    irrMaterial->Lighting = material->lighting;
+    return *irrMaterial;
+  }
+};
+
 extern "C" {
   irr_scene_IAnimatedMeshSceneNode*
   irr_scene_addAnimatedMeshSceneNode(irr_scene_ISceneManager* smgr,
@@ -112,6 +174,55 @@ extern "C" {
                               makeActive);
   }
 
+  irr_scene_ICustomSceneNode*
+  irr_scene_addCustomSceneNode(irr_scene_ISceneManager* smgr,
+                               irr_scene_ISceneNode* parent,
+                               int id,
+                               irr_core_vector3df* position,
+                               irr_core_vector3df* rotation,
+                               irr_core_vector3df* scale,
+                               void (*render)(),
+                               irr_core_aabbox3d_f32* (*getBoundingBox)(),
+                               int (*getMaterialCount)(),
+                               irr_video_SMaterial* (*getMaterial)(unsigned int i))
+  {
+    if (parent == NULL)
+      {
+        parent = irr_scene_getRootSceneNode(smgr);
+      }
+
+    const irr::core::vector3df iPosition =
+      position ?
+      irr::core::vector3df(position->x, position->y, position->z) :
+      irr::core::vector3df(0, 0, 0);
+
+    const irr::core::vector3df iRotation =
+      rotation ?
+      irr::core::vector3df(rotation->x, rotation->y, rotation->z) :
+      irr::core::vector3df(0, 0, 0);
+
+    const irr::core::vector3df& iScale =
+      scale ?
+      irr::core::vector3df(scale->x, scale->y, scale->z) :
+      irr::core::vector3df(1, 1, 1);
+
+    CustomSceneNode *node =
+      new CustomSceneNode((irr::scene::ISceneNode*)parent,
+                          (irr::scene::ISceneManager*)smgr,
+                          id,
+                          iPosition,
+                          iRotation,
+                          iScale,
+                          render,
+                          getBoundingBox,
+                          getMaterialCount,
+                          getMaterial);
+    node->drop();
+    node = 0;
+    return NULL;
+    //return node;
+  }
+
   irr_scene_IMeshSceneNode*
   irr_scene_addOctreeSceneNodeAM(irr_scene_ISceneManager* smgr,
                                  irr_scene_IAnimatedMesh* mesh,