package projectzombie.model;

import gl_engine.texture.TextureRef3D;
import gl_engine.vec.Vec2d;

public class ModelBox extends Model
{
	private int animationSize;
	private int animationSpeed;
	private TextureRef3D ref;
	private Vec2d size;
	protected int flags = 0;
	protected double distance = 0.125;
	
	public ModelBox(TextureRef3D ref, Vec2d size, int animationSize, int animationSpeed)
	{
		this.ref = ref;
		this.size = size;
		
		this.animationSize = animationSize;
		this.animationSpeed = animationSpeed;
	}
	
	public ModelBox(TextureRef3D tex, int animationSize, int animationSpeed) {
		this(tex, new Vec2d(1, 1), animationSize, animationSpeed);
	}
	
	public ModelBox(TextureRef3D tex, Vec2d size) {
		this(tex, size, 1, 1);
	}
	
	public ModelBox(TextureRef3D tex) {
		this(tex, new Vec2d(1, 1), 1, 1);
	}
	
	@Override
	public int getSize() {
		return 16;
	}
	
	@Override
	public int getIndexSize() {
		return 24;
	}
	
	@Override
	public float[] getVerticies()
	{
		float x = (float)size.x / 2;
		float y = (float)size.y;
		float d = (float)distance;
		
		int asi = animationSize;
		int asp = animationSpeed;
		
		return new float[]
		{
				-x, 0,  d, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, 0, flags,
				 x, 0,  d, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, 0, flags,
				 x, y,  d, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, 0, flags,
				-x, y,  d, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, 0, flags,
				
				-x, 0, -d, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, 0, flags,
				 x, 0, -d, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, 0, flags,
				 x, y, -d, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, 0, flags,
				-x, y, -d, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, 0, flags,
				
				 d, 0, -x, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, 0, flags,
				 d, 0,  x, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, 0, flags,
				 d, y,  x, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, 0, flags,
				 d, y, -x, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, 0, flags,
				
				-d, 0, -x, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, 0, flags,
				-d, 0,  x, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, 0, flags,
				-d, y,  x, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, 0, flags,
				-d, y, -x, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, 0, flags,
		};
	}
	
	@Override
	public int[] getIndicies() {
		return new int[] {
				0, 1, 2,
				2, 3, 0,
				
				4, 5, 6,
				6, 7, 4,
				
				8, 9, 10,
				10, 11, 8,
				
				12, 13, 14,
				14, 15, 12,
		};
	}
	
	@Override
	public TextureRef3D[] getTextures()
	{
		return new TextureRef3D[] {
				ref, ref, ref, ref,
				ref, ref, ref, ref,
				ref, ref, ref, ref,
				ref, ref, ref, ref,
		};
	}
	
	@Override
	public double getHeight() {
		return size.x;
	}
	
	@Override
	public double getWidth() {
		return size.y;
	}
}
