扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:dandanCool 来源:blog 2007年11月13日
关键字:
private float xloc = 0.0f; private float yloc = 0.0f; private float zloc = 0.0f; private float xrot = 0.0f; private float yrot = 0.0f; private float zrot = 0.0f; private float xscale = 1.0f; private float yscale = 1.0f; private float zscale = 1.0f; |
public float XLoc { get { return xloc; } set { xloc = value; } } ………… |
public virtual void Render() { objdevice.MultiplyTransform(TransformType.World,Matrix.Translation(xloc, yloc, zloc)); objdevice.MultiplyTransform(TransformType.World,Matrix.RotationAxis(new Vector3(1.0f, 0.0f, 0.0f), xrot)); objdevice.MultiplyTransform(TransformType.World,Matrix.RotationAxis(new Vector3(0.0f, 1.0f, 0.0f), yrot)); objdevice.MultiplyTransform(TransformType.World,Matrix.RotationAxis(new Vector3(0.0f, 0.0f, 1.0f), zrot)); objdevice.MultiplyTransform(TransformType.World,Matrix.Scaling(xscale, yscale, zscale)); return; } |
public override void Render() { base.Render(); //把位置变为世界坐标 // meshDevice.Transform.World = Matrix.Multiply(locationOffset, worldTransform); //绘制网格 。。。。。。 } |
public class cModel { private cMeshObject mesh1 = null; private cMeshObject mesh2 = null; private bool modelloaded; } |
public void Load(ref Device device) { mesh1 = new Earth(ref device); mesh2 = new Earth(ref device); if (mesh1.LoadMesh(@"..\..\earth2.x")) { modelloaded = true; } else { modelloaded = false; } if (mesh2.LoadMesh(@"..\..\moon.x")) { mesh2.XLoc += 20.0f; modelloaded = true; } else { modelloaded = false; } } |
public void Update(int dir) { if(dir > 0) { mesh1.YRot += 0.02f; mesh2.YRot += 0.05f; } else if(dir < 0) { mesh1.YRot -= 0.02f; mesh2.YRot -= 0.05f; } } |
public void Render(ref Device device) { device.Transform.World = Matrix.Identity; if(modelloaded) { mesh1.Render(); mesh2.Render(); } } |
public void LoadLights(ref Device device) { device.Lights[0].Type = LightType.Directional; device.Lights[0].Diffuse = Color.White; device.Lights[0].Position = new Vector3(0.0f, 0.0f, 25.0f); device.Lights[0].Direction = new Vector3(0, 0, -1); } public void Light(ref Device device) { device.Lights[0].Update(); device.Lights[0].Enabled = true; } |
private Microsoft.DirectX.DirectInput.Device mouse = null; public System.Threading.AutoResetEvent MouseUpdated; private float x, y, z = 0.0f; private byte[] buttons; |
public CMouse(System.Windows.Forms.Control control) { mouse = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Mouse); mouse.SetCooperativeLevel(control, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive); mouse.Properties.AxisModeAbsolute = false; MouseUpdated = new System.Threading.AutoResetEvent(false); mouse.SetEventNotification(MouseUpdated); mouse.Acquire(); Update(); } |
public void Update() { MouseState state = mouse.CurrentMouseState; x = state.X; y = state.Y; z = state.Z; buttons = state.GetMouseButtons(); } |
public bool LeftButtonDown { get { bool a; return a = (buttons[0] != 0); } } |
private CModel model = null; private CMouse mouse = null; private bool leftbuttondown = false; private float mousexloc; |
public void InitializeInput() { mouse = new CMouse(this); } |
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; } } |
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(); } |
static void Main() { using (Form1 EarthForm = new Form1()) { EarthForm.InitializeGraphics(); EarthForm.InitializeInput(); EarthForm.Show(); while(EarthForm.Created) { EarthForm.Render(); Application.DoEvents(); } EarthForm.Dispose(); } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者