23 cerr <<
"Chain::BeginCreateChain - called after BeginCreateChain()" << endl;
36 cerr <<
"Chain::RemoveJoint - attempted to edit the chain before calling BeginCreateChain" << endl;
64 cerr <<
"Chain::AddRoot - attempted to add a root before calling BeginCreateChain" << endl;
69 cerr <<
"Chain::AddRoot - root is already set" << endl;
91 cerr <<
"Chain::AddRoot - attempted to add a root before calling BeginCreateChain" << endl;
96 cerr <<
"Chain::AddRoot - root is already set" << endl;
111 cerr <<
"Chain::AddJoint - parent " << parent_name <<
" not found for " << target->
name << endl;
121 cerr <<
"Chain::AddJoint - attempted to add a joint before calling BeginCreateChain" << endl;
126 cerr <<
"Chain::AddJoint - root is not set" << endl;
131 cerr <<
"Chain::AddJoint - parent is NULL" << endl;
136 cerr <<
"Joint::AddJoint - parent joint is not added yet" << endl;
141 cerr <<
"Joint::AddJoint - joint " << target->
name <<
" already exists" << endl;
144 if(!target)
return 0;
145 target->
chain =
this;
173 const char* charname,
Joint* parent_joint)
175 if(!joint_data.
name)
return -1;
178 if(parent_joint) last_joint = parent_joint;
180 for(i=0; i<num_joint; i++)
183 jdata->
name =
new char [strlen(joint_data.
name) + 5];
188 cerr << new_joint->
name <<
" added to " << last_joint->
basename << endl;
189 last_joint = new_joint;
198 fVec3 cur_pos_offset(init_pos);
199 fMat33 cur_att_offset(init_att);
200 for(i=0; i<num_char; i++)
202 char* charname =
new char [strlen(charname_base) + 5];
203 sprintf(charname,
"%s%04d", charname_base, i+init_num);
204 Load(prmname, charname);
208 tmp.
mul(cur_att_offset, pos_offset);
209 cur_pos_offset += tmp;
210 tmpr.
mul(cur_att_offset, att_offset);
211 cur_att_offset.
set(tmpr);
215 cerr << charname <<
": " << char_root->
rel_pos << endl << char_root->
rel_att << endl;
230 cerr <<
"Chain::EndCreateChain - called before BeginCreateChain()" << endl;
254 TransformNode* tnode = sg->findTransformNode(cur->
name);
258 float abs_pos[3], abs_att[3][3], abs_scale[3];
259 get_abs_matrix(tnode, abs_pos, abs_att, abs_scale);
263 cur->
abs_att(0,0) = abs_att[0][0];
264 cur->
abs_att(0,1) = abs_att[0][1];
265 cur->
abs_att(0,2) = abs_att[0][2];
266 cur->
abs_att(1,0) = abs_att[1][0];
267 cur->
abs_att(1,1) = abs_att[1][1];
268 cur->
abs_att(1,2) = abs_att[1][2];
269 cur->
abs_att(2,0) = abs_att[2][0];
270 cur->
abs_att(2,1) = abs_att[2][1];
271 cur->
abs_att(2,2) = abs_att[2][2];
282 TransformNode* tnode = sg->findTransformNode(cur->
name);
286 static fVec3 pp, rel_pos;
287 static fMat33 tr, rel_att;
int CreateParallel(int num_char, const char *prmname, const char *charname, const fVec3 &init_pos=0.0, const fMat33 &init_att=1.0, const fVec3 &pos_offset=0.0, const fMat33 &att_offset=1.0, int init_num=0)
Automatically generate multiple identical chains.
void add(const fVec3 &vec1, const fVec3 &vec2)
int remove_child(Joint *j)
virtual int init(SceneGraph *sg)
Initialize the parameters.
Joint * child
pointer to the child joint
Joint * AddRoot(const char *name=0, const fVec3 &grav=fVec3(0.0, 0.0, 9.8))
Add the (unique) root joint.
void zero()
Creates a zero vector.
void set(const fMat33 &mat)
Copies a matrix.
void mul(const fMat33 &mat1, const fMat33 &mat2)
friend fMat33 tran(const fMat33 &m)
Returns the transpose.
void set_relative_positions(SceneGraph *sg)
int in_create_chain
true if between BeginCreateChain() and EndCreateChain().
int RemoveJoint(Joint *j)
disconnect joint j from its parent
png_infop png_charpp name
void calc_abs_positions(Joint *cur, SceneGraph *sg)
fVec3 loc_lin_acc
linear acceleration in local frame
fVec3 init_pos
origin of the joint value (for prismatic joints)
Joint * root
Chain information.
char * parent_name
parent joint's name
int Load(const char *fname, const char *charname=0)
Load the chain from a file in original (*.prm) format.
void identity()
Identity matrix.
int BeginCreateChain(int append=false)
Indicates begining of creating a kinematic chain.
void set(double *v)
Set element values from array or three values.
fEulerPara rel_ep
Euler parameter representation of rel_att (for 0/3/6 DOF joints)
char * basename
joint base name (without the character name)
void set(const fVec3 &v, double s)
Set the elements.
fVec3 rel_pos
(initial) position in parent joint's frame (for 0/3/6 DOF joints)
JointType j_type
joint type
fMat33 abs_att
absolute orientation
char * name
joint name (including the character name)
int EndCreateChain(SceneGraph *sg=NULL)
End editing a chain.
fMat33 init_att
origin of the joint value (for rotational joints)
Joint * brother
pointer to the brother joint
int AddJoint(Joint *target, Joint *p)
Add a new joint target as a child of joint p.
Classes for defining open/closed kinematic chains.
fMat33 rel_att
(initial) orientation in parent joint's frame (for 0/3/6 DOF joints)
void calc_rel_positions(Joint *cur, SceneGraph *sg)
std::string sprintf(char const *__restrict fmt,...)
Temporary storage for basic joint information.
void sub(const fVec3 &vec1, const fVec3 &vec2)
int SetJointValue(double _q)
int CreateSerial(int num_joint, const JointData &joint_data, const char *charname=0, Joint *parent_joint=0)
Automatically generate a serial chain.
virtual int clear_data()
Clear arrays only; don't delete joints.
Joint * FindJoint(const char *jname, const char *charname=0)
Find a joint from name.
fVec3 abs_pos
absolute position
void mul(const fVec3 &vec, double d)
The class for representing a joint.
Joint * parent
pointer to the parent joint
virtual void Clear()
Remove all joints and clear all parameters.
Joint * FindCharacterRoot(const char *charname)
Find the root joint of the character with name charname.