The easiest way to do that is to create the model of your armature with the point of the hinge at the origin (0.0, 0.0, 0.0). Here is an example, the left set of cubes have their origin in their centres, the right set of cubes have their origins at the bottom edge.
Code: Select all
'' ----------------------------------------------------------------------------
'' Wiggling stacks of cubes
'' ----------------------------------------------------------------------------
'' ////////////////////////////////////////////////////////////////////////////
'' Includes for extension libraries
#include "IrrlichtWrapper.bi"
'' ////////////////////////////////////////////////////////////////////////////
'' global variables
' irrlicht objects
DIM MeshCentre as irr_mesh
DIM MeshOffset as irr_mesh
DIM MeshTexture as irr_texture
DIM OurCamera as irr_camera
DIM i as Integer
DIM LeftNodes(0 to 7) as IRR_NODE
DIM RightNodes(0 to 7) as IRR_NODE
DIM LastLeftNode as IRR_NODE
DIM LastRightNode as IRR_NODE
DIM CubeRotation as double
'' ////////////////////////////////////////////////////////////////////////////
'' GDB debugger main() function
' -----------------------------------------------------------------------------
' start the irrlicht interface
IrrStart( IRR_EDT_OPENGL, 600, 600, IRR_BITS_PER_PIXEL_32, _
IRR_WINDOWED, IRR_SHADOWS, IRR_IGNORE_EVENTS )
' set the window caption
IrrSetWindowCaption( "Wiggling Cubes" )
' a mesh is created from an array of types called vertices that define a point
' in space. and an array of indices to these vertices that are grouped into
' threes to create triangles that form the mesh
DIM vertsCentre(0 to 7) as IRR_VERT => _
{(-5.0,-10.0,-5.0, 0.0,0.0,0.0, &h00FFFFFF, 0.0,1.0), _
(-5.0, 10.0,-5.0, 0.0,0.0,0.0, &h00FFFFFF, 0.0,0.0), _
( 5.0, 10.0,-5.0, 0.0,0.0,0.0, &h00FFFFFF, 1.0,0.0), _
( 5.0,-10.0,-5.0, 0.0,0.0,0.0, &h00FFFFFF, 1.0,1.0), _
(-5.0,-10.0, 5.0, 0.0,0.0,0.0, &h00FFFFFF, 0.0,0.0), _
( 5.0,-10.0, 5.0, 0.0,0.0,0.0, &h00FFFFFF, 0.0,1.0), _
( 5.0, 10.0, 5.0, 0.0,0.0,0.0, &h00FFFFFF, 0.0,0.0), _
(-5.0, 10.0, 5.0, 0.0,0.0,0.0, &h00FFFFFF, 0.0,1.0)}
DIM vertsOffset(0 to 7) as IRR_VERT => _
{(-5.0, 0.0,-5.0, 0.0,0.0,0.0, &h00FFFFFF, 0.0,1.0), _
(-5.0, 20.0,-5.0, 0.0,0.0,0.0, &h00FFFFFF, 0.0,0.0), _
( 5.0, 20.0,-5.0, 0.0,0.0,0.0, &h00FFFFFF, 1.0,0.0), _
( 5.0, 0.0,-5.0, 0.0,0.0,0.0, &h00FFFFFF, 1.0,1.0), _
(-5.0, 0.0, 5.0, 0.0,0.0,0.0, &h00FFFFFF, 0.0,0.0), _
( 5.0, 0.0, 5.0, 0.0,0.0,0.0, &h00FFFFFF, 0.0,1.0), _
( 5.0, 20.0, 5.0, 0.0,0.0,0.0, &h00FFFFFF, 0.0,0.0), _
(-5.0, 20.0, 5.0, 0.0,0.0,0.0, &h00FFFFFF, 0.0,1.0)}
DIM indices(0 to 35) as ushort = {0,1,2, 2,3,0, 4,5,6, _
6,7,4, 0,3,5, 5,4,0, _
3,2,6, 6,5,3, 2,1,7, _
7,6,2, 1,0,4, 4,7,1 }
' -----------------------------------------------------------------------------
' create the mesh from the array of vertices and indices
MeshCentre = IrrCreateMesh( "MeshCentre", 8, vertsCentre(0), 36, indices(0))
MeshOffset = IrrCreateMesh( "MeshOffset", 8, vertsOffset(0), 36, indices(0))
' load texture resource for texturing the nodes
MeshTexture = IrrGetTexture( "./media/texture.jpg" )
' add two a chains of nodes
for i = 0 to 7
LeftNodes(i) = IrrAddMeshToScene( MeshCentre )
IrrSetNodeMaterialTexture( LeftNodes(i), MeshTexture, 0 )
if i > 0 then
IrrSetNodeParent( LeftNodes(i), LastLeftNode )
IrrSetNodePosition( LeftNodes(i), 0.0, 20.0, 0.0 )
else
IrrSetNodePosition( LeftNodes(i), -20.0, 0.0, 0.0 )
end if
RightNodes(i) = IrrAddMeshToScene( MeshOffset )
IrrSetNodeMaterialTexture( RightNodes(i), MeshTexture, 0 )
if i > 0 then
IrrSetNodeParent( RightNodes(i), LastRightNode )
IrrSetNodePosition( RightNodes(i), 0.0, 20.0, 0.0 )
else
IrrSetNodePosition( RightNodes(i), 20.0, 0.0, 0.0 )
end if
LastLeftNode = LeftNodes(i)
LastRightNode = RightNodes(i)
next i
' add a bright ambient light to the scene to brighten everything up
IrrSetAmbientLight( 1,1,1 )
' add a camera into the scene and resposition it to look at the pyramid
OurCamera = IrrAddFPSCamera
IrrSetNodePosition( OurCamera, 30,50,-125)
IrrSetCameraTarget(OurCamera, 0,75,0)
IrrHideMouse
' -----------------------------------------------------------------------------
' while the irrlicht environment is still running
WHILE IrrRunning
' begin the scene, erasing the canvas with sky-blue before rendering
IrrBeginScene( 240, 255, 255 )
' animate the scene
CubeRotation = cos(timer) * 10
for i = 0 to 7
IrrSetNodeRotation( LeftNodes(i), 0.0, 0.0, CubeRotation )
IrrSetNodeRotation( RightNodes(i), 0.0, 0.0, CubeRotation )
next i
' draw the scene
IrrDrawScene
' end drawing the scene and render it
IrrEndScene
WEND
' -----------------------------------------------------------------------------
' Stop the irrlicht engine and release resources
IrrStop