📄 earth.cs
字号:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace WindowsFormsApplication1
{
class Earth : BaseEarth
{
public Earth(ref Device device, Matrix location)
: base(ref device)
{
meshDevice = device;
locationOffset = location;
}
private Material[] mMaterials; //保存材质
private Texture[] mTextures; //保存纹理
private Matrix locationOffset; //用来保存网格对象的相对位置
//private Mesh mMesh = null; //三角形网格对象
private Device meshDevice; //需要显示在哪个设备上。
public bool LoadMesh(string meshfile)
{
ExtendedMaterial[] mtrl;
try
{
// 装载文件
mMesh = Mesh.FromFile(meshfile, MeshFlags.Managed, meshDevice, out mtrl);
// 如果有材质的话,装入它们
if ((mtrl != null) && (mtrl.Length > 0))
{
mMaterials = new Material[mtrl.Length];
mTextures = new Texture[mtrl.Length];
// 得到材质和纹理
for (int i = 0; i < mtrl.Length; i++)
{
mMaterials[i] = mtrl[i].Material3D;
if ((mtrl[i].TextureFilename != null) && (mtrl[i].TextureFilename != string.Empty))
{
//前面得到的纹理的路径是相对路径,需要保存的是绝对路径,通过应用程序路径可以获得
mTextures[i] = TextureLoader.FromFile(meshDevice, @"..\..\" + mtrl[i].TextureFilename);
}
}
}
return true;
}
catch
{
return false;
}
}
public void Render(Matrix worldTransform)
{
//把位置变为世界坐标
meshDevice.Transform.World = Matrix.Multiply(locationOffset, worldTransform);
//绘制网格
for (int i = 0; i < mMaterials.Length; i++)
{
meshDevice.Material = mMaterials[i];
meshDevice.SetTexture(0, mTextures[i]);
mMesh.DrawSubset(i);
}
}
public override void Render()
{
base.Render();
//把位置变为世界坐标
// meshDevice.Transform.World = Matrix.Multiply(locationOffset, worldTransform);
//绘制网格
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -