package toolbox;

import javax.vecmath.Matrix3f;
import javax.vecmath.Matrix4f;
import javax.vecmath.Vector3f;

import entities.Camera;

public class Maths {

	public static Matrix4f createTransformationMatrix(Vector3f translation, Vector3f rotation, float scale) {
		// Need to rework all of this this is really not optimum ...
		Matrix4f matrix = new Matrix4f();
		matrix.setIdentity();
		Matrix3f rotationMatX = new Matrix3f();
		rotationMatX.rotX(rotation.x);
		Matrix3f rotationMatY = new Matrix3f();
		rotationMatY.rotY(rotation.y);
		Matrix3f rotationMatZ = new Matrix3f();
		rotationMatZ.rotZ(rotation.z);
		rotationMatX.mul(rotationMatY);
		rotationMatX.mul(rotationMatZ);
		matrix.set(rotationMatX, translation, scale);
//		matrix.rotX(rotation.x);
//		matrix.rotY(rotation.y);
//		matrix.rotZ(rotation.z);
//		System.out.println("elementPosition :" + translation + " " + matrix) ;
//		matrix.setTranslation(translation);
//		matrix.setScale(scale);
		//System.out.println("elementPosition :" + translation + " " + matrix) ;
		return matrix;
	}
	public static Matrix4f createViewMatrix(Camera camera) {
		// Need to rework all of this this is really not optimum ...
		Matrix4f matrix = new Matrix4f();
		matrix.setIdentity();
		Matrix3f rotationMatX = new Matrix3f();
		rotationMatX.rotX(camera.getPitch());
		Matrix3f rotationMatY = new Matrix3f();
		rotationMatY.rotY(camera.getYaw());
		Matrix3f rotationMatZ = new Matrix3f();
		rotationMatZ.rotZ(camera.getRoll());
		rotationMatX.mul(rotationMatY);
		rotationMatX.mul(rotationMatZ);
		Vector3f camarePos = camera.getPosition();
		matrix.set(rotationMatX, new Vector3f(-camarePos.x,-camarePos.y,-camarePos.z), 1);
		return matrix;
	}
}
