-
Notifications
You must be signed in to change notification settings - Fork 131
Open
Description
There is an optimization you can make for you Triangle type, though it sort of prevents using Triangle literals.
type Triangle struct {
V1, V2, V3 Vector
Box Box
intersection func(Ray) HIt
}
func NewTriangle(....) Triangle {
t.intersection = t.generateInsersectionFunction()
return t
}
func (t *Triangle) generateInsersectionFunction() {
// Precalculate things like determinants etc here, return the function with these pre-computed
}
func (t *Triangle) Intersection(r Ray) {
if t.intersection == nil { t.generateIntersectionFunction()}
return t.intersection(r)
}
a useful optimization if you are doing a lots of intersections.
Metadata
Metadata
Assignees
Labels
No labels