public static EntityModel CreateRectangle(Vector2 size, EntityID texid) { Vector2[] vertices = new Vector2[] { new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1) }; int[] elements = new int[] { 0, 1, 2, 3, 0 }; Vector2[] uvs; int t = (int)texid; if (t < 128) { //16 x 16 float x = ((float)(t % EntityTextureSize)) / EntityTextureSize; float y = ((float)(t / EntityTextureSize)) / EntityTextureSize; float s = 1f / EntityTextureSize; float h = 1f / (EntityTextureSize * EntityTextureSize * 2); uvs = new Vector2[] { new Vector2(x + h, y + s - h), new Vector2(x + h, y + h), new Vector2(x + s - h, y + h), new Vector2(x + s - h, y + s - h) }; } else { //16 x 32 float x = ((float)(t % EntityTextureSize)) / EntityTextureSize; float y = ((float)(t / EntityTextureSize)) / EntityTextureSize; float s = 1f / EntityTextureSize; float h = 1f / (EntityTextureSize * EntityTextureSize * 2); uvs = new Vector2[] { new Vector2(x + h, y + 2 * s - h), new Vector2(x + h, y + h), new Vector2(x + s - h, y + h), new Vector2(x + s - h, y + 2 * s - h) }; } EntityVAO vao = new EntityVAO(vertices, elements, uvs); return(new EntityModel(vao, BeginMode.TriangleStrip, size)); }
public static EntityModel CreateHitboxRectangle() { Vector2[] vertices = new Vector2[] { new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 0) }; int[] elements = new int[] { 0, 1, 2, 3, 0 }; int t = (int)EntityID.HitboxOutline; float x = ((float)(t % EntityTextureSize)) / EntityTextureSize; float y = ((float)(t / EntityTextureSize)) / EntityTextureSize; float s = 1f / EntityTextureSize; float h = 1f / (EntityTextureSize * EntityTextureSize * 2); Vector2[] uvs = new Vector2[] { new Vector2(x + h, y + s - h), new Vector2(x + h, y + h), new Vector2(x + s - h, y + h), new Vector2(x + s - h, y + s - h) }; var vao = new EntityVAO(vertices, elements, uvs); return(new EntityModel(vao, BeginMode.LineStrip, new Vector2(1, 1))); }
public EntityModel(EntityVAO vao, BeginMode drawmode, Vector2 size) { this.vao = vao; this.drawmode = drawmode; this.size = size; }