-
Notifications
You must be signed in to change notification settings - Fork 0
/
planes.go
71 lines (57 loc) · 1.51 KB
/
planes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package jbtracer
import (
"fmt"
"math"
)
type Plane struct {
transform *Matrix
material *Material
}
// NewPlane creates a new Plane
func NewPlane() *Plane {
return &Plane{
transform: IdentityMatrix(),
material: NewMaterial(),
}
}
// String returns a string representation of the Plane
func (a *Plane) String() string {
return fmt.Sprintf("%+v", *a)
}
// Transform returns the transform for this Plane
func (a *Plane) Transform() *Matrix {
return a.transform
}
// SetTransform sets the transform for this Plane
func (a *Plane) SetTransform(transform *Matrix) {
a.transform = transform
}
// Equal returns whether the two Planes are the same
func (a *Plane) Equal(b Shape) bool {
if sb, ok := b.(*Plane); !ok {
return false
} else {
return a != nil && sb != nil && a.transform.Equal(sb.transform) && a.material.Equal(sb.material)
}
}
// Material returns the material for this Plane
func (a *Plane) Material() *Material {
return a.material
}
// SetMaterial sets the material for this Plane
func (a *Plane) SetMaterial(material *Material) {
a.material = material
}
// Intersections returns the intersections of the provided Ray
// with the Plane
func (plane *Plane) Intersections(r *Ray) IntersectionSlice {
if math.Abs(r.Direction.Y) < Epsilon {
return nil
}
t := -1 * r.Origin.Y / r.Direction.Y
return IntersectionSlice{NewIntersection(plane, t)}
}
// NormalAt returns the surface normal to the Plane at the given Point.
func (plane *Plane) NormalAt(objectPoint *Tuple) *Tuple {
return NewVector(0, 1, 0)
}