zoukankan      html  css  js  c++  java
  • 一起学WP7 XNA游戏开发(八. 让3d model动起来)

    如何让3d model动起来,其实就是要给modelbone设置动作,这样整个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);

     

    四.将设置的动作赋给bonesTransform

    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

  • 相关阅读:
    RMQ(非log2储存方法)
    2016年5月份学习记录
    NOIP200504循环
    膜拜acm大牛 虽然我不会这题,但是AC还是没有问题的~(转自hzwer)
    最长公共子序列的长度
    菜鸟,大牛和教主三者的区别(转自hzwer)
    NOIP201205Vigenère密码
    NOIP200503采药
    公路乘车
    NOIP200902分数线划定
  • 原文地址:https://www.cnblogs.com/randylee/p/1979841.html
Copyright © 2011-2022 走看看