PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/tutorial/vision/opengl/NeHe/lesson06/cube.e

http://github.com/tybor/Liberty
Specman e | 142 lines | 112 code | 29 blank | 1 comment | 1 complexity | 4988cf0fead1f7bfb1e4ba47b1314c88 MD5 | raw file
  1class CUBE
  2
  3inherit
  4	GL_OBJECT
  5
  6creation
  7	make_at_origin, make_with_position
  8
  9feature{ANY}
 10	
 11	build is
 12		do
 13			create vertices.make(24)
 14			vertices.put(create {VERTEX}.make(-1, 1, 1), 0)
 15			vertices.put(create {VERTEX}.make(-1, -1, 1), 1)
 16			vertices.put(create {VERTEX}.make(1, -1, 1), 2)
 17			vertices.put(create {VERTEX}.make(1, 1, 1), 3)
 18			vertices.put(create {VERTEX}.make(1, 1, -1), 4)
 19			vertices.put(create {VERTEX}.make(-1, 1, -1), 5)
 20			vertices.put(create {VERTEX}.make(-1, -1, -1), 6)
 21			vertices.put(create {VERTEX}.make(1, -1, -1), 7)
 22			
 23			vertices.put(create {VERTEX}.make(-1, 1, 1), 8)
 24			vertices.put(create {VERTEX}.make(-1, -1, 1), 9)
 25			vertices.put(create {VERTEX}.make(1, -1, 1), 10)
 26			vertices.put(create {VERTEX}.make(1, 1, 1), 11)
 27			vertices.put(create {VERTEX}.make(1, 1, -1), 12)
 28			vertices.put(create {VERTEX}.make(-1, 1, -1), 13)
 29			vertices.put(create {VERTEX}.make(-1, -1, -1), 14)
 30			vertices.put(create {VERTEX}.make(1, -1, -1), 15)
 31			
 32			vertices.put(create {VERTEX}.make(-1, 1, 1), 16)
 33			vertices.put(create {VERTEX}.make(-1, -1, 1), 17)
 34			vertices.put(create {VERTEX}.make(1, -1, 1), 18)
 35			vertices.put(create {VERTEX}.make(1, 1, 1), 19)
 36			vertices.put(create {VERTEX}.make(1, 1, -1), 20)
 37			vertices.put(create {VERTEX}.make(-1, 1, -1), 21)
 38			vertices.put(create {VERTEX}.make(-1, -1, -1), 22)
 39			vertices.put(create {VERTEX}.make(1, -1, -1), 23)
 40
 41			-- Here, vertices can only be shared between two facets of the same cube's face because of texture mapping
 42			facets.add_last(create {FACET}.make(vertices.item(0), vertices.item(1), vertices.item(3)))
 43			facets.add_last(create {FACET}.make(vertices.item(1), vertices.item(2), vertices.item(3)))
 44
 45			facets.add_last(create {FACET}.make(vertices.item(11), vertices.item(10), vertices.item(4)))
 46			facets.add_last(create {FACET}.make(vertices.item(10), vertices.item(7), vertices.item(4)))
 47
 48			facets.add_last(create {FACET}.make(vertices.item(5), vertices.item(6), vertices.item(8)))
 49			facets.add_last(create {FACET}.make(vertices.item(6), vertices.item(9), vertices.item(8)))
 50
 51			facets.add_last(create {FACET}.make(vertices.item(13), vertices.item(16), vertices.item(12)))
 52			facets.add_last(create {FACET}.make(vertices.item(16), vertices.item(19), vertices.item(12)))
 53
 54			facets.add_last(create {FACET}.make(vertices.item(17), vertices.item(14), vertices.item(18)))
 55			facets.add_last(create {FACET}.make(vertices.item(14), vertices.item(15), vertices.item(18)))
 56
 57			facets.add_last(create {FACET}.make(vertices.item(20), vertices.item(23), vertices.item(21)))
 58			facets.add_last(create {FACET}.make(vertices.item(23), vertices.item(22), vertices.item(21)))
 59			
 60			load_textures
 61
 62			facets.item(facets.lower + 0).set_texture(texture)
 63			facets.item(facets.lower + 0).vertex1.set_2d_texture_coord(0, 1)
 64			facets.item(facets.lower + 0).vertex2.set_2d_texture_coord(0, 0)
 65			facets.item(facets.lower + 0).vertex3.set_2d_texture_coord(1, 1)
 66
 67			facets.item(facets.lower + 1).set_texture(texture)
 68			facets.item(facets.lower + 1).vertex1.set_2d_texture_coord(0, 0)
 69			facets.item(facets.lower + 1).vertex2.set_2d_texture_coord(1, 0)
 70			facets.item(facets.lower + 1).vertex3.set_2d_texture_coord(1, 1)
 71
 72			facets.item(facets.lower + 2).set_texture(texture)
 73			facets.item(facets.lower + 2).vertex1.set_2d_texture_coord(0, 1)
 74			facets.item(facets.lower + 2).vertex2.set_2d_texture_coord(0, 0)
 75			facets.item(facets.lower + 2).vertex3.set_2d_texture_coord(1, 1)
 76
 77			facets.item(facets.lower + 3).set_texture(texture)
 78			facets.item(facets.lower + 3).vertex1.set_2d_texture_coord(0, 0)
 79			facets.item(facets.lower + 3).vertex2.set_2d_texture_coord(1, 0)
 80			facets.item(facets.lower + 3).vertex3.set_2d_texture_coord(1, 1)
 81
 82			facets.item(facets.lower + 4).set_texture(texture)
 83			facets.item(facets.lower + 4).vertex1.set_2d_texture_coord(0, 1)
 84			facets.item(facets.lower + 4).vertex2.set_2d_texture_coord(0, 0)
 85			facets.item(facets.lower + 4).vertex3.set_2d_texture_coord(1, 1)
 86
 87			facets.item(facets.lower + 5).set_texture(texture)
 88			facets.item(facets.lower + 5).vertex1.set_2d_texture_coord(0, 0)
 89			facets.item(facets.lower + 5).vertex2.set_2d_texture_coord(1, 0)
 90			facets.item(facets.lower + 5).vertex3.set_2d_texture_coord(1, 1)
 91
 92			facets.item(facets.lower + 6).set_texture(texture)
 93			facets.item(facets.lower + 6).vertex1.set_2d_texture_coord(0, 1)
 94			facets.item(facets.lower + 6).vertex2.set_2d_texture_coord(0, 0)
 95			facets.item(facets.lower + 6).vertex3.set_2d_texture_coord(1, 1)
 96
 97			facets.item(facets.lower + 7).set_texture(texture)
 98			facets.item(facets.lower + 7).vertex1.set_2d_texture_coord(0, 0)
 99			facets.item(facets.lower + 7).vertex2.set_2d_texture_coord(1, 0)
100			facets.item(facets.lower + 7).vertex3.set_2d_texture_coord(1, 1)
101
102			facets.item(facets.lower + 8).set_texture(texture)
103			facets.item(facets.lower + 8).vertex1.set_2d_texture_coord(0, 1)
104			facets.item(facets.lower + 8).vertex2.set_2d_texture_coord(0, 0)
105			facets.item(facets.lower + 8).vertex3.set_2d_texture_coord(1, 1)
106
107			facets.item(facets.lower + 9).set_texture(texture)
108			facets.item(facets.lower + 9).vertex1.set_2d_texture_coord(0, 0)
109			facets.item(facets.lower + 9).vertex2.set_2d_texture_coord(1, 0)
110			facets.item(facets.lower + 9).vertex3.set_2d_texture_coord(1, 1)
111
112			facets.item(facets.lower + 10).set_texture(texture)
113			facets.item(facets.lower + 10).vertex1.set_2d_texture_coord(0, 1)
114			facets.item(facets.lower + 10).vertex2.set_2d_texture_coord(0, 0)
115			facets.item(facets.lower + 10).vertex3.set_2d_texture_coord(1, 1)
116
117			facets.item(facets.lower + 11).set_texture(texture)
118			facets.item(facets.lower + 11).vertex1.set_2d_texture_coord(0, 0)
119			facets.item(facets.lower + 11).vertex2.set_2d_texture_coord(1, 0)
120			facets.item(facets.lower + 11).vertex3.set_2d_texture_coord(1, 1)
121		end
122	
123	load_textures is
124		local
125			image: BMP_IMG
126		do
127			create image.load_from_file("nehe.bmp")
128			if image.is_loaded then
129				create texture.make(image)
130			end
131		end
132
133	turn (angle: REAL) is
134		do
135			set_orientation(0.2 * angle, 0.3 * angle, 0.4 * angle)
136		end
137	
138feature{}
139	texture: TEXTURE_2D
140	vertices: FAST_ARRAY[VERTEX]
141
142end