Class: Gosu::Image

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

Instance Method Summary collapse

Instance Method Details

#draw_3d(x, y, z, options = {}) ⇒ Object

x, y and z are relative to the center of the image



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/retro_render.rb', line 21

def draw_3d(x, y, z, options = {})
	width, height = self.width, self.height
	x, y, w, h = 0.0, 0.0, 1.0, 1.0

	if options.has_key?(:rect)
		# rect uses the convention [x, y, w, h], expressed in opengl (from 0.0 to 1.0, origin on bottom-left corner)
		x, y, w, h = options[:rect][0].to_f, options[:rect][1].to_f, options[:rect][2].to_f, options[:rect][3].to_f
		x = 0.0 if x < 0.0 or x > 1.0
		y = 0.0 if y < 0.0 or y > 1.0
		w = 0.0 if w < 0.0 or w > 1.0
		h = 0.0 if h < 0.0 or h > 1.0
		width, height = w * self.width, h * self.height
	end
	
	glBindTexture(GL_TEXTURE_2D, self.gl_tex_info.tex_name)
	glEnable(GL_ALPHA_TEST)
	glPushMatrix
	glTranslate(x, y, z)
	glScale(width, height, 1.0)		
	
	if options.has_key?(:rot)
		# rot uses the convention [x, y, z], expressed in degrees
		glRotate(options[:rot][0], 1, 0, 0)
		glRotate(options[:rot][1], 0, 1, 0)
		glRotate(options[:rot][2], 0, 0, 1)
	end

	glBegin(GL_QUADS)
		self.gl_tex_info.tex_coord_2d(x, y); glVertex3f(-0.5, -0.5, 0.0)
		self.gl_tex_info.tex_coord_2d(x + w, y); glVertex3f(0.5, -0.5, 0.0)
		self.gl_tex_info.tex_coord_2d(x + w, y + h); glVertex3f(0.5, 0.5, 0.0)
		self.gl_tex_info.tex_coord_2d(x, y + h); glVertex3f(-0.5, 0.5, 0.0)
	glEnd
	glPopMatrix
	glDisable(GL_ALPHA_TEST)
end