[ODE] newbie joint question
Piotr Obrzut
piotr_obrzut at o2.pl
Fri Dec 3 14:33:05 MST 2004
Hi,
DL> I'm not sure what you are asking, but if you are using Cal3D to draw your
DL> model and you are setting the bone rotations manually (taken from ODE rigid
DL> body positions) then make sure you call calculateState() for each bone that
DL> you modify, it would look something like this:
pBone->>setRotation ( pBone->getRotation() * DeltaQuat );
pBone->>calculateState();
actualy this is the way by which i'm updating Cal3d model pos (it is
writien with use of CrystalSpace interface on ODE, but i think that
the idea is clear enough, it looks quite nice only for geting bodies
positions and aplaing them to the Cal3d model)
CalSkeleton* skeleton = cal_model->getSkeleton ();
std::vector<CalBone*> bone_vect = skeleton->getVectorBone ();
bone_vect[0]->setRotation (get_cal_quaternion (bodies[0]->GetOrientation ()));
csVector3 vec = bodies[0]->GetPosition ();
bone_vect[0]->setTranslation (CalVector (vec [0], vec[1], vec[2]));
for (unsigned int i = 1; i < bodies.size (); i++)
{
int p_id = bone_vect[i]->getCoreBone ()->getParentId ();
csReversibleTransform trans = bodies[i]->GetTransform () / bodies[p_id]->GetTransform ();
bones[i]->setRotation (get_cal_quaternion (trans.GetO2T ()));
csVector3 vect = trans.GetO2TTranslation ();
bones[i]->setTranslation (CalVector (vect[0], vect[1], vect [2]));
}
skeleton->calculateState ();
The problem is in joints between mentioned ODE bodies and this is
the way i'm making joints:
for (unsigned int i = 0; i < bodies.size (); i++)
{
std::string name = bones[i]->getCoreBone ()->getName ();
CalCoreBone* cbone = bones[i]->getCoreBone ();
std::list<int> ch_list = cbone->getListChildId ();
for (std::list<int>::iterator ch_it = ch_list.begin (); ch_it != ch_list.end (); ch_it++)
{
csRef<iJoint> joint = dyn_sys->CreateJoint ();
joint->SetTransConstraints (1, 1, 1);
joint->SetRotConstraints (0,0,0);
joint->SetTransform (csReversibleTransform ()); //0 transform
joint->Attach (bodies[i], bodies[*ch_it]);
/*here CrystalSpace is making ODE joint like this:
jointID = dJointCreateBall (dynsys->GetWorldID(), 0);
dJointAttach (jointID, bodyID[0], bodyID[1]);
pos = transform.GetOrigin();
dJointSetBallAnchor (jointID, pos.x, pos.y, pos.z);
it is a ball joint b/c its translation is all constrainted and
its rotation is not
*/
}
}
and after bodies[2]->AddForce (csVector3 (0,20,0)) Caly model
looks like that: http://mathrick.org/files/joint_error.JPG
--
greetings,
Piotr Obrzut
More information about the ODE
mailing list