Class: BoidView

Inherits:
View show all
Defined in:
ext/ruby/qtruby/examples/ruboids/ruboids/BoidView.rb

Constant Summary collapse

BODY_COLOR =
[0, 0, 0]
BEAK_COLOR =
[0.75, 0.5, 0.0]
SHADOW_COLOR =
[0.25, 0.55, 0.25]
HALF_WING_BASE =
3
HALF_LENGTH =
5
HALF_THICKNESS =
1
NOSE_LENGTH =
3
@@object =
nil
@@shadow =
nil
@@wings =
nil
@@wingsShadows =
nil

Instance Attribute Summary

Attributes inherited from View

#color, #model, #object, #shadow

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from View

#draw, #drawShadow, #shadowColorForHeight

Constructor Details

#initialize(model) ⇒ BoidView

Returns a new instance of BoidView.



26
27
28
29
30
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/BoidView.rb', line 26

def initialize(model)
	super(model, [0, 0, 0])
	@wings = nil
	@wingsShadows = nil
end

Class Method Details

.makeBodyObject



111
112
113
114
115
116
117
118
119
120
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/BoidView.rb', line 111

def BoidView.makeBody
	p0 = Point::ORIGIN.dup()
	p1 = Point::ORIGIN.dup()
	dims = Point.new(HALF_THICKNESS, HALF_THICKNESS, HALF_LENGTH)
	p0.subtractPoint(dims)
	p1.addPoint(dims)

	Color(BODY_COLOR)
	Graphics.boxFromCorners(p0, p1)
end

.makeNoseObject



145
146
147
148
149
150
151
152
153
154
155
156
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/BoidView.rb', line 145

def BoidView.makeNose()
	Color(BEAK_COLOR)
	Begin(TRIANGLE_FAN)

	Vertex(0, 0, HALF_LENGTH + NOSE_LENGTH)
	Vertex( HALF_THICKNESS,  HALF_THICKNESS, HALF_LENGTH)
	Vertex(-HALF_THICKNESS,  HALF_THICKNESS, HALF_LENGTH)
	Vertex(-HALF_THICKNESS, -HALF_THICKNESS, HALF_LENGTH)
	Vertex( HALF_THICKNESS, -HALF_THICKNESS, HALF_LENGTH)

	End()
end

.makeObjectObject



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/BoidView.rb', line 69

def BoidView.makeObject
	makeWings()

	object = GenLists(1)
	NewList(object, COMPILE)

	makeBody()
	makeNose()

	EndList()

	return object
end

.makeOneWing(len) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/BoidView.rb', line 129

def BoidView.makeOneWing(len)
	wing = GenLists(1)
	NewList(wing, COMPILE)

	Color(BODY_COLOR)
	Begin(TRIANGLES)

	Vertex(0, 0, -HALF_WING_BASE)
	Vertex(len, 0, 0)
	Vertex(0, 0, HALF_WING_BASE)

	End()
	EndList()
	return wing
end

.makeShadowObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/BoidView.rb', line 83

def BoidView.makeShadow
	@@shadow = GenLists(1)
	NewList(@@shadow, COMPILE)

	p0 = Point::ORIGIN.dup()
	p1 = Point::ORIGIN.dup()
	dims = Point.new(HALF_THICKNESS, HALF_THICKNESS, HALF_LENGTH)
	p0.subtractPoint(dims)
	p1.addPoint(dims)
	
	groundLevel = -($PARAMS['world_height'] / 2) + 1

	Color(SHADOW_COLOR)
	Begin(QUADS)
	Vertex(p1.x, groundLevel, p0.z)
	Vertex(p0.x, groundLevel, p0.z)
	Vertex(p0.x, groundLevel, p1.z)
	Vertex(p1.x, groundLevel, p1.z)
	End()
#  	Begin(TRIANGLES)
#  	Vertex(p1.x, groundLevel, p1.z)
#  	Vertex(0, groundLevel, p0.z)
#  	Vertex(p0.x, groundLevel, p1.z)
#  	End()

	EndList()
end

.makeWingsObject



122
123
124
125
126
127
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/BoidView.rb', line 122

def BoidView.makeWings
	@@wings = []
	len = -$PARAMS['boid_wing_length']
	@@wings << makeOneWing(len)
	@@wings << makeOneWing(-len)
end

Instance Method Details

#drawObjectObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/BoidView.rb', line 44

def drawObject
	super()

	angle = 0
	case model.wingFlapPos
	when 0
 angle = 60
	when 1, 7
 angle = 30
	when 2, 6
 angle = 0
	when 3, 5
 angle = -30
	when 4
 angle = -60
	end

	PushMatrix()
	Rotate(angle, 0, 0, 1)
	CallList(@wings[0])
	Rotate(angle * -2, 0, 0, 1)
	CallList(@wings[1])
	PopMatrix()
end

#makeObjectObject



32
33
34
35
36
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/BoidView.rb', line 32

def makeObject
	@@object = BoidView.makeObject() unless @@object
	@object = @@object
	@wings = @@wings
end

#makeShadowObject



38
39
40
41
42
# File 'ext/ruby/qtruby/examples/ruboids/ruboids/BoidView.rb', line 38

def makeShadow
	BoidView.makeShadow() unless @@shadow
	@shadow = @@shadow
	@wingsShadows = @@wingsShadows
end