package projectzombie.model.player;

import gl_engine.texture.TextureRef3D;
import projectzombie.init.Resources;
import projectzombie.model.Model;

public class ModelPlayerHead extends Model
{
	protected TextureRef3D hair_top, hair_front, hair_back, hair_sides;
	protected TextureRef3D head_top, head_front, head_back, head_bottom, head_sides;
	protected int head_color = 0;
	protected int hair_color = 0;
	protected int head_flags = 0;
	protected int hair_flags = 0;
	
	public ModelPlayerHead()
	{
		hair_top = Resources.ATLAS.get("/entity/player/hair_top.png");
		hair_front = Resources.ATLAS.get("/entity/player/hair_front.png");
		hair_back = Resources.ATLAS.get("/entity/player/hair_back.png");
		hair_sides = Resources.ATLAS.get("/entity/player/hair_side.png");
		
		head_top = Resources.ATLAS.get("/entity/player/head_top.png");
		head_front = Resources.ATLAS.get("/entity/player/head_front.png");
		head_back = Resources.ATLAS.get("/entity/player/head_back.png");
		head_bottom = Resources.ATLAS.get("/entity/player/head_bottom.png");
		head_sides = Resources.ATLAS.get("/entity/player/head_side.png");
	}

	@Override
	public int[] getIndicies()
	{
		int[] indicies = new int[getIndexSize()];
		
		for(int i=0;i<indicies.length/6;i++) {
			indicies[i*6+0] = i*4+0;
			indicies[i*6+1] = i*4+1;
			indicies[i*6+2] = i*4+2;
			indicies[i*6+3] = i*4+2;
			indicies[i*6+4] = i*4+3;
			indicies[i*6+5] = i*4+0;
		}
		
		return indicies;
	}

	@Override
	public float[] getVerticies()
	{
		float he_f = head_flags;
		float ha_f = hair_flags;
		float he_c = head_color;
		float ha_c = hair_color;
		
		float x = 0.25f;
		float y = x * 2;
		float z = x * 1.1f;
		float m = y * 1.1f;
		
		int asi = 1;
		int asp = 1;
		
		return new float[]
		{
				 // Head
				-x, 0,  x, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, he_c, he_f,
				 x, 0,  x, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, he_c, he_f,
				 x, y,  x, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, he_c, he_f,
				-x, y,  x, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, he_c, he_f,
				
				-x, 0, -x, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, he_c, he_f,
				 x, 0, -x, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, he_c, he_f,
				 x, y, -x, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, he_c, he_f,
				-x, y, -x, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, he_c, he_f,
				
				 x, 0, -x, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, he_c, he_f,
				 x, 0,  x, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, he_c, he_f,
				 x, y,  x, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, he_c, he_f,
				 x, y, -x, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, he_c, he_f,
				
				-x, 0, -x, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, he_c, he_f,
				-x, 0,  x, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, he_c, he_f,
				-x, y,  x, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, he_c, he_f,
				-x, y, -x, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, he_c, he_f,
				
				-x, y, -x, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, he_c, he_f,
				-x, y,  x, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, he_c, he_f,
				 x, y,  x, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, he_c, he_f,
				 x, y, -x, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, he_c, he_f,
				
				-x, 0, -x, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, he_c, he_f,
				-x, 0,  x, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, he_c, he_f,
				 x, 0,  x, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, he_c, he_f,
				 x, 0, -x, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, he_c, he_f,
				 
				 // Hair
				-z, 0,  z, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, ha_c, ha_f,
				 z, 0,  z, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, ha_c, ha_f,
				 z, m,  z, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, ha_c, ha_f,
				-z, m,  z, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, ha_c, ha_f,

				-z, 0, -z, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, ha_c, ha_f,
				 z, 0, -z, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, ha_c, ha_f,
				 z, m, -z, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, ha_c, ha_f,
				-z, m, -z, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, ha_c, ha_f,

				 z, 0, -z, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, ha_c, ha_f,
				 z, 0,  z, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, ha_c, ha_f,
				 z, m,  z, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, ha_c, ha_f,
				 z, m, -z, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, ha_c, ha_f,

				-z, 0, -z, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, ha_c, ha_f,
				-z, 0,  z, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, ha_c, ha_f,
				-z, m,  z, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, ha_c, ha_f,
				-z, m, -z, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, ha_c, ha_f,

				-z, m, -z, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, ha_c, ha_f,
				-z, m,  z, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, 1, ha_c, ha_f,
				 z, m,  z, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, ha_c, ha_f,
				 z, m, -z, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, 1, ha_c, ha_f,
		};
	}

	@Override
	public TextureRef3D[] getTextures()
	{
		return new TextureRef3D[] {
				head_front, head_front, head_front, head_front,
				head_back, head_back, head_back, head_back,
				head_sides, head_sides, head_sides, head_sides,
				head_sides, head_sides, head_sides, head_sides,
				head_top, head_top, head_top, head_top,
				head_bottom, head_bottom, head_bottom, head_bottom,
				
				hair_front, hair_front, hair_front, hair_front,
				hair_back, hair_back, hair_back, hair_back,
				hair_sides, hair_sides, hair_sides, hair_sides,
				hair_sides, hair_sides, hair_sides, hair_sides,
				hair_top, hair_top, hair_top, hair_top,
		};
	}

	@Override
	public double getWidth() {
		return 1;
	}

	@Override
	public double getHeight() {
		return 1;
	}

	@Override
	public int getIndexSize() {
		return 66;
	}

	@Override
	public int getSize() {
		return 44;
	}

}
