Ring Array Slave and Master Controllers

This section discusses the use of controllers within the Ring Array plug-in.

Each box object node in the circle of the Ring Array has a slave controller that positions it within the system. As mentioned previously, the slave controllers have their position and orientation set by the RingMaster. The method of a controller that the system calls to get its value (position) at a certain time is called GetValue(). The slave controller implementation looks like this:

void SlaveControl::GetValue(TimeValue t,
              void *val,
              Interval &valid,
              GetSetMethod method)
{
   assert(master);
   master->GetValue(t,val,valid,method,id);
}

This method simply calls the RingMaster's method of the same name. The RingMaster uses the id passed to know which of the nodes in the Ring Array it is returning the position of. The id, as well as the user interface parameters, determines the position and rotation angle returned from the controller.

The RingMaster implementation of GetValue() looks like this:

// ======= This method is the crux of the system plug-in ==========
// It takes an input (parent) matrix and modifies it according to the id
// passed in. This id represents the position in the Ring Array system
// of the node that is having its position set.
//
// The slave controllers that set the position and orientation of the
// Ring Array nodes call this method in their implementation of the
// method Control::GetValue().
void RingMaster::GetValue(   TimeValue t,
              void *val,
              Interval &valid,
              GetSetMethod method,
              int id)
{
   Matrix3 tmat, *mat = (Matrix3*)val;
   tmat.IdentityMatrix();
 
   // Retrieve the values of the UI parameters at the time passed in.
   floatradius = GetRad(t,valid);
   floatamplitude = GetAmp(t,valid);
   floatcycles = GetCyc(t,valid);
   floatphase = GetPhs(t,valid);
 
// Calculate the Z angle rotation for the nodes based on the number
   // of nodes in the Ring Array and the id of the node passed in.
   floatang = float(id)*TWO_PI/(float)GetNum(t,valid);
 
   // Calculate the translation of the node based on the id and the UI
   // parameters.
   tmat.Translate(Point3(radius, 0.0f,
   amplitude*(float)cos(cycles*ang + TWO_PI*phase)));
   tmat.RotateZ(ang);
 
   // There are two ways of updating a value; relative or absolute.
   // If the value is relative the calculated position is applied to
   // the input value using matrix multiplication. If the method
   // is absolute then the value is simply set to the calculated value.
   (*mat) = (method==CTRL_RELATIVE) ? tmat*(*mat) : tmat;
 
   // Make sure the UI spinners track when animating and in Motion Panel
   UpdateUI(t);
}

Thus the slave controllers do nothing more than call the master which establishes the proper values so each node is positioned properly within the ring. The above code is the basis of the Ring Array system.