Skip to content

Optimization for intersections on Triangle #4

@yarbelk

Description

@yarbelk

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions