No center, just translated

This commit is contained in:
Crizomb 2025-09-27 04:25:17 +02:00
parent a7f8b46910
commit 2e77c2e411
2 changed files with 5 additions and 8 deletions

View file

@ -2,34 +2,31 @@ package main
// Sphere // Sphere
type Sphere struct { type Sphere struct {
center Vector3
radius float64 radius float64
material Material material Material
} }
func (s Sphere) Distance(p Vector3) (float64, Material) { func (s Sphere) Distance(p Vector3) (float64, Material) {
return p.Sub(s.center).Length() - s.radius, s.material return p.Length() - s.radius, s.material
} }
// Box // Box
type Box struct { type Box struct {
center Vector3
dimensions Vector3 dimensions Vector3
material Material material Material
} }
func (s Box) Distance(p Vector3) (float64, Material) { func (s Box) Distance(p Vector3) (float64, Material) {
q := p.Sub(s.center).Abs().Sub(s.dimensions) q := p.Abs().Sub(s.dimensions)
return q.Max(0.0).Length() + min(max(q.X, max(q.Y, q.Z)), 0.0), s.material return q.Max(0.0).Length() + min(max(q.X, max(q.Y, q.Z)), 0.0), s.material
} }
// Plane // Plane
type Plane struct { type Plane struct {
normal Vector3 normal Vector3
height float64
material Material material Material
} }
func (s Plane) Distance(p Vector3) (float64, Material) { func (s Plane) Distance(p Vector3) (float64, Material) {
return p.Dot(s.normal) - s.height, s.material return p.Dot(s.normal), s.material
} }

View file

@ -34,8 +34,8 @@ func init() {
sphereMat := RED_MAT sphereMat := RED_MAT
sphereMat.specularFac = 0.5 sphereMat.specularFac = 0.5
sphere := Sphere{Vector3{0, 100, 5}, 10, sphereMat} sphere := TranslatedSDF{Sphere{10, sphereMat}, Vector3{0, 100, 5}}
plane := Plane{Vector3{0, 0, 1}, 0, WHITE_GREY_GRID_MAT} plane := Plane{Vector3{0, 0, 1}, WHITE_GREY_GRID_MAT}
scene = SmoothUnionSDF{sphere, plane, 2} scene = SmoothUnionSDF{sphere, plane, 2}