一起学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
轉載于:https://www.cnblogs.com/randylee/archive/2011/03/10/1979841.html
總結
以上是生活随笔為你收集整理的一起学WP7 XNA游戏开发(八. 让3d model动起来)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 求一个好听时尚的团队名字!
- 下一篇: 替换WCF默认序列化方式