Skip to content

Commit 22f0433

Browse files
committed
Updated readme and version number
1 parent 46ad654 commit 22f0433

File tree

3 files changed

+68
-30
lines changed

3 files changed

+68
-30
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ target/
55
# Intellij
66
.bsp/
77
.idea/
8-
*.iws
8+
*.iws
9+
10+
# Directories
11+
.DS_Store
12+
.directory

Readme.md

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,29 @@ A Scala library for vectors and matrix math.
55

66
## Project goals
77

8-
The goal of VecMatLib is to provide easy-to-use and efficient linear algebra operations.
8+
The goal of VecMatLib is to provide easy-to-use and efficient linear algebra operations, needed by any 3D application.
99

1010
Vectors and matrices structures are written in Scala to make the best use possible of Scala's operator overloading.
1111
All methods with symbolic names have an alias for better interoperability with java.
1212

13-
All operations in VecMatLib are designed to **not** modify the object on which the operation is invoked to respect the principles of purity and immutability of functional programming.
13+
All operations in VecMatLib are designed to **not** modify the object on which the operation is invoked to respect the
14+
principles of purity and immutability of functional programming.
1415

1516
## Vector math
1617

17-
The vector package offers 2-dimensional, 3-dimensional, and 4-dimensional vectors of type int, float, and double with all their basic operations.
18-
All operations do not modify the vector on which the operation is performed.
18+
The vector package offers 2-dimensional, 3-dimensional, and 4-dimensional vectors of type int, float, and double with
19+
all their basic operations. All operations do not modify the vector on which the operation is performed.
1920

2021
Scala example:
21-
22-
```scala
22+
```
2323
var a = Vec3f(1.0f, 1.0f, 1.0f)
2424
var b = Vec3f(0.5f, 0.5f, 0.5f)
2525
2626
// 'a' and 'b' will not change
2727
val c = a + b
2828
2929
// Increase 'a' by 'b'
30-
a = a + b
30+
a = a + b // or a += b
3131
3232
// Other operations
3333
val dotProduct = a dot b
@@ -36,8 +36,7 @@ val reflection = b.reflect(normal)
3636
```
3737

3838
Java example:
39-
40-
```java
39+
```
4140
Vec3f a = new Vec3f(1.0f, 1.0f, 1.0f);
4241
Vec3f b = new Vec3f(0.5f, 0.5f, 0.5f);
4342
@@ -55,20 +54,21 @@ Vec3f reflection = b.reflect(normal);
5554

5655
## Matrix math
5756

58-
The matrix package offers 2x2, 3x3, and 4x4 matrices of type int, float, and double with all their basic operations as well as methods to build matrices out of basic transformations.
59-
All operations do not modify the matrix on which the operation is performed.
57+
The matrix package offers 2x2, 3x3, and 4x4 matrices of type Int, Float, and Double with all their basic operations as
58+
well as methods to build matrices out of basic transformations. All operations do not modify the matrix on which the
59+
operation is performed.
6060

6161
The following example shows how a translation matrix is created and how the transformation is applied.
6262

63-
```scala
63+
```
6464
var position = Vec4f(x, y, z, 1.0f)
6565
val translation = Mat4f.translation(tx, ty, tz)
6666
6767
// will result in (x + tx, y + ty, z + tz, 1.0f)
6868
position = translation * position
6969
```
7070

71-
```java
71+
```
7272
Vec4f position = new Vec4f(x, y, z, 1.0f);
7373
Mat4f translation = Mat4f.translation(tx, ty, tz);
7474
@@ -79,7 +79,7 @@ position = translation.multiply(position);
7979
Matrices can be multiplied together, allowing to create more complex transformations.
8080
The same pattern can be used to create projection matrices and camera view matrices.
8181

82-
```scala
82+
```
8383
val transform = Mat4f.translation(tx, ty, tz) * Mat4f.rotation(rx, ry, rz) * Mat4f.scaling(sx, sy, sz)
8484
var point = Vec4f(x, y, z, 1.0f)
8585
@@ -89,7 +89,7 @@ var point = Vec4f(x, y, z, 1.0f)
8989
point = transform * point
9090
```
9191

92-
```java
92+
```
9393
Mat4f transform = Mat4f.translation(tx, ty, tz)
9494
.multiply(Mat4f.rotation(rx, ry, rz))
9595
.multiply(Mat4f.scaling(sx, sy, sz));
@@ -103,58 +103,92 @@ point = transform.multiply(point);
103103

104104
## Color math
105105

106-
VecMatLib also provides a structure to represent a color as four-dimensional or three-dimensional floating point tuples with values between 0.0 and 1.0.
107-
Such representation of colors resembles the one used in the [OpenGL Shading Language](https://www.khronos.org/opengl/wiki/OpenGL_Shading_Language).
106+
VecMatLib also provides a structure to represent a color as four-dimensional or three-dimensional floating point tuples
107+
with values between 0.0 and 1.0. Such representation of colors resembles the one used in the
108+
[OpenGL Shading Language](https://www.khronos.org/opengl/wiki/OpenGL_Shading_Language).
108109

109-
```scala
110+
```
110111
val white = Color3f(1.0f, 1.0f, 1.0f) // RGB #FFFFFF
111112
val green = Color3f(0.0f, 1.0f, 0.0f) // RGB #00FF00
112113
val transparentBlue = Color4f(0.0f, 0.0f, 1.0f, 0.5f) // RGBA #0000FF88
113114
```
114115

115-
Values outside the (0.0, 1.0) range are allowed.
116+
Values outside the (0.0, 1.0) range are still allowed.
117+
118+
## Quaternions
119+
120+
The quaternion package provides a `QuaternionF` and a `QuaternionD` for single-precision and double-precision
121+
quaternions respectively. Operations concerning quaternions follow the same principles as the ones concerning vectors
122+
and matrices.
123+
124+
```
125+
val eulerAngles = Vec3d(math.Pi * 0.5, 0.0, math.Pi * 0.5)
126+
val rotation = QuaternionD(eulerAngles)
127+
```
116128

117129
## Using with LWJGL
118130

119-
VecMatLib can be used together with [LWJGL](https://lwjgl.org) to set uniform variables in shaders.
131+
VecMatLib can be used together with [LWJGL](https://lwjgl.org) to build transformation matrices and set uniform
132+
variables in shaders.
120133

121134
This example first creates a 3D float vector, then loads the value into the active shader program.
122135

123-
```java
136+
```
124137
Vec3f lightPosition = new Vec3f(-3.0f, 10.0f, 6.0f);
125138
int location = GL20.glGetUniformLocation(program, "light_position");
126139
GL20.glUniform3f(location, lightPosition.x(), lightPosition.y(), lightPosition.z());
127140
```
128141

129-
An LWJGL project using VecMatLib is [LWJRE](https://github.com/LWJRE), a general purpose rendering engine written in Java.
142+
Matrices can be loaded into shaders by converting them into float buffers by using the `BufferUtils` class provided by
143+
LWJGL.
144+
145+
```
146+
FloatBuffer buffer = BufferUtils.createFloatBuffer(9);
147+
buffer.put(matrix.m00()); buffer.put(matrix.m01()); buffer.put(matrix.m02());
148+
buffer.put(matrix.m10()); buffer.put(matrix.m11()); buffer.put(matrix.m12());
149+
buffer.put(matrix.m20()); buffer.put(matrix.m21()); buffer.put(matrix.m22());
150+
GL20.glUniformMatrix3fv(location, true, buffer.flip());
151+
```
152+
153+
Note that matrices in OpenGL uses column-major matrix order, therefore the matrix must be transposed by passing `true`
154+
to the OpenGL method when it is loaded.
155+
156+
An LWJGL project using VecMatLib is [LWJRE](https://github.com/HexagonNico/LWJRE-Engine), a general purpose rendering
157+
and physics engine written in Java.
158+
159+
## Multithreading
160+
161+
Due to VecMatLib not using any internal or temporal objects during any computations, neither modifying objects on which
162+
operations are called, it can be used safely in a multithreaded application.
130163

131164
## Add VecMatLib to your project
132165

133166
### sbt
134167

135168
```
136-
libraryDependencies += "io.github.hexagonnico" % "vecmatlib" % "2.2"
169+
libraryDependencies += "io.github.hexagonnico" % "vecmatlib" % "2.3"
137170
```
138171

139172
### Maven
140173

141-
```xml
174+
```
142175
<dependency>
143176
<groupId>io.github.hexagonnico</groupId>
144177
<artifactId>vecmatlib</artifactId>
145-
<version>2.2</version>
178+
<version>2.3</version>
146179
</dependency>
147180
```
148181

149182
### Gradle
150183

151-
```groovy
152-
implementation 'io.github.hexagonnico:vecmatlib:2.2'
184+
```
185+
implementation 'io.github.hexagonnico:vecmatlib:2.3'
153186
```
154187

155188
## Contributing
156189

157190
VecMatLib was developed by a single person.
158191
Initially a university project, later completed and turned into a fully usable library.
159192

160-
Your contributions are always welcome! Please submit a pull request or open an issue if you want to contribute with bug fixes, code improvements, documentation, and better unit test coverage.
193+
Your contributions are always welcome! Please submit a pull request or open an issue if you want to contribute with bug
194+
fixes, code improvements, documentation, and better unit test coverage.

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ThisBuild / version := "2.2"
1+
ThisBuild / version := "2.3"
22

33
ThisBuild / scalaVersion := "2.13.10"
44

0 commit comments

Comments
 (0)