项目作者: nickscha

项目描述 :
A lightweight geometry libary with fluent API
高级语言: Java
项目地址: git://github.com/nickscha/geom.git
创建时间: 2017-05-21T19:24:39Z
项目社区:https://github.com/nickscha/geom

开源协议:Apache License 2.0

下载


geom

Maven
javadoc
Build Status
codecov.io
License

A lightweight geometry liberay with fluent API.

Maven

  1. <dependency>
  2. <groupId>com.github.nickscha</groupId>
  3. <artifactId>geom</artifactId>
  4. <version>0.0.2</version>
  5. </dependency>

The artifact is published under https://oss.sonatype.org

Supported Types

Class names are aligned with GLSL names.

Type Components Progress
Vectors Vec1f, Vec2f, Vec3f, Vec4f 80%
Vec1d, Vec2d, Vec3d, Vec4d 80%
Matrices Mat3f, Mat4f 60%
Mat3d, Mat4d 60%
Quaternions Quatf 40%
Quatd 40%
Transform Transf, Transd 20%

Roadmap version 0.0.3

  • Add cascading Transform (Transf) class for translating, scaling and rotating matrices based on their parent matrices.
  • Enhance Javadocs

Requirements

  • Java 8 or later

Examples

For more examples have a look at the src/test/resources/demo directory.

MVP (Model View Projection Matrix)

  1. Vec3f myObjectPosInScene = Vec3f.of(3, 5, -2);
  2. Mat4f rotationMatrix = myObjectPosInScene.rotationMatrix();
  3. Mat4f modelMatrix = Mat4f.modelMatrix(myObjectPosInScene);
  4. // The view matrix is functionally equivalent to a camera. It does the
  5. // same thing as a model matrix, but it applies the same transformations
  6. // equally to every object in the scene. Moving the whole world 5 units
  7. // towards us is the same as if we had walked 5 units forwards.
  8. Mat4f viewMatrix = Mat4f.viewMatrix(myObjectPosInScene, rotationMatrix);
  9. // We shrink the model secene to the specified ratios and define that
  10. // objects nearer than one and farther than ten gets clipped out.
  11. Mat4f projectionMatrix = Mat4f.projectionMatrix(90, 1024 / 860, 1, 10);
  12. // The object to render has been moved from model to view (aka world)
  13. // space to the projection matrix (rectangle as the screen)
  14. Mat4f mvpMatrix = Mat4f.mvpMatrix(modelMatrix, viewMatrix, projectionMatrix);

Look at

Imagine an object in your 3d scene which should look always to your camera.
Here we resolve the roatation matrix for the model…

  1. Vec3f camera = Vec3f.of(0, 5, 5);
  2. Vec3f modelToLookAtCamera = Vec3f.of(7, 7, 7);
  3. Mat4f.lookAtMatrix(camera, modelToLookAtCamera, Vec3f.of(0, 1, 0));

Calculating Normals based on two vectors

In this demo we will calculate the normal vector based on two supplied vectors.

  1. Vec3f one = Vec3f.of(1, 1, 1);
  2. Vec3f two = Vec3f.of(-1, -1, -1);
  3. Vec3f normalized = one.cross(two).normalize(); // Result is 0,0,0

Swizzling types

Geom provides swizzling for all types.

  1. Vec2f res = Vec3f.of(1, 2, 1).mul(2).xy();
  2. Mat4f res = Vec3f.of(6, 2, 1).scaleMatrix();

Serialization

Geom provides a general purpose serialization for all types.

  1. byte[] data = Vec3f.of(1,2,3).toBytes();
  2. Vec3f res = Vec3f.fromBytes(data);