but, the sword is delayed compared with the movement of hand bone.
Is this a my mistake?
Code: Select all
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
{
Device = createDevice(video::EDT_DIRECT3D9, dimension2d<s32>(1024, 768), 32, false, false,true);
IVideoDriver *Driver = Device->getVideoDriver();
ISceneManager *Scene = Device->getSceneManager();
//create camera
ICameraSceneNode *camera;
camera = Scene->addCameraSceneNode(0, vector3df(-2,2,-2), vector3df(0,1,0));
//set up vector
camera->setUpVector(vector3df(0.0f,1.0f,0.0f));
matrix4 projMat;
projMat.buildProjectionMatrixPerspectiveFovLH(45.0f,1.3333f,1.0f,10000.0f);
camera->setProjectionMatrix(projMat);
//create character mesh
IAnimatedMesh* meshPC = Scene->getMesh("mypc.x");
IAnimatedMeshSceneNode* nodePC = Scene->addAnimatedMeshSceneNode(meshPC);
nodePC->setMaterialFlag(EMF_LIGHTING,false);
nodePC->setAnimationSpeed(5000);
IBoneSceneNode* bone = nodePC->getJointNode("game_HumanRPalm");
//create sword mesh
IAnimatedMesh* meshWP = Scene->getMesh("sword.x");
IAnimatedMeshSceneNode* nodeWP = Scene->addAnimatedMeshSceneNode(meshWP);
nodeWP->setMaterialFlag(EMF_LIGHTING,false);
nodeWP->setParent(bone);
float add=0;
while(Device->run())
{
if(nodePC->getPosition().Z > 5)
add = -0.1;
if(nodePC->getPosition().Z <= 0)
add = 0.1;
nodePC->setPosition(nodePC->getPosition()+vector3df(0,0,add));
//render
Driver->beginScene(true, true, SColor(0,100,100,160));
Scene->drawAll();
Driver->endScene();
}
Device->drop();
return 0;
}