Page 1 of 2

problem Billboard's position

Posted: Fri Apr 29, 2011 9:23 am
by klikli234
I have a gun muzzle bone node.
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
Image

Posted: Fri Apr 29, 2011 11:51 am
by shadowslair
Show us some code please. Especially the one where you create your character, weapon, attach the weapon and billboard to the muzzle and the way you update them. :roll:

Posted: Fri Apr 29, 2011 11:59 am
by klikli234
thx
here it is

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

		}


Posted: Fri Apr 29, 2011 12:00 pm
by klikli234
ok! what should I do

Posted: Fri Apr 29, 2011 12:20 pm
by shadowslair
Ok, this is some really hard to read code, I got a bit confused by all these rotation and position sets and copies, but maybe try this:

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);

Posted: Fri Apr 29, 2011 12:37 pm
by klikli234
but
Doesn't work.
flash has been in one place

if I set weaponnode as parents , the nodemuzzleflash can follow my character

Posted: Fri Apr 29, 2011 12:55 pm
by klikli234
Has always been there
Image

Posted: Fri Apr 29, 2011 12:57 pm
by shadowslair
Once you create the character, weapon and flash nodes and set the correct parents, no additional calls like

Code: Select all

vector3df flashpos = flashbonescenenode->getPosition() + weaponnode->getPosition();
         nodemuzzleflash->setPosition(flashpos);
will 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.

Posted: Fri Apr 29, 2011 1:34 pm
by klikli234
I'm sorry, I still can't solve the problem.
:(

How do I calculated flash world coordinates

Posted: Fri Apr 29, 2011 2:04 pm
by klikli234
shadowslair wrote:Once you create the character, weapon and flash nodes and set the correct parents, no additional calls like

Code: Select all

vector3df flashpos = flashbonescenenode->getPosition() + weaponnode->getPosition();
         nodemuzzleflash->setPosition(flashpos);
will 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.
Still doesn't work, the flash didn't move

Posted: Fri Apr 29, 2011 2:10 pm
by shadowslair
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());

Posted: Fri Apr 29, 2011 2:27 pm
by klikli234
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());
No matter what I move,
Bone's world coordinates didn't change.

Posted: Fri Apr 29, 2011 2:41 pm
by nespa
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;

Posted: Fri Apr 29, 2011 3:10 pm
by klikli234
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;
thanks,
but useless.
I moved the other bones.
This time the billboard not will keep relative position to the gun

Posted: Fri Apr 29, 2011 3:48 pm
by hybrid
If we should really help you (not sure if you want, it's hard to assess your intention from the few words you use) you should reduce your code to a minial setup. Load the mesh, attach the flash, let the animation run. This should be possible in less than 30 lines of code. Then check if the flash will move with the gun or not. Please show us the code after checking the results, and also the new screenshots with the new code.