Class: Stagecraft::Bounding::Plane

Inherits:
Object
  • Object
show all
Defined in:
lib/stagecraft/core/bounding.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(normal, constant) ⇒ Plane

Returns a new instance of Plane.

Raises:

  • (ArgumentError)


83
84
85
86
87
88
89
# File 'lib/stagecraft/core/bounding.rb', line 83

def initialize(normal, constant)
  length = normal.length
  raise ArgumentError, "plane normal cannot be zero" if length.zero?

  @normal = normal / length
  @constant = constant.to_f / length
end

Instance Attribute Details

#constantObject (readonly)

Returns the value of attribute constant.



81
82
83
# File 'lib/stagecraft/core/bounding.rb', line 81

def constant
  @constant
end

#normalObject (readonly)

Returns the value of attribute normal.



81
82
83
# File 'lib/stagecraft/core/bounding.rb', line 81

def normal
  @normal
end

Instance Method Details

#distance_to_point(point) ⇒ Object



91
92
93
# File 'lib/stagecraft/core/bounding.rb', line 91

def distance_to_point(point)
  normal.dot(point) + constant
end

#intersects_sphere?(sphere) ⇒ Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/stagecraft/core/bounding.rb', line 95

def intersects_sphere?(sphere)
  distance_to_point(sphere.center) >= -sphere.radius
end