Lab 2
In this lab you will learn the following:
variables (p. 67), arrays (p. 72), matrices (p. 74), type conversions (p. 77), operators (p. 81), booleans (p. 83), relational operators (p. 85), logical operators (p. 88), looping (p. 92), scope (p. 98), global procedures (p. 103), eval command (p. 106), displaying warnings and errors (p. 122), objects (p. 127), "list all" script (p. 129), hierarchies (p. 131), transforms (p. 133).
Working methods:
Study pages 67-134 till section "Transformation matrices".
Assignment:
Write the makeBoxFromObject() function that builds a box made from multiple appearances of the object type it receives as a first parameter.
The second parameter passed to this function is the distance between the object appearances in the box.
The next 3 parameters are number of objects generated along X, Y and Z axis.
Bellow is the skeleton of the function you need to write:
proc makeBoxFromObject(
string $object, // if unsupported replaced with polyCube
int $distanceBetweenObjects, // if < 2 replaced with 2
int $numberOfObjectsAlongAxisX, // if < 2 replaced with 2
int $numberOfObjectsAlongAxisY, // if < 2 replaced with 2
int $numberOfObjectsAlongAxisZ // if < 2 replaced with 2
){
// check if distance and number of objects along each axis >= 2,
// if not set it to 2.
. . .
// check if given object is supported
. . .
// if object is not supported give a warning that it will be replaced
// by polyCube
. . .
// create a box from multiple appearances of $object,
// use $distanceBetweenObjects to set the distance
// between objects that will form the box shape
. . .
}
The function should check if the received in the first parameter object type is supported.
Supported object types are: sphere, polyCube, polyCone. If unsupported type was passed
give a warning message and replace the value with polyCube.
Notice that starting from the second parameter you also have to
check if their values are > = 2, otherwise you will not be able to construct
the box shape from the given object type. If value is < 2 replace it with 2.
Test your function with the following input:
makeBoxFromObject("poly", 3, 5, 2, 3);
As you can see "poly" is not supported, so it will be replaced with polyCube.
The warning message has to be displayed saying that poly was replaced with polyCube.
The distance between the cubes is 3 and there will be 5 cubes generated along X axis,
2 cubes along Y axis and 3 cubes along Z axis to form the shape of a box as in the
picture bellow:
Now call the function with the following parameters:
makeBoxFromObject("sphere", 0, 1, 1, 1);
This time we did pass a valid object type "sphere" so the box shape will
be made from spheres. However the distance between spheres is 0 and number of
spheres along the X, Y, Z is 1, all those values will be replaced with 2 in
order to build the box as in the picture bellow:
Finally test the function with the following input:
makeBoxFromObject("polyCone", 2, 5, 5, 5);
The function should produce something similar to the picture bellow:
Guidelines:
Tip: use arrays, eval() command to create objects with unique names so you could refer to them
and -relative attribute to move objects.