using System; using System.Drawing; namespace InteriorWise { public class Light : Entity { Color color = Color.White; public Light(string name) : base(name) { } public Color Color { get { return color; } set { color = value; } } public void Activate(int id) { Microsoft.DirectX.Direct3D.Light dxLight = new Microsoft.DirectX.Direct3D.Light(); dxLight.Diffuse = color; dxLight.Type = Microsoft.DirectX.Direct3D.LightType.Point; dxLight.Position = Position; dxLight.Range = 200.0f; DirectXCore.device3D.Lights[id].FromLight(dxLight); DirectXCore.device3D.Lights[id].Enabled = true; DirectXCore.device3D.Lights[id].Update(); } } }
Material mat = new Material(); mat.Diffuse = color; DirectXCore.device3D.Material = mat;
public void LoadFromXml(string file) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(file); XmlNode obj = xmlDoc.SelectSingleNode("/object"); if (obj != null) { wireFrame = bool.Parse(obj.Attributes["wireFrame"].Value); culling = bool.Parse(obj.Attributes["culling"].Value); name = obj.Attributes["name"].Value; position.X = float.Parse(obj.Attributes["x"].Value); position.Y = float.Parse(obj.Attributes["y"].Value); position.Z = float.Parse(obj.Attributes["z"].Value); localTexture = Texture.FromBitmap(DirectXCore.device3D, (Bitmap)Bitmap.FromFile(obj.Attributes["texture"].Value), Usage.AutoGenerateMipMap, Pool.Managed); XmlNode vertices = xmlDoc.SelectSingleNode("/object/vertices"); XmlNode faces = xmlDoc.SelectSingleNode("/object/faces"); mesh = new Mesh(faces.ChildNodes.Count, vertices.ChildNodes.Count, MeshFlags.Managed, CustomVertex.PositionNormalTextured.Format, DirectXCore.device3D); GraphicsStream data = mesh.LockIndexBuffer(LockFlags.None); foreach (XmlNode face in faces.ChildNodes) { data.Write(short.Parse(face.Attributes["a"].Value)); data.Write(short.Parse(face.Attributes["b"].Value)); data.Write(short.Parse(face.Attributes["c"].Value)); } mesh.UnlockIndexBuffer(); data = mesh.LockVertexBuffer(LockFlags.None); foreach (XmlNode vertex in vertices.ChildNodes) { data.Write(float.Parse(vertex.Attributes["x"].Value)); data.Write(float.Parse(vertex.Attributes["y"].Value)); data.Write(float.Parse(vertex.Attributes["z"].Value)); data.Write(0); data.Write(0); data.Write(0); data.Write(float.Parse(vertex.Attributes["u"].Value)); data.Write(float.Parse(vertex.Attributes["v"].Value)); } mesh.UnlockVertexBuffer(); } mesh.ComputeNormals(); }
ArrayList lights = new ArrayList(); public void AddLight(Light light) { lights.Add(light); }
public void Render() { if (camera == null) return; camera.Activate(); int index = 0; foreach (Light l in lights) { l.Activate(index++); } foreach (Object3D obj in objects) { obj.Render(); } }