Class: RBGL::Engine::ClipSpaceClipper

Inherits:
Object
  • Object
show all
Defined in:
lib/rbgl/engine/clip_space_clipper.rb

Constant Summary collapse

CLIP_PLANES =
[
  ->(position) { position.x + position.w },
  ->(position) { position.w - position.x },
  ->(position) { position.y + position.w },
  ->(position) { position.w - position.y },
  ->(position) { position.z + position.w },
  ->(position) { position.w - position.z }
].freeze

Instance Method Summary collapse

Instance Method Details

#clip(v0, v1, v2) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/rbgl/engine/clip_space_clipper.rb', line 15

def clip(v0, v1, v2)
  polygon = [v0, v1, v2]

  CLIP_PLANES.each do |plane|
    polygon = clip_against_plane(polygon, plane)
    return [] if polygon.empty?
  end

  triangulate(polygon)
end

#clip_line(v0, v1) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/rbgl/engine/clip_space_clipper.rb', line 26

def clip_line(v0, v1)
  segment = [duplicate_vertex(v0), duplicate_vertex(v1)]

  CLIP_PLANES.each do |plane|
    segment = clip_segment_against_plane(segment, plane)
    return nil unless segment
  end

  segment
end

#visible_point?(vertex) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/rbgl/engine/clip_space_clipper.rb', line 37

def visible_point?(vertex)
  CLIP_PLANES.all? { |plane| signed_distance(vertex, plane) >= 0 }
end