- MEL Lecture 2
-
-
-
-
- sphere -radius 1.0 -axis
0 1 0 -name ball; move -2 2 0;
- cone -radius 1.0 -axis
0 1 0 - name cone; move 2 2 0;
-
-
-
-
-
-
-
-
- (1)
-
-
- if (frame % 10 == 0){ // page 83 (modulus) and page 86 (comparison operators)
-
-
- float $x = ball.tx;
- float $y = ball.ty;
- float $z = ball.tz;
-
-
- ball.tx = cone.tx;
- ball.ty = cone.ty;
- ball.tz = cone.tz;
-
-
- cone.tx = $x;
- cone.ty = $y;
- cone.tz = $z;
- }
-
-
-
-
-
-
-
-
-
-
- (2)
-
-
- float $ballS;
- float $coneS;
-
-
- if (frame == 0) {
- $ballS = ball.sx;
- $coneS = cone.sx;
- cone.sx = cone.sy = cone.sz
= 0.;
- }
- else {
-
-
- if (frame <= 15) {
- ball.sx = ball.sy =
ball.sz = (15. - frame) * $ballS / 14.;
- cone.sx = cone.sy =
cone.sz = (frame - 1.) * $coneS / 14.;
- }
- else if (frame <=
30) {
- ball.sx = ball.sy =
ball.sz = (30. - frame) * $coneS / 14.;
- cone.sx = cone.sy =
cone.sz = (frame - 16.) * $ballS / 14.;
- }
- }
-
-
-
-
-
-
- OR
-
-
-
-
-
-
- float $ballS;
- float $coneS;
-
-
- if (frame == 0) {
- $ballS = ball.sx;
- $coneS = cone.sx;
- cone.sx = cone.sy = cone.sz
= 0.;
- }
-
-
- if (frame >= 1 &&
frame <= 15) { // page
88 (logical operators).
- ball.sx = ball.sy = ball.sz
= (15. - frame) * $ballS / 14.;
- cone.sx = cone.sy = cone.sz
= (frame - 1.) * $coneS / 14.;
- }
-
-
- if (frame >= 16 &&
frame <= 30) {
- ball.sx = ball.sy = ball.sz
= (30. - frame) * $coneS / 14.;
- cone.sx = cone.sy = cone.sz
= (frame - 16.) * $ballS / 14.;
- }
-
-
-
-
-
-
-
-
- (3)
- sphere -radius 1.0 -axis
0 1 0 -name ball; move -4 0 0;
- sphere -radius 1.0 -axis
0 1 0 -name ball; move -2 0 0;
- sphere -radius 1.0 -axis
0 1 0 -name ball; move 0 0 0;
- sphere -radius 1.0 -axis
0 1 0 -name ball; move 2 0 0;
- sphere -radius 1.0 -axis
0 1 0 -name ball; move 4 0 0;
-
-
-
-
- (4)
- cone -radius 1.0 -axis
0 1 0 - name cone; move -4 0 0;
- cone -radius 1.0 -axis
0 1 0 - name cone; move -2 0 0;
- cone -radius 1.0 -axis
0 1 0 - name cone; move 0 0 0;
- cone -radius 1.0 -axis
0 1 0 - name cone; move 2 0 0;
- cone -radius 1.0 -axis
0 1 0 - name cone; move 4 0 0;
-
-
-
-
- (5)
- if (rand( 0., 1.) <
.5) sphere -radius 1.0 -axis 0 1 0 -name ball; else cone -radius
1.0 -axis 0 1 0 - name cone; move -4 0 0;
- if (rand( 0., 1.) <
.5) sphere -radius 1.0 -axis 0 1 0 -name ball; else cone -radius
1.0 -axis 0 1 0 - name cone; move -2 0 0;
- if (rand( 0., 1.) <
.5) sphere -radius 1.0 -axis 0 1 0 -name ball; else cone -radius
1.0 -axis 0 1 0 - name cone; move 0 0 0;
- if (rand( 0., 1.) <
.5) sphere -radius 1.0 -axis 0 1 0 -name ball; else cone -radius
1.0 -axis 0 1 0 - name cone; move 2 0 0;
- if (rand( 0., 1.) <
.5) sphere -radius 1.0 -axis 0 1 0 -name ball; else cone -radius
1.0 -axis 0 1 0 - name cone; move 4 0 0;
-
-
-
-
- (5a)
- (in scene, select all objects)
- string $obj[] = `ls -sl`;
- print $obj;
-
-
-
-
- OR
-
-
-
-
- string $obj[] = `ls "sphere"
"sphere?" "sphere??" "cone" "cone?"
"cone??"`;
- print $obj;
-
-
-
-
-
-
- (6)
- string $spheres[] = `ls
"sphere" "sphere?" "sphere??"`;
- int $numSpheres = size(
$spheres ); // page 73.
- print $numSpheres;
-
-
- string $cones[] = `ls
"cone" "cone?" "cone??"`;
- int $numCones = size(
$cones );
- print $numCones;
-
-
-
-
-
-
-
-
- (3+)
- LOOPS:
-
-
-
-
- Initialization
- Test
- Do Something
- Increment
-
-
-
-
-
-
- Initialize variable(s)
- while ( test-using-variable
is true ) {
- Do Something
- Increment variable(s)
- }
-
-
-
-
-
-
-
-
- int i = 0;
- int $x = -4;
- while ($i < 5) { //
page 93
- sphere -radius 1.0 -axis
0 1 0 -name ball; move $x 0 0;
- $x = $x + 2;
- $i = $i + 1;
- }
-
-
-
-
-
-
- OR
-
-
-
-
-
-
-
-
- int i = 0;
- int $x = -4;
- while ($i < 5) {
- sphere -radius 1.0 -axis
0 1 0 -name ball; move $x 0 0;
- $x += 2;
- $i++;
- }
-
-
-
-
-
-
- OR
-
-
-
-
-
-
-
-