Help with "animateJoints()"

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
andreasky
Posts: 30
Joined: Tue Jun 09, 2009 2:36 pm

Help with "animateJoints()"

Post by andreasky »

Hi,

I tried to create a 3D model with an animation and to export it as ".X" file. I wrote the simple source file with Irrlicht API. It is a simple file.
"test.X" contains a simple 3D model which should go up and down in the animation I created (120 frames, running at 24 fps).
The problem is that I cannot see the animation running, after "animateJoints()".

Here is the code. I could also attach "test.X" file and some screenshots

==========================================

// Irrlicht
#include <irrlicht.h>
#include <iostream>
#include <fstream>

using namespace std;
using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;


#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif


// MAIN

int main()
{
// create Irrlicht device
IrrlichtDevice* device = createDevice( video::EDT_OPENGL, dimension2d<s32>(800, 600), 32,
false, false);

if (device == 0)
return 1; // could not create selected driver.

video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();

// create camera
smgr->addCameraSceneNodeFPS(0, 100.0f, .1f);

// Load Char
IAnimatedMesh* CharMesh = smgr->getMesh("../../media/test.X");
if (!CharMesh) return 1;

IAnimatedMeshSceneNode* CharNode = smgr->addAnimatedMeshSceneNode( CharMesh );
if (!CharNode) return 1;


// Initilise
CharNode->setMaterialFlag(EMF_LIGHTING, false);
CharNode->setAnimationSpeed(10);

// Prepare for Joint Control
CharNode->setJointMode(EJUOR_CONTROL); //To write positions to the mesh on render



int lastFPS = -1;


f32 headRotation = 0;
f32 headPosition = 0;


u32 jointNumber=CharNode->getJointCount();

// Get the Joint you want to MANIPULATE, and its Parent
IBoneSceneNode* thisJoint = CharNode->getJointNode("joint5");

ofstream out("jointPos.txt");

out<<"The number of Joint is: "<<jointNumber<<endl;

u32 boneIndex=thisJoint->getBoneIndex();
out<<"The selected bone is: "<<boneIndex<<endl;

const c8 *boneName;

for (int i = 0; i < jointNumber; i++)
{

IBoneSceneNode* joint = CharNode->getJointNode(i);
boneName=joint->getBoneName();
out<<"The name of the bone is: "<<boneName<<endl;
}


vector3df jointInitialPos = thisJoint->getAbsolutePosition();

out<<"The initial position of the joint is: "<<
jointInitialPos.X<<" "<<jointInitialPos.Y<<" "<<jointInitialPos.Z<<endl;

vector3df newJointPos = jointInitialPos + vector3df(5,0,0);
thisJoint->setPosition( newJointPos );

//vector3df jointPos = thisJoint->getAbsolutePosition();

out<<"The final position of the joint is: "<<
newJointPos.X<<" "<<newJointPos.Y<<" "<<newJointPos.Z<<endl;

out.close();



while(device->run())
{
// Here I have problems: the animation I exported in the ".X" fiel does not run. I created an animation at 24 fps.

CharNode->animateJoints();

// do Irrlicht stuff

driver->beginScene(true, true, video::SColor(255,113,113,133));

smgr->drawAll(); // draw the 3d scene
device->getGUIEnvironment()->drawAll(); // draw the gui environment (the logo)

driver->endScene();

int fps = driver->getFPS();

if (lastFPS != fps)
{
core::stringw tmp(L"fmx's funny dwarf head joint manipulation demo! [");
tmp += driver->getName();
tmp += L"] fps: ";
tmp += fps;

device->setWindowCaption(tmp.c_str());
lastFPS = fps;
}
}


// show cursor
// device->getCursorControl()->setVisible(true);

device->drop();



return 0;
}

==========================================
CuteAlien
Admin
Posts: 9930
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

What do you try to do? Do you just want to play an .X animation or are you trying to mix manual and automatic animation?
For the first you do not need the call to animateJoints. Animated scenenodes should animate already automatically. For mixing... uhm sorry ... I haven't done that yet myself so far.

Also some small hint for posting code - there is this nice tag for "code" which makes code look a lot more readable in the forum :-)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply