KotlinRay/src/main/kotlin/things/Plane.kt

17 lines
No EOL
478 B
Kotlin

package things
import Hit
import math.Point
import math.Ray
import math.Vector
import materials.Material
data class Plane(val point: Point, val normal: Vector, val material: Material) : Thing {
override fun intersects(ray: Ray): Hit? {
val bottom = normal dot ray.direction
if (bottom == 0.0f) return null
val t = (normal dot point - ray.origin) / bottom
if (t <= 0.0f) return null
return Hit(ray.at(t), normal, t, material)
}
}