// ParticleCloud_Get(): void * ParticleCloud_Get( void *_inst, unsigned long vid ) { ParticleCloud_Instance *inst = (ParticleCloud_Instance *)_inst; static double fvalue = 0; static int ivalue = 0; if( inst != NULL ) { switch( vid ) { case PC_START_FRAME: fvalue = inst->GetStartTime(); return &fvalue; break; case PC_BIRTH_RATE: ivalue = inst->GetBirthRate(); return &ivalue; break; case PC_FROZEN: ivalue = inst->GetUseFrozen() ? 1 : 0; return &ivalue; break; case PC_INDICES: ivalue = inst->GetShowIndices() ? 1 : 0; return &ivalue; break; } } return NULL; }
// ParticleCloud_ChangeID(): void ParticleCloud_ChangeID( LWInstance _inst, const LWItemID *ids ) { ParticleCloud_Instance *inst = (ParticleCloud_Instance *)_inst; int i, j; for( j=0; j != (int)LWITEM_NULL; j++ ) { for( i=0; i != (int)LWITEM_NULL; i+=2 ) { if( ids[i] == inst->GetItems()[i] ) { inst->GetItems()[i] = ids[i]; break; } } } }
// ParticleCloud_Set(): en_LWXPRefreshCodes ParticleCloud_Set( void *_inst, unsigned long vid, void *value ) { ParticleCloud_Instance *inst = (ParticleCloud_Instance *)_inst; LWInstUpdate *instupdate = (LWInstUpdate *)inst->global( LWINSTUPDATE_GLOBAL, GFUSE_TRANSIENT ); en_LWXPRefreshCodes retval; if( inst != NULL ) { switch ( vid ) { case PC_START_FRAME: inst->SetStartTime( *(double *)value ); retval = LWXPRC_DFLT; break; case PC_BIRTH_RATE: inst->SetBirthRate( *(int *)value ); retval = LWXPRC_DFLT; break; case PC_FROZEN: inst->SetUseFrozen( (*(int *)value) != 0 ); retval = LWXPRC_DFLT; break; case PC_INDICES: inst->SetShowIndices( (*(int *)value) != 0 ); retval = LWXPRC_DFLT; break; default: retval = LWXPRC_NONE; break; } } instupdate( LWCUSTOMOBJ_HCLASS, _inst ); return retval; }
// ParticleCloud_NewTime(): LWError ParticleCloud_NewTime( LWInstance _inst, LWFrame frame, LWTime time ) { ParticleCloud_Instance *inst = (ParticleCloud_Instance *)_inst; inst->SetNow( frame, time ); return NULL; }
// ParticleCloud_UseItems(): const LWItemID * ParticleCloud_UseItems( LWInstance _inst ) { ParticleCloud_Instance *inst = (ParticleCloud_Instance *)_inst; return inst->GetItems(); }
// ParticleCloud_Evaluate(): void ParticleCloud_Evaluate( LWInstance _inst, const LWCustomObjAccess *access ) { ParticleCloud_Instance *inst = (ParticleCloud_Instance *)_inst; LWObjectInfo *object_info = (LWObjectInfo *)inst->global( LWOBJECTINFO_GLOBAL, GFUSE_TRANSIENT ); LWItemInfo *item_info = (LWItemInfo *)inst->global( LWITEMINFO_GLOBAL, GFUSE_TRANSIENT ); LWMeshInfoID mesh = object_info->meshInfo( inst->GetItems()[0], (inst->GetUseFrozen() ? 1 : 0) ); ParticleCloud_Point::mesh = mesh; // Get the point positions DynArray< ParticleCloud_Point * > points; mesh->scanPoints( mesh, PointScan_GetPositions, &points ); // Get the item's transformation matrix LWDVector item_position, item_right, item_up, item_forward; LWFMatrix4 M; item_info->param( inst->GetItems()[0], LWIP_POSITION, inst->GetTime(), item_position ); item_info->param( inst->GetItems()[0], LWIP_RIGHT, inst->GetTime(), item_right ); item_info->param( inst->GetItems()[0], LWIP_UP, inst->GetTime(), item_up ); item_info->param( inst->GetItems()[0], LWIP_FORWARD, inst->GetTime(), item_forward ); unsigned long i; for ( i = 0; i < 3; i++ ) { M[ 0 ][ i ] = ( float ) item_right[ i ]; M[ 1 ][ i ] = ( float ) item_up[ i ]; M[ 2 ][ i ] = ( float ) item_forward[ i ]; M[ 3 ][ i ] = ( float ) item_position[ i ]; M[ i ][ 3 ] = 0.0f; } M[ 3 ][ 3 ] = 1.0f; // Display each point LWFVector local, world; double position[3]; char buffer[10]; float color[4] = { 0.75, 1.0, 0.75, 1.0 }; access->setColor( access->dispData, color ); for( i=0; i < points.NumElements(); i++ ) { // Convert from local to world space local[0] = points[i]->position[0]; local[1] = points[i]->position[1]; local[2] = points[i]->position[2]; LWVecMath::transformp( local, M, world ); // Convert to doubles position[0] = world[0]; position[1] = world[1]; position[2] = world[2]; // Draw the point access->point( access->dispData, position, LWCSYS_WORLD ); // Draw the point index if( inst->GetShowIndices() ) { sprintf( buffer, "%d", i ); access->text( access->dispData, position, buffer, 0, LWCSYS_WORLD ); } } }