(r Ray)
| 34 | } |
| 35 | |
| 36 | func (c *Cube) Intersect(r Ray) Hit { |
| 37 | n := c.Min.Sub(r.Origin).Div(r.Direction) |
| 38 | f := c.Max.Sub(r.Origin).Div(r.Direction) |
| 39 | n, f = n.Min(f), n.Max(f) |
| 40 | t0 := math.Max(math.Max(n.X, n.Y), n.Z) |
| 41 | t1 := math.Min(math.Min(f.X, f.Y), f.Z) |
| 42 | if t0 < 1e-3 && t1 > 1e-3 { |
| 43 | return Hit{c, t1} |
| 44 | } |
| 45 | if t0 >= 1e-3 && t0 < t1 { |
| 46 | return Hit{c, t0} |
| 47 | } |
| 48 | return NoHit |
| 49 | } |
| 50 | |
| 51 | func (c *Cube) Paths() Paths { |
| 52 | x1, y1, z1 := c.Min.X, c.Min.Y, c.Min.Z |