Property definitions

gamnit $ Cuboid :: defaultinit
# Cuboid, or rectangular prism, with 6 faces and right angles
#
# Can be created from a `Boxed3d` using `to_mesh`.
class Cuboid
	super Mesh

	# Width, on the X axis
	var width: Float

	# Height, on the Y axis
	var height: Float

	# Depth, on the Z axis
	var depth: Float

	redef var vertices is lazy do
		var a = [-0.5*width, -0.5*height, -0.5*depth]
		var b = [ 0.5*width, -0.5*height, -0.5*depth]
		var c = [-0.5*width,  0.5*height, -0.5*depth]
		var d = [ 0.5*width,  0.5*height, -0.5*depth]

		var e = [-0.5*width, -0.5*height,  0.5*depth]
		var f = [ 0.5*width, -0.5*height,  0.5*depth]
		var g = [-0.5*width,  0.5*height,  0.5*depth]
		var h = [ 0.5*width,  0.5*height,  0.5*depth]

		var vertices = new Array[Float]
		for v in [a, c, d, a, d, b, # front
		          f, h, g, f, g, e, # back
		          b, d, h, b, h, f, # right
		          e, g, c, e, c, a, # left
		          e, a, b, e, b, f, # bottom
		          c, g, h, c, h, d  # top
				  ] do vertices.add_all v
		return vertices
	end

	redef var normals is lazy do
		var normals = new Array[Float]
		var faces_normals = [
			[0.0, 0.0, -1.0],
			[0.0, 0.0,  1.0],
			[ 1.0, 0.0, 0.0],
			[-1.0, 0.0, 0.0],
			[0.0, -1.0, 0.0],
			[0.0,  1.0, 0.0]]
		for f in faces_normals do for i in 6.times do normals.add_all f
		return normals
	end

	redef var texture_coords: Array[Float] is lazy do
		var a = [0.0, 1.0]
		var b = [1.0, 1.0]
		var c = [0.0, 0.0]
		var d = [1.0, 0.0]

		var texture_coords = new Array[Float]
		var face = [a, c, d, a, d, b]
		for i in 6.times do for v in face do texture_coords.add_all v
		return texture_coords
	end

	redef var center = new Point3d[Float](0.0, 0.0, 0.0) is lazy
end
lib/gamnit/depth/more_meshes.nit:82,1--145,3