Posted: Wed Feb 13, 2008 5:10 am
nobody?
Official forum of the Irrlicht Engine
https://irrlicht.sourceforge.io/forum/
well that's a little tricky, changing the joints parents. you can do it manually (with setPosition and setRotation) or just change it in a modelling program.i can connect model to joint, but can i connect joint to joint?
try updating the absolute positions after you move the joint.but the funny thing, that it isn't always... if i change something at the joints place (in the code), it becomes slow, and if i start to use other things (programming, but not the joints), then it becomes good... xD maybe just the debugging?
Code: Select all
void UpdateAbsoluteTransformationAndChildren(ISceneNode *Node)
{
Node->updateAbsolutePosition();
core::list<ISceneNode*>::ConstIterator it = Node->getChildren().begin();
for (; it != Node->getChildren().end(); ++it)
{
UpdateAbsoluteTransformationAndChildren((*it));
}
}
Code: Select all
Player::Player(char *mdl, char* tx)
{
char path[256] = {0};
sprintf(path,"%s\\legs.b3d",mdl);
model = new NewtonModel;
model->mesh = Game.smgr->getMesh(path);
model->node = Game.smgr->addAnimatedMeshSceneNode(model->mesh);
model->node->setMaterialTexture(0,Game.driver->getTexture(tx));
model->collision = NewtonCreateBox(Game.nWorld,50,50,35,NULL);
model->body = NewtonCreateBody(Game.nWorld,model->collision);
int characterID = NewtonMaterialCreateGroupID(Game.nWorld);
NewtonMaterialSetDefaultElasticity (Game.nWorld, Game.levelID, characterID, 0.1f);
NewtonMaterialSetDefaultFriction (Game.nWorld, Game.levelID, characterID, 10.4f, 10.4f);
// end of materials
NewtonBodySetMaterialGroupID (model->body, characterID);
NewtonBodySetUserData(model->body, model->node);
NewtonBodySetMassMatrix(model->body,10.0f,150.0f,150.0f,150.0f);
// disable auto freeze management for the player
NewtonBodySetAutoFreeze (model->body, 0);
// keep the player always active
NewtonWorldUnfreezeBody (Game.nWorld, model->body);
NewtonBodySetTransformCallback(model->body, PlayerSetMeshTransformEvent);
NewtonBodySetForceAndTorqueCallback(model->body, PlayerApplyForceAndTorqueEvent);
matrix4 mat;
mat.setTranslation(vector3df(300,800,300));
NewtonBodySetMatrix(model->body, mat.pointer());
vector3df upDirection (0.0f, 1.0f, 0.0f);
m_upVector = NewtonConstraintCreateUpVector (Game.nWorld, &upDirection.X, model->body);
sprintf(path,"%s\\torso.b3d",mdl);
torso = Game.smgr->addAnimatedMeshSceneNode(Game.smgr->getMesh(path));
sprintf(path,"%s\\head.b3d",mdl);
head = Game.smgr->addAnimatedMeshSceneNode(Game.smgr->getMesh(path));
sprintf(path,"%s\\larm.b3d",mdl);
larm = Game.smgr->addAnimatedMeshSceneNode(Game.smgr->getMesh(path));
sprintf(path,"%s\\rarm.b3d",mdl);
rarm = Game.smgr->addAnimatedMeshSceneNode(Game.smgr->getMesh(path));
sprintf(path,"%s\\lhand.b3d",mdl);
lhand = Game.smgr->addAnimatedMeshSceneNode(Game.smgr->getMesh(path));
sprintf(path,"%s\\rhand.b3d",mdl);
rhand = Game.smgr->addAnimatedMeshSceneNode(Game.smgr->getMesh(path));
jTorso = model->node->getJointNode("torso");
jHead = torso->getJointNode("head");
jrArm = torso->getJointNode("rarm");
jlArm = torso->getJointNode("larm");
jlHand = larm->getJointNode("lhand");
jrHand = rarm->getJointNode("rhand");
jTorso->addChild(torso);
jHead->addChild(head);
jlArm->addChild(larm);
jrArm->addChild(rarm);
jlHand->addChild(lhand);
jrHand->addChild(rhand);
}
Code: Select all
void Player::UpdateJoints()
{
UpdateAbsoluteTransformationAndChildren(model->node);
}
void CGame::Render()
{
driver->beginScene(true, true, video::SColor(0,220,220,255));
player->UpdateJoints();
// render the scene
smgr->drawAll();
driver->endScene();
// Draw fps counter
int fps = driver->getFPS();
if (lastFPS != fps)
{
wchar_t tmp[1024];
swprintf(tmp, 1024, L"Newton Example [fps:%d] [triangles:%d]",
fps, driver->getPrimitiveCountDrawn());
device->setWindowCaption(tmp);
lastFPS = fps;
}
}
Code: Select all
jTorso = model->node->getJointNode("torso");
jHead = torso->getJointNode("head");
jrArm = torso->getJointNode("rarm");
jlArm = torso->getJointNode("larm");
jlHand = larm->getJointNode("lhand");
jrHand = rarm->getJointNode("rhand");
Code: Select all
#include "irrlicht.h"
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
IrrlichtDevice *device;
IAnimatedMeshSceneNode *legs;
#pragma comment (lib,"irrlicht.lib")
class MyEventReceiver:public irr::IEventReceiver {
public:
bool OnEvent(const SEvent& event)
{
if (event.EventType == EET_KEY_INPUT_EVENT)
{
vector3df currot;
switch(event.KeyInput.Key)
{
case KEY_KEY_A:
currot = legs->getRotation();
currot.Y-=5;
legs->setRotation(currot);
break;
case KEY_KEY_D:
currot = legs->getRotation();
currot.Y+=5;
legs->setRotation(currot);
break;
case KEY_ESCAPE:
device->closeDevice();
break;
}
}
return false;
}
};
int main(int argc, char* argv[])
{
IVideoDriver* driver;
ISceneManager* smgr;
IGUIEnvironment* guienv;
ICameraSceneNode *cam;
u32 lasttick;
int lastFPS = -1;
MyEventReceiver event;
// Init the Irrlicht engine
device = createDevice(EDT_DIRECT3D9, dimension2d<s32>(640, 480), 16, false, true, false,&event);
driver = device->getVideoDriver();
smgr = device->getSceneManager();
cam = smgr->addCameraSceneNode();
cam->setPosition(vector3df(0, 50, 0));
lasttick = 0;
// add skybox
smgr->addSkyBoxSceneNode(driver->getTexture("data\\world/irrlicht2_up.jpg"),
driver->getTexture("data\\world/irrlicht2_dn.jpg"),
driver->getTexture("data\\world/irrlicht2_lf.jpg"),
driver->getTexture("data\\world/irrlicht2_rt.jpg"),
driver->getTexture("data\\world/irrlicht2_ft.jpg"),
driver->getTexture("data\\world/irrlicht2_bk.jpg"));
IAnimatedMeshSceneNode *head,*torso,*larm,*rarm,*lhand,*rhand;
IBoneSceneNode *jTorso, *jHead, *jrArm,*jlArm,*jlHand,*jrHand;
char path[256] = {0};
char *mdl = "data\\models\\chimi";
sprintf(path,"%s\\legs.b3d",mdl);
legs = smgr->addAnimatedMeshSceneNode(smgr->getMesh(path));
sprintf(path,"%s\\torso.b3d",mdl);
torso = smgr->addAnimatedMeshSceneNode(smgr->getMesh(path));
sprintf(path,"%s\\head.b3d",mdl);
head = smgr->addAnimatedMeshSceneNode(smgr->getMesh(path));
sprintf(path,"%s\\larm.b3d",mdl);
larm = smgr->addAnimatedMeshSceneNode(smgr->getMesh(path));
sprintf(path,"%s\\rarm.b3d",mdl);
rarm = smgr->addAnimatedMeshSceneNode(smgr->getMesh(path));
sprintf(path,"%s\\lhand.b3d",mdl);
lhand = smgr->addAnimatedMeshSceneNode(smgr->getMesh(path));
sprintf(path,"%s\\rhand.b3d",mdl);
rhand = smgr->addAnimatedMeshSceneNode(smgr->getMesh(path));
jTorso = legs->getJointNode("torso");
jHead = torso->getJointNode("head");
jrArm = torso->getJointNode("rarm");
jlArm = torso->getJointNode("larm");
jlHand = larm->getJointNode("lhand");
jrHand = rarm->getJointNode("rhand");
jTorso->addChild(torso);
jHead->addChild(head);
jlArm->addChild(larm);
jrArm->addChild(rarm);
jlHand->addChild(lhand);
jrHand->addChild(rhand);
larm->setVisible(false);
rarm->setVisible(false);
legs->setPosition(vector3df(20,0,20));
cam->setTarget(vector3df(20,50,20));
scene::ISceneNodeAnimator* anim = smgr->createRotationAnimator(
core::vector3df(0,0.3f,0));
legs->addAnimator(anim);
while (device->run())
{
driver->beginScene(true, true, video::SColor(0,220,220,255));
// render the scene
smgr->drawAll();
driver->endScene();
// Draw fps counter
int fps = driver->getFPS();
if (lastFPS != fps)
{
wchar_t tmp[1024];
swprintf(tmp, 1024, L"Model Viewer [fps:%d] [triangles:%d]",
fps, driver->getPrimitiveCountDrawn());
device->setWindowCaption(tmp);
lastFPS = fps;
}
}
device->drop();
return 0;
}
Code: Select all
legs->addAnimator(anim);
...
smgr->drawAll();