Class: Geom::Triangle

Inherits:
Object
  • Object
show all
Defined in:
lib/geom/triangle.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vertices, texcoord = nil, normal = nil) ⇒ Triangle

Returns a new instance of Triangle.



6
7
8
9
10
11
12
13
14
# File 'lib/geom/triangle.rb', line 6

def initialize(vertices,texcoord=nil,normal=nil)
  unless vertices.length == 3
    raise "Triangle must consist of exactly 3 vertices"
  end
  @normal   = normal || Number3D.new
  @vertices = vertices
  @texcoord = texcoord
  create_normal
end

Instance Attribute Details

#normalObject

Returns the value of attribute normal.



4
5
6
# File 'lib/geom/triangle.rb', line 4

def normal
  @normal
end

#texcoordObject

Returns the value of attribute texcoord.



4
5
6
# File 'lib/geom/triangle.rb', line 4

def texcoord
  @texcoord
end

#verticesObject

Returns the value of attribute vertices.



4
5
6
# File 'lib/geom/triangle.rb', line 4

def vertices
  @vertices
end

Instance Method Details

#cloneObject



22
23
24
# File 'lib/geom/triangle.rb', line 22

def clone
  Triangle.new(@vertices.collect{|v| v.clone},@texcoord.collect{|uv| uv.clone})
end

#flip_normalObject



16
17
18
19
20
# File 'lib/geom/triangle.rb', line 16

def flip_normal
  @normal.x = -@normal.x
  @normal.y = -@normal.y
  @normal.z = -@normal.z
end