You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.3 KiB
Kotlin
54 lines
1.3 KiB
Kotlin
package me.eater.threedom.gl.dom
|
|
|
|
import me.eater.threedom.dom.IDocument
|
|
import me.eater.threedom.dom.Node
|
|
import org.joml.Matrix4d
|
|
import org.joml.Matrix4dc
|
|
|
|
class PerspectiveCamera(document: IDocument?) : Node<PerspectiveCamera>(document), ICamera<PerspectiveCamera> {
|
|
override fun cloneSelf(): PerspectiveCamera =
|
|
PerspectiveCamera(document)
|
|
|
|
var fieldOfView: Double = 45.0
|
|
set(value) {
|
|
field = value
|
|
updateProjection()
|
|
}
|
|
|
|
var far: Double = 100.0
|
|
set(value) {
|
|
field = value
|
|
updateProjection()
|
|
}
|
|
|
|
var near: Double = 0.1
|
|
set(value) {
|
|
field = value
|
|
updateProjection()
|
|
}
|
|
|
|
override var width: Double = 800.0
|
|
set(value) {
|
|
field = value
|
|
updateProjection()
|
|
}
|
|
|
|
override var height: Double = 600.0
|
|
set(value) {
|
|
field = value
|
|
updateProjection()
|
|
}
|
|
|
|
private fun updateProjection() {
|
|
projection = makeProjection()
|
|
}
|
|
|
|
private fun makeProjection(): Matrix4dc = Matrix4d().perspective(fieldOfView, width / height, near, far)
|
|
|
|
override var projection: Matrix4dc = makeProjection()
|
|
private set
|
|
|
|
override val view: Matrix4dc
|
|
get() = absolute
|
|
}
|