next up previous contents index
Next: Cancer Up: Linking Objects Together Previous: Link Operators

Bind

  Linking objects together creates a linked list of objects with the last object that was linked to the list at the front. However if an operation is applied to an object once other objects have been linked to it, the operation will only apply to the object at the front of the linked list. To apply an operation to all of the objects in the list the object needs to be ``bound''. This creates a new object which refers to all the objects in the list. A linked list of objects needs to be bound if you want a linear transformation, a LINK, a material or a texture to apply to all the objects that have been linked together.

  the_object = bind(the_object);

You can LINK several objects together before binding but the object that is linked to a chain must not be part of a chain. The object that it is linked to can be a chain.

For example

This show the correct order to link objects together.

  LINK(obj1, PLUS, obj2);
  LINK(obj1, PLUS, obj3);
  LINK(obj1, PLUS, obj4);
  LINK(the_scene, PLUS, shift(4, 3, 5, bind(the_object);

But this attempts to link a chain onto another object.

  LINK(obj1, PLUS, obj2);
  LINK(obj3, PLUS, obj1);
  LINK(the_scene, PLUS, obj3);

When obj1 is linked to obj3 it is an ``impure object'' as it is part of a chain. Similarly obj3 is impure when it is linked to the scene.

The warning produced is:

*** WARNING ***
link: attempt to link impure object\index{impure object}

(Objects are linked in a chain. The link command
when applied to a (possibly already chained) object
adds the object you pass it to the end of the chain
and returns the new end of the chain. This means that
the object to be added must not be part of a chain
(a 'pure' object). To turn a chain of objects into
a pure object, use the bind() command to create a
pointer that points to the chain as a single object.)

Instead the objects could be combined like this:

 
  LINK(obj1, PLUS, obj2);
  LINK(obj3, PLUS, bind(obj1));
  LINK(the_scene, PLUS, bind(obj3));

If a material, texture or transformation is applied to an unbound object, then the move will only apply to the object at the front of the list. Fig 8 shows the scene for examples 1, 2 and 3 below.

  \\example 1;
  object obj1 = new_sphere();
  object obj2 = shift(1,1,1, new_cube());
  LINK(obj1, PLUS, obj2);
  LINK(the_scene, PLUS, bind(obj1));

  \\example 2;
  object obj1 = new_sphere();
  object obj2 = shift(1,1,1, new_cube());
  LINK(obj1, PLUS, obj2);
  obj1->material = dkblue;
  obj1 = shift(1, 1, 1, obj1);
  LINK(the_scene, PLUS, bind(obj1));

  \\example 3; 
  object obj1 = new_sphere();
  object obj2 = shift(1,1,1, new_cube());
  LINK(obj1, PLUS, obj2);
  obj1 = bind(obj1);
  obj1->material = dkblue;
  obj1 = shift(1, 1, 1, obj1);
  LINK(the_scene, PLUS, obj1);

  figure224
Figure 8: When to Bind an Object

\


Sophie Day
Fri Feb 20 15:47:19 NZDT 1998