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

  • 相关阅读:
    黑产及社会工程学-学习历程
    ACE_Get_Opt函数笔记
    PlatformIO+Jlink进行调试
    Mac下搭建基于PlatformIO的嵌入式开发环境(STM32开发)
    选择排序
    插入排序
    JPEG原理详解 (转载)
    双链表基本操作
    单链表基本操作
    顺序表基本操作
  • 原文地址:https://www.cnblogs.com/randylee/p/1979841.html
Copyright © 2011-2022 走看看