ConstructBox:
PROC
[dx, dy, dz:
REAL]
RETURNS
[shape:
Shape]
~
{
AddVert:
PROC [x, y, z, u, v:
REAL] ~ {
vtx: Vertex ¬ NEW[VertexRep ¬ [point: [x, y, z], normal: norm, texture: [u, v]]];
shape.vertices ¬ G3dShape.AddToVertexSequence[shape.vertices, vtx];
};
norm: Triple;
shape ¬ NEW[ShapeRep ¬ []];
we do each face individually to preserve unique texturing information for each face
near face
norm ¬ [ 0.0, -1.0, 0.0];
AddVert[-dx, -dy, -dz, 0.0, 1.0]; -- near lower left
AddVert[-dx, -dy, dz, 0.0, 0.0]; -- near upper left
AddVert[ dx, -dy, dz, 1.0, 0.0]; -- near upper right
AddVert[ dx, -dy, -dz, 1.0, 1.0]; -- near lower right
right face
norm ¬ [1.0, 0.0, 0.0];
AddVert[ dx, -dy, -dz, 0.0, 1.0]; -- near lower right
AddVert[ dx, -dy, dz, 0.0, 0.0]; -- near upper right
AddVert[ dx, dy, dz, 1.0, 0.0]; -- far upper right
AddVert[ dx, dy, -dz, 1.0, 1.0]; -- far lower right
upper face
norm ¬ [ 0.0, 0.0, 1.0];
AddVert[-dx, -dy, dz, 0.0, 1.0]; -- near upper left
AddVert[-dx, dy, dz, 0.0, 0.0]; -- far upper left
AddVert[ dx, dy, dz, 1.0, 0.0]; -- far upper right
AddVert[ dx, -dy, dz, 1.0, 1.0]; -- near upper right
left face
norm ¬ [-1.0, 0.0, 0.0];
AddVert[-dx, dy, -dz, 0.0, 1.0]; -- far lower left
AddVert[-dx, dy, dz, 0.0, 0.0]; -- far upper left
AddVert[-dx, -dy, dz, 1.0, 0.0]; -- near upper left
AddVert[-dx, -dy, -dz, 1.0, 1.0]; -- near lower left
far face
norm ¬ [ 0.0, 1.0, 0.0];
AddVert[ dx, dy, -dz, 0.0, 1.0]; -- far lower right
AddVert[ dx, dy, dz, 0.0, 0.0]; -- far upper right
AddVert[-dx, dy, dz, 1.0, 0.0]; -- far upper left
AddVert[-dx, dy, -dz, 1.0, 1.0]; -- far lower left
lower face
norm ¬ [ 0.0, 0.0, -1.0];
AddVert[-dx, dy, -dz, 0.0, 1.0]; -- far lower left
AddVert[-dx, -dy, -dz, 0.0, 0.0]; -- near lower left
AddVert[ dx, -dy, -dz, 1.0, 0.0]; -- near lower right
AddVert[ dx, dy, -dz, 1.0, 1.0]; -- far lower right
G3dSweep.AddGeneralQuadrilateralToShape[shape, 0, 1, 2, 3]; -- near
G3dSweep.AddGeneralQuadrilateralToShape[shape, 4, 5, 6, 7]; -- right
G3dSweep.AddGeneralQuadrilateralToShape[shape, 8, 9, 10, 11]; -- upper
G3dSweep.AddGeneralQuadrilateralToShape[shape, 12, 13, 14, 15]; -- left
G3dSweep.AddGeneralQuadrilateralToShape[shape, 16, 17, 18, 19]; -- far
G3dSweep.AddGeneralQuadrilateralToShape[shape, 20, 21, 22, 23]; -- lower
RETURN[shape];
};