Skip to content

Commit 1392101

Browse files
committed
Matrices premuliplying
1 parent b1ca0d8 commit 1392101

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

common/src/main/kotlin/com/lambda/graphics/buffer/vao/IRenderContext.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
package com.lambda.graphics.buffer.vao
22

3+
import com.lambda.graphics.gl.Matrices
4+
import org.joml.Matrix4f
35
import java.awt.Color
46

57
interface IRenderContext {
68
fun vec3(x: Double, y: Double, z: Double): IRenderContext
79
fun vec2(x: Double, y: Double): IRenderContext
10+
11+
fun vec3m(x: Double, y: Double, z: Double, matrix4f: Matrix4f = Matrices.peek()): IRenderContext
12+
fun vec2m(x: Double, y: Double, matrix4f: Matrix4f = Matrices.peek()): IRenderContext
13+
814
fun float(v: Double): IRenderContext
915
fun color(color: Color): IRenderContext
1016
fun end(): Int

common/src/main/kotlin/com/lambda/graphics/buffer/vao/VAO.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.lambda.graphics.gl.VaoUtils.unbindIndexBuffer
2121
import com.lambda.graphics.gl.VaoUtils.unbindVertexArray
2222
import com.lambda.graphics.gl.VaoUtils.unbindVertexBuffer
2323
import com.lambda.threading.runGameScheduled
24+
import org.joml.*
2425
import org.lwjgl.opengl.GL30C.*
2526
import java.awt.Color
2627
import java.nio.ByteBuffer
@@ -88,6 +89,19 @@ class VAO(
8889
return this
8990
}
9091

92+
override fun vec3m(x: Double, y: Double, z: Double, matrix4f: Matrix4f): IRenderContext {
93+
// ToDo: optimize at runtime
94+
val vec = Vector4d(x, y, z, 1.0).apply(Matrix4d(matrix4f)::transform)
95+
verticesPosition += vec3(verticesPosition, vec.x, vec.y, vec.z)
96+
return this
97+
}
98+
99+
override fun vec2m(x: Double, y: Double, matrix4f: Matrix4f): IRenderContext {
100+
val vec = Vector4d(x, y, 0.0, 1.0).apply(Matrix4d(matrix4f)::transform)
101+
verticesPosition += vec2(verticesPosition, vec.x, vec.y)
102+
return this
103+
}
104+
91105
override fun float(v: Double): VAO {
92106
verticesPosition += float(verticesPosition, v)
93107
return this

0 commit comments

Comments
 (0)