C#+Direct3D9.0开发实例之月亮绕着地球转
http://tech.ddvip.com 2006年08月02日 社区交流
本文详细介绍C#+Direct3D9.0开发实例之月亮绕着地球转
添加UpdateInputState()方法,当按下鼠标左键时,将leftbuttondown值设置为真,当鼠标抬起时,将mousexloc置0:
private void UpdateInputState()
{
mouse.Update();
if (mouse.LeftButtonDown)
{
if(leftbuttondown == false)
{
mousexloc = 0.0f;
leftbuttondown = true;
}
else
{
mousexloc = -mouse.X;
}
}
else
{
leftbuttondown = false;
mousexloc = 0.0f;
}
}
在此程序中,只对X值进行了操作,即只能左右转。
Render()方法更新如下:
public void Render()
{
UpdateInputState();
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.DarkGray, 1.0f, 0);
SetupCamera();
device.BeginScene();
model.Update((int)mousexloc);
model.Light(ref device);
model.Render(ref device);
device.EndScene();
device.Present();
}
最后更改Main()主函数:
static void Main()
{
using (Form1 EarthForm = new Form1())
{
EarthForm.InitializeGraphics();
EarthForm.InitializeInput();
EarthForm.Show();
while(EarthForm.Created)
{
EarthForm.Render();
Application.DoEvents();
}
EarthForm.Dispose();
}
运行程序,按下鼠标左键拖动,即可旋转月球与地球。
作者:dandanCool 责编:豆豆技术应用