Skip to content

Commit

Permalink
Origin/Volume: Introduce support for custom origins and use in Volume
Browse files Browse the repository at this point in the history
  • Loading branch information
skalarproduktraum committed Apr 17, 2024
1 parent f277113 commit 777f600
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
9 changes: 6 additions & 3 deletions src/main/kotlin/graphics/scenery/Origin.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package graphics.scenery

import org.joml.Vector3f

/**
* Enum class to store origin information, e.g. for use with [graphics.scenery.volumes.Volume]s
*
* @author Ulrik Guenther <[email protected]>
*/
enum class Origin {
Center,
FrontBottomLeft
sealed class Origin {
object Center: Origin()

Check warning on line 11 in src/main/kotlin/graphics/scenery/Origin.kt

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/main/kotlin/graphics/scenery/Origin.kt#L11

Center is missing required documentation.
object FrontBottomLeft: Origin()

Check warning on line 12 in src/main/kotlin/graphics/scenery/Origin.kt

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/main/kotlin/graphics/scenery/Origin.kt#L12

FrontBottomLeft is missing required documentation.
class Custom(val origin: Vector3f): Origin()

Check warning on line 13 in src/main/kotlin/graphics/scenery/Origin.kt

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/main/kotlin/graphics/scenery/Origin.kt#L13

Custom is missing required documentation.
}
13 changes: 8 additions & 5 deletions src/main/kotlin/graphics/scenery/volumes/Volume.kt
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ open class Volume(
}

/** What to use as the volume's origin, scenery's default is [Origin.Center], BVV's default is [Origin.FrontBottomLeft]. **/
var origin = Origin.Center
var origin: Origin = Origin.Center

/** Rendering method */
var renderingMethod = RenderingMethod.AlphaBlending
Expand Down Expand Up @@ -1221,14 +1221,17 @@ open class Volume(
* into account.
*/
override fun composeModel() {
val shift = Vector3f(volume.getDimensions()) * (-0.5f)

model.translation(position)
model.mul(Matrix4f().set(this.rotation))
model.scale(scale)
model.scale(volume.localScale())
if (volume.origin == Origin.Center) {
model.translate(shift)
when(val o = volume.origin) {
is Origin.Center -> {
val shift = Vector3f(volume.getDimensions()) * (-0.5f)
model.translate(shift)
}
is Origin.Custom -> model.translate(o.origin)
else -> {}
}
}
}
Expand Down

0 comments on commit 777f600

Please sign in to comment.