Learn WP7 XNA game development together (8. Let the 3d model work)

Source: Internet
Author: User

How to make the 3d model work is actually to set the action for the bone of the model, so that the entire model will work.

1. Obtain Bones

You can view the names of all bones in the fbx file, so that you can obtain bones by name.

TurretBone = tankModel. Bones ["turret_geo"];

CannonBone = tankModel. Bones ["canon_geo"];

HatchBone = tankModel. Bones ["hatch_geo"];

 

2. Save bones Original Transform

TurretTransform = turretBone. Transform;

CannonTransform = cannonBone. Transform;

HatchTransform = hatchBone. Transform;

 

3. Set actions for Bones

// Set the change value of the action

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 );

// Create an action matrix

Turrenttation = Matrix. CreateRotationY (turrenttationvalue );

CannonRotation = Matrix. CreateRotationX (cannonRotationValue );

HatchRotation = Matrix. CreateRotationX (hatchRotationValue );

 

4. Assign the set action to bones Transform

TurretBone. Transform = turretation * turretTransform;

CannonBone. Transform = cannonRotation * cannonTransform;

HatchBone. Transform = hatchRotation * hatchTransform;

 

From the above implementation code, we can see that if you want to make the 3d model move, you only need to assign the action and the amount of changes to the bones contained in the model.

 

Example: 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.