8 //#include <appbiped.h>
19 mpm_motion
*mpd_motion_table
;
22 void mp_old_init(int max_mtab
)
26 mpd_motion_table
=(mpm_motion
*)Malloc(max_mtab
*sizeof(mpm_motion
));
28 //DbgSetLogFile(MP_SRC, "mpout.txt");
30 for (i
= 0; i
< max_mtab
; i
++)
32 mpd_motion_table
[i
].handle
=MP_MOT_INVALID
;
35 mpd_max_mtab
= max_mtab
;
40 Free(mpd_motion_table
);
44 // this is clearly imbecilic, but we don't really know what motion loading should
46 int mp_old_load_motion(Id motID
)
51 while ((i
< mpd_max_mtab
) && (mpd_motion_table
[i
].handle
!= MP_MOT_INVALID
))
56 if (i
== mpd_max_mtab
)
58 result
= MP_MOT_INVALID
;
62 if (ResExtract(motID
, (void *) &mpd_motion_table
[i
]))
64 mpd_motion_table
[i
].handle
= i
;
74 float MotionWeight
= 1.0;
82 // THIS IS THE UPDATE FUNCTION FOR LG-BIPED DATA.
84 void mp_old_update(multiped
* mp
, float dt
, mxs_vector
* pos
, mxs_matrix
* orient
)
86 int i
, res_id
, res_index
, norm_id
, bend
, frame
;
88 unsigned char * motion_data
;
98 mxs_matrix m1
, m2
, uppertorso_offset
, lowerab_direc
;
99 mxs_real r1
, r2
, r3
, r4
;
102 int num_effectors
= 0;
103 mps_motion_node
* node
;
114 if (mp_list_count(&mp
->main_motion
))
116 //m = &mpd_motion_table[mp->motions[0].handle];
117 node
= (mps_motion_node
*) mp_list_traverse(&mp
->main_motion
, NULL
);
118 m
= &mpd_motion_table
[node
->handle
];
119 num_frames
= m
->info
.num_frames
;
121 frame_inc
= ((float) m
->info
.frequency
) * dt
/ 1000.0;
122 node
->frame
+= frame_inc
;
123 frame
= (int) floor(node
->frame
+ 0.5);
125 if (frame
< m
->info
.num_frames
)
127 res_id
= REFID(m
->component
->ref
);
129 Spew(MP_SRC
, ("\nnew frame\n\n"));
131 // Loop through component motions, finding torsos, limbs, and effectors.
134 for (i
= 0; i
< MAX_COMPONENTS
; i
++, cm
++)
136 if ((cm
->ctype
> MPCT_NULL
) && (cm
->ctype
<= MPCT_HAND
))
138 res_index
= REFINDEX(cm
->ref
);
140 motion_data
= (unsigned char *) RefLock(cm
->ref
);
145 torsos
[num_torsos
++] = i
;
150 limbs
[num_limbs
++] = i
;
156 effectors
[num_effectors
++] = i
;
165 for (i
= 0; i
< num_torsos
; i
++)
167 cm
= m
->component
+ torsos
[i
];
169 motion_data
= (unsigned char *) RefLock(cm
->ref
);
171 //Spew(MP_SRC, ("torso\n"));
173 td
= (trunk_data
*) motion_data
;
174 tc
= (trunk_capture
*) (motion_data
+ sizeof(trunk_data
));
177 // pelvis and torso orientations.
178 mx_mul_mat(&m1
, orient
, &tc
->base_orient
);
179 mx_copy_mat(&lowerab_direc
, &m1
);
180 mx_copy_vec(&mp
->norm
[NORM_PELV
], &m1
.vec
[1]);
182 mx_copy_mat(&uppertorso_offset
, &tc
->ab_orient
);
183 mx_mul_mat(&m2
, &m1
, &tc
->ab_orient
);
184 mx_copy_vec(&mp
->norm
[NORM_UPTORS
], &m2
.vec
[1]);
187 mx_mat_mul_vec(&v1
, orient
, &tc
->base
);
189 //mx_add_vec(&mp->joints[BUTT], pos, &v1);
190 mp
->joints
[BUTT
].x
= node
->base_pos
.x
+ v1
.x
;
191 mp
->joints
[BUTT
].y
= node
->base_pos
.y
+ v1
.y
;
192 mp
->joints
[BUTT
].z
= v1
.z
;
194 mx_copy_vec(pos
, &mp
->joints
[BUTT
]);
198 mx_scaleeq_vec(&v1
, td
->ab_per
* td
->spine_len
);
199 mx_mat_muleq_vec(&m1
, &v1
);
200 mx_add_vec(&mp
->joints
[ABDOMEN
], &mp
->joints
[BUTT
], &v1
);
205 mx_scaleeq_vec(&v1
, (1 - td
->ab_per
) * td
->spine_len
);
206 mx_mat_muleq_vec(&m2
, &v1
);
207 mx_add_vec(&mp
->joints
[NECK
], &mp
->joints
[ABDOMEN
], &v1
);
211 mx_copy_vec(&v1
, &tc
->lshldr
);
212 mx_mat_muleq_vec(&m2
, &v1
);
213 mx_add_vec(&mp
->joints
[LSHLDR
], &mp
->joints
[ABDOMEN
], &v1
);
214 mx_copy_vec(&v1
, &tc
->rshldr
);
215 mx_mat_muleq_vec(&m2
, &v1
);
216 mx_add_vec(&mp
->joints
[RSHLDR
], &mp
->joints
[ABDOMEN
], &v1
);
221 mx_scaleeq_vec(&v1
, td
->hip_width
/ 2);
222 mx_mat_muleq_vec(&m1
, &v1
);
223 mx_scale_vec(&v2
, &v1
, -1);
224 mx_add_vec(&mp
->joints
[LHIP
], &mp
->joints
[BUTT
], &v1
);
225 mx_add_vec(&mp
->joints
[RHIP
], &mp
->joints
[BUTT
], &v2
);
230 for (i
= 0; i
< num_limbs
; i
++)
232 cm
= m
->component
+ limbs
[i
];
233 motion_data
= (unsigned char *) RefLock(cm
->ref
);
235 ld
= (limb_data
*) motion_data
;
236 lc
= (limb_capture
*) (motion_data
+ sizeof(limb_data
));
239 //Spew(MP_SRC, ("limb: %s -> %s\n", Jnt[ld->base_joint_id], Jnt[ld->end_joint_id]));
241 switch (ld
->base_joint_id
)
244 dst
= mp
->joints
+ LELBOW
;
245 mx_mul_mat(&m1
, &lowerab_direc
, &uppertorso_offset
);
251 dst
= mp
->joints
+ RELBOW
;
252 mx_mul_mat(&m1
, &lowerab_direc
, &uppertorso_offset
);
258 dst
= mp
->joints
+ LKNEE
;
259 mx_copy_mat(&m1
, &lowerab_direc
);
265 dst
= mp
->joints
+ RKNEE
;
266 mx_copy_mat(&m1
, &lowerab_direc
);
272 mx_mat_mul_vec(&v1
, &m1
, &lc
->e_data
);
273 mx_add_vec(&mp
->joints
[ld
->end_joint_id
], &mp
->joints
[ld
->base_joint_id
], &v1
);
275 mx_mat_mul_vec(&mp
->norm
[norm_id
], &m1
, &lc
->n_data
);
277 // solve for joint position.
279 mx_sub_vec(&v1
, &mp
->joints
[ld
->end_joint_id
], &mp
->joints
[ld
->base_joint_id
]);
280 r1
= mx_dot_vec(&v1
, &v1
);
283 r3
= ld
->len1
* ld
->len1
- ld
->len2
* ld
->len2
;
284 r4
= ((r3
/r1
) + 1.0) / 2.0;
286 dst
->x
= mp
->joints
[ld
->base_joint_id
].x
+ v1
.x
* r4
;
287 dst
->y
= mp
->joints
[ld
->base_joint_id
].y
+ v1
.y
* r4
;
288 dst
->z
= mp
->joints
[ld
->base_joint_id
].z
+ v1
.z
* r4
;
290 mx_cross_vec(&v2
, &mp
->norm
[norm_id
], &v1
);
291 r4
= (r3
/r2
+ r2
) / 2.0;
292 r4
= sqrt((ld
->len1
* ld
->len1
) - (r4
* r4
)) / r2
;
305 for (i
= 0; i
< num_effectors
; i
++)
307 cm
= m
->component
+ effectors
[i
];
308 motion_data
= (unsigned char *) RefLock(cm
->ref
);
310 ed
= (effec_data
*) motion_data
;
312 if (cm
->ctype
== MPCT_HAND
)
314 hc
= (hand_capture
*) (motion_data
+ sizeof(effec_data
));
316 ec
= &hc
->effec_table
;
320 ec
= (effec_capture
*) (motion_data
+ sizeof(effec_data
));
324 //Spew(MP_SRC, ("effector: %s -> %s\n", Jnt[ed->base_joint_id], Jnt[ed->eff_pos_id]));
326 dst
= mp
->joints
+ ed
->eff_pos_id
;
328 switch (ed
->eff_pos_id
)
335 norm_id
= NORM_LHAND
;
339 norm_id
= NORM_RHAND
;
351 Spew(MP_SRC
, ("neglected effector\n"));
354 mx_copy_mat(&m1
, &ec
->e_data
);
355 mx_mul_mat(&m2
, &uppertorso_offset
, &m1
);
356 mx_mul_mat(&m1
, &lowerab_direc
, &m2
);
357 mx_copy_vec(&v1
, &m1
.vec
[0]);
358 mx_scaleeq_vec(&v1
, ed
->len1
);
359 mx_add_vec(&mp
->joints
[ed
->eff_pos_id
], &mp
->joints
[ed
->base_joint_id
], &v1
);
360 mx_copy_vec(&mp
->norm
[norm_id
], &m1
.vec
[1]);
362 if (norm_id
== NORM_HEAD
)
364 //Spew(MP_SRC, ("head normal: %f, %f, %f\n", fix_from_float(m1.vec[1].x), fix_from_float(m1.vec[1].y), fix_from_float(m1.vec[1].z)));
370 mp->motions[0].frame++;
371 if (mp->motions[0].frame >= num_frames)
374 mp->num_active_motions = 0;
384 void mp_start_motion(multiped * mp, unsigned int motion_num, mxs_vector * start_pos, mxs_matrix * start_orient)
386 mpm_motion * m = &mpd_qmotion_table[motion_num];
388 //mx_mat2ang(start_orient, &m->info.start_orient);
389 //mx_copy_mat(start_orient, &m->info.start_orient);
390 //mx_identity_mat(start_orient);
392 mp->motion = motion_num;
394 mx_copy_vec(&mp->base_pos, start_pos);
401 void mp_stop_all_motions(multiped * mp)