FXobject target; FXeffect effect; // ... // get first target of the effect target = fxEffectTargetFirst( effect, FX_NOFLAG ); // displace the points on the target // and cycle through the rest of the targets while( target ) { // displace the points // ... // get next target (if any) target = fxEffectTargetNext( effect, target, FX_NOFLAG ); }
while
loop above, not including the call to fxEffectTargetNext() (remember, our Callback gets called once for each target, so there's no need to manually get the next one). That leaves us with simply displacing the points of the target.FX_EFFECTSCAN( MyScanFunc, void, data ) // expands to: FXintf MyScanFunc( FXeffect effect, FXtool tool, FXobject target, void *data ) { // displace the points // ... return FX_TRUE; }
void
and data
in FX_EFFECTSCAN(). All of the Enumeration Callbacks allow you to pass yourself some data that you create. Put another way, when you start the enumeration, you can pass some data that messiah will in turn pass to your Enumeration Callback each time that it is called. The reason for this is efficency. For example lets say that there is some value that only needs to be calculated once, independent of which target is currently being deformed. It would be very inefficent for us to calculate it in our scan_func() because we would be calculating it once for each target. Instead if we could calculate it once, then pass it to our scan_func() we would keep things efficent and have that value available to us in our scan_func().void
*,
but by changing void
in FX_EFFECTSCAN() to some other data type the pointer gets cast to that type for us.// get state data from the effect MyEffectData *med = fxObjectGetTypeData( effect, FX_NOFLAG ); // start the target enumeration // with med being passed to each call of our callback fxEffectTargetScan( effect, &MyScanFunc, med, FX_NOFLAG ); // ... // Our target enumeration callback ( scan_func() ) FX_EFFECTSCAN( MyScanFunc, MyEffectData, theData ) { // now theData is a MyEffectData * that points to // our effect's state data, neat huh? // displace points // ... return FX_TRUE; }
FXobject target; FXeffect effect; FXvecd cur_pos; // ... // get the first target of the effect target = fxEffectTargetFirst( effect, FX_NOFLAG ); // get the number of points in the mesh fxMeshNumPoints( target, &num_points, FX_NOFLAG ); // tell messiah that we're going to start displacing points on this object fxDisplaceBegin( target, FX_NOFLAG ); // loop through all of the points, displacing them in Y by the current time value // (exciting effect, huh?) for( i = 0; i < num_points; i++ ) { // get the point's current position fxMeshPoint( target, i, cur_pos, FX_NOFLAG ); // add the current time to the Y value of the current position cur_pos[ypos] += NOW; // now set the point's position to this adjusted value fxDisplacePoint( target, i, cur_pos[xpos], cur_pos[ypos], cur_pos[zpos] ); } // tell messiah that we're done displacing points fxDisplaceEnd( target, FX_NOFLAG );
// remember, NOW is actually a call to fxFrameCalcGet() // so we don't want to call this for each point in the mesh FXdouble time = NOW; // start enumerating points for displacement, passing the current time fxDisplaceScan( target, FX_NULLID, FX_WEIGHT_DONTCREATE, &MyDisplaceScan, &time, FX_NOFLAG ); // ... FX_DISPLACESCAN( MyDisplaceScan, FXdouble, now ) // expands to: FXint MyDisplaceScan(FX_DisplacePoint *p, FXdouble *now) { // copy the current position to the new position FX_VEC3COPY( p->new_pos, p->cur_pos ); // same affect as the previous example, offset Y based on the time p->new_pos[ypos] += *now; return FX_TRUE; }
FXobject weightTool, target; // ... // start point enumeration, this time using weights fxDisplaceScan( target, weightTool, FX_WEIGHT_SETUP, &MyDisplaceScan, &time, FX_NOFLAG );
FX_DISPLACESCAN( MyDisplaceScan, FXdouble, now ) { // copy the current position to the new position FX_VEC3COPY( p->new_pos, p->cur_pos ); // same boring affect as before p->new_pos[ypos] += *now; // if weights are to be used, then scale the displacement by the weight if( p->flags & FX_DISPFLAG_WEIGHT ) FX_VEC3SCALE1( p->new_pos, p->weight ); return FX_TRUE; }
© 2003 pmG WorldWide,
LLC.
|
Last
Updated on Thu Jul 10 04:49:36 2003
|