package xaero.rotatenjump.game.graphics.model;

import java.util.Arrays;

/**
 * Created by xaero on 18/08/2017.
 */

public class RightPolygon extends Model {

    public RightPolygon(int sides){
        float[] vertexArray = new float[(sides + 1) * VERTEX_SIZE];
        short[] indexArray = new short[sides * 3];
        vertexArray[0] = vertexArray[1] = vertexArray[2] = 0;//center point
        vertexArray[7] = 1;//normal z
        System.out.println(vertexArray.length);
        for(int i = 0; i < sides; i++){
            float angle = (float) ((2f * Math.PI / sides) * i);
            vertexArray[VERTEX_SIZE * (i + 1)] = (float)Math.cos(angle);
            vertexArray[VERTEX_SIZE * (i + 1) + 1] = (float)Math.sin(angle);
            vertexArray[VERTEX_SIZE * (i + 1) + 7] = vertexArray[VERTEX_SIZE * (i + 1) + 8] =
                    vertexArray[VERTEX_SIZE * (i + 1) + 9] = vertexArray[VERTEX_SIZE * (i + 1) + 10] =
                            vertexArray[VERTEX_SIZE * (i + 1) + 11] = 1;//normal z and colour
            //vertexArray[VERTEX_SIZE * i + 2] = 0;//0 by default, so not needed
            indexArray[3 * i] = 0;//center
            indexArray[3 * i + 1] = (short)(i == 0 ? sides : i);//previous
            indexArray[3 * i + 2] = (short)(i + 1);//current
        }
        System.out.println(Arrays.toString(vertexArray));
        create(vertexArray, indexArray);
    }

}
