一.载入:
protected override void LoadContent()
{
tankModel = Content.Load<Model>("tank");//载入fbx model
tankBonesTransforms = new Matrix[tankModel.Bones.Count];//创建一个model的boneTransform数组,用来保存所有的model boneTransform.
}
二.绘制:
tankModel.CopyAbsoluteBoneTransformsTo(tankBonesTransforms);//将model中的boneTransform拷到数组中,为绘制做准备
Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 10, 20000);//创建投影矩阵
Matrix view = Matrix.CreateLookAt(new Vector3(1500, 550, 0) * 1 + new Vector3(0, 150, 0), new Vector3(0, 150, 0), Vector3.Up);//创建视图矩阵,将世界坐标转为摄像机的坐标
foreach (ModelMesh m in tankModel.Meshes)//开始绘制世界坐标中的每个对象
{
foreach (BasicEffect e in m.Effects)
{
e.World = tankBonesTransforms[m.ParentBone.Index];
e.View = view;
e.Projection = projection;
e.LightingEnabled = true;
e.SpecularColor = new Vector3(0.8f, 0.8f, 0.6f);
e.SpecularPower = 16;
e.TextureEnabled = true;
}
m.Draw();//使用ModelMesh中的draw方法来进行绘制,而不是用SpriteBatch中的draw方法来绘制
示例下载地址:http://www.52winphone.com/bbs/viewthread.php?tid=282&extra=page%3D1
本文作者:未知