public Area(float x, float y, float width, float height) { //conver 0 - 1 to (-1) - 1 x = 2 * x - 1; y = -2 * y + 1; width *= 2f; height *= 2f; Vector2[] verts = new Vector2[] { new Vector2(x, y), new Vector2(x, y - height), new Vector2(x + width, y), new Vector2(x + width, y - height), }; Vector2[] uvs = new Vector2[] { new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 1), new Vector2(1, 0) }; Vao = new VAO(verts); Vao.addAttributeArray(uvs, 2, 1); }
public SkyBox(string directory, string ext = ".png") { Texture = new TextureCube(directory, ext); Vector3[] positions = new Vector3[] { new Vector3(1.0f, -1.0f, -1.0f), new Vector3(1.0f, -1.0f, 1.0f), new Vector3(-1.0f, -1.0f, 1.0f), new Vector3(-1.0f, -1.0f, -1.0f), new Vector3(1.0f, 1.0f, -1.0f), new Vector3(1.0f, 1.0f, 1.0f), new Vector3(-1.0f, 1.0f, 1.0f), new Vector3(-1.0f, 1.0f, -1.0f) }; uint[] elements = new uint[] { 0, 1, 2, 3, 4, 7, 6, 5, 0, 4, 5, 1, 1, 5, 6, 2, 2, 6, 7, 3, 4, 0, 3, 7 }; Vao = new VAO(positions); Vao.addElementArray(elements); Shader = Shaders.SkyboxShader(); }
public Model(VAO _vao, Texture t) { this.Vao = _vao; this.Texture = t; this.Transform = Matrix4.Identity; this.pickColor = new Vector3(1, 0, 0); }
public Model(VAO _vao, Texture t, ShaderProgram defaultShader) { this.Shader = defaultShader; this.Vao = _vao; this.Texture = t; this.Position = new Vector3(0); this.Transform = Matrix4.Identity; this.Rotation = Matrix4.Identity; this.Scale = 1f; this.createTransform(); this.pickColor = new Vector3(1, 0, 0); }
public Billboard(ShaderProgram program, Texture texture, Vector3[] locations, Vector3[] colors) { this.Program = program; this.Texture = texture; int[] elements = new int[locations.Length]; for (int i = 0; i < elements.Length; i++) { elements[i] = i; } this.billboard = new VAO(program, new VBO <Vector3>(locations), new VBO <Vector3>(colors), new VBO <int>(elements)); this.billboard.DrawMode = BeginMode.Points; this.billboard.DisposeChildren = true; this.Color = new Vector4(1, 1, 1, 1); }
public Billboard(Material program, Texture texture, Vector3[] locations, Vector3[] colors) { Program = program; Texture = texture; uint[] elements = new uint[locations.Length]; for (uint i = 0; i < elements.Length; i++) { elements[i] = i; } billboard = new VAO(program, new VBO <Vector3>(locations), new VBO <Vector3>(colors), new VBO <uint>(elements)) { DrawMode = BeginMode.Points, DisposeChildren = true }; Color = new Vector4(1, 1, 1, 1); }
public static VAO LoadAsVAO(string path) { List <Vector3> positions = new List <Vector3>(); List <Vector2> uvs = new List <Vector2>(); List <Vector3> normals = new List <Vector3>(); List <VertexData> verts = new List <VertexData>(); hasUvs = false; hasNormals = false; if (!File.Exists(path)) { throw new FileNotFoundException(); } string[] lines = File.ReadAllLines(path); foreach (string str in lines) { if (!string.IsNullOrWhiteSpace(str) && str.Length > 2) { switch (str.Substring(0, 2)) { case "v ": parseVert(str, positions); break; case "vt": parseTexture(str, uvs); break; case "vn": parseNormal(str, normals); break; case "f ": parseFace(str, positions, uvs, normals, verts); break; } } } Console.WriteLine("Loaded file {0}, with {1} with vertices", path, verts.Count); List <Vector3> p = new List <Vector3>(); List <Vector2> u = new List <Vector2>(); List <Vector3> n = new List <Vector3>(); uint[] e = new uint[verts.Count]; Dictionary <VertexData, int> vertices = new Dictionary <VertexData, int>(); Stopwatch watch = new Stopwatch(); watch.Start(); for (int i = 0; i < verts.Count; i++) { if (!vertices.ContainsKey(verts[i])) { p.Add(verts[i].position); u.Add(verts[i].uv); n.Add(verts[i].normal); e[i] = (uint)p.Count - 1; vertices.Add(verts[i], vertices.Count); } else { e[i] = (uint)vertices[verts[i]]; } } watch.Stop(); Console.WriteLine(watch.ElapsedMilliseconds); VAO vao = new VAO(p.ToArray()); if (hasUvs) { vao.addAttributeArray(u.ToArray(), 2, 1); } if (hasNormals) { vao.addAttributeArray(n.ToArray(), 3, 2); } vao.addElementArray(e); return(vao); }