一起学WP7 XNA游戏开发(八. 让3d model动起来)


如何让3d model动起来,其实就是要给model的bone设置动作,这样整个model就会动起来了。

  一.获取Bones

  在fbx文件中可以看到所有bones的名称,这样就可以通过名称来获取到bones。

  turretBone = tankModel.Bones["turret_geo"];
   cannonBone = tankModel.Bones["canon_geo"];
   hatchBone = tankModel.Bones["hatch_geo"];

  二.保存bones原始Transform

turretTransform = turretBone.Transform;
   cannonTransform = cannonBone.Transform;
   hatchTransform = hatchBone.Transform;

  三.为Bones设置动作

//设置动作的变化值
turretRotationValue = (float)Math.Sin(time * 0.333f) * 1.25f;
   cannonRotationValue = (float)Math.Sin(time * 0.25f) * 0.333f - 0.333f;
   hatchRotationValue = MathHelper.Clamp((float)Math.Sin(time * 2) * 2, -1, 0);
   //创建动作矩阵
   turretRotation = Matrix.CreateRotationY(turretRotationValue);
   cannonRotation = Matrix.CreateRotationX(cannonRotationValue);
   hatchRotation = Matrix.CreateRotationX(hatchRotationValue);

  四.将设置的动作赋给bones的Transform

turretBone.Transform = turretRotation * turretTransform;
   cannonBone.Transform = cannonRotation * cannonTransform;
   hatchBone.Transform = hatchRotation * hatchTransform;

  由以上的实现代码可以看出,如果想让3d model 动起来,只要给model所包含的bones赋予动作,以及动作的变化量,就可以了。

  示例下载地址:http://www.52winphone.com/bbs/viewthread.php?tid=300&extra=page%3D1


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3