//************************************ // Method: PWOverlapSphereCB // FullName: PWOverlapSphereCB // Access: public // Returns: CKERROR // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ CKERROR PWOverlapSphereCB(const CKBehaviorContext& behcontext) { CKBehavior *beh = behcontext.Behavior; switch(behcontext.CallbackMessage) { case CKM_BEHAVIORATTACH: case CKM_BEHAVIORLOAD: case CKM_BEHAVIORSETTINGSEDITED: { DWORD groups; beh->GetLocalParameterValue(bbS_Groups,&groups); beh->EnableInputParameter(bbI_Groups,groups); DWORD mask; beh->GetLocalParameterValue(bbS_Mask,&mask); beh->EnableInputParameter(bbI_Mask,mask); } break; } return CKBR_OK; }
//************************************ // Method: PBPhysicalizeCB // FullName: PBPhysicalizeCB // Access: public // Returns: CKERROR // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ CKERROR PBPhysicalizeCB(const CKBehaviorContext& behcontext) { CKBehavior *beh = behcontext.Behavior; switch(behcontext.CallbackMessage) { case CKM_BEHAVIORATTACH: case CKM_BEHAVIORLOAD: case CKM_BEHAVIORSETTINGSEDITED: { DWORD useDWorld; beh->GetLocalParameterValue(bbS_USE_DEFAULT_WORLD,&useDWorld); beh->EnableInputParameter(bbI_TargetWorld,!useDWorld); /* DWORD useDWorldSS; beh->GetLocalParameterValue(bbS_USE_WORLD_SLEEP_SETTINGS,&useDWorldSS); beh->EnableInputParameter(bbI_SleepSettings,!useDWorldSS); DWORD useDWorldDS; beh->GetLocalParameterValue(bbS_USE_WORLD_DAMPING_SETTINGS,&useDWorldDS); beh->EnableInputParameter(bbI_DampingSettings,!useDWorldDS); */ DWORD useDWorldM; beh->GetLocalParameterValue(bbS_USE_WORLD_MATERIAL,&useDWorldM); beh->EnableInputParameter(bbI_Material,!useDWorldM); } break; } return CKBR_OK; }
//************************************ // Method: PJRevoluteCB // FullName: PJRevoluteCB // Access: public // Returns: CKERROR // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ CKERROR PJRevoluteCB(const CKBehaviorContext& behcontext) { CKBehavior *beh = behcontext.Behavior; switch(behcontext.CallbackMessage) { case CKM_BEHAVIORATTACH: case CKM_BEHAVIORLOAD: case CKM_BEHAVIORSETTINGSEDITED: { DWORD twistLimit; beh->GetLocalParameterValue(1,&twistLimit); beh->EnableInputParameter(bbI_HighLimit,twistLimit); beh->EnableInputParameter(bbI_LowLimit,twistLimit); DWORD springSwing; beh->GetLocalParameterValue(0,&springSwing); beh->EnableInputParameter(bbI_Spring,springSwing); DWORD motor; beh->GetLocalParameterValue(2,&motor); beh->EnableInputParameter(bbI_Motor,motor); break; } } return CKBR_OK; }
/* ******************************************************************* * Function: int RetrieveCICB( const CKBehaviorContext& behaviorContext ) * * Description : The Behavior Callback function is called by Virtools when various events happen * in the life of a BuildingBlock. Exactly which events trigger a call to the * Behavior Callback function is defined in the Behavior Prototype, along with the * declaration of the function pointer * * Parameters : * behaviourContext r Behavior context reference, which gives * access to frequently used global objects * ( context, level, manager, etc... ) * * Returns : int, The return value of the callback function should be one of the CK_BEHAVIOR_RETURN values. * ******************************************************************* */ CKERROR RetrieveCICB(const CKBehaviorContext& behcontext) { /************************************************************************/ /* collecting data : */ /* */ CKBehavior *beh = behcontext.Behavior; CKContext* ctx = beh->GetCKContext(); CKParameterManager *pm = static_cast<CKParameterManager*>(ctx->GetParameterManager()); /************************************************************************/ /* process virtools callbacks : */ /* */ switch(behcontext.CallbackMessage) { case CKM_BEHAVIOREDITED: case CKM_BEHAVIORSETTINGSEDITED: { assert(beh && ctx); BOOL getAsString,outputAttriubtes = false; beh->GetLocalParameterValue(BEH_SETTINGS_GET_AS_STRING,&getAsString); beh->GetLocalParameterValue(BEH_SETTINGS_GET_CUSTOM_ATTRIBUTES,&outputAttriubtes); ////////////////////////////////////////////////////////////////////////// // get ci by string if(getAsString) { CKParameterOut* ciValue = beh->GetOutputParameter(0); ciValue->SetType(pm->ParameterGuidToType(CKPGUID_STRING)); } if(outputAttriubtes) { beh->CreateOutputParameter("Default Value",CKPGUID_STRING); beh->CreateOutputParameter("Unique name",CKPGUID_STRING); beh->CreateOutputParameter("Description",CKPGUID_STRING); beh->CreateOutputParameter("Runtime flags",CIPRTFLAGSGUID); beh->CreateOutputParameter("Type",CKPGUID_PARAMETERTYPE); } int p_count = beh->GetOutputParameterCount(); while( (outputAttriubtes ? BEH_OUT_MAX_COUNT : BEH_OUT_MIN_COUNT ) < p_count ) { CKDestroyObject( beh->RemoveOutputParameter( --p_count) ); } } } return CKBR_OK; }
/* ******************************************************************* * Function: int BehaviourFunction( const CKBehaviorContext& behaviorContext ) * * Description : The execution function is the function that will be called * during the process loop of the behavior engine, if the behavior * is defined as using an execution function. This function is not * called if the behavior is defined as a graph. This function is the * heart of the behavior: it should compute the essence of the behavior, * in an incremental way. The minimum amount of computing should be * done at each call, to leave time for the other behaviors to run. * The function receives the delay in milliseconds that has elapsed * since the last behavioral process, and should rely on this value to * manage the amount of effect it has on its computation, if the effect * of this computation relies on time. * * Paramters : * behaviourContext r Behavior context reference, which gives access to * frequently used global objects ( context, level, manager, etc... ) * * Returns : int, If it is done, it should return CKBR_OK. If it returns * CKBR_ACTIVATENEXTFRAME, the behavior will again be called * during the next process loop. * ******************************************************************* */ int CGBLBuildCommand::BehaviourFunction(const CKBehaviorContext& behaviorContext) { CKBehavior* behavior = behaviorContext.Behavior; CKContext* context = behaviorContext.Context; if( behavior->IsInputActive(EGBLBuildCommandBehInputs::BuildCommand) ) { DeactivateInputs(behaviorContext); DeactivateOutputs(behaviorContext); return DoBuildCommand (behaviorContext); } if( behavior->IsInputActive(EGBLBuildCommandBehInputs::CancelOperation)) { DeactivateInputs(behaviorContext); DeactivateOutputs(behaviorContext); ClearParameterOutputs (behaviorContext); int stateValue = EGBLBuildCommandState::Initial; behavior->SetLocalParameterValue (gblBuildCommandStateLocalPos, &stateValue); int initialParameterPosition = 0; behavior->SetLocalParameterValue (currentParameterPositionLocalPos, &initialParameterPosition); char *emptyString = ""; behavior->SetLocalParameterValue(commandStringLocalPos, emptyString, strlen(emptyString)+1); behavior->ActivateOutput (EGBLBuildCommandBehOutputs::Cancelled); } if( behavior->IsInputActive(EGBLBuildCommandBehInputs::ReadNextParameterValue)) { DeactivateInputs(behaviorContext); DeactivateOutputs(behaviorContext); int stateValue = 0; behavior->GetLocalParameterValue (gblBuildCommandStateLocalPos, &stateValue); if (! ( (stateValue == EGBLBuildCommandState::AwaitingParametersForUntargeted) || (stateValue == EGBLBuildCommandState::AwaitingParametersForNetwork) || (stateValue == EGBLBuildCommandState::GetTargets) ) ) { int stateValue = EGBLBuildCommandState::Initial; behavior->SetLocalParameterValue (gblBuildCommandStateLocalPos, &stateValue); int initialParameterPosition = 0; behavior->SetLocalParameterValue (currentParameterPositionLocalPos, &initialParameterPosition); char *emptyString = ""; behavior->SetLocalParameterValue(commandStringLocalPos, emptyString, strlen(emptyString)+1); CKParameterOut *parameterOutError = behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetError); TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLFC_ERROR_BUILDCOMMAND_INVALID_STATE,GBLFC_ERROR_BUILDCOMMAND_INVALID_STATE_DESC); behavior->ActivateOutput (EGBLBuildCommandBehOutputs::Error); } return DoReadNextParameterValue (behaviorContext); } return CKBR_OK; }
int TextureSinus(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; // we get the amount value float xamp=0.1f; beh->GetInputParameterValue(0, &xamp); // we get the amount value float yamp=0.1f; beh->GetInputParameterValue(1, &yamp); float l= 1.0f; beh->GetInputParameterValue(2, &l); // we get the saved uv's VxUV* savedUV = (VxUV*) beh->GetLocalParameterReadDataPtr(0); // we get the interpolated mesh CKMesh *mesh = (CKMesh*) beh->GetInputParameterObject(4); int channel = -1; beh->GetInputParameterValue(3, &channel); int channelcount = mesh->GetChannelCount(); if (channel < -1 || channel >= channelcount) { beh->ActivateInput(0, FALSE); beh->ActivateOutput(0); return CKBR_PARAMETERERROR; } CKDWORD Stride; VxUV *uvarray = (VxUV*) mesh->GetModifierUVs(&Stride,channel); int pointsNumber = mesh->GetModifierUVCount(channel); float time; beh->GetLocalParameterValue(1, &time); float t; for( int i=0 ; i<pointsNumber ; i++, uvarray =(VxUV *)((BYTE *)uvarray + Stride)) { t = ((float)i/pointsNumber-0.5f)*4.0f+time*l; uvarray->u = savedUV[i].u + ( 0.5f - savedUV[i].u ) * xamp * cosf(t); uvarray->v = savedUV[i].v + ( 0.5f - savedUV[i].v ) * yamp * sinf(t); } mesh->ModifierUVMove(channel); float pi = 3.1415926535f; time += behcontext.DeltaTime * 0.001f; if(l*time > 2*pi) time -= (2*pi / l); beh->SetLocalParameterValue(1, &time); beh->ActivateInput(0, FALSE); beh->ActivateOutput(0); return CKBR_OK; }
CKERROR GeneralCameraOrbitCallback(const CKBehaviorContext& context) { CKBehavior* beh = context.Behavior; switch(context.CallbackMessage) { case CKM_BEHAVIORCREATE: case CKM_BEHAVIORLOAD: { VxVector InitialAngles(INF,INF,INF); beh->SetLocalParameterValue(LOCAL_INIT,&InitialAngles); VxVector RotationAngles(0,0,0); beh->SetLocalParameterValue(LOCAL_ROT,&RotationAngles); } break; case CKM_BEHAVIORSETTINGSEDITED: { // Update the needed input for "returns" CKBOOL Returns = TRUE; beh->GetLocalParameterValue(LOCAL_RETURN,&Returns); beh->EnableInputParameter(IN_SPEED_RETURN, Returns); // Updates the needed inputs for limiting the move CKBOOL Limited = TRUE; beh->GetLocalParameterValue(LOCAL_LIMITS,&Limited); beh->EnableInputParameter(IN_MIN_H,Limited); beh->EnableInputParameter(IN_MAX_H,Limited); beh->EnableInputParameter(IN_MIN_V,Limited); beh->EnableInputParameter(IN_MAX_V,Limited); beh->EnableInputParameter(IN_MIN_ZOOM,Limited); beh->EnableInputParameter(IN_MAX_ZOOM,Limited); } break; default: break; } return CKBR_OK; }
int MidiEvent(const CKBehaviorContext& behcontext) { CKBehavior *beh = behcontext.Behavior; if( beh->IsInputActive(1) ){ // OFF beh->ActivateInput(1, FALSE); return CKBR_OK; } CKBOOL combiWasOK = FALSE; if( beh->IsInputActive(0) ){ // ON beh->ActivateInput(0, FALSE); beh->SetLocalParameterValue(0, &combiWasOK); } else { beh->GetLocalParameterValue(0, &combiWasOK); } MidiManager *mm = (MidiManager *) behcontext.Context->GetManagerByGuid( MIDI_MANAGER_GUID ); // Channel int channel=0; beh->GetInputParameterValue(0, &channel); int note, count = beh->GetInputParameterCount(); //--- test if all input notes are activated or not for( int a=1 ; a<count ; a++ ){ beh->GetInputParameterValue(a, ¬e); if( !mm->IsNoteActive(note, channel) ) break; } if( a==count ){ // All notes are pressed if( !combiWasOK ){ beh->ActivateOutput(0); combiWasOK = TRUE; beh->SetLocalParameterValue(0, &combiWasOK); return CKBR_ACTIVATENEXTFRAME; } } else { // Not all notes are pressed if( combiWasOK ){ beh->ActivateOutput(1); combiWasOK = FALSE; beh->SetLocalParameterValue(0, &combiWasOK); return CKBR_ACTIVATENEXTFRAME; } } return CKBR_ACTIVATENEXTFRAME; }
/* ******************************************************************* * Function: int CISIteratorCB( const CKBehaviorContext& behaviorContext ) * * Description : The Behavior Callback function is called by Virtools when various events happen * in the life of a BuildingBlock. Exactly which events trigger a call to the * Behavior Callback function is defined in the Behavior Prototype, along with the * declaration of the function pointer * * Parameters : * behaviourContext r Behavior context reference, which gives * access to frequently used global objects * ( context, level, manager, etc... ) * * Returns : int, The return value of the callback function should be one of the CK_BEHAVIOR_RETURN values. * ******************************************************************* */ CKERROR CISIteratorCB(const CKBehaviorContext& behcontext) { /************************************************************************/ /* collecting data : */ /* */ CKBehavior *beh = behcontext.Behavior; CKContext* ctx = beh->GetCKContext(); CKParameterManager *pm = static_cast<CKParameterManager*>(ctx->GetParameterManager()); CGBLCIConfigurationController* cman=(CGBLCIConfigurationController*)ctx->GetManagerByGuid(CONFIGURATION_MAN_GUID); /************************************************************************/ /* process virtools callbacks : */ /* */ switch(behcontext.CallbackMessage) { case CKM_BEHAVIORRESET: { CKDataArray *array = NULL; beh->SetLocalParameterValue(BEH_LOCAL_PAR_INDEX_CIID_LIST,&array); break; } case CKM_BEHAVIOREDITED: case CKM_BEHAVIORSETTINGSEDITED : { assert(beh && ctx); BOOL getFromDB = false; beh->GetLocalParameterValue(BEH_LOCAL_PAR_INDEX_DB_MODE,&getFromDB); if( getFromDB && ( beh->GetInputParameterCount() == BEH_IN_INDEX_MIN_COUNT ) ) { beh->CreateInputParameter("CIS ID", CKPGUID_INT); } ////////////////////////////////////////////////////////////////////////// //remove all pIns : int p_count = beh->GetInputParameterCount(); while( (getFromDB ? BEH_IN_INDEX_MAX_COUNT : BEH_IN_INDEX_MIN_COUNT ) < p_count ) { CKDestroyObject( beh->RemoveInputParameter( --p_count) ); } break; } } return CKBR_OK; }
bool pRayCastReport::onHit(const NxRaycastHit& hit) { CKBehavior *beh =(CKBehavior*)GetPMan()->m_Context->GetObject(mCurrentBehavior); if ( beh ) { pRayCastHits *carray = NULL; beh->GetLocalParameterValue(0,&carray); if (carray) { //carray->clear(); }else { carray = new pRayCastHits(); } //carray->push_back(const_cast<NxRaycastHit&>(&hit)); NxRaycastHit *_hit = new NxRaycastHit(); _hit->distance = hit.distance; _hit->faceID = hit.faceID; _hit->flags = hit.flags; _hit->internalFaceID = hit.internalFaceID; _hit->materialIndex = hit.materialIndex; _hit->shape = hit.shape; _hit->u = hit.u; _hit->v = hit.v; _hit->worldImpact = hit.worldImpact; _hit->worldNormal = hit.worldNormal; const char *name = hit.shape->getName(); carray->push_back(_hit); beh->SetLocalParameterValue(0,&carray); } return true; }
//************************************ // Method: PBGet2CB // FullName: PBGet2CB // Access: public // Returns: CKERROR // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ CKERROR PBGet2CB(const CKBehaviorContext& behcontext) { CKBehavior *beh = behcontext.Behavior; switch(behcontext.CallbackMessage) { case CKM_BEHAVIORATTACH: case CKM_BEHAVIORLOAD: case CKM_BEHAVIORSETTINGSEDITED: { DWORD collGroup; beh->GetLocalParameterValue(bbI_CollisionGroup,&collGroup); beh->EnableOutputParameter(bbI_CollisionGroup,collGroup); DWORD kinematic; beh->GetLocalParameterValue(bbI_Kinematic,&kinematic); beh->EnableOutputParameter(bbI_Kinematic,kinematic); DWORD grav; beh->GetLocalParameterValue(bbI_Gravity,&grav); beh->EnableOutputParameter(bbI_Gravity,grav); DWORD coll; beh->GetLocalParameterValue(bbI_Collision,&coll); beh->EnableOutputParameter(bbI_Collision,coll); DWORD mOff; beh->GetLocalParameterValue(bbI_MassOffset,&mOff); beh->EnableOutputParameter(bbI_MassOffset,mOff); DWORD pOff; beh->GetLocalParameterValue(bbI_ShapeOffset,&pOff); beh->EnableOutputParameter(bbI_ShapeOffset,pOff); } break; } return CKBR_OK; }
int GeneralCameraOrbit(const CKBehaviorContext& behcontext,INPUTPROCESSFUNCTION InputFunction) { // Get the behavior CKBehavior* beh = behcontext.Behavior; float delta = behcontext.DeltaTime; // Current state of the behavior CKBOOL stopping; // Indicates the behavior we are stopping if returns, stop otherwise CKBOOL Returns = TRUE; beh->GetLocalParameterValue(LOCAL_RETURN,&Returns); // Stop Entrance, we stop if (beh->IsInputActive(1)) { // Set IO State beh->ActivateInput(1,FALSE); // A protection in case we stop the behavior before having started it VxVector InitialAngles; beh->GetLocalParameterValue(LOCAL_INIT,&InitialAngles); // Get current position VxVector RotationAngles; beh->GetLocalParameterValue(LOCAL_ROT,&RotationAngles); // Stopping Now stopping = TRUE; beh->SetLocalParameterValue(LOCAL_STOPPING,&stopping); if ( !Returns || ((RotationAngles.x == 0) && (RotationAngles.y == 0)) ) { beh->ActivateOutput(1,TRUE); return CKBR_OK; } } // Gets the current camera CKCamera *Camera = (CKCamera *) beh->GetTarget(); if( !Camera ) return CKBR_OWNERERROR; // Gets the target informations VxVector TargetPosition; beh->GetInputParameterValue(IN_TARGET_POS,&TargetPosition); CK3dEntity* TargetRef = (CK3dEntity*)beh->GetInputParameterObject(IN_TARGET_REF); ////////////////////////////////////////////// // Gets the input parameters of the behavior ////////////////////////////////////////////// VxVector InitialAngles(0,0,0), RotationAngles(0,0,0); // First entrance, sets the initial values here only if (beh->IsInputActive(0)) { // Sets IO State beh->ActivateInput(0,FALSE); beh->ActivateOutput(0,TRUE); // Not Stopping stopping = FALSE; beh->SetLocalParameterValue(LOCAL_STOPPING,&stopping); // Compute the Initial Angles, the radius VxVector InitialPosition; Camera->GetPosition(&InitialPosition, TargetRef); InitialPosition -= TargetPosition; InitialAngles.z = Magnitude(InitialPosition); if ( InitialAngles.z == 0.0f ) { InitialAngles.x = 0.0f; InitialAngles.y = 0.0f; } else { // Vertical Polar Angle float d; InitialPosition.Normalize(); d = DotProduct(InitialPosition,VxVector::axisY()); // bound the value of d to avoid errors due to precision. if (d < -1) d = -1; else if (d > 1) d = 1; InitialAngles.y = acosf(d); // Horizontal Polar Angle InitialPosition.y = 0; if ( (InitialPosition.x == 0.0f) && (InitialPosition.y == 0.0f) && (InitialPosition.z == 0.0f) ) InitialAngles.x = PI/2; else { InitialPosition.Normalize(); d = DotProduct(InitialPosition,VxVector::axisX()); // bound the value of d to avoid eroors due to precision. if (d < -1) d = -1; else if (d > 1) d = 1; InitialAngles.x = acosf(d); d = DotProduct(InitialPosition,VxVector::axisZ()); if (d < 0) InitialAngles.x *= -1; } // In case the camera has the head down, we need to inverse the commands when we go // Up otherwise, the user will have the feeling to turn on the wrong direction. VxVector CamUp; Camera->GetOrientation(NULL,&CamUp,NULL,NULL); if ( CamUp.y < 0 ) { InitialAngles.x += PI; InitialAngles.y *= -1; InitialAngles.x = (float)fmod(InitialAngles.x,2*PI); } } // Reset stopping stopping = FALSE; // Sets the values in memory beh->SetLocalParameterValue(LOCAL_INIT,&InitialAngles); beh->SetLocalParameterValue(LOCAL_ROT,&RotationAngles); beh->SetLocalParameterValue(LOCAL_STOPPING,&stopping); // Only initialization on "On" entrance return CKBR_ACTIVATENEXTFRAME; } // Auto-activation of the behavior beh->GetLocalParameterValue(LOCAL_INIT,&InitialAngles); beh->GetLocalParameterValue(LOCAL_ROT,&RotationAngles); beh->GetLocalParameterValue(LOCAL_STOPPING,&stopping); // Get the input manager CKInputManager *input = (CKInputManager*)behcontext.Context->GetManagerByGuid(INPUT_MANAGER_GUID); // Call the input processing function InputFunction (&RotationAngles,beh,input,delta,Returns,stopping); // Do nothing when initial angle were not initialized. // Simply stop the BB. No output activated. if ( (InitialAngles.x == INF) || (RotationAngles.x == INF) ) return CKBR_OK; // When we are exactly on the top or the bottom of the target, +/-90°, // The LookAt BB won't rotate the camera when we turn right or left as // it already looks at the target. Therefore, when we are at +/-90°, we // add or remove a little something. if ( (RotationAngles.y==PI/2) || (RotationAngles.y == -PI/2) ) { // Get Min, Max // If equals, nothing to change, it is the given value. float MinH = -PI/2; float MaxH = PI/2; beh->GetInputParameterValue(IN_MIN_H, &MinH); beh->GetInputParameterValue(IN_MAX_H, &MaxH); if ( MaxH - MinH > 2 * STEP ) { float sign = (RotationAngles.y > 0) ? 1.0f : -1.0f; if ( MaxH >= sign * PI/2 + STEP ) RotationAngles.y += STEP; else RotationAngles.y -= STEP; } } // We memorize the new state with modulos RotationAngles.x = (float)fmod(RotationAngles.x,2*PI); RotationAngles.y = (float)fmod(RotationAngles.y,2*PI); beh->SetLocalParameterValue(LOCAL_ROT,&RotationAngles); // Computes the coordinates of the camera in the target referential thanks to the // current polar angles and radius informations. And moves the camera VxVector Position; Position = InitialAngles + RotationAngles; Position = Position.z * (cosf(Position.x) * sinf(Position.y) * VxVector::axisX() + sinf(Position.x) * sinf(Position.y) * VxVector::axisZ() + cosf(Position.y) * VxVector::axisY()); Position += TargetPosition; Camera->SetPosition(&Position, TargetRef, FALSE); // Does the camera has a Target ? CK3dEntity *CameraTarget; CKBOOL CameraHasTarget = CKIsChildClassOf(Camera,CKCID_TARGETCAMERA) && (CameraTarget=((CKTargetCamera*)Camera)->GetTarget()); // Orients the Camera. The LookAt implies that when the camera reach // the 90°, it may be flipped and suddently have the head up and down. // Therefore we use the target for target cameras as we have to use the // target. But for free cameras, we do our own look at using our rotation // angle to avoid this problem. if (CameraHasTarget) CameraTarget->SetPosition(&TargetPosition, TargetRef, TRUE); else { // New direction VxVector Dir; Dir = TargetPosition - Position; // Temp Right Value VxMatrix mat; VxVector R(0,0,-1); // Up for (0,0) angle Vx3DMatrixFromRotationAndOrigin(mat,VxVector::axisY(),VxVector(0,0,0),InitialAngles.x + RotationAngles.x); R.Rotate(mat); // Get Up VxVector Up; Up = CrossProduct(R,Dir); Camera->SetOrientation(&Dir,&Up,NULL,TargetRef); //Camera->LookAt(&TargetPosition,TargetRef); } // Stop is finished, reset values. if ( stopping && ((RotationAngles.x == 0) && (RotationAngles.y == 0)) ) { beh->ActivateOutput(1,TRUE); return CKBR_OK; } else // Come back next frame return CKBR_ACTIVATENEXTFRAME; }
/* ******************************************************************* * Function: int CGBLBuildCommand::DoBuildCommand(const CKBehaviorContext& behaviorContext) * * Description : Starts building the command. Find required GBLWaitForCommand BB, * determine its target (GBLTarget) and take corresponded actions. * * Parameters : * behaviourContext r Behavior context reference, which gives * access to frequently used global objects * ( context, level, manager, etc... ) * ******************************************************************* */ int CGBLBuildCommand::DoBuildCommand(const CKBehaviorContext& behaviorContext) { CKBehavior* behavior = behaviorContext.Behavior; CKContext* context = behaviorContext.Context; //set to initial state int stateValue = EGBLBuildCommandState::Initial; behavior->SetLocalParameterValue (gblBuildCommandStateLocalPos, &stateValue); int initialParameterPosition = 0; behavior->SetLocalParameterValue (currentParameterPositionLocalPos, &initialParameterPosition); char *emptyString = ""; behavior->SetLocalParameterValue(commandStringLocalPos, emptyString, strlen(emptyString)+1); ClearParameterOutputs(behaviorContext); int targetID = 0; behavior->GetInputParameterValue (EGBLBuildCommandParamInputs::SetCommandID, &targetID); CKBehavior* targetBB = CGBLCommandUtil::GetTargetCommand (targetID, behaviorContext); if (targetBB == NULL) { CKParameterOut *parameterOutError = behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetError); TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLFC_ERROR_BUILDCOMMAND_TARGET_NOT_FOUND,GBLFC_ERROR_BUILDCOMMAND_TARGET_NOT_FOUND_DESC); behavior->ActivateOutput (EGBLBuildCommandBehOutputs::Error); return CKBR_OK; } CK_ID targetBBID = targetBB->GetID(); behavior->SetLocalParameterValue (targetBBLocalPos, &targetBBID); int gblTatgetType = -1; targetBB->GetLocalParameterValue (CGBLWaitForCommand::EGBLWaitForCommandLocalVariables::EGBLFCTarget, &gblTatgetType); switch (gblTatgetType) { case CGBLWaitForCommand::EGBLFCTarget::Untargeted: { XString commandString; commandString << targetID << CGBLCommandUtil::commandSeparator; behavior->SetLocalParameterValue(commandStringLocalPos, commandString.Str(), strlen(commandString.Str()) + 1 ); return DoHandleNextLocalArgument (behaviorContext); } break; case CGBLWaitForCommand::EGBLFCTarget::Player: case CGBLWaitForCommand::EGBLFCTarget::Team: { //set state to GetTargets int stateValue = EGBLBuildCommandState::GetTargets; behavior->SetLocalParameterValue (gblBuildCommandStateLocalPos,&stateValue); //get list of recipients behavior->SetOutputParameterValue (EGBLBuildCommandParamOutputs::GetTarget, &gblTatgetType); behavior->ActivateOutput (EGBLBuildCommandBehOutputs::ListRecipients); return CKBR_OK; } break; default: CKParameterOut *parameterOutError = behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetError); TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLFC_ERROR_BUILDCOMMAND_UNSPECIFIED_RECIPIENT,GBLFC_ERROR_BUILDCOMMAND_UNSPECIFIED_RECIPIENT_DESC); behavior->ActivateOutput (EGBLBuildCommandBehOutputs::Error); break; } return CKBR_OK; }
/* ******************************************************************* * Function: int CGBLBuildCommand::DoReadNextParameterValue (const CKBehaviorContext& behaviorContext) * * Description : Read next provided argument from SetParameterString p-in and add it to command string * * Parameters : * behaviourContext r Behavior context reference, which gives * access to frequently used global objects * ( context, level, manager, etc... ) * ******************************************************************* */ int CGBLBuildCommand::DoReadNextParameterValue (const CKBehaviorContext& behaviorContext) { CKBehavior* behavior = behaviorContext.Behavior; CKContext* context = behaviorContext.Context; int gblBuildCommandState; behavior->GetLocalParameterValue (gblBuildCommandStateLocalPos, &gblBuildCommandState); switch (gblBuildCommandState) { case EGBLBuildCommandState::Initial: { CKParameterOut *parameterOutError = behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetError); TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLFC_ERROR_BUILDCOMMAND_INVALID_STATE,GBLFC_ERROR_BUILDCOMMAND_INVALID_STATE_DESC); behavior->ActivateOutput (EGBLBuildCommandBehOutputs::Error); return CKBR_OK; } break; case EGBLBuildCommandState::GetTargets: { //check if the array of recipients is provided void* recipients = NULL; recipients = behavior->GetInputParameter (EGBLBuildCommandParamInputs::SetDests)->GetDirectSource()->GetValueObject(); if (recipients == NULL) { CKParameterOut *parameterOutError = behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetError); TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLFC_ERROR_BUILDCOMMAND_NO_DESTS,GBLFC_ERROR_BUILDCOMMAND_NO_DESTS_DESC); behavior->ActivateOutput (EGBLBuildCommandBehOutputs::Error); return CKBR_OK; } int targetID = 0; behavior->GetInputParameterValue (EGBLBuildCommandParamInputs::SetCommandID, &targetID); XString commandString; commandString << targetID << CGBLCommandUtil::commandSeparator; behavior->SetLocalParameterValue(commandStringLocalPos, commandString.Str(), strlen(commandString.Str()) + 1 ); //check if there are more arguments return DoHandleNextNetworkArgument (behaviorContext); } break; case EGBLBuildCommandState::AwaitingParametersForNetwork: case EGBLBuildCommandState::AwaitingParametersForUntargeted: { CKSTRING commandString = (CKSTRING) behavior->GetLocalParameter(commandStringLocalPos)->GetReadDataPtr(); CKSTRING argumentString = (CKSTRING) behavior->GetInputParameter(EGBLBuildCommandParamInputs::SetParameterString)->GetReadDataPtr(); //char commandString[512]; //char argumentString[512]; //behavior->GetLocalParameterValue(commandStringLocalPos,&commandString); //behavior->GetInputParameterValue (EGBLBuildCommandParamInputs::SetParameterString, &argumentString); if (strlen (argumentString) == 0) { behavior->ActivateOutput (EGBLBuildCommandBehOutputs::InvalidValue); return CKBR_OK; } CKSTRING argumentType = (CKSTRING) behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetArgumentType)->GetReadDataPtr(); if ( (strcmp (argumentType, "Integer") == 0) || (strcmp (argumentType, "Float") == 0)) { bool isArgumentNumeric = CGBLCommandUtil::IsNumeric(argumentString); if (!isArgumentNumeric) { behavior->ActivateOutput (EGBLBuildCommandBehOutputs::InvalidValue); return CKBR_OK; } } XString updatedCommandString; updatedCommandString << commandString << argumentString << CGBLCommandUtil::commandSeparator; behavior->SetLocalParameterValue(commandStringLocalPos, updatedCommandString.Str(), strlen(updatedCommandString.Str()) + 1 ); if (gblBuildCommandState == EGBLBuildCommandState::AwaitingParametersForUntargeted) { return DoHandleNextLocalArgument (behaviorContext); } return DoHandleNextNetworkArgument (behaviorContext); } break; default: break; } return CKBR_OK; }
/* ******************************************************************* * Function: int BehaviourFunction( const CKBehaviorContext& behaviorContext ) * * Description : The execution function is the function that will be called * during the process loop of the behavior engine, if the behavior * is defined as using an execution function. This function is not * called if the behavior is defined as a graph. This function is the * heart of the behavior: it should compute the essence of the behavior, * in an incremental way. The minimum amount of computing should be * done at each call, to leave time for the other behaviors to run. * The function receives the delay in milliseconds that has elapsed * since the last behavioral process, and should rely on this value to * manage the amount of effect it has on its computation, if the effect * of this computation relies on time. * * Parameters : * behaviourContext r Behavior context reference, which gives access to * frequently used global objects ( context, level, manager, etc... ) * * Returns : int, If it is done, it should return CKBR_OK. If it returns * CKBR_ACTIVATENEXTFRAME, the behavior will again be called * during the next process loop. * ******************************************************************* */ int RetrieveCI(const CKBehaviorContext& behcontext) { /************************************************************************/ /* collecting data : */ /* */ CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; CGBLCIConfigurationController* cman=(CGBLCIConfigurationController*)ctx->GetManagerByGuid(CONFIGURATION_MAN_GUID); IGBLCIManageInterface *cisFac = cman->GetCISFactoryInterface(); IGBLCIAccessInterface * accessInterface = cman->GetCISAccessInterface(); BOOL getAsString,outputAttriubtes = false; beh->GetLocalParameterValue(BEH_SETTINGS_GET_AS_STRING,&getAsString); beh->GetLocalParameterValue(BEH_SETTINGS_GET_CUSTOM_ATTRIBUTES,&outputAttriubtes); using namespace GBLCommon::BehaviorTools; using namespace GBLCommon::ParameterTools; using namespace Customisation::typedefs; int idCI = GetInputParameterValue<int>(beh,BEH_PAR_INDEX_CI); CGBLCI *currentCI = NULL; CGBLSMStorageManager *storageManager = static_cast<CGBLSMStorageManager *>(ctx->GetManagerByGuid(GBLSMStorageManagerGUID)); IGBLSMConfigurationAccess* smCIS = storageManager->GetConfigurationInterface(); currentCI = new CGBLCI("temp",CKPGUID_INT); CGBLCOError returnValue = accessInterface->GetCI(currentCI,idCI); //get error parameter CKParameterOut *parameterOutError = beh->GetOutputParameter(BEH_PIN_OUT_INDEX_ERROR); // check results and output error if (returnValue == CGBLCOError::EGBLCOErrorType::GBLCO_OK) { ////////////////////////////////////////////////////////////////////////// // output values : CKParameterOut *pout = beh->GetOutputParameter(1); if(getAsString) { //output the value VxScratch sbuffer(currentCI->realValue->GetDataSize()); CKSTRING buffer = (CKSTRING)sbuffer.Mem(); currentCI->realValue->GetStringValue(buffer); pout->SetStringValue(buffer); }else { CKParameterManager *pm = static_cast<CKParameterManager*>(ctx->GetParameterManager()); if ( beh->GetOutputParameter(0)->GetType() == currentCI->realValue->GetType() ) { pout->CopyValue(currentCI->realValue); }else { pout->SetType(currentCI->realValue->GetType()); return CKBR_PARAMETERERROR; } } ////////////////////////////////////////////////////////////////////////// // output custom attributes : if(outputAttriubtes) { //output unique name : CKParameterOut *poutName = beh->GetOutputParameter(BEH_OUT_INDEX_UNAME); poutName->SetStringValue(currentCI->name.Str()); //output description : CKParameterOut *poutDescription = beh->GetOutputParameter(BEH_OUT_INDEX_DESCRIPTION); poutDescription->SetStringValue(currentCI->description.Str()); //output default value : CKParameterOut *poutDefaultValue = beh->GetOutputParameter(BEH_OUT_INDEX_DEFAULTVALUE); TypeCheckedParameterCopy(poutDefaultValue,currentCI->defaultValue); if(getAsString) { XString outDefValue = GBLCommon::ParameterTools::GetParameterAsString(currentCI->defaultValue); poutDefaultValue->SetStringValue( outDefValue.Str() ); }else{ poutDefaultValue->CopyValue(currentCI->defaultValue,TRUE); } //output flags : int flags = 0 ; beh->SetOutputParameterValue(BEH_OUT_INDEX_FLAGS,¤tCI->flags); //output type int type = ctx->GetParameterManager()->ParameterGuidToType(currentCI->type); beh->SetOutputParameterValue(BEH_OUT_INDEX_TYPE,&type); } TGBLError::SetTGBLError(parameterOutError,returnValue.GetType(),returnValue.GetCode(),(CKSTRING)returnValue.GetDescription()); beh->ActivateOutput(BEH_PIN_OUT_INDEX_SUCCESS, true); } else { CGBLCOError::EGBLCOErrorType tType = CGBLCOError::EGBLCOErrorType::GBLCO_OK; switch((CGBLCOError::EGBLCOErrorType)returnValue) { case 0: tType = CGBLCOError::EGBLCOErrorType::GBLCO_OK; break; case 1: tType = CGBLCOError::EGBLCOErrorType::GBLCO_FATAL; break; case 2: tType = CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL; break; case 3: tType = CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL; break; } TGBLError::SetTGBLError(parameterOutError,tType,returnValue.GetCode(),(CKSTRING)returnValue.GetDescription()); beh->ActivateOutput(BEH_PIN_OUT_INDEX_ERROR, true); } return CKBR_OK; }
/* ******************************************************************* * Function: int CGBLBuildCommand::DoHandleNextNetworkArgument (const CKBehaviorContext& behaviorContext) * * Description : Checks if there are more arguments to be specified for network command * and takes corresponded actions * * Parameters : * behaviourContext r Behavior context reference, which gives * access to frequently used global objects * ( context, level, manager, etc... ) * ******************************************************************* */ int CGBLBuildCommand::DoHandleNextNetworkArgument (const CKBehaviorContext& behaviorContext) { CKBehavior* behavior = behaviorContext.Behavior; CKContext* context = behaviorContext.Context; int gblBuildCommandState; CKBehavior* targetBB = NULL; CK_ID targetID; behavior->GetLocalParameterValue (targetBBLocalPos, &targetID); targetBB = (CKBehavior*)behaviorContext.Context->GetObject(targetID); if (targetBB == NULL) { CKParameterOut *parameterOutError = behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetError); TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLFC_ERROR_BUILDCOMMAND_TARGET_NOT_FOUND,GBLFC_ERROR_BUILDCOMMAND_TARGET_NOT_FOUND_DESC); behavior->ActivateOutput (EGBLBuildCommandBehOutputs::Error); return CKBR_OK; } int currentParameterPosition = 0; behavior->GetLocalParameterValue (currentParameterPositionLocalPos, ¤tParameterPosition); CKParameter* nextArgument = CGBLCommandUtil::GetCommandArgument(*targetBB, currentParameterPosition); currentParameterPosition++; behavior->SetLocalParameterValue (currentParameterPositionLocalPos, ¤tParameterPosition); if (nextArgument == NULL) { //no arguments required, build finished CKParameter *outputCommandString, *localCommandString; CKParameter *outputDests; CKParameterIn *inputDests; ClearParameterOutputs(behaviorContext); outputCommandString = (CKParameter*) behavior->GetOutputParameter (EGBLBuildCommandParamOutputs::GetCommandString); localCommandString = (CKParameter*) behavior->GetLocalParameter (commandStringLocalPos); outputCommandString->CopyValue(localCommandString); // Copy list of recipients from input to output outputDests = (CKParameter*) (behavior->GetOutputParameter (EGBLBuildCommandParamOutputs::GetDests)); inputDests = behavior->GetInputParameter (EGBLBuildCommandParamInputs::SetDests); outputDests->CopyValue(inputDests->GetDirectSource()); gblBuildCommandState = EGBLBuildCommandState::Completed; behavior->SetLocalParameterValue (gblBuildCommandStateLocalPos, &gblBuildCommandState); behavior->ActivateOutput (EGBLBuildCommandBehOutputs::HandleTargetedCommand); return CKBR_OK; } else { //get next argument gblBuildCommandState = EGBLBuildCommandState::AwaitingParametersForNetwork; behavior->SetLocalParameterValue (gblBuildCommandStateLocalPos, &gblBuildCommandState); GetNextArgument (nextArgument, targetBB, behaviorContext); return CKBR_OK; } }
/* ******************************************************************* * Function: int CGBLBuildCommand::DoHandleNextLocalArgument (const CKBehaviorContext& behaviorContext) * * Description : Checks if there are more arguments to be specified for global command * and takes corresponded actions * * Parameters : * behaviourContext r Behavior context reference, which gives * access to frequently used global objects * ( context, level, manager, etc... ) * ******************************************************************* */ int CGBLBuildCommand::DoHandleNextLocalArgument (const CKBehaviorContext& behaviorContext) { CKBehavior* behavior = behaviorContext.Behavior; CKContext* context = behaviorContext.Context; int gblBuildCommandState; CKBehavior* targetBB = NULL; CK_ID targetID; behavior->GetLocalParameterValue (targetBBLocalPos, &targetID); targetBB = (CKBehavior*)behaviorContext.Context->GetObject(targetID); if (targetBB == NULL) { CKParameterOut *parameterOutError = behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetError); TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLFC_ERROR_BUILDCOMMAND_TARGET_NOT_FOUND,GBLFC_ERROR_BUILDCOMMAND_TARGET_NOT_FOUND_DESC); behavior->ActivateOutput (EGBLBuildCommandBehOutputs::Error); return CKBR_OK; } int currentParameterPosition = 0; behavior->GetLocalParameterValue (currentParameterPositionLocalPos, ¤tParameterPosition); CKParameter* nextArgument = CGBLCommandUtil::GetCommandArgument(*targetBB, currentParameterPosition); currentParameterPosition++; behavior->SetLocalParameterValue (currentParameterPositionLocalPos, ¤tParameterPosition); if (nextArgument == NULL) { //no arguments required, build finished //char commandString[512]; //behavior->GetLocalParameterValue(commandStringLocalPos,&commandString); CKSTRING commandString = (CKSTRING) behavior->GetLocalParameter(commandStringLocalPos)->GetReadDataPtr(); int res = CGBLCommandUtil::InvokeCommand (commandString, behaviorContext); ClearParameterOutputs(behaviorContext); if (res != CK_OK) { CKParameterOut *parameterOutError = behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetError); TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLFC_ERROR_BUILDCOMMAND_INVOKING_FAILED, GBLFC_ERROR_BUILDCOMMAND_INVOKING_FAILED_DESC); behavior->ActivateOutput (EGBLBuildCommandBehOutputs::Error); return CKBR_OK; } behavior->ActivateOutput (EGBLBuildCommandBehOutputs::HandleUntargetedCommand); return CKBR_OK; } else { //get next argument gblBuildCommandState = EGBLBuildCommandState::AwaitingParametersForUntargeted; behavior->SetLocalParameterValue (gblBuildCommandStateLocalPos, &gblBuildCommandState); GetNextArgument (nextArgument, targetBB, behaviorContext); return CKBR_OK; } }
//************************************ // Method: PJRevolute // FullName: PJRevolute // Access: public // Returns: int // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ int PJRevolute(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; PhysicManager *pm = GetPMan(); pFactory *pf = pFactory::Instance(); using namespace vtTools::BehaviorTools; if( beh->IsInputActive(0) ) { beh->ActivateInput(0,FALSE); ////////////////////////////////////////////////////////////////////////// //the object A: CK3dEntity *target = (CK3dEntity *) beh->GetTarget(); CK3dEntity *targetB = (CK3dEntity *) beh->GetInputParameterObject(bI_ObjectB); if (!pFactory::Instance()->jointCheckPreRequisites(target,targetB,JT_Revolute)) { return CK_OK; } // the world : pWorld *worldA=GetPMan()->getWorldByBody(target); pWorld *worldB=GetPMan()->getWorldByBody(targetB); if (!worldA && ! worldB ) { return 0; } if (!worldA) { worldA = worldB; } if (!worldA) { beh->ActivateOutput(0); return 0; } // the physic object A : pRigidBody*bodyA= worldA->getBody(target); pRigidBody*bodyB= worldA->getBody(targetB); //anchor : VxVector anchor = GetInputParameterValue<VxVector>(beh,bI_Anchor); VxVector anchorOut = anchor; CK3dEntity*anchorReference = (CK3dEntity *) beh->GetInputParameterObject(bI_AnchorRef); if (anchorReference) { anchorReference->Transform(&anchorOut,&anchor); } //swing axis VxVector Axis = GetInputParameterValue<VxVector>(beh,bI_Axis); VxVector axisOut = Axis; CK3dEntity*axisReference = (CK3dEntity *) beh->GetInputParameterObject(bI_AxisRef); if (axisReference) { VxVector dir,up,right; axisReference->GetOrientation(&dir,&up,&right); axisReference->TransformVector(&axisOut,&up); } ////////////////////////////////////////////////////////////////////////// //limit high : pJointLimit limitH; pJointLimit limitL; DWORD limit; beh->GetLocalParameterValue(1,&limit); if (limit) { CKParameterIn *par = beh->GetInputParameter(bbI_HighLimit); if (par) { CKParameter *rPar = par->GetRealSource(); if (rPar) { limitH = pFactory::Instance()->createLimitFromParameter(rPar); } } } if (limit) { CKParameterIn *par = beh->GetInputParameter(bbI_LowLimit); if (par) { CKParameter *rPar = par->GetRealSource(); if (rPar) { limitL = pFactory::Instance()->createLimitFromParameter(rPar); } } } ////////////////////////////////////////////////////////////////////////// DWORD spring; pSpring sSpring; beh->GetLocalParameterValue(0,&spring); if (spring) { CKParameterIn *par = beh->GetInputParameter(bbI_Spring); if (par) { CKParameter *rPar = par->GetRealSource(); if (rPar) { sSpring = pFactory::Instance()->createSpringFromParameter(rPar); } } } pMotor motor; DWORD hasMotor; beh->GetLocalParameterValue(2,&hasMotor); if (hasMotor) { CKParameterIn *par = beh->GetInputParameter(bbI_Motor); if (par) { CKParameter *rPar = par->GetRealSource(); if (rPar) { motor = pFactory::Instance()->createMotorFromParameter(rPar); } } } int col = GetInputParameterValue<int>(beh,bbI_Collision); ProjectionMode mode =GetInputParameterValue<ProjectionMode>(beh,bbI_PMode); float distance = GetInputParameterValue<float>(beh,bbI_PDistance); float angle= GetInputParameterValue<float>(beh,bbI_PAngle); ////////////////////////////////////////////////////////////////////////// // pJointRevolute *joint = static_cast<pJointRevolute*>(worldA->getJoint(target,targetB,JT_Revolute)); if(bodyA || bodyB) { ////////////////////////////////////////////////////////////////////////// //joint create ? if (!joint) { joint = static_cast<pJointRevolute*>(pFactory::Instance()->createRevoluteJoint(target,targetB,anchorOut,axisOut)); } ////////////////////////////////////////////////////////////////////////// Modification : if (joint) { joint->setGlobalAxis(axisOut); joint->setGlobalAnchor(anchorOut); if (mode!=0) { joint->setProjectionMode(mode); joint->setProjectionDistance(distance); joint->setProjectionAngle(angle); } ////////////////////////////////////////////////////////////////////////// if(limit) { joint->setHighLimit(limitH); joint->setLowLimit(limitL); } ////////////////////////////////////////////////////////////////////////// if (spring) { joint->setSpring(sSpring); } if (hasMotor) { joint->setMotor(motor); } joint->enableCollision(col); } } beh->ActivateOutput(0); } return 0; }
/* ******************************************************************* * Function: int GetCIValue( const CKBehaviorContext& behaviorContext ) * * Description : The execution function is the function that will be called * during the process loop of the behavior engine, if the behavior * is defined as using an execution function. This function is not * called if the behavior is defined as a graph. This function is the * heart of the behavior: it should compute the essence of the behavior, * in an incremental way. The minimum amount of computing should be * done at each call, to leave time for the other behaviors to run. * The function receives the delay in milliseconds that has elapsed * since the last behavioral process, and should rely on this value to * manage the amount of effect it has on its computation, if the effect * of this computation relies on time. * * Parameters : * behaviourContext r Behavior context reference, which gives access to * frequently used global objects ( context, level, manager, etc... ) * * Returns : int, If it is done, it should return CKBR_OK. If it returns * CKBR_ACTIVATENEXTFRAME, the behavior will again be called * during the next process loop. * ******************************************************************* */ int GetCIValue(const CKBehaviorContext& behcontext) { /************************************************************************/ /* collecting data : */ /* */ CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; CGBLCIConfigurationController* cman=(CGBLCIConfigurationController*)ctx->GetManagerByGuid(CONFIGURATION_MAN_GUID); BOOL getByName,getAsString,outputAttriubtes,outputOnChange = false; beh->GetLocalParameterValue(BEH_SETTINGS_GET_BY_NAME,&getByName); beh->GetLocalParameterValue(BEH_SETTINGS_GET_AS_STRING,&getAsString); beh->GetLocalParameterValue(BEH_SETTINGS_GET_CUSTOM_ATTRIBUTES,&outputAttriubtes); beh->GetLocalParameterValue(BEH_SETTINGS_OUTPUT_ON_CHANGE,&outputOnChange); // Beh Input 1 activated : switch of on event mode ///////////////////////////////////////////////// if( outputOnChange && beh->IsInputActive(1) ) { beh->ActivateInput(1,FALSE); return CKBR_OK; } using namespace GBLCommon::BehaviorTools; using namespace Customisation::typedefs; Customisation::typedefs::CIS* currentCIS = cman->GetCIS(); if( !currentCIS) { return CKBR_PARAMETERERROR; } CGBLCI *currentCI = NULL; //get by uniquie name mode ? if( getByName ) { CISIterator it = currentCIS->Find( new CGBLCIID (GetInputParameterValue<CKSTRING>(beh,0) , 0 ) ); if (it == currentCIS->End() ) { return CKBR_PARAMETERERROR; }else { currentCI = *it; } //////// then get the custom parameter : }else { CKParameter *ciPar = beh->GetInputParameter(0)->GetRealSource(); currentCI = static_cast<CGBLCI *>(ciPar->GetAppData()); if (!currentCI) { return CKBR_PARAMETERERROR; } } ////////////////////////////////////////////////////////////////////////// // output values : CKParameterOut *pout = beh->GetOutputParameter(0); if(getAsString) { //output the value VxScratch sbuffer(currentCI->realValue->GetDataSize()); CKSTRING buffer = (CKSTRING)sbuffer.Mem(); currentCI->realValue->GetStringValue(buffer); pout->SetStringValue(buffer); }else { CKParameterManager *pm = static_cast<CKParameterManager*>(ctx->GetParameterManager()); if ( beh->GetOutputParameter(0)->GetType() == currentCI->realValue->GetType() ) { pout->CopyValue(currentCI->realValue); }else { pout->SetType(currentCI->realValue->GetType()); return CKBR_PARAMETERERROR; } } using namespace GBLCommon::ParameterTools; ////////////////////////////////////////////////////////////////////////// // output custom attributes : if(outputAttriubtes) { //output unique name : CKParameterOut *poutName = beh->GetOutputParameter(BEH_OUT_INDEX_UNAME); poutName->SetStringValue(currentCI->name.Str()); //output description : CKParameterOut *poutDescription = beh->GetOutputParameter(BEH_OUT_INDEX_DESCRIPTION); poutDescription->SetStringValue(currentCI->description.Str()); //output default value : CKParameterOut *poutDefaultValue = beh->GetOutputParameter(BEH_OUT_INDEX_DEFAULTVALUE); TypeCheckedParameterCopy(poutDefaultValue,currentCI->defaultValue); if(getAsString) { XString outDefValue = GBLCommon::ParameterTools::GetParameterAsString(currentCI->defaultValue); poutDefaultValue->SetStringValue( outDefValue.Str() ); }else{ poutDefaultValue->CopyValue(currentCI->defaultValue,TRUE); } //output flags : int flags = 0 ; beh->SetOutputParameterValue(BEH_OUT_INDEX_FLAGS,¤tCI->flags); //output type int type = ctx->GetParameterManager()->ParameterGuidToType(currentCI->type); beh->SetOutputParameterValue(BEH_OUT_INDEX_TYPE,&type); } if (outputOnChange && (currentCI->ciState & CGBLCI::GBL_CI_STATE::GBL_CI_CHANGED) ) { //reset state : currentCI->ciState = 0L; beh->ActivateOutput(0); } if (!outputOnChange) { beh->ActivateOutput(0); } return outputOnChange ? CKBR_ACTIVATENEXTFRAME : CKBR_OK; }
//************************************ // Method: PBPhysicalize // FullName: PBPhysicalize // Access: public // Returns: int // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ int PBPhysicalize(const CKBehaviorContext& behcontext) { using namespace vtTools::BehaviorTools; using namespace vtTools; using namespace vtTools::AttributeTools; ////////////////////////////////////////////////////////////////////////// //basic parameters CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; PhysicManager *pm = GetPMan(); pFactory *pf = pFactory::Instance(); ////////////////////////////////////////////////////////////////////////// //settings int useDWorld; beh->GetLocalParameterValue(bbS_USE_DEFAULT_WORLD,&useDWorld); // int useWorldSS; beh->GetLocalParameterValue(bbS_USE_WORLD_SLEEP_SETTINGS,&useWorldSS); // int useWorldDS; beh->GetLocalParameterValue(bbS_USE_WORLD_DAMPING_SETTINGS,&useWorldDS); int useWorldM; beh->GetLocalParameterValue(bbS_USE_WORLD_MATERIAL,&useWorldM); int addAttributes; beh->GetLocalParameterValue(bbS_ADD_ATTRIBUTES,&addAttributes); ////////////////////////////////////////////////////////////////////////// //the object : CK3dEntity *referenceObject = (CK3dEntity *) beh->GetTarget(); if( !referenceObject ) return CKBR_OWNERERROR; ////////////////////////////////////////////////////////////////////////// //the world : CK3dEntity*worldRef = NULL; if (!useDWorld) { worldRef = (CK3dEntity *) beh->GetInputParameterObject(bbI_TargetWorld); } // the world : pWorld *world=GetPMan()->getWorld(worldRef,referenceObject); if (!world) { beh->ActivateOutput(0); return 0; } pRigidBody*result = world->getBody(referenceObject); if (result) { beh->ActivateOutput(0); return 0; } ////////////////////////////////////////////////////////////////////////// //pick up some parameters : int flags = GetInputParameterValue<int>(beh,bbI_Flags); int hType = GetInputParameterValue<int>(beh,bbI_HullType); float density = GetInputParameterValue<float>(beh,bbI_Density); float skinWidth = GetInputParameterValue<float>(beh,bbI_SkinWidth); int hierarchy = GetInputParameterValue<int>(beh,bbI_Hierachy); float newDensity = GetInputParameterValue<float>(beh,bbI_NewDensity); float totalMass = GetInputParameterValue<float>(beh,bbI_TotalMass); VxVector massOffset = GetInputParameterValue<VxVector>(beh,bbI_MassShift); VxVector shapeOffset = GetInputParameterValue<VxVector>(beh,bbI_ShapeShift); ////////////////////////////////////////////////////////////////////////// // we remove the old physic attribute : if (referenceObject->HasAttribute(GetPMan()->GetPAttribute())) { referenceObject->RemoveAttribute(GetPMan()->GetPAttribute()); } referenceObject->SetAttribute(GetPMan()->GetPAttribute()); SetAttributeValue<int>(referenceObject,GetPMan()->GetPAttribute(),E_PPS_HIRARCHY,&hierarchy); SetAttributeValue<int>(referenceObject,GetPMan()->GetPAttribute(),E_PPS_HULLTYPE,&hType); SetAttributeValue<int>(referenceObject,GetPMan()->GetPAttribute(),E_PPS_BODY_FLAGS,&flags); SetAttributeValue<float>(referenceObject,GetPMan()->GetPAttribute(),E_PPS_DENSITY,&density); SetAttributeValue<float>(referenceObject,GetPMan()->GetPAttribute(),E_PPS_NEW_DENSITY,&newDensity); SetAttributeValue<float>(referenceObject,GetPMan()->GetPAttribute(),E_PPS_TOTAL_MASS,&totalMass); SetAttributeValue<VxVector>(referenceObject,GetPMan()->GetPAttribute(),E_PPS_MASS_OFFSET,&massOffset); //SetAttributeValue<VxVector>(referenceObject,GetPMan()->GetPAttribute(),E_PPS_MASS_OFFSET,&massOffset); CK_ID wID = world->getReference()->GetID(); AttributeTools::SetAttributeValue<CK_ID>(referenceObject,GetPMan()->GetPAttribute(),E_PPS_WORLD,&wID); ////////////////////////////////////////////////////////////////////////// //Material : if (!useWorldM) { if (referenceObject->HasAttribute(GetPMan()->att_surface_props)) { referenceObject->RemoveAttribute(GetPMan()->att_surface_props); } referenceObject->SetAttribute(GetPMan()->att_surface_props); CKParameterIn *pMatIn = beh->GetInputParameter(bbI_Material); CKParameter *pMat = pMatIn->GetRealSource(); CKParameterOut* pout = referenceObject->GetAttributeParameter(GetPMan()->att_surface_props); int error = pout->CopyValue(pMat); pout->Update(); } pRigidBody *body = pFactory::Instance()->createRigidBodyFull(referenceObject,worldRef); if (body) { body->translateLocalShapePosition(shapeOffset); } //GetPMan()->checkWorlds(); if (!addAttributes) { referenceObject->RemoveAttribute(GetPMan()->GetPAttribute()); referenceObject->RemoveAttribute(GetPMan()->att_surface_props); } beh->ActivateOutput(0); return 0; }
//************************************ // Method: PWOverlapSphere // FullName: PWOverlapSphere // Access: public // Returns: int // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ int PWOverlapSphere(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; PhysicManager *pm = GetPMan(); pFactory *pf = pFactory::Instance(); using namespace vtTools::BehaviorTools; using namespace vtTools::ParameterTools; ////////////////////////////////////////////////////////////////////////// //the object : CK3dEntity *target = (CK3dEntity *) beh->GetTarget(); if( !target ) return CKBR_OWNERERROR; ////////////////////////////////////////////////////////////////////////// // the world : pWorld *world=GetPMan()->getWorld(target->GetID()); if (!world) { beh->ActivateOutput(bbOT_No); return 0; } NxScene *scene = world->getScene(); if (!scene) { beh->ActivateOutput(bbOT_No); return 0; } if( beh->IsInputActive(0) ) { beh->ActivateInput(0,FALSE); CKGroup *carray = (CKGroup*)beh->GetLocalParameterObject(bbS_Result); if (carray) { //carray->clear(); carray->Clear(); }else { CK_OBJECTCREATION_OPTIONS creaoptions = (CK_OBJECTCREATION_OPTIONS)(CK_OBJECTCREATION_NONAMECHECK|CK_OBJECTCREATION_DYNAMIC); carray = (CKGroup*)ctx()->CreateObject(CKCID_GROUP,"asdasd",creaoptions); } beh->SetLocalParameterObject(0,carray); int hitIndex = 0; beh->SetLocalParameterValue(bbS_Index,&hitIndex); int hitSize = 0; beh->SetLocalParameterValue(bbS_Size,&hitSize); ////////////////////////////////////////////////////////////////////////// int types = GetInputParameterValue<int>(beh,bbI_ShapesType); int accurate = GetInputParameterValue<int>(beh,bbI_Accurate); DWORD groupsEnabled; DWORD groups = 0xffffffff; beh->GetLocalParameterValue(bbS_Groups,&groupsEnabled); if (groupsEnabled) { groups = GetInputParameterValue<int>(beh,bbI_Groups); } pGroupsMask *gmask = NULL; DWORD mask; beh->GetLocalParameterValue(bbS_Mask,&mask); if (mask) { CKParameter *maskP = beh->GetInputParameter(bbI_Mask)->GetRealSource(); gmask->bits0 = GetValueFromParameterStruct<int>(maskP,0); gmask->bits1 = GetValueFromParameterStruct<int>(maskP,1); gmask->bits2 = GetValueFromParameterStruct<int>(maskP,2); gmask->bits3 = GetValueFromParameterStruct<int>(maskP,3); } float radius = GetInputParameterValue<float>(beh,bbI_Radius); VxVector center = GetInputParameterValue<VxVector>(beh,bbI_Center); VxSphere sphere(center,radius); CK3dEntity *shape = (CK3dEntity*)beh->GetInputParameterObject(bbI_Ref); int nbShapes = world->overlapSphereShapes(sphere,shape,(pShapesType)types,carray,groups,gmask,accurate); if (nbShapes) { beh->ActivateOutput(bbOT_Yes); beh->ActivateInput(1,TRUE); }else{ beh->ActivateOutput(bbOT_No); } } if( beh->IsInputActive(1) ) { beh->ActivateInput(1,FALSE); CKGroup *carray = (CKGroup*)beh->GetLocalParameterObject(bbS_Result); ////////////////////////////////////////////////////////////////////////// if (carray) { if (carray->GetObjectCount()) { CKBeObject *hit = carray->GetObject(carray->GetObjectCount()-1); if (hit) { beh->SetOutputParameterObject(0,hit); carray->RemoveObject(hit); if (carray->GetObjectCount()) { beh->ActivateOutput(bbOT_Next); }else { beh->ActivateOutput(bbOT_Finish); CKDestroyObject(carray); } } }else{ beh->ActivateOutput(bbOT_Finish); CKDestroyObject(carray); } }else { beh->ActivateOutput(bbOT_Finish); CKDestroyObject(carray); } } return 0; }
//************************************ // Method: PCGroupTriggerEvent // FullName: PCGroupTriggerEvent // Access: public // Returns: int // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ int PCGroupTriggerEvent(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; PhysicManager *pm = GetPMan(); pFactory *pf = pFactory::Instance(); using namespace vtTools::BehaviorTools; ////////////////////////////////////////////////////////////////////////// //the object : CKGroup *target = (CKGroup *) beh->GetTarget(); if( !target ) return CKBR_OWNERERROR; //int extraFilter = GetInputParameterValue<int>(beh,0); //int remove = GetInputParameterValue<int>(beh,1); int nbOfEvents = getEventCount(); if (!nbOfEvents) { beh->ActivateOutput(bbO_None); return 0; } /************************************************************************/ /* handle init */ /************************************************************************/ if( beh->IsInputActive(bbI_Init) ) { beh->ActivateInput(bbI_Init,FALSE); int index = 0;beh->SetLocalParameterValue(0,&index); //we have some, forward to in 1:next if (nbOfEvents) { beh->ActivateInput(bbI_Next,TRUE); beh->ActivateOutput(bbO_HasMore); } } /************************************************************************/ /* handle trigger 'next' */ /************************************************************************/ if( beh->IsInputActive(bbI_Next) ) { beh->ActivateInput(bbI_Next,FALSE); int index = 0;beh->GetLocalParameterValue(0,&index); for (int i = index ; i < GetPMan()->getTriggers().Size(); i++ ) { pTriggerEntry &entry = *GetPMan()->getTriggers().At(i); if (!entry.triggered) { if (isInGroup(target,entry.triggerShapeEnt)) { beh->SetOutputParameterObject(0,entry.triggerShapeEnt); beh->SetOutputParameterObject(1,entry.otherObject); SetOutputParameterValue<int>(beh,2,entry.triggerEvent); entry.triggered = true; //trigger out if(entry.triggerEvent == NX_TRIGGER_ON_ENTER) { beh->ActivateOutput(bbO_Enter); } if(entry.triggerEvent == NX_TRIGGER_ON_STAY) { beh->ActivateOutput(bbO_Stay); } if(entry.triggerEvent == NX_TRIGGER_ON_LEAVE) { beh->ActivateOutput(bbO_Leave); } //store index beh->SetLocalParameterValue(1,&index); int nbOfLeftEvents = getEventCount(); if (nbOfLeftEvents) { beh->ActivateOutput(bbO_HasMore); return 0; }else { beh->ActivateOutput(bbO_None); return 0; } } } } } /************************************************************************/ /* */ /************************************************************************/ return 0; }
/* ******************************************************************* * Function: int GetCIValueCB( const CKBehaviorContext& behaviorContext ) * * Description : The Behavior Callback function is called by Virtools when various events happen * in the life of a BuildingBlock. Exactly which events trigger a call to the * Behavior Callback function is defined in the Behavior Prototype, along with the * declaration of the function pointer * * Parameters : * behaviourContext r Behavior context reference, which gives * access to frequently used global objects * ( context, level, manager, etc... ) * * Returns : int, The return value of the callback function should be one of the CK_BEHAVIOR_RETURN values. * ******************************************************************* */ CKERROR GetCIValueCB(const CKBehaviorContext& behcontext) { /************************************************************************/ /* collecting data : */ /* */ CKBehavior *beh = behcontext.Behavior; CKContext* ctx = beh->GetCKContext(); CKParameterManager *pm = static_cast<CKParameterManager*>(ctx->GetParameterManager()); /************************************************************************/ /* process virtools callbacks : */ /* */ switch(behcontext.CallbackMessage) { case CKM_BEHAVIOREDITED: case CKM_BEHAVIORSETTINGSEDITED: { assert(beh && ctx); BOOL getByName,getAsString,outputAttriubtes,outputOnChange = false; beh->GetLocalParameterValue(BEH_SETTINGS_GET_BY_NAME,&getByName); beh->GetLocalParameterValue(BEH_SETTINGS_GET_AS_STRING,&getAsString); beh->GetLocalParameterValue(BEH_SETTINGS_GET_CUSTOM_ATTRIBUTES,&outputAttriubtes); beh->GetLocalParameterValue(BEH_SETTINGS_OUTPUT_ON_CHANGE,&outputOnChange); ////////////////////////////////////////////////////////////////////////// //we add beh - in - trigger, if we are in event mode: if (outputOnChange) { beh->AddInput("Stop"); //change to correct name : CKBehaviorIO * out_trigger = beh->GetOutput(0); out_trigger->SetName("Change detected"); }else { //change to correct name : CKBehaviorIO * out_trigger = beh->GetOutput(0); out_trigger->SetName("Finish"); } //remove unecessary beh - input triggers from even-mode : int count = beh->GetInputCount(); while( (outputOnChange ? BEH_IN_TRIGGER_MAX_COUNT : BEH_IN_TRIGGER_MIN_COUNT ) <= count ) beh->DeleteInput( count-- ); CKParameterIn *ciIn = beh->GetInputParameter(0); if( getByName ) { ciIn->SetType(pm->ParameterGuidToType(CKPGUID_STRING)); ciIn->SetName("unique name of the configurable information"); }else { ciIn->SetType(pm->ParameterGuidToType(CIPARAMETERGUID)); ciIn->SetName("Configurable Information"); } if(outputAttriubtes) { beh->CreateOutputParameter("Default Value",CKPGUID_STRING); beh->CreateOutputParameter("Unique name",CKPGUID_STRING); beh->CreateOutputParameter("Description",CKPGUID_STRING); beh->CreateOutputParameter("Runtime flags",CIPRTFLAGSGUID); beh->CreateOutputParameter("Type",CKPGUID_PARAMETERTYPE); } int p_count = beh->GetOutputParameterCount(); while( (outputAttriubtes ? BEH_OUT_MAX_COUNT : BEH_OUT_MIN_COUNT ) < p_count ) { CKDestroyObject( beh->RemoveOutputParameter( --p_count) ); } } } return CKBR_OK; }
/* ******************************************************************* * Function: BehaviourFunction() * * Description : Is called every frame from Virtools. Executes the behaviour of the BB. * * Parameters : * behContext, r: Passed in from Virtools * * Returns : A CKBR_... return value * ******************************************************************* */ int CGBLListBox::BehaviourFunction(const CKBehaviorContext& behContext) { static VxRect fullUVRect(0.0f, 0.0f, 1.0f, 1.0f); // The default return code is CKBR_ACTIVATENEXTFRAME which forces BehaviourFunction() to be called next frame CK_BEHAVIOR_RETURN behReturn = CKBR_ACTIVATENEXTFRAME; CKBehavior* beh = behContext.Behavior; // Call the helper class to implement our base class functionality // If it returns FALSE, we must return the error code and not perform any behavioural functionality CKBOOL isFocussed = FALSE; if (!CGBLWidget::ExecuteBaseBehaviour(behContext, &isFocussed, &behReturn)) { return behReturn; } // Check for mouse and keyboard inputs CKInputManager* inputManager = (CKInputManager*)behContext.Context->GetManagerByGuid(INPUT_MANAGER_GUID); if (!inputManager) { assert(NULL); return CKBR_OK; } // Get material CKMaterial* material = (CKMaterial*)beh->GetInputParameterObject(eParamInputMaterial); if (!material) { // Output an error - we need a material CGBLWidget::OutputBBErrorMsg(beh, "Please attach a material to the building block"); return CKBR_OK; } // Get font VirtoolsSource::CKTextureFont* font = CGBLWidget::GetFont(behContext.Context, beh); if (!font) { // Output an error - we need a font attached CGBLWidget::OutputBBErrorMsg(beh, "Please attach a font to the building block"); return CKBR_OK; } // Are we using proportional scaling? CKBOOL isPropScaling = CGBLWidget::IsProportionalScaling(beh); // Get the font height CKRenderContext* renderContext = behContext.Context->GetPlayerRenderContext(); float fontHeight = CGBLWidget::GetFontHeight(font, renderContext, isPropScaling); // Get columns array, doesn't matter if we can't get it CKDataArray* columnsArray = static_cast<CKDataArray*>(beh->GetInputParameterObject(eParamInputColumnsArray)); int numColumns = columnsArray ? columnsArray->GetRowCount() : 1; CKSTRING errMsg = ValidateColumnsArray(columnsArray); if (errMsg) { CGBLWidget::OutputBBErrorMsg(beh, errMsg); return CKBR_OK; } // Get the string list array and check it's of the right type CKDataArray* stringListArray = static_cast<CKDataArray*>(beh->GetInputParameterObject(eParamInputStringListArray)); errMsg = CGBLWidget::ValidateStringListArray(stringListArray, numColumns - 1); if (errMsg) { CGBLWidget::OutputBBErrorMsg(beh, errMsg); return CKBR_OK; } CKBeObject* beObject = beh->GetTarget(); CKRenderObject* renderObject = CKRenderObject::Cast(beObject); // Add a render callback to allow our widget to render itself next frame renderObject->AddPostRenderCallBack(RenderCallback, (void *)behContext.Behavior->GetID(), TRUE); CK2dEntity* ent = CK2dEntity::Cast(renderObject); VxRect clientRect; ent->GetExtents(fullUVRect, clientRect); // Check for Select b-in if (beh->IsInputActive(eBehInputSelect)) { // Reset b-in beh->ActivateInput(eBehInputSelect, FALSE); int select = 0; beh->GetInputParameterValue(eParamInputSelectedItem, &select); // Check we are in single selection mode int selectionType = 0; beh->GetLocalParameterValue(eLocalParamSelectionType, &selectionType); if (selectionType == eSelectionTypeSingleSelection) { // Is this row selectable? CKBOOL selectable = FALSE; stringListArray->GetElementValue(select, CGBLWidget::eStringListArrayColumnSelectable, &selectable); if (selectable || (select < 0) || (select >= stringListArray->GetRowCount()) ) { // Select only this row for (int selRow = 0;selRow < stringListArray->GetRowCount();selRow++) { CKBOOL bSelect = (selRow == select); stringListArray->SetElementValue(selRow, CGBLWidget::eStringListArrayColumnSelected, &bSelect); } // Set focus to this item too if (selectable) beh->SetLocalParameterValue(eLocalParamFocussedItem, &select); // Update selected item p-out beh->SetOutputParameterValue(eParamOutputSelectedItem, &select); // Activate new selection b-out beh->ActivateOutput(eBehOutputNewSelection); // Do we need to scroll? int scrollOffset; beh->GetLocalParameterValue(eLocalParamScrollOffset, &scrollOffset); VxRect stringListRect = GetRectStringList(clientRect, fontHeight, columnsArray); if (!CGBLWidget::GetListRowRect(stringListRect, select, scrollOffset, stringListArray->GetRowCount(), fontHeight, NULL)) { // Set the scroll offset to the focussed item scrollOffset = select; beh->SetLocalParameterValue(eLocalParamScrollOffset, &scrollOffset); } } } } // Check for Focus b-in if (beh->IsInputActive(eBehInputFocus)) { // Reset b-in beh->ActivateInput(eBehInputFocus, FALSE); // Set focus int nFocus = 0; beh->GetInputParameterValue(eParamInputFocusItem, &nFocus); // Copy to focus item and scroll offset beh->SetLocalParameterValue(eLocalParamFocussedItem, &nFocus); // Do we need to scroll? int scrollOffset; beh->GetLocalParameterValue(eLocalParamScrollOffset, &scrollOffset); VxRect stringListRect = GetRectStringList(clientRect, fontHeight, columnsArray); if (!CGBLWidget::GetListRowRect(stringListRect, nFocus, scrollOffset, stringListArray->GetRowCount(), fontHeight, NULL)) { // Set the scroll offset to the focussed item scrollOffset = nFocus; beh->SetLocalParameterValue(eLocalParamScrollOffset, &scrollOffset); } } // Only handle mouse clicks and keyboard input when enabled if (CGBLWidget::IsWidgetEnabled(beh)) { // Handle the clicking of the scroll buttons HandleScrollButtonClicks(beh, inputManager, ent, clientRect, fontHeight, behContext.DeltaTime); // Get the string list area VxRect stringListRect = GetRectStringList(clientRect, fontHeight, columnsArray); if (isFocussed) { // Handle the pressing of the arrow keys HandleArrowKeyPresses(beh, inputManager, behContext.DeltaTime, stringListRect, fontHeight, stringListArray); // Handle the pressing of the space bar to select HandleSpaceBarPress(beh, inputManager, stringListArray); } // Handle clicking on the rows HandleListItemClicks(beh, inputManager, ent, stringListRect, stringListArray, fontHeight); } return behReturn; }
/* ******************************************************************* * Function: int PacketIterator( const CKBehaviorContext& behaviorContext ) * * Description : The execution function is the function that will be called * during the process loop of the behavior engine, if the behavior * is defined as using an execution function. This function is not * called if the behavior is defined as a graph. This function is the * heart of the behavior: it should compute the essence of the behavior, * in an incremental way. The minimum amount of computing should be * done at each call, to leave time for the other behaviors to run. * The function receives the delay in milliseconds that has elapsed * since the last behavioral process, and should rely on this value to * manage the amount of effect it has on its computation, if the effect * of this computation relies on time. * * Parameters : * behaviourContext r Behavior context reference, which gives access to * frequently used global objects ( context, level, manager, etc... ) * * Returns : int, If it is done, it should return CKBR_OK. If it returns * CKBR_ACTIVATENEXTFRAME, the behavior will again be called * during the next process loop. * ******************************************************************* */ int PacketIterator(const CKBehaviorContext& behcontext) { /************************************************************************/ /* collecting data : */ /* */ CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; CGBLCIConfigurationController* cman=(CGBLCIConfigurationController*)ctx->GetManagerByGuid(CONFIGURATION_MAN_GUID); CGBLCONetwork *networkInterface = cman->GetNetworkInterface(); ////////////////////////////////////////////////////////////////////////// /* check network -interace : */ if(!networkInterface->IsValid()) { //try to init the network interface : if ( networkInterface->Init() != CGBLCOError::GBLCO_OK ) { return CKBR_PARAMETERERROR; } } ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// //output packet info, this infos /*get the last index */ int index = 0; beh->GetLocalParameterValue(0, &index); /* bounding check for the index: if out of range, set to zero and save it.*/ if(index >= networkInterface->GetOutgoingPackets()->Size() ) { index = 0; beh->SetLocalParameterValue(0,&index); beh->ActivateOutput(0); return CKBR_OK; } /*************************************/ /* behavior trigger event processing : */ /* */ /* */ /* Reset/On : sets the index to zero and save it */ if( beh->IsInputActive(0) ) { beh->ActivateInput(0,FALSE); index = 0 ; beh->SetLocalParameterValue(0,&index); beh->ActivateInput(1,TRUE); } /* Loop In : */ if( beh->IsInputActive(1) ) { beh->ActivateInput(1,FALSE); if(networkInterface->GetOutgoingPackets()->Size() && index < networkInterface->GetOutgoingPackets()->Size() ) { //the following call is virtual. Both versions of ForwardPacketToScript are passing parameters to this building block. cman->GetNetworkInterface()->ForwardPacketToScript(beh,index); index++; beh->SetLocalParameterValue(0,&index); return CKBR_OK; } } return CKBR_OK; }
int PMaterialIterator(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; PhysicManager *pm = GetPMan(); pFactory *pf = pFactory::Instance(); if (beh->IsInputActive(0)) { beh->ActivateInput(0,FALSE); ////////////////////////////////////////////////////////////////////////// //we reset our session counter int sessionIndex=-1; beh->SetOutputParameterValue(0,&sessionIndex); LMaterials*sResults = NULL; beh->GetLocalParameterValue(0,&sResults); if (!sResults) { sResults = new LMaterials(); }else sResults->clear(); NxScene * scene = GetPMan()->getDefaultWorld()->getScene(); for(int i = 0 ; i < GetPMan()->getDefaultWorld()->getScene()->getNbMaterials() ; i ++) { NxMaterial *currentMaterial = scene->getMaterialFromIndex(i); sResults->push_back(currentMaterial); } beh->SetLocalParameterValue(0,&sResults); if (sResults->size()) { beh->ActivateInput(1); }else { beh->ActivateOutput(0); return 0; } } if( beh->IsInputActive(1) ) { beh->ActivateInput(1,FALSE); int currentIndex=0; CKParameterOut *pout = beh->GetOutputParameter(0); pout->GetValue(¤tIndex); currentIndex++; LMaterials *sResults = NULL; beh->GetLocalParameterValue(0,&sResults); if (!sResults) { beh->ActivateOutput(0); return 0; } if (currentIndex>=sResults->size()) { sResults->clear(); beh->ActivateOutput(0); return 0; } NxMaterial * material = sResults->at(currentIndex); if (material!=NULL) { int sIndex = currentIndex+1; beh->SetOutputParameterValue(0,&sIndex); //SetOutputParameterValue<int>(beh,O_XML,material->xmlLinkID); SetOutputParameterValue<float>(beh,O_DFRICTION,material->getDynamicFriction()); SetOutputParameterValue<float>(beh,O_SFRICTION,material->getStaticFriction()); SetOutputParameterValue<float>(beh,O_RES,material->getRestitution()); SetOutputParameterValue<float>(beh,O_DFRICTIONV,material->getDynamicFrictionV()); SetOutputParameterValue<float>(beh,O_SFRICTIONV,material->getStaticFrictionV()); SetOutputParameterValue<VxVector>(beh,O_ANIS,getFrom(material->getDirOfAnisotropy())); SetOutputParameterValue<int>(beh,O_FCMODE,material->getFrictionCombineMode()); SetOutputParameterValue<int>(beh,O_RCMODE,material->getFrictionCombineMode()); SetOutputParameterValue<int>(beh,O_FLAGS,material->getFlags()); } if(material->userData ) { pMaterial *bMaterial = static_cast<pMaterial*>(material->userData); if (bMaterial && bMaterial->xmlLinkID ) { int xid = bMaterial->xmlLinkID; XString nodeName = vtAgeia::getEnumDescription(GetPMan()->GetContext()->GetParameterManager(),VTE_XML_MATERIAL_TYPE,xid); CKParameterOut *nameStr = beh->GetOutputParameter(O_NAME); nameStr->SetStringValue(nodeName.Str()); } } //pFactory::Instance()->copyTo(beh->GetOutputParameter(O_MATERIAL),material); beh->ActivateOutput(0); } return 0; }
/* ******************************************************************* * Function: int CISIteratorBB( const CKBehaviorContext& behaviorContext ) * * Description : The execution function is the function that will be called * during the process loop of the behavior engine, if the behavior * is defined as using an execution function. This function is not * called if the behavior is defined as a graph. This function is the * heart of the behavior: it should compute the essence of the behavior, * in an incremental way. The minimum amount of computing should be * done at each call, to leave time for the other behaviors to run. * The function receives the delay in milliseconds that has elapsed * since the last behavioral process, and should rely on this value to * manage the amount of effect it has on its computation, if the effect * of this computation relies on time. * * Parameters : * behaviourContext r Behavior context reference, which gives access to * frequently used global objects ( context, level, manager, etc... ) * * Returns : int, If it is done, it should return CKBR_OK. If it returns * CKBR_ACTIVATENEXTFRAME, the behavior will again be called * during the next process loop. * ******************************************************************* */ int CISIteratorBB(const CKBehaviorContext& behcontext) { /************************************************************************/ /* collecting data : */ /* */ CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; CGBLCIConfigurationController* cman=(CGBLCIConfigurationController*)ctx->GetManagerByGuid(CONFIGURATION_MAN_GUID); /*get the last index */ int index = 0; beh->GetLocalParameterValue(BEH_LOCAL_PAR_INDEX_INDEX, &index); BOOL getFromDB = false; beh->GetLocalParameterValue(BEH_LOCAL_PAR_INDEX_DB_MODE,&getFromDB); using namespace GBLCommon::BehaviorTools; using namespace GBLCommon::ParameterTools; using namespace Customisation::typedefs; /************************************************************************/ /* behavior trigger event processing : */ /* */ /* */ /* Reset/On : sets the index to zero and save it */ if( beh->IsInputActive(0) ) { beh->ActivateInput(0,FALSE); if (getFromDB) { CKDataArray * resultArray = NULL; beh->GetLocalParameterValue(BEH_LOCAL_PAR_INDEX_CIID_LIST,&resultArray); if (resultArray) { resultArray->Clear(); while ( resultArray->GetColumnCount() ) resultArray->RemoveColumn(0); } else { resultArray = static_cast<CKDataArray*>(ctx->CreateObject( CKCID_DATAARRAY, "IGBLSMConfigurationAccess::CIS_IDLIST", CK_OBJECTCREATION_DYNAMIC )); } ctx->GetCurrentLevel()->AddObject( resultArray ); ////////////////////////////////////////////////////////////////////////// retrieve list of CI ID's : CGBLSMStorageManager *storageManager = static_cast<CGBLSMStorageManager *>(ctx->GetManagerByGuid(GBLSMStorageManagerGUID)); IGBLSMConfigurationAccess* smCIS = storageManager->GetConfigurationInterface(); int idCIS = GetInputParameterValue<int>(beh,BEH_IN_PAR_CIS_ID); smCIS->RetrieveCIList(resultArray,CGBLCISID(idCIS)); beh->SetLocalParameterValue(BEH_LOCAL_PAR_INDEX_CIID_LIST,&resultArray,sizeof(CKDataArray*)); int cis_size = resultArray->GetRowCount(); beh->SetLocalParameterValue(BEH_LOCAL_PAR_INDEX_CIS_SIZE,&cis_size); }else { Customisation::typedefs::CIS* currentCIS = cman->GetCIS(); if(!currentCIS) Logger::ShowDebugMessage(ctx,Logger::ELOGERROR,"CISIterator : couldn't find CIS"); } //reset counter : index = 0 ; beh->SetLocalParameterValue(BEH_LOCAL_PAR_INDEX_INDEX,&index); beh->ActivateInput(1,TRUE); } //get LA_ID : int cisSize; beh->GetLocalParameterValue(BEH_LOCAL_PAR_INDEX_CIS_SIZE,&cisSize); /* bounding check for the index: if out of range, set to zero and save it.*/ if(index > cisSize -1 ) { index = 0; beh->SetLocalParameterValue(BEH_LOCAL_PAR_INDEX_INDEX,&index); beh->ActivateOutput(0); return CKBR_OK; } /* Loop In : */ if( beh->IsInputActive(1) ) { beh->ActivateInput(1,FALSE); CGBLCI *currentCI = NULL; //ctx->OutputToConsole("asfasdf"); if (getFromDB) { CKDataArray * resultArray = NULL; beh->GetLocalParameterValue(BEH_LOCAL_PAR_INDEX_CIID_LIST,&resultArray); if (resultArray) { CGBLSMStorageManager *storageManager = static_cast<CGBLSMStorageManager *>(ctx->GetManagerByGuid(GBLSMStorageManagerGUID)); IGBLSMConfigurationAccess* smCIS = storageManager->GetConfigurationInterface(); CGBLCIConfigurationController* cman=static_cast<CGBLCIConfigurationController*>(ctx->GetManagerByGuid(CONFIGURATION_MAN_GUID)); IGBLCIAccessInterface * accessInterface = cman->GetCISAccessInterface(); currentCI = new CGBLCI("temp",CKPGUID_INT); int idCI; resultArray->GetElementValue(index,0,&idCI); accessInterface->GetCI(currentCI,idCI); beh->SetOutputParameterValue(BEH_OUT_PAR_INDEX_DB_INDEX,&idCI); }else { ctx->OutputToConsole("wrong array"); } }else { Customisation::typedefs::CISIterator it = cman->GetCIS()->GetIteratorByIndex(index); currentCI = (CGBLCI *)*it; } if (currentCI) { //output name : CKParameterOut *outName = beh->GetOutputParameter(BEH_OUT_PAR_INDEX_UNAME); outName->SetStringValue(currentCI->name.Str()); //output description: CKParameterOut *outDescr = beh->GetOutputParameter(BEH_OUT_PAR_INDEX_DESCRIPTION); outDescr->SetStringValue(currentCI->description.Str()); //output type int type = ctx->GetParameterManager()->ParameterGuidToType(currentCI->type); beh->SetOutputParameterValue(BEH_OUT_PAR_INDEX_TYPE,&type); //output value: CKParameterOut *outStrValue = beh->GetOutputParameter(BEH_OUT_PAR_INDEX_VALUE); outStrValue->SetStringValue(GetParameterAsString(currentCI->realValue)); //output default value: CKParameterOut *outDefaultStrValue = beh->GetOutputParameter(BEH_OUT_PAR_INDEX_DEFAULTVALUE); outDefaultStrValue->SetStringValue(GetParameterAsString(currentCI->defaultValue)); //output flags : beh->SetOutputParameterValue(BEH_OUT_PAR_INDEX_FLAGS,¤tCI->flags); }else { Logger::ShowDebugMessage(ctx,Logger::ELOGERROR,"CISIterator : couldn't find CI Parameter"); } //increase counter : index++; beh->SetLocalParameterValue(BEH_LOCAL_PAR_INDEX_INDEX,&index); beh->ActivateOutput(1); } return CKBR_OK; }
/* ******************************************************************* * Function: RenderCallback() * * Description : Is called from Virtools every frame. We draw the widget's visual elements in this function. * * Parameters : * Passed in from Virtools. See Virtools SDK documentation: * *renderContext, rw: * renderObject, rw: * *iArg, rw: * * Returns : Return TRUE for success or FALSE for failure. The implications of returning FALSE are not documented in the Virtools * SDK documentation. Let's hope it doesn't format the user's hard disk. * ******************************************************************* */ CKBOOL CGBLListBox::RenderCallback(CKRenderContext *renderContext, CKRenderObject* renderObject, void *iArg) { const int cFixedStringBufferSize = 256; static VxRect fullUVRect(0.0f, 0.0f, 1.0f, 1.0f); CKContext* context = renderContext->GetCKContext(); CK2dEntity* ent = CK2dEntity::Cast(renderObject); // Sanity check if (!ent) { assert(NULL); return FALSE; } // Get a pointer to the building block behaviour CKBehavior* beh = (CKBehavior*)context->GetObject(reinterpret_cast<CK_ID>(iArg)); if (!beh) return FALSE; // Use clipping class to manage the clipping for us CGBLRenderClipper cRenderClipper(renderContext, ent); // Get client rectangle VxRect clientRect; ent->GetExtents(fullUVRect, clientRect); // Get the font from the base helper class VirtoolsSource::CKTextureFont* font = CGBLWidget::GetFont(context, beh); if (!font) { // Don't output an error - we check for a font in the behavioural function return FALSE; } // Get material CKMaterial* material = (CKMaterial*)beh->GetInputParameterObject(eParamInputMaterial); if (!material) { return FALSE; } // Are we using proportional scaling? CKBOOL isPropScaling = CGBLWidget::IsProportionalScaling(beh); // Get the font height float fontHeight = CGBLWidget::GetFontHeight(font, renderContext, isPropScaling); // Render down arrow CKBOOL isDownButtonPressed = FALSE; beh->GetLocalParameterValue(eLocalParamIsScrollDownButtonPressed, &isDownButtonPressed); VxRect buttonRect = GetRectDownArrow(clientRect, fontHeight); CGBLWidget::DrawMaterialRectangle(renderContext, material, buttonRect, isDownButtonPressed ? CGBLWidgetsTheme::GetListBoxRegionDownArrowPressed() : CGBLWidgetsTheme::GetListBoxRegionDownArrowUnpressed(), clientRect); // Render up arrow CKBOOL isUpButtonPressed = FALSE; beh->GetLocalParameterValue(eLocalParamIsScrollUpButtonPressed, &isUpButtonPressed); buttonRect = GetRectUpArrow(clientRect, fontHeight); CGBLWidget::DrawMaterialRectangle(renderContext, material, buttonRect, isUpButtonPressed ? CGBLWidgetsTheme::GetListBoxRegionUpArrowPressed() : CGBLWidgetsTheme::GetListBoxRegionUpArrowUnpressed(), clientRect); // Render headings if present // Get columns array CKDataArray* columnsArray = static_cast<CKDataArray*>(beh->GetInputParameterObject(eParamInputColumnsArray)); int numColumns = columnsArray ? columnsArray->GetRowCount() : 1; // If we have at least one row in the columns array, we are drawing headings if (columnsArray && (columnsArray->GetRowCount() >= 1)) { VxRect headingsRect = GetRectHeadings(clientRect, fontHeight, columnsArray); VxRect headingRect = headingsRect; for (int column = 0;column < numColumns;column++) { headingRect.right = headingRect.left + GetColumnWidth(beh, columnsArray, column) * headingsRect.GetWidth() / 100.0f; // Draw heading background CGBLWidget::DrawMaterialRectangle(renderContext, material, headingRect, CGBLWidgetsTheme::GetListBoxRegionHeadingBackground(), headingsRect); // Draw heading text CKCHAR fixedBuffer[cFixedStringBufferSize]; CKSTRING headingText = NULL; int labelLength = columnsArray->GetElementStringValue(column, eColumnsArrayColumnHeading, NULL); if (labelLength > cFixedStringBufferSize) headingText = new CKCHAR[labelLength]; else headingText = fixedBuffer; if (headingText) { columnsArray->GetElementStringValue(column, eColumnsArrayColumnHeading, headingText); int textOptions = TEXT_CLIP; if (isPropScaling) textOptions |= TEXT_SCREEN; VxRect clippedHeadingRect = headingRect; clippedHeadingRect.Clip(headingsRect); // Use margin clippedHeadingRect.left += CGBLWidgetsTheme::GetStringListBoxTextMargin() * fontHeight; font->DrawCKText(renderContext, ent, headingText, VALIGN_BOTTOM | HALIGN_LEFT, clippedHeadingRect, NULL, textOptions, TRUE); // Delete the buffer? if (headingText != fixedBuffer) delete[] headingText; } // Move to next heading headingRect.left = headingRect.right; } } // Get data array and output error if we don't have one CKDataArray* stringListArray = static_cast<CKDataArray*>(beh->GetInputParameterObject(eParamInputStringListArray)); if (!stringListArray) return FALSE; // Get space for list box strings area VxRect stringListRect = GetRectStringList(clientRect, fontHeight, columnsArray); // Draw columns backgrounds now VxRect columnRect = stringListRect; for (int column = 0;column < numColumns;column++) { columnRect.right = columnRect.left + GetColumnWidth(beh, columnsArray, column) * stringListRect.GetWidth() / 100.0f; // Draw column background CGBLWidget::DrawMaterialRectangle(renderContext, material, columnRect, CGBLWidgetsTheme::GetListBoxRegionColumnBackground(), stringListRect); // Move to next column columnRect.left = columnRect.right; } // Get the scroll offset int scrollOffset = 0; beh->GetLocalParameterValue(eLocalParamScrollOffset, &scrollOffset); // Range check the scroll offset int nRowsVisible = static_cast<int>(stringListRect.GetHeight() / fontHeight + 0.01); // Add fudge factor to avoid rounding down errors if ((scrollOffset + nRowsVisible - 1) >= stringListArray->GetRowCount()) scrollOffset = stringListArray->GetRowCount() - nRowsVisible; if (scrollOffset < 0) scrollOffset = 0; // Re-set scroll offset local param beh->SetLocalParameterValue(eLocalParamScrollOffset, &scrollOffset); // Draw any selection highlights VxRect rowRect; for (int row = scrollOffset; CGBLWidget::GetListRowRect(stringListRect, row, scrollOffset, stringListArray->GetRowCount(), fontHeight, &rowRect); row++) { CKBOOL rowSelected = FALSE; stringListArray->GetElementValue(row, CGBLWidget::eStringListArrayColumnSelected, &rowSelected); if (rowSelected) CGBLWidget::DrawMaterialRectangle(renderContext, material, rowRect, CGBLWidgetsTheme::GetListBoxRegionSelectedBackground()); } // Draw column strings now columnRect = stringListRect; for (int column = 0;column < numColumns;column++) { columnRect.right = columnRect.left + GetColumnWidth(beh, columnsArray, column) * stringListRect.GetWidth() / 100.0f; // Select which column to pick from the string list array int arrayColumn; if (column) arrayColumn = column + CGBLWidget::eStringListArrayColumnAdditionalLabels - 1; else arrayColumn = column; VxRect clippedColumnRect = columnRect; clippedColumnRect.Clip(stringListRect); CGBLWidget::DrawStringListColumn(renderContext, ent, font, isPropScaling, stringListArray, arrayColumn, clippedColumnRect, scrollOffset, column == 0); // Move to next column columnRect.left = columnRect.right; } // Disable the scroll buttons? if (scrollOffset == 0) CGBLWidget::DrawDisabledRectangle(renderContext, GetRectUpArrow(clientRect, fontHeight), clientRect); if ((scrollOffset + nRowsVisible) > (stringListArray->GetRowCount() - 1) ) CGBLWidget::DrawDisabledRectangle(renderContext, GetRectDownArrow(clientRect, fontHeight), clientRect); CKBOOL isFocussed = CGBLWidget::IsWidgetFocussed(beh); // If we're focussed, draw a focus rectangle around our focussed item if (isFocussed) { int focussedItem = 0; beh->GetLocalParameterValue(eLocalParamFocussedItem, &focussedItem); if (CGBLWidget::GetListRowRect(stringListRect, focussedItem, scrollOffset, stringListArray->GetRowCount(), fontHeight, &rowRect)) { // draw focus around the selected item CGBLWidget::DrawFocusHighlight(renderContext, beh, rowRect, FALSE); } else { // see if the list is empty if ((!stringListArray)||(stringListArray->GetRowCount()<=0)) { // Draw focus around the full list box CGBLWidget::DrawFocusHighlight(renderContext, beh, clientRect, FALSE); } else { // The list isnt empty but the current item is unselectable } } } // If widget is disabled, draw whole widget area disabled if (!CGBLWidget::IsWidgetEnabled(beh)) { CGBLWidget::DrawDisabledRectangle(renderContext, GetRectUpArrow(clientRect, fontHeight), clientRect); CGBLWidget::DrawDisabledRectangle(renderContext, GetRectDownArrow(clientRect, fontHeight), clientRect); CGBLWidget::DrawDisabledRectangle(renderContext, GetRectHeadings(clientRect, fontHeight, columnsArray), clientRect); CGBLWidget::DrawDisabledRectangle(renderContext, GetRectStringList(clientRect, fontHeight, columnsArray), clientRect); } return TRUE; }
//************************************ // Method: PBGet2 // FullName: PBGet2 // Access: public // Returns: int // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ int PBGet2(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; PhysicManager *pm = GetPMan(); pFactory *pf = pFactory::Instance(); using namespace vtTools::BehaviorTools; if( beh->IsInputActive(0) ) { ////////////////////////////////////////////////////////////////////////// //the object : CK3dEntity *target = (CK3dEntity *) beh->GetTarget(); if( !target ) return CKBR_OWNERERROR; ////////////////////////////////////////////////////////////////////////// // the world : pWorld *world=GetPMan()->getWorldByBody(target); if (!world) { beh->ActivateOutput(0); return 0; } // body exists already ? clean and delete it : pRigidBody*result = world->getBody(target); if(result) { ////////////////////////////////////////////////////////////////////////// //linear damp : DWORD cGroup; beh->GetLocalParameterValue(bbI_CollisionGroup,&cGroup); if (cGroup) { int val = result->getCollisionsGroup(); SetOutputParameterValue<int>(beh,bbI_CollisionGroup,val); } DWORD kine; beh->GetLocalParameterValue(bbI_Kinematic,&kine); if (kine) { int val = result->isKinematic(); SetOutputParameterValue<int>(beh,bbI_Kinematic,val); } DWORD gravity; beh->GetLocalParameterValue(bbI_Gravity,&gravity); if (gravity) { int val = result->getActor()->readBodyFlag(NX_BF_DISABLE_GRAVITY); SetOutputParameterValue<int>(beh,bbI_Gravity,!val); } DWORD col; beh->GetLocalParameterValue(bbI_Collision,&col); if (col) { int val = result->isCollisionEnabled(); SetOutputParameterValue<int>(beh,bbI_Collision,val); } DWORD mass; beh->GetLocalParameterValue(bbI_MassOffset,&mass); if (mass) { VxVector val = result->getMassOffset(); SetOutputParameterValue<VxVector>(beh,bbI_MassOffset,val); } DWORD pivot; beh->GetLocalParameterValue(bbI_ShapeOffset,&pivot); if (mass) { // VxVector val = result->getPivotOffset(); // SetOutputParameterValue<VxVector>(beh,bbI_ShapeOffset,val); } } beh->ActivateInput(0,FALSE); beh->ActivateOutput(0); } return 0; }