我正在尝试使用我给出的翻译和方向数据来执行人体动画。我有一组使用贴片制作的刚体部分,所有贴片都以(0,0,0)为中心来代表人体并进行相应的翻译。我为每个人设置了一个层次结构,并为每个刚体段执行了一个变换矩阵。肢体部分开始相互抵消并产生问题。例如,即使它遵循适当的运动,手臂的刚体也会移动,就像它没有相对的原点一样。这个动作类似于将刚体从贴片重心移开?虽然它应该移动,一端固定而另一端跟随翻译数据。有人能让我知道我做错了什么吗?我的代码布局是:
% Body segment lengths
xlength = somevalue
ylength = somevalue
zlength = somevalue
% Translation data
Xdata
Ydata
Zdata
% Orientation data
Yaw = rotation about z axis
Pitch = rotation about x axis
Roll = rotation about y axis
Vertices = [xlength*ones(8,1),ylength*ones(8,1),zlength*ones(8,1)]...
.*[-0.5,-0.5,-0.5;
0.5,-0.5,-0.5;
-0.5,0.5,-0.5;
-0.5,-0.5,0.5;
0.5,0.5,-0.5;
-0.5,0.5,0.5;
0.5,-0.5,0.5;
0.5,0.5,0.5];
% Create patches
for i = 1:6
% create faces for patches
end
% create axes
ax = axes(...)
% draw patches
bodysegmentPatch = patch(patchxdata,patchydata,patchzdata)
% create hierarchy using hgtransform
pelvis = hgtransform('Parent',ax);
trunk = hgtransform('Parent',pelvis);
head = hgtransform('Parent',trunk);
leftupperarm = hgtransform('Parent',trunk);
leftforearm = hgtransform('Parent',leftupperarm);
rightupperarm = hgtransform('Parent',trunk);
rightforearm = hgtransform('Parent',rightupperarm);
leftthigh = hgtransform('Parent',pelvis);
leftcalf = hgtransform('Parent',leftthigh);
rightthigh = hgtransform('Parent',pelvis);
rightcalf = hgtransform('Parent',rightthigh);
% set patches to hierarchy
set(pelvisPatch,'Parent',pelvis)
% Animation loop
for i = 1:n
% translation of body segment
bodysegmentT = makehgtform('translate',[x(i) y(i) z(i)]);
% rotation of body segment
bodysegmentR = makehgtform('yrotate',Roll(i),'xrotate',Pitch(i),'zrotate',Yaw(i));
% Create transform matrices
set(pelvis,'Matrix',pelvisR);
set(trunk,'Matrix',trunkR*pelvisR);
set(leftupperarm,'Matrix',leftupperarmT*leftupperarmR*trunkR*pelvisR);
drawnow
end
答案 0 :(得分:0)
我不确定你的问题究竟是什么,但是如果不仔细查看你的代码,我猜这可能是做这些骨架转换时常见错误之一。
不要放弃!这些转换可能很棘手,而且通常看起来很混乱,而实际上代码真的很接近正确。