https://github.com/nickscha/geom
A lightweight geometry libary with fluent API
https://github.com/nickscha/geom
geom geometry-library glsl graphics java lwjgl math-library
Last synced: about 1 year ago
JSON representation
A lightweight geometry libary with fluent API
- Host: GitHub
- URL: https://github.com/nickscha/geom
- Owner: nickscha
- License: apache-2.0
- Created: 2017-05-21T19:24:39.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-04-16T19:02:17.000Z (about 7 years ago)
- Last Synced: 2025-02-21T14:35:52.991Z (over 1 year ago)
- Topics: geom, geometry-library, glsl, graphics, java, lwjgl, math-library
- Language: Java
- Homepage:
- Size: 134 KB
- Stars: 4
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# geom
[](https://maven-badges.herokuapp.com/maven-central/com.github.nickscha/geom)
[](http://javadoc.io/doc/com.github.nickscha/geom)



A lightweight geometry liberay with fluent API.
## Maven
```xml
com.github.nickscha
geom
0.0.2
```
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)
```java
Vec3f myObjectPosInScene = Vec3f.of(3, 5, -2);
Mat4f rotationMatrix = myObjectPosInScene.rotationMatrix();
Mat4f modelMatrix = Mat4f.modelMatrix(myObjectPosInScene);
// The view matrix is functionally equivalent to a camera. It does the
// same thing as a model matrix, but it applies the same transformations
// equally to every object in the scene. Moving the whole world 5 units
// towards us is the same as if we had walked 5 units forwards.
Mat4f viewMatrix = Mat4f.viewMatrix(myObjectPosInScene, rotationMatrix);
// We shrink the model secene to the specified ratios and define that
// objects nearer than one and farther than ten gets clipped out.
Mat4f projectionMatrix = Mat4f.projectionMatrix(90, 1024 / 860, 1, 10);
// The object to render has been moved from model to view (aka world)
// space to the projection matrix (rectangle as the screen)
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...
```java
Vec3f camera = Vec3f.of(0, 5, 5);
Vec3f modelToLookAtCamera = Vec3f.of(7, 7, 7);
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.
```java
Vec3f one = Vec3f.of(1, 1, 1);
Vec3f two = Vec3f.of(-1, -1, -1);
Vec3f normalized = one.cross(two).normalize(); // Result is 0,0,0
```
### Swizzling types
Geom provides swizzling for all types.
```java
Vec2f res = Vec3f.of(1, 2, 1).mul(2).xy();
Mat4f res = Vec3f.of(6, 2, 1).scaleMatrix();
```
### Serialization
Geom provides a general purpose serialization for all types.
```java
byte[] data = Vec3f.of(1,2,3).toBytes();
Vec3f res = Vec3f.fromBytes(data);
```