But muzzle bone node's position is unchanged, no matter where I move
what should I do?
or how to gets the position of the node for muzzle bone in the whole world coordinates.
thanks very much


Code: Select all
/*
* 人物模型节点 character node
*/
node = smgr->addAnimatedMeshSceneNode(Urban_Mesh,0);
node->setPosition(core::vector3df(0,36.f,0)); // Put its feet on the floor.
node->setRotation(core::vector3df(0,180.f,0)); // And turn it towards the camera.
node->setMaterialFlag(EMF_LIGHTING, false);
/*
* 载入枪 load gun mesh
*/
ISkinnedMesh* M4a1_Mesh = (ISkinnedMesh*)smgr->getMesh("weapon/m4a1-1.x");
scene::IAnimatedMeshSceneNode* weaponnode = 0;
weaponnode = smgr->addAnimatedMeshSceneNode(M4a1_Mesh,0);
weaponnode->setMaterialFlag(EMF_LIGHTING, false);
weaponnode->setRotation(core::vector3df(0,180.f,0));
/*
* 得到flash位置骨头节点 flash bone node
*/
IBoneSceneNode* flashbonescenenode = weaponnode->getJointNode("flash");
/*
* 载入火花 flash billboard node
*/
IBillboardSceneNode* nodemuzzleflash = 0;
video::ITexture* images = device->getVideoDriver()->getTexture("weapon/m4a1_muzzleflash.bmp");
nodemuzzleflash = smgr->addBillboardSceneNode(weaponnode,core::dimension2d<f32>(5,5));
nodemuzzleflash->setMaterialFlag(EMF_LIGHTING, false);
nodemuzzleflash->setMaterialTexture(0,images);
nodemuzzleflash->setMaterialFlag(video::EMF_ZWRITE_ENABLE, false);
nodemuzzleflash->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);
nodemuzzleflash->setVisible(false);
/*
* 得到控制两个控制上半身方向的节点 It is used to control the upper body
*/
IBoneSceneNode* boneNode1 = node->getJointNode("U_Bip01_Spine");
IBoneSceneNode* boneNode2 = node->getJointNode("U_Bip01_Spine1");
IBoneSceneNode* boneNode3 = node->getJointNode("U_Bip01_R_Hand");
while(device->run())
if (device->isWindowActive())
{
/*
* 跟新骨头节点和枪和人物 updata weapon node and character node position
*/
if(PlayerState == MOVED)
{
//do something updata rotation weapnode and characters node and bonenode1
}
}
if(PlayerState == STANDED)
{
/*
* 身体和上半身的左右转动 upperbody look left look right by bonenode1
*/
// do something updata rotation bonenode1
}
if(PlayerState == JUMPED)
{
//do something updata rotation weapnode and characters node and bonenode1
}
if(UpperBodyState == RELOAD)
{//状态改变
if( Reload_Animator->getCurrentFrame() == Reload_Animator->getEndFrame() )
{
UpperBodyState = IDLE;
}
}
/*
* 上半身上下看骨头节点 upper body look up look down by bonenode2
*/
// do something updata rotation bonenode2
//here updata flash position but I don.t kown how to do it .I've tried many way
}
Code: Select all
/*
* ???
*/
ISkinnedMesh* M4a1_Mesh = (ISkinnedMesh*)smgr->getMesh("weapon/m4a1-1.x");
scene::IAnimatedMeshSceneNode* weaponnode = 0;
weaponnode = smgr->addAnimatedMeshSceneNode(M4a1_Mesh, 0);
//weaponnode = smgr->addAnimatedMeshSceneNode(M4a1_Mesh, USUALLY_CHARACTER_RIGHT_HAND_JOINT_HERE); //### HERE
weaponnode->setMaterialFlag(EMF_LIGHTING, false);
weaponnode->setRotation(core::vector3df(0,180.f,0));
/*
* ??flash??????
*/
IBoneSceneNode* flashbonescenenode = weaponnode->getJointNode("flash");
if (!flashbonescenenode) //###### HERE
printf("\n\n FAILED LOADING joint 'flash' \a \n"); //###### HERE the "\a will make it say BEEP! if it`s not loaded properly
/*
* ????
*/
IBillboardSceneNode* nodemuzzleflash = 0;
video::ITexture* images = device->getVideoDriver()->getTexture("weapon/m4a1_muzzleflash.bmp");
nodemuzzleflash = smgr->addBillboardSceneNode(flashbonescenenode,core::dimension2d<f32>(5,5)); //###### HERE you want your flamerose child of the muzzle bone
nodemuzzleflash->setMaterialFlag(EMF_LIGHTING, false);
nodemuzzleflash->setMaterialTexture(0,images);
nodemuzzleflash->setMaterialFlag(video::EMF_ZWRITE_ENABLE, false);
nodemuzzleflash->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);
nodemuzzleflash->setVisible(false);Code: Select all
vector3df flashpos = flashbonescenenode->getPosition() + weaponnode->getPosition();
nodemuzzleflash->setPosition(flashpos);Still doesn't work, the flash didn't moveshadowslair wrote:Once you create the character, weapon and flash nodes and set the correct parents, no additional calls likewill be needed. All this is causing you trouble. When a node has a parent Irrlicht updates its transformation according his parent, so everything else should work more or less as expected. And your images are not showing up here for some reason.Code: Select all
vector3df flashpos = flashbonescenenode->getPosition() + weaponnode->getPosition(); nodemuzzleflash->setPosition(flashpos);
Code: Select all
flashbonescenenode->updateAbsolutePosition(); // just to make sure it`s updated. You usually don`t need to call it every time, depending on the case.
core::vector3df myBoneWorldPostion(flashbonescenenode->getAbsolutePosition());No matter what I move,shadowslair wrote:That`s exactly what I wanted to say- you don`t need to if you setup your parent-child pairs correctly. But as you intend on positioning it manually, for getting world (absolute) positions you can try:
Code: Select all
flashbonescenenode->updateAbsolutePosition(); // just to make sure it`s updated. You usually don`t need to call it every time, depending on the case. core::vector3df myBoneWorldPostion(flashbonescenenode->getAbsolutePosition());
thanks,nespa wrote:when you load the mesh gun, it is loaded at 0,0,0 coordinates, then create a billboard , position it in front of the gun, then bind the billboard as child to the mesh gun;
then, all the times you move the gun, the billboard will keep relative position to the gun;