Learn WP7 XNA Game Development (eight. Let 3d model Move up)

Source: Internet
Author: User
Tags sin
How to let 3d model move up, in fact is to give model bone set action, so the whole model will move up.

A Get Bones

You can see the names of all the bones in the fbx file so that you can get to bones by name.

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

Two Save Bones Original Transform

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

Three Set actions for 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);

Four Assigns the set action to the bones transform

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

From the above implementation code can be seen, if you want to let 3d model to move up, as long as the model contains the bones to give action, as well as the changes in the amount of movement, it can be.

Sample Download Address: http://www.52winphone.com/bbs/viewthread.php?tid=300&extra=page%3D1



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.