import $ from 'jquery';

/**
 * Initialize the parameters
 * @param {any} context the program context
 */
export function initParams(context: any) {
	context.params = {
		distance: parseFloat(<string>$('#distance').val()) +
			parseFloat(<string>$('#distancefine').val()),
		circleSize: parseFloat(<string>$('#circlesize').val()),
		fov: parseFloat(<string>$('#fov').val()),
		length: 0,
		avg: {
			x: 0,
			y: 0,
			z: 0,
		},
		range: 0,
		rot: {
			x: parseFloat(<string>$('#rotx').val()),
			y: parseFloat(<string>$('#roty').val()),
			z: parseFloat(<string>$('#rotz').val()),
		},
		rotSpeed: parseFloat(<string>$('#rotspeed').val()),
		instanceNumber: parseFloat(<string>$('#instance').val()),
		squareRotation: 0,
		camRot: {
			x: 0,
			y: 0,
		},
		camPos: {
			x: 0,
			y: 0,
			z: 0,
		},
		keyboard: {
			w: false,
			a: false,
			s: false,
			d: false,
			space: false,
			shift: false,
		},
	};
}

/**
 * Set the program info
 * @param {any} context the program context
 */
export function setProgramInfo(context: any) {
	context.programInfo = {
		program: context.shaderProgram,
		attribLocations: {
			vertexPosition: context.gl.getAttribLocation(context.shaderProgram,
				'aVertexPosition'),
			vertexNormal: context.gl.getAttribLocation(context.shaderProgram,
				'aVertexNormal'),
			textureCoord: context.gl.getAttribLocation(context.shaderProgram,
				'aTextureCoord'),
		},
		uniformLocations: {
			projectionMatrix: context.gl.getUniformLocation(
				context.shaderProgram, 'uProjectionMatrix'),
			viewMatrix: context.gl.getUniformLocation(
				context.shaderProgram, 'uviewMatrix'),
			modelMatrix: context.gl.getUniformLocation(
				context.shaderProgram, 'umodelMatrix'),
			normalModelMatrix: context.gl.getUniformLocation(
				context.shaderProgram, 'unormalModelMatrix'),
			uSampler: context.gl.getUniformLocation(
				context.shaderProgram, 'uSampler'),
			time: context.gl.getUniformLocation(
				context.shaderProgram, 'time'),
		},
	};
}
