Materials
This commit is contained in:
parent
c0c129db88
commit
f5d4a5cb7e
5 changed files with 113 additions and 106 deletions
|
|
@ -2,33 +2,33 @@ package main
|
|||
|
||||
// Sphere
|
||||
type Sphere struct {
|
||||
center Vector3
|
||||
radius float64
|
||||
color Color
|
||||
center Vector3
|
||||
radius float64
|
||||
material Material
|
||||
}
|
||||
|
||||
func (s Sphere) Distance(p Vector3) (float64, Color) {
|
||||
return p.Sub(s.center).Length() - s.radius, s.color
|
||||
func (s Sphere) Distance(p Vector3) (float64, Material) {
|
||||
return p.Sub(s.center).Length() - s.radius, s.material
|
||||
}
|
||||
|
||||
// Box
|
||||
type Box struct {
|
||||
center Vector3
|
||||
dimensions Vector3
|
||||
color Color
|
||||
material Material
|
||||
}
|
||||
|
||||
func (s Box) Distance(p Vector3) (float64, Color) {
|
||||
func (s Box) Distance(p Vector3) (float64, Material) {
|
||||
q := p.Sub(s.center).Abs().Sub(s.dimensions)
|
||||
return q.Max(0.0).Length() + min(max(q.X, max(q.Y, q.Z)), 0.0), s.color
|
||||
return q.Max(0.0).Length() + min(max(q.X, max(q.Y, q.Z)), 0.0), s.material
|
||||
}
|
||||
|
||||
type Plane struct {
|
||||
normal Vector3
|
||||
height float64
|
||||
color Color
|
||||
normal Vector3
|
||||
height float64
|
||||
material Material
|
||||
}
|
||||
|
||||
func (s Plane) Distance(p Vector3) (float64, Color) {
|
||||
return p.Dot(s.normal) + s.height, s.color
|
||||
func (s Plane) Distance(p Vector3) (float64, Material) {
|
||||
return p.Dot(s.normal) - s.height, s.material
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue