meshMaterials = new Material[1];
meshTextures = new Texture[1];
/*meshMaterials[0].Ambient = e.material.Ambient;
meshMaterials[0].Diffuse = e.material.Diffuse;
meshMaterials[0].Emissive = e.material.Shininess;
meshMaterials[0].Specular = e.material.Specular;
*/
meshMaterials[0].Ambient = Color.FromArgb((int)e.material.Ambient[0], (int)e.material.Ambient[1], (int)e.material.Ambient[2]);
meshMaterials[0].Diffuse = Color.FromArgb((int)e.material.Diffuse[0], (int)e.material.Diffuse[1], (int)e.material.Diffuse[2]);
//meshMaterials[0].Emissive = e.material.Shininess;
meshMaterials[0].Specular = Color.FromArgb((int)e.material.Specular[0], (int)e.material.Specular[1], (int)e.material.Specular[2]);
// Load our mesh
/*Model model = new ThreeDSFile(file).ThreeDSModel;
for (int i = 0; i < model.Entities.Count; i++)
{
Entity e = model.Entities[i];
for(int i2=0;i2<e.indices.Length;i2++)
{
e.indices[i2].vertex1;
}
};
model.Entities.
* */
} private void SetupCamera()
{
device.RenderState.CullMode = Cull.None;
device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, this.Width / this.Height, 1.0f, 10000.0f);
device.Transform.View = Matrix.LookAtLH(new Vector3(0,0, 580.0f), new Vector3(), new Vector3(0,1,0));
//device.RenderState.Ambient = Color.DarkBlue;
device.Lights[0].Type = LightType.Directional;
device.Lights[0].Diffuse = Color.White;
device.Lights[0].Direction = new Vector3(0, -1, -1);
//device.Lights[0].Commit();
device.Lights[0].Enabled = true; } protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.CornflowerBlue, 1.0f, 0); SetupCamera(); device.BeginScene(); // Draw our Mesh
DrawMesh(angle / (float)Math.PI, angle / (float)Math.PI * 2.0f, angle / (float)Math.PI / 4.0f, 0.0f, 0.0f, 0.0f); device.EndScene(); device.Present(); this.Invalidate();
} private void DrawMesh(float yaw, float pitch, float roll, float x, float y, float z)
{
angle += 0.1f; device.Transform.World = Matrix.RotationYawPitchRoll(yaw, pitch, roll) * Matrix.Translation(x, y, z);
for (int i = 0; i < meshMaterials.Length; i++)
{
Material boxMaterial = new Material();
boxMaterial.Ambient = Color.White;
boxMaterial.Diffuse = Color.White;
device.Material = boxMaterial;
//device.Material = meshMaterials[i];
//device.SetTexture(0, meshTextures[i]);
mesh.DrawSubset(i);
}
} /// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.Size = new Size(800,600);
this.Text = "Form1";
}
#endregion/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
using (Form1 frm = new Form1())
{
// Show our form and initialize our graphics engine
frm.Show();
frm.InitializeGraphics();
Application.Run(frm);
}
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货