using System; using System.Windows.Forms; using Microsoft.DirectX.Direct3D; namespace blue_dish_te { /// /// Objekt pro vykreslovani stropu. Objekt si vytvori VertexBuffer a naplni jej vrcholy. /// Metoda Render vykresli buffer do zarizeni device (parametr konstruktoru) /// internal class Strop { private Device device; private VertexBuffer vb = null; private Texture t; public char type = ' '; /// /// Konstruktor vytvori VertexBuffer a naplni ho souradnicemi /// /// Reference na device do ktereho se bude kreslit public Strop(Device dev) { device = dev; //inicializace textury try { t = TextureLoader.FromFile(device, "textury/strop.jpg"); } catch (Exception e) { MessageBox.Show("Nepovedlo se nacist texturu pro strop."); Console.WriteLine(e); return; } //nacteni bodu vb = new VertexBuffer(typeof(CustomVertex.PositionNormalTextured), //buffer obsahuje pouze souradnice, normaly a nastaveni pozic na texture 5, //celkem 5 bodu device, //zarizeni pro ktere je buffer vytovren Usage.WriteOnly, //do bufferu se bude pouze zapisovat CustomVertex.PositionNormalTextured.Format, //format vrcholu Pool.Managed); //jakym zpusobem je VB zpravovan //uzamceni VB a ziskani pole CustomVertex.PositionNormalTextured[] v = (CustomVertex.PositionNormalTextured[]) vb.Lock(0, 0); //naplneni VB souradnicemi vrcholu x y z nx ny nz u v v[0] = new CustomVertex.PositionNormalTextured(2, 3, 2, 0, -1, 0, 1, 1); v[1] = new CustomVertex.PositionNormalTextured(0, 3, 2, 0, -1, 0, 0, 1); v[2] = new CustomVertex.PositionNormalTextured(2, 3, 0, 0, -1, 0, 1, 0); v[3] = new CustomVertex.PositionNormalTextured(0, 3, 2, 0, -1, 0, 0, 1); v[4] = new CustomVertex.PositionNormalTextured(0, 3, 0, 0, -1, 0, 0, 0); vb.Unlock(); //odemknuti VB } /// /// Vykresleni VertexBufferu jako trojuhelnikoveho stripu /// public void Render() { device.SetTexture(0, t); // nastaveni textury device.SetStreamSource(0, vb, 0); //nastaveni zdroje dat device.VertexFormat = CustomVertex.PositionNormalTextured.Format; //format dat device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 3); //vykresleni VB jako TriangleStrip } } }