示例#1
0
文件: Maths.java 项目: elsantiF/Voxel
 /**
  * Create a Transformation Matrix 2D
  *
  * @param translation Position
  * @param scale Scale
  * @return Transformation Matrix 2D
  */
 public static Matrix4f createTransformationMatrix(Vector2f translation, Vector2f scale) {
   Matrix4f matrix = new Matrix4f();
   matrix.setIdentity();
   Matrix4f.translate(translation, matrix, matrix);
   Matrix4f.scale(new Vector3f(scale.x, scale.y, 1f), matrix, matrix);
   return matrix;
 }
示例#2
0
文件: Maths.java 项目: elsantiF/Voxel
 /**
  * Create a Transformation Matrix 3D
  *
  * @param translation Position
  * @param rx Rotation X
  * @param ry Rotation Y
  * @param rz Rotation Z
  * @param scale Scale
  * @return Transformation Matrix 3D
  */
 public static Matrix4f createTransformationMatrix(
     Vector3f translation, float rx, float ry, float rz, float scale) {
   Matrix4f matrix = new Matrix4f();
   matrix.setIdentity();
   Matrix4f.translate(translation, matrix, matrix);
   Matrix4f.rotate((float) Math.toRadians(rx), new Vector3f(1, 0, 0), matrix, matrix);
   Matrix4f.rotate((float) Math.toRadians(ry), new Vector3f(0, 1, 0), matrix, matrix);
   Matrix4f.rotate((float) Math.toRadians(rz), new Vector3f(0, 0, 1), matrix, matrix);
   Matrix4f.scale(new Vector3f(scale, scale, scale), matrix, matrix);
   return matrix;
 }
示例#3
0
文件: Maths.java 项目: elsantiF/Voxel
  /**
   * Create orthographic matrix
   *
   * @param left
   * @param right
   * @param bottom
   * @param top
   * @param near
   * @param far
   * @return Matrix4f
   */
  public static Matrix4f orthographic(
      float left, float right, float bottom, float top, float near, float far) {
    Matrix4f matrix = new Matrix4f();
    matrix.m00 = 2.0f / (right - left);
    matrix.m11 = 2.0f / (top - bottom);
    matrix.m22 = 2.0f / (near - far);

    matrix.m03 = (left + right) / (left - right);
    matrix.m13 = (bottom + top) / (bottom - top);
    matrix.m23 = (far + near) / (far - near);

    matrix.m33 = 1.0f;

    return matrix;
  }
示例#4
0
文件: Maths.java 项目: elsantiF/Voxel
 /**
  * Create a View Matrix
  *
  * @param camera Camera
  * @return View Matrix
  */
 public static Matrix4f createViewMatrix(Camera camera) {
   Matrix4f viewMatrix = new Matrix4f();
   viewMatrix.setIdentity();
   Matrix4f.rotate(
       (float) Math.toRadians(camera.getPitch()), new Vector3f(1, 0, 0), viewMatrix, viewMatrix);
   Matrix4f.rotate(
       (float) Math.toRadians(camera.getYaw()), new Vector3f(0, 1, 0), viewMatrix, viewMatrix);
   Matrix4f.rotate(
       (float) Math.toRadians(camera.getRoll()), new Vector3f(0, 0, 1), viewMatrix, viewMatrix);
   Vector3f cameraPost = camera.getPosition();
   Vector3f negativeCameraPos = new Vector3f(-cameraPost.x, -cameraPost.y, -cameraPost.z);
   Matrix4f.translate(negativeCameraPos, viewMatrix, viewMatrix);
   return viewMatrix;
 }