void MovimentadorMembro::setarAnguloPerna(IAnimatedMeshSceneNode * node,std::string nome_bone,float angulo)
{
	std::string pe_esquerdo_bone			=       "Foot_L";
	std::string coxa_direita_bone			=       "UpLeg_R";
	std::string coxa_esquerda_bone			=       "UpLeg_L";
	std::string perna_esquerda_bone			=       "LoLeg_L";
	IBoneSceneNode * coxaDir = node->getJointNode(coxa_direita_bone.c_str());
	if(coxaDir)
	{
		irr::core::vector3df rot = coxaDir->getRotation();
		rot.Z = 0;
		coxaDir->setRotation(rot);
	}

	IBoneSceneNode * coxaEsq = node->getJointNode(coxa_esquerda_bone.c_str());
	if(coxaEsq)
	{
		irr::core::vector3df rot = coxaEsq->getRotation();
		rot.Z = 0;
		coxaEsq->setRotation(rot);
	}


	IBoneSceneNode * bone = node->getJointNode(nome_bone.c_str());  
	if(bone)
	{
		vector3df rot = bone->getRotation();
		rot.Y = angulo;

		bone->setRotation(rot);               
	}
}
예제 #2
0
int main()
{

   IrrlichtDevice *device =
      createDevice( video::EDT_OPENGL, dimension2d<u32>(800, 600));


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

        smgr->addCameraSceneNode(0, vector3df(0,10,-10), vector3df(0,5,0));

        IAnimatedMesh* mesh = smgr->getMesh("ninja.b3d");
   IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);
   node->setMaterialFlag(EMF_LIGHTING, false);
   node->setMaterialTexture( 0, driver->getTexture("nskinrd.jpg") );
        node->setRotation(vector3df(0,180,0)); // let ninja be in front to us

        node->setJointMode(EJUOR_CONTROL); // tell irrlicht that you want to control joint positions

        IBoneSceneNode* bone = node->getJointNode("Joint10"); // create IBoneSceneNode and select the desired bone

   while(device->run()) {
            bone->setRotation(bone->getRotation() + vector3df(1,0,0)); // rotate bone

            driver->beginScene();
            smgr->drawAll();
            driver->endScene();
   }


   device->drop();

   return 0;
}
void MovimentadorPernaDireita::mover(irr::scene::IAnimatedMeshSceneNode * node,tipos::Esqueleto esqueleto)
{
	std::string coxa_esquerda_bone			=       "UpLeg_L";
	std::string perna_esquerda_bone			=       "LoLeg_L";
	std::string pe_esquerdo_bone_1             =       "Foot_L";
	std::string pe_esquerdo_bone_2             =       "Toe_L";

	tipos::Vetor v3_ = Vetor(esqueleto.joelho_esquerdo.x,esqueleto.abdomen.y);
	Vetor p1_ = esqueleto.abdomen;
	Vetor p2_ = esqueleto.joelho_esquerdo;
	Vetor p3_ = v3_;
	float a1_ = CalculosUteis::anguloEntrePontos(p1_,p2_,p3_);
	if(!_isnan(a1_))
		setarAnguloBone(node,coxa_esquerda_bone,-90 + a1_);
	//setarAnguloPerna(node,coxa_direita_bone,90-a1_);


	float angulo_joelho = CalculosUteis::anguloEntrePontos(esqueleto.joelho_esquerdo,esqueleto.abdomen,esqueleto.pe_esquerdo);
	if(!_isnan(angulo_joelho))
	{

		setarAnguloPerna(node,perna_esquerda_bone, angulo_joelho);

		IBoneSceneNode * joelho = node->getJointNode(perna_esquerda_bone.c_str());
		core::vector3df rot=  joelho->getRotation();
		//rot.Y = angulo_joelho; 
		rot.Z = 180;
		joelho->setRotation(rot);


	}
	//

	IBoneSceneNode * pe_1 = node->getJointNode(pe_esquerdo_bone_1.c_str());
	IBoneSceneNode * pe_2 = node->getJointNode(pe_esquerdo_bone_2.c_str());
	pos_1 = Vetor(pe_1->getAbsolutePosition().X,pe_1->getAbsolutePosition().Y,pe_1->getAbsolutePosition().Z);
	pos_2 = Vetor(pe_2->getAbsolutePosition().X,pe_2->getAbsolutePosition().Y,pe_2->getAbsolutePosition().Z);
/*
	bool tem = false;
	for(int i=0;i<marcadores.size();i++)
	{
		if( ( (marcadores[i]->pontoDentroMarcador(pos_1)) || (marcadores[i]->pontoDentroMarcador(pos_2)) ) && i!=indiceAnterior)
		{
			if(!cronometro.iniciado())
			{
				cronometro.iniciarContagem();						
			}
			tem = true;
			indiceAtual = i;
		}
	}
	if(!tem)
	{
		cronometro.pararContagem();
	}
	*/
}
void MovimentadorMembro::setarAnguloBone(IAnimatedMeshSceneNode * node, std::string nome_bone,float angulo)
{
	IBoneSceneNode * bone = node->getJointNode(nome_bone.c_str());  
	if(bone)
	{
		core::vector3df rot = bone->getRotation();
		rot.Y = angulo;
		bone->setRotation(rot);               
	}

}
void TransformadorAtualizarPosicaoBracoDireito::transformar(irr::scene::IAnimatedMeshSceneNode * node, tipos::Esqueleto esqueleto)
{
	IBoneSceneNode * ombro = node->getJointNode("UpArm_R");
	IBoneSceneNode * cotovelo = node->getJointNode("UpArm_R");
	float menorDistancia = 999;
	float anguloOmbro = 0;
	float anguloCotovelo = 0;
	//int anguloMinimo = -60;
	//int anguloMaximo = 60;
	int anguloMinimoOmbro = ombro->getRotation().Y - 20;
	int anguloMaximoOmbro = ombro->getRotation().Y + 20;
	int anguloMinimoCotovelo = cotovelo->getRotation().Y - 20;
	int anguloMaximoCotovelo = cotovelo->getRotation().Y + 20;
	
	for (int i = anguloMinimoOmbro ;i < anguloMaximoOmbro ;i++)
	{
		core::vector3df rotOmbro = ombro->getRotation();
		rotOmbro.Y = i;
		ombro->setRotation(rotOmbro);
		for(int j =anguloMinimoCotovelo ; j< anguloMaximoCotovelo ;j++)
		{
			core::vector3df rotCot = cotovelo->getRotation();
			rotCot.Y = j;
			cotovelo->setRotation(rotCot);
			IBoneSceneNode * mao = node->getJointNode("Hand_R");
			
			node->updateAbsolutePosition();
			for(int i=0;i<node->getJointCount();i++)
			{
				node->getJointNode(i)->updateAbsolutePosition();
			}
			float distancia = CalculosUteis::distanciaEntrePontos(
				Vetor(mao->getAbsolutePosition().X,mao->getAbsolutePosition().Y,mao->getAbsolutePosition().Z),
				esqueletoRef.mao_direita);
			if(distancia<menorDistancia)
			{
				menorDistancia = distancia;
				anguloOmbro = i;
				anguloCotovelo = j;
			}


			
		}
		
		
	}

	printf("i: %f j: %f distancia : %f\n",anguloOmbro,anguloCotovelo,menorDistancia);
	core::vector3df rotOmbro = ombro->getRotation();
		rotOmbro.Y = anguloOmbro;
		ombro->setRotation(rotOmbro);

		core::vector3df rotCot = cotovelo->getRotation();
		rotCot.Y = anguloCotovelo;
		cotovelo->setRotation(rotCot);
}
		void world_avatar::initialize()
		{
			core::vector3df targetPos(3000, 0, 3000);

			ISceneManager *sceneManager = device_->getSceneManager();
			IVideoDriver *driver = device_->getVideoDriver();

			camera_ = sceneManager->addCameraSceneNode(0);

			camera_->setPosition(core::vector3df(2700 * 2, 200, 2600 * 2));
			camera_->setTarget(targetPos);
			camera_->setFarValue(42000.0f);

			mesh_ = device_->getSceneManager()->getMesh("data/assets/Skeleton.Male.x");
			meshNode_ = device_->getSceneManager()->addAnimatedMeshSceneNode(mesh_);
			meshNode_->setAnimationSpeed(30);
			meshNode_->setMaterialFlag(video::EMF_LIGHTING, false);
			meshNode_->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, false);
			meshNode_->setDebugDataVisible(scene::EDS_OFF);
			meshNode_->setScale(core::vector3df(200,200,200));
			meshNode_->setPosition(targetPos);

			//core::quaternion q;
			//q.fromAngleAxis(90 * core::DEGTORAD, core::vector3df(1, 0, 0));
			//core::matrix4 m1 = q.getMatrix();

			//meshNode_->updateAbsolutePosition();
			//core::matrix4 m2 = meshNode_->getAbsoluteTransformation();

			//core::matrix4 m = m1*m2;
			//meshNode_->setRotation(m.getRotationDegrees());

			ITexture* test = driver->getTexture("data/assets/upper-body.png");
			meshNode_->getMaterial(0).TextureLayer[0].Texture = test;
			ITexture* test2 = driver->getTexture("data/assets/lower-body.png");
			meshNode_->getMaterial(1).TextureLayer[0].Texture = test2;
			ITexture* test3 = driver->getTexture("data/assets/head.png");
			meshNode_->getMaterial(2).TextureLayer[0].Texture = test3;

			//meshNode_->setJointMode(EJUOR_CONTROL);
			IBoneSceneNode* rightUpperArm = meshNode_->getJointNode((u32)0);
			core::vector3df cpos = rightUpperArm->getRotation();
			cpos.Z -= 1.5;
			rightUpperArm->setRotation(cpos);
		}
TransformadorAtualizarPosicaoBracoDireito::TransformadorAtualizarPosicaoBracoDireito(IAnimatedMeshSceneNode * node)
{
	TransformadorAtualizarPosicaoBracoDireito::primeiro = true;
	TransformadorAtualizarPosicaoBracoDireito::node	=	node;
	
	esqueletoRef.abdomen = Vetor( node->getJointNode("Root")->getAbsolutePosition().X , node->getJointNode("Root")->getAbsolutePosition().Y, node->getJointNode("Root")->getAbsolutePosition().Z);
	esqueletoRef.ombro_direito = Vetor( node->getJointNode("UpArm_R")->getAbsolutePosition().X , node->getJointNode("UpArm_R")->getAbsolutePosition().Y, node->getJointNode("UpArm_R")->getAbsolutePosition().Z);
	esqueletoRef.cotovelo_direito = Vetor( node->getJointNode("LoArm_R")->getAbsolutePosition().X , node->getJointNode("LoArm_R")->getAbsolutePosition().Y, node->getJointNode("LoArm_R")->getAbsolutePosition().Z);
	esqueletoRef.mao_direita  = Vetor( node->getJointNode("Hand_R")->getAbsolutePosition().X , node->getJointNode("Hand_R")->getAbsolutePosition().Y, node->getJointNode("Hand_R")->getAbsolutePosition().Z);

	distanciaCotoveloMao = CalculosUteis::distanciaEntrePontos(esqueletoRef.cotovelo_direito,esqueletoRef.mao_direita);
	distanciaOmbroCotovelo = CalculosUteis::distanciaEntrePontos(esqueletoRef.ombro_direito,esqueletoRef.cotovelo_direito);
	
	IBoneSceneNode * nodeOmbro = node->getJointNode("UpArm_R");	
	core::vector3df rotOmbro = nodeOmbro->getRotation();	
	rotOmbro.Y = 0;
	//nodeOmbro->setRotation(rotOmbro);
}