谢谢指教,新手
解决方案 »
- 怎样使datagridview在输入完一行后,禁止自动新增一行?
- 通信方面问题
- web.config中采用forms验证时,如果使一些aspx不必验证?求高手解答。。
- 求助 ,关于ragged array,读取txt文件到listbox上
- 子类对象赋给基类对象,为什么?
- 请问c#语言容易被反向编译吗?可读性怎么样?怎样保护自己的程序代码?
- 请问rss阅读器一般是怎么实现的?
- 发布程序时,如何把“解决VS2005中文输入法半角/全角自动切换的补丁”一起添加进必备程序的选项里?一定要是SmartClient方式发布的
- 如何实现一个向导窗口?
- 有没有一个Form里面的所有控件的列表
- 关于窗体之间调用的一个问题
- 关于打印的2个问题求解?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace MeshExample
{
public partial class Form1 : Form
{ private Device device = null;
private Mesh boxMesh = null;
private Mesh cylinderMesh = null;
private Mesh polygonMesh = null;
private Mesh sphereMesh = null;
private Mesh teapotMesh = null;
private Mesh torusMesh = null;
private Mesh textMesh = null;
private Microsoft.DirectX.Direct3D.Font d3dfont;
private string helpString;
private bool showHelpString = true;
private float angle = 0.0f;
private int rotatorXYZ = 0;
private bool enableRotator = true;
private bool enableCullMode = false;
private bool enableSolidMode = false; public Form1()
{
InitializeComponent();
}
public bool InitializeGraphics()
{
try
{
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Hardware, this,
CreateFlags.SoftwareVertexProcessing, presentParams);
return true;
}
catch (DirectXException)
{
return false;
}
}
private void SetupCamera()
{
float fieldOfView = (float)Math.PI / 4;
float aspectRatio = this.Width / this.Height;
float nearPlane = 1.0f;
float farPlane = 100.0f;
device.Transform.Projection =
Matrix.PerspectiveFovLH(fieldOfView, aspectRatio, nearPlane, farPlane);
Vector3 cameraPosition = new Vector3(0, 0, -18.0f);
Vector3 cameraTarget = new Vector3(0, 0, 0);
Vector3 upDirection = new Vector3(0, 1, 0);
device.Transform.View = Matrix.LookAtLH(cameraPosition, cameraTarget, upDirection);
device.RenderState.Lighting = false;
device.RenderState.CullMode = (enableCullMode ? Cull.CounterClockwise : Cull.None);
device.RenderState.FillMode = (enableSolidMode ? FillMode.Solid : FillMode.WireFrame);
}
private void SetWorldTransform(float x, float y, float z)
{
Vector3 world;
if (rotatorXYZ == 0)
{
world = new Vector3(angle, 0, 0);
}
else if (rotatorXYZ == 1)
{
world = new Vector3(0, angle, 0);
}
else
{
world = new Vector3(0, 0, angle);
}
device.Transform.World = Matrix.RotationAxis(world, angle) * Matrix.Translation(x, y, z);
if (enableRotator == true)
{
angle += 0.03f / (float)Math.PI;
}
}
private void Form1_Load(object sender, EventArgs e)
{
this.Width = 575;
this.Height = 475;
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
this.KeyPreview = true;
helpString = "<Esc>:退出\n\n\n" +
"<F1>:显示/隐藏提示信息\n" +
"<F2>:实心/线框\n" +
"<F3>:旋转/不旋转\n" +
"<F4>:旋转轴(x轴、y轴、z轴)\n" +
"<F5>:背景剔除/不剔除\n\n";
System.Drawing.Font winFont = new System.Drawing.Font("宋体", 9, FontStyle.Regular);
d3dfont = new Microsoft.DirectX.Direct3D.Font(device, winFont);
d3dfont.PreloadText(helpString);
textMesh = Mesh.TextFromFont(
device, new System.Drawing.Font("宋体", 12), "Mesh对象展示", 1.0f, 0.3f);
boxMesh = Mesh.Box(device, 2.0f, 2.0f, 2.0f);
cylinderMesh = Mesh.Cylinder(device, 1.0f, 0.5f, 2.0f, 10, 10);
polygonMesh = Mesh.Polygon(device, 0.4f, 20);
sphereMesh = Mesh.Sphere(device, 1.0f, 20, 10);
teapotMesh = Mesh.Teapot(device);
torusMesh = Mesh.Torus(device, 0.3f, 1.0f, 20, 20); } private void Form1_Paint(object sender, PaintEventArgs e)
{
SetupCamera();
device.Clear(ClearFlags.Target , Color.DarkSeaGreen, 1.0f, 0);
device.BeginScene();
// 绘制文本
SetWorldTransform(0, 5, 0);
textMesh.DrawSubset(0);
// 绘制立方体
SetWorldTransform(-5, 0, 0);
boxMesh.DrawSubset(0);
// 绘制圆筒
SetWorldTransform(0, 0, 0);
cylinderMesh.DrawSubset(0);
// 绘制多边形
SetWorldTransform(5, 0, 0);
polygonMesh.DrawSubset(0);
// 绘制球形
SetWorldTransform(-5, -5, 0);
sphereMesh.DrawSubset(0);
// 绘制茶壶
SetWorldTransform(0, -5, 0);
teapotMesh.DrawSubset(0);
// 绘制圆环
SetWorldTransform(5, -5, 0);
torusMesh.DrawSubset(0);
if (showHelpString == true)
{
d3dfont.DrawText(null, helpString, 25, 30, Color.Tomato);
}
device.EndScene();
device.Present();
if (WindowState != FormWindowState.Minimized)
{
this.Invalidate();
} } private void Form1_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Escape:
this.Close();
break;
case Keys.F1:
showHelpString = !showHelpString;
break;
case Keys.F2:
enableSolidMode = !enableSolidMode;
break;
case Keys.F3:
enableRotator = !enableRotator;
break;
case Keys.F4:
rotatorXYZ = (rotatorXYZ + 1) % 3;
break;
case Keys.F5:
enableCullMode = !enableCullMode;
break;
} }
}
}
提示应用程序错误