
By the way, I attach now the images I said posts ago, in case they are useful to other users

Descrition of the mesh used

T Position

ForkPosition

Problem with depth

Code: Select all
//Class def: std::vector< core::quaternion > lInitialRotations;
//First time I read geometry:
if ( firstTime )
{
this->setJointMode(EJUOR_CONTROL);
lInitialRotations.push_back(core::quaternion(this->getJointNode("neck" )->getRotation())); //0
lInitialRotations.push_back(core::quaternion(this->getJointNode("torso" )->getRotation())); //1
lInitialRotations.push_back(core::quaternion(this->getJointNode("pelvis" )->getRotation())); //2
lInitialRotations.push_back(core::quaternion(this->getJointNode("root" )->getRotation())); //3
lInitialRotations.push_back(core::quaternion(this->getJointNode("lshoulder" )->getRotation())); //4
lInitialRotations.push_back(core::quaternion(this->getJointNode("lelbow" )->getRotation())); //5
lInitialRotations.push_back(core::quaternion(this->getJointNode("lhip" )->getRotation())); //6
lInitialRotations.push_back(core::quaternion(this->getJointNode("lknee" )->getRotation())); //7
lInitialRotations.push_back(core::quaternion(this->getJointNode("rshoulder" )->getRotation())); //8
lInitialRotations.push_back(core::quaternion(this->getJointNode("relbow" )->getRotation())); //9
lInitialRotations.push_back(core::quaternion(this->getJointNode("rhip" )->getRotation())); //10
lInitialRotations.push_back(core::quaternion(this->getJointNode("rknee" )->getRotation())); //11
}
//Moving the mesh
this->animateJoints();
core::quaternion qrhip = lInitialRotations[10];
core::quaternion qtorso = lInitialRotations[1];
core::quaternion qpelvis = lInitialRotations[2];
core::quaternion qroot = lInitialRotations[3];
core::quaternion rotAccum = qrhip * qpelvis * qtorso * qroot;
//core::quaternion rotAccum = qroot * qtorso * qpelvis * qrhip;
core::vector3df lRotationV;
rotAccum.toEuler(lRotationV);
core::vector3df lRotationVDEG;
lRotationVDEG = lRotationV * core::RADTODEG;
this->getJointNode("rhip")->setRotation( lRotationVDEG );
Code: Select all
animateJoints()
ent1ty wrote: success is a matter of concentration and desire
at a cost measure in computer resourcesButler Lampson wrote: all problems in Computer Science can be solved by another level of indirection
Code: Select all
core::quaternion rotAccum = qrhip;
Code: Select all
this->getJointNode("rhip")->setRotation( this->getJointNode("rhip")->getRotation() );
Code: Select all
//First time
this->setJointMode( EJUOR_CONTROL );
std::vector< core::CMyQuaternion > lInitialRotations;
lInitialRotations.push_back(core::CMyQuaternion(this->getJointNode("neck" )->getRotation()*core::DEGTORAD)); //0
lInitialRotations.push_back(core::CMyQuaternion(this->getJointNode("torso" )->getRotation()*core::DEGTORAD)); //1
lInitialRotations.push_back(core::CMyQuaternion(this->getJointNode("pelvis" )->getRotation()*core::DEGTORAD)); //2
lInitialRotations.push_back(core::CMyQuaternion(this->getJointNode("root" )->getRotation()*core::DEGTORAD)); //3
lInitialRotations.push_back(core::CMyQuaternion(this->getJointNode("lshoulder" )->getRotation()*core::DEGTORAD)); //4
lInitialRotations.push_back(core::CMyQuaternion(this->getJointNode("lelbow" )->getRotation()*core::DEGTORAD)); //5
lInitialRotations.push_back(core::CMyQuaternion(this->getJointNode("lhip" )->getRotation()*core::DEGTORAD)); //6
lInitialRotations.push_back(core::CMyQuaternion(this->getJointNode("lknee" )->getRotation()*core::DEGTORAD)); //7
lInitialRotations.push_back(core::CMyQuaternion(this->getJointNode("rshoulder" )->getRotation()*core::DEGTORAD)); //8
lInitialRotations.push_back(core::CMyQuaternion(this->getJointNode("relbow" )->getRotation()*core::DEGTORAD)); //9
lInitialRotations.push_back(core::CMyQuaternion(this->getJointNode("rhip" )->getRotation()*core::DEGTORAD)); //10
lInitialRotations.push_back(core::CMyQuaternion(this->getJointNode("rknee" )->getRotation()*core::DEGTORAD)); //11
//Moving the bones
core::CMyQuaternion rotAccum = lInitialRotations[10];
core::vector3df lRotationV;
core::vector3df lRotationVDEG;
lRotationV = rotAccum.ConvertToEuler();
lRotationVDEG = lRotationV * core::RADTODEG;
this->getJointNode("rhip")->setRotation( lRotationVDEG );
Code: Select all
CMyQuaternion::CMyQuaternion(vector3df eul)
{
// Assuming the angles are in radians.
f32 c1 = cos(eul.X*0.5f);
f32 s1 = sin(eul.X*0.5f);
f32 c2 = cos(eul.Y*0.5f);
f32 s2 = sin(eul.Y*0.5f);
f32 c3 = cos(eul.Z*0.5f);
f32 s3 = sin(eul.Z*0.5f);
f32 c1c2 = c1*c2;
f32 s1s2 = s1*s2;
this->W =c1c2*c3 - s1s2*s3;
this->X =c1c2*s3 + s1s2*c3;
this->Y =s1*c2*c3 + c1*s2*s3;
this->Z =c1*s2*c3 - s1*c2*s3;
}
vector3df CMyQuaternion::ConvertToEuler(void)
{
f32 sqw = this->W*this->W;
f32 sqx = this->X*this->X;
f32 sqy = this->Y*this->Y;
f32 sqz = this->Z*this->Z;
f32 heading = 0;
f32 attitude = 0;
f32 bank = 0;
f32 unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
f32 test = this->X*this->Y + this->Z*this->W;
// singularity at north pole
if (test > 0.499*unit)
{
heading = 2 * atan2(this->X,this->W);
attitude = HALF_PI;
bank = 0;
return vector3df(heading,attitude,bank);
}
// singularity at south pole
if (test < -0.499*unit)
{
heading = -2 * atan2(this->X,this->W);
attitude = -HALF_PI;
bank = 0;
return vector3df(heading,attitude,bank);
}
heading = atan2( 2*this->Y*this->W-2*this->X*this->Z , sqx - sqy - sqz + sqw);
attitude = asin(2*test/unit);
bank = atan2(2*this->X*this->W-2*this->Y*this->Z , -sqx + sqy - sqz + sqw);
return vector3df(heading,attitude,bank);
}