CKERROR MidiEventCallBack(const CKBehaviorContext& behcontext){ CKBehavior *beh = behcontext.Behavior; MidiManager *mm = (MidiManager *) behcontext.Context->GetManagerByGuid( MIDI_MANAGER_GUID ); switch( behcontext.CallbackMessage ){ case CKM_BEHAVIOREDITED: { int c_pin = beh->GetInputParameterCount(); char name[20]; CKParameterIn *pin; for( int a=2 ; a<c_pin ; a++){ pin = beh->GetInputParameter(a); sprintf( name, "Note %d", a); pin->SetName( name ); pin->SetGUID( CKPGUID_INT ); } } break; case CKM_BEHAVIORATTACH: case CKM_BEHAVIORLOAD: { mm->AddMidiBBref(); } break; case CKM_BEHAVIORDETACH: { mm->RemoveMidiBBref(); } break; } return CKBR_OK; }
/* ******************************************************************* * Function: BOOL :CreateIO(CKBehavior* behaviour, CKBehavior* script) * * Description : Check if all the Inputs,Outputs, pIns and pOuts of both behavior are matching * * Parameters : * behaviour Behavior 1, usually the BG wrapper BB. * script Behavior 2, usually the wrapped BG. * * Returns : BOOL * ******************************************************************* */ BOOL GBLCOBGWrapper::CreateIO(CKBehavior* behaviour, CKBehavior* script) { int iIO; int nbPin; // Input nbPin = script->GetInputCount(); for (iIO = 0; iIO < nbPin; iIO++) { CKBehaviorIO* pPin = script->GetInput(iIO); if (pPin == NULL) return FALSE; if (behaviour->AddInput(pPin->GetName()) != iIO) return FALSE; } // Output nbPin = script->GetOutputCount(); for (iIO = 0; iIO < nbPin; iIO++) { CKBehaviorIO* pPin = script->GetOutput(iIO); if (pPin == NULL) return FALSE; if (behaviour->AddOutput(pPin->GetName()) != iIO) return FALSE; } // Parameter In nbPin = script->GetInputParameterCount(); for (iIO = 0; iIO < nbPin; iIO++) { CKParameterIn* pPin = script->GetInputParameter(iIO); if (pPin == NULL) return FALSE; CKParameterIn* pPin2; if ((pPin2 = behaviour->CreateInputParameter(pPin->GetName(), (CKParameterType)pPin->GetType())) == NULL) return FALSE; } // Parameter Out nbPin = script->GetOutputParameterCount(); for (iIO = 0; iIO < nbPin; iIO++) { CKParameterOut* pPin = script->GetOutputParameter(iIO); if (pPin == NULL) return FALSE; if (behaviour->CreateOutputParameter(pPin->GetName(), (CKParameterType)pPin->GetType()) == NULL) return FALSE; } return TRUE; }
/* ******************************************************************* * Function: BOOL CheckIO(CKBehavior* behaviour, CKBehavior* script) * * Description : Check if all the Inputs,Outputs, pIns and pOuts of both behavior are matching * * Parameters : * behaviour Behavior 1, usually the BG wrapper BB. * script Behavior 2, usually the wrapped BG. * * Returns : BOOL * ******************************************************************* */ BOOL GBLCOBGWrapper::CheckIO(CKBehavior* behaviour, CKBehavior* script) { int iParam; int nbPin0, nbPin1; int flag = 0; // Input nbPin0 = behaviour->GetInputCount(); nbPin1 = script->GetInputCount(); if (nbPin0 != nbPin1) return FALSE; // Ouput nbPin0 = behaviour->GetOutputCount(); nbPin1 = script->GetOutputCount(); if (nbPin0 != nbPin1) return FALSE; // Parameter In nbPin0 = behaviour->GetInputParameterCount(); nbPin1 = script->GetInputParameterCount(); if (nbPin0 != nbPin1) return FALSE; for (iParam = 0; iParam < nbPin0; iParam++) { CKParameterIn* pSin = script->GetInputParameter(iParam); CKParameterIn* pBin = behaviour->GetInputParameter(iParam); if (pSin == NULL || pBin == NULL) return FALSE; if (pSin->GetType() != pBin->GetType()) return FALSE; } // Parameter Out nbPin0 = behaviour->GetOutputParameterCount(); nbPin1 = script->GetOutputParameterCount(); if (nbPin0 != nbPin1) return FALSE; for (iParam = 0; iParam < nbPin0; iParam++) { CKParameterOut* pSout = script->GetOutputParameter(iParam); CKParameterOut* pBout = behaviour->GetOutputParameter(iParam); if (pSout == NULL || pBout == NULL) return FALSE; if (pSout->GetType() != pBout->GetType()) return FALSE; } return TRUE; }
/* ******************************************************************* * Function: int CGBLBuildCommand::GetNextArgument (CKParameter* nextArgument,CKBehavior* targetBB, const CKBehaviorContext& behaviorContext) * * Description : This function sets corresponding outputs with requested argument's * name, type and if the type of arguments is TGBLFCStringFromList, it also * provides designer specified list array with GetDesignerSpecifiedList output. * * Parameters : * behaviourContext r Behavior context reference, which gives * access to frequently used global objects * ( context, level, manager, etc... ) * * nextArgument r Required argument to have parameters provided by the command * * targetBB r Target GBLWaitForCommand building block * * Returns : int, The return value is 0 if no error occured or -1 on error * ******************************************************************* */ int CGBLBuildCommand::GetNextArgument (CKParameter* nextArgument,CKBehavior* targetBB, const CKBehaviorContext& behaviorContext) { CKBehavior* behavior = behaviorContext.Behavior; CKContext* context = behaviorContext.Context; XString typeName = context->GetParameterManager()->ParameterTypeToName(nextArgument->GetType()); XString argumentName = nextArgument->GetName(); if (typeName == "TGBLFCStringFromList") { int inputs = targetBB->GetInputParameterCount(); for (int i=0; i<inputs; i++) { CKParameterIn *parameterInput = targetBB->GetInputParameter(i); if ( argumentName == parameterInput->GetName() ) { CKParameterOut *parameterOutput = behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetDesignerSpecifiedList); context->OutputToConsole(context->GetParameterManager()->ParameterTypeToName(parameterOutput->GetType()), FALSE); context->OutputToConsole(context->GetParameterManager()->ParameterTypeToName(parameterInput->GetType()), FALSE); parameterOutput->CopyValue (parameterInput->GetDirectSource()); break; } } } behavior->SetOutputParameterValue (EGBLBuildCommandParamOutputs::GetArgumentType, typeName.Str(), strlen (typeName.Str()) + 1 ); behavior->SetOutputParameterValue (EGBLBuildCommandParamOutputs::GetArgumentName, argumentName.Str(), strlen (argumentName.Str()) + 1 ); behavior->ActivateOutput (EGBLBuildCommandBehOutputs::GetNextParameterValue); return 0; }
int GBLCOBGWrapper::BehaviourFunction( const CKBehaviorContext& behContext ) { CKBehavior *behaviour = behContext.Behavior; CKContext *context = behContext.Context; int iPin, nbPin; CKBehavior* script = (CKBehavior*)behaviour->GetLocalParameterObject(EGBLCOBGWRAPPERPARAM_PARAMETER_SCRIPT); if (script == NULL) return CKBR_GENERICERROR; // Activate the right inputs nbPin = behaviour->GetInputCount(); for (iPin = 0; iPin < nbPin; iPin++) { if (behaviour->IsInputActive(iPin)) { script->ActivateInput(iPin, TRUE); behaviour->ActivateInput(iPin, FALSE); } } // Deactivate all the outputs nbPin = script->GetOutputCount(); for (iPin = 0; iPin < nbPin; iPin++) { behaviour->ActivateOutput(iPin, FALSE); } // Parameter In: Set Source int nbPinBB = behaviour->GetInputParameterCount(); int nbPinBG = script->GetInputParameterCount(); if (nbPinBB != nbPinBG) return CKBR_GENERICERROR; for (iPin = 0; iPin < nbPinBB; iPin++) { CKParameterIn *pBin = behaviour->GetInputParameter(iPin); CKParameter* pSource = pBin->GetDirectSource(); CKParameterIn *pSin = script->GetInputParameter(iPin); pSin->SetDirectSource(pSource); } // Execute the contained script CKERROR result = script->Execute(behContext.DeltaTime); // The script loop on itself too much times if (result == CKBR_INFINITELOOP) { context->OutputToConsoleExBeep("Execute Script : Script %s Executed too much times",script->GetName()); script->Activate(FALSE,FALSE); return CKBR_OK; } // Activate the right outputs nbPin = script->GetOutputCount(); for (iPin = 0; iPin < nbPin; iPin++) { if (script->IsOutputActive(iPin)) { behaviour->ActivateOutput(iPin); script->ActivateOutput(iPin, FALSE); } } // Update Parameters Out nbPin = behaviour->GetOutputParameterCount(); for (iPin = 0; iPin < nbPin; iPin++) { CKParameterOut *pBout = behaviour->GetOutputParameter(iPin); CKParameterOut *pSout = script->GetOutputParameter(iPin); pBout->CopyValue(pSout, TRUE); } // Test if there are any active sub-behaviors, restart the next frame if any BOOL bActivateNextFrame = FALSE; ActivateNextFrameSubBB(script,bActivateNextFrame); if (bActivateNextFrame) return CKBR_ACTIVATENEXTFRAME; // return the execute value return result; }
//************************************ // 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; }
int PVSetMotorValues(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); CK3dEntity *target = (CK3dEntity *) beh->GetTarget(); if( !target ) bbSErrorME(E_PE_REF); pRigidBody *body = GetPMan()->getBody(target); if (!body) bbSErrorME(E_PE_NoBody); pVehicle *v = body->getVehicle(); if (!v) bbSErrorME(E_PE_NoVeh); if (!v->isValidEngine()) bbErrorME("Vehicle is not complete"); pEngine *engine = v->getEngine(); if (!engine) bbErrorME("No valid engine"); CK2dCurve* pOCurve = NULL; //optional BB_DECLARE_PIMAP;//retrieves the parameter input configuration array BBSParameter(I_XML);//our bb settings concated as s##I_XML BBSParameter(I_Flags); BBSParameter(I_Clutch); BBSParameter(I_tList); BBSParameter(I_maxRPM); BBSParameter(I_minRPM); BBSParameter(I_maxTorque); BBSParameter(I_intertia); BBSParameter(I_engineFriction); BBSParameter(I_breakCoeff); BBSParameter(I_GroundForceFeedBackScale); if (sI_XML){ int xmlLink = GetInputParameterValue<int>(beh,BB_IP_INDEX(I_XML)); } if (sI_GroundForceFeedBackScale) engine->setForceFeedbackScale(GetInputParameterValue<float>(beh,BB_IP_INDEX(I_GroundForceFeedBackScale))); if (sI_Flags) engine->setFlags(GetInputParameterValue<int>(beh,BB_IP_INDEX(I_Flags))); if (sI_Clutch) engine->setClutch(GetInputParameterValue<float>(beh,BB_IP_INDEX(I_Clutch))); if (sI_maxTorque) engine->setMaxTorque(GetInputParameterValue<float>(beh,BB_IP_INDEX(I_maxTorque))); if (sI_maxTorque) engine->setMaxTorque(GetInputParameterValue<float>(beh,BB_IP_INDEX(I_maxTorque))); if (sI_maxRPM) engine->setMaxRPM(GetInputParameterValue<float>(beh,BB_IP_INDEX(I_maxRPM))); if (sI_minRPM) engine->setIdleRPM(GetInputParameterValue<float>(beh,BB_IP_INDEX(I_minRPM))); if (sI_engineFriction) engine->setFriction(GetInputParameterValue<float>(beh,BB_IP_INDEX(I_engineFriction))); if (sI_intertia) engine->SetInertia(GetInputParameterValue<float>(beh,BB_IP_INDEX(I_intertia))); if (sI_breakCoeff) engine->setBrakingCoeff(GetInputParameterValue<float>(beh,BB_IP_INDEX(I_breakCoeff))); if (sI_tList){ CKParameterIn *inP = beh->GetInputParameter(BB_IP_INDEX(I_tList)); CKParameter *pout= inP->GetDirectSource(); if (pout) { if (engine->getTorqueCurve()) { pLinearInterpolation &curve = *engine->getTorqueCurve(); curve.clear(); IParameter::Instance()->copyTo(curve,pout); engine->preStep(); } } //engine->setTorqueCurve(); } ////////////////////////////////////////////////////////////////////////// //a optinal curve to display ratio between horse power and rpm /* DWORD outputCurve; beh->GetLocalParameterValue(BB_PMAP_SIZE(gPIMAP),&outputCurve);//special settings ! if (outputCurve) beh->GetOutputParameterValue(0,&pOCurve); */ ////////////////////////////////////////////////////////////////////////// // // Checking we have to replace of the entire motor object ! // if (sI_tList) { float maxInputRPM =0.0f; float maxInputNM =0.0f; ////////////////////////////////////////////////////////////////////////// // // this is only a test run ! pLinearInterpolation nTable; //getNewTorqueTable(beh,nTable,maxInputRPM,maxInputNM,NULL); if (nTable.getSize() ) { /* if (pOCurve) { while (pOCurve->GetControlPointCount()) { pOCurve->DeleteControlPoint(pOCurve->GetControlPoint(0)); pOCurve->Update(); } } */ ////////////////////////////////////////////////////////////////////////// // we just copy into the motor we can get ! ////////////////////////////////////////////////////////////////////////// // we make a new torque ratios //getNewTorqueTable(beh,mDesc->torqueCurve,maxInputRPM,maxInputNM,pOCurve); /* if (!mDesc->isValid()) bbErrorME("motor description was invalid, aborting update "); if (!motor) { motor = pFactory::Instance()->createVehicleMotor(*mDesc); v->setMotor(motor); }else { if (mDesc->torqueCurve.getSize()) { motor->loadNewTorqueCurve(mDesc->torqueCurve); } }*/ } } ////////////////////////////////////////////////////////////////////////// // // Flexibility : // /* if (sI_minRDown && motor )motor->setMinRpmToGearDown(mDDown); if (sI_maxRUp && motor )motor->setMaxRpmToGearUp(mDUp); if (sI_maxR && motor )motor->setMaxRpm(maxR); if (sI_minR && motor )motor->setMinRpm(minR); */ if ( pOCurve ) { /* #ifdef _DEBUG XString error; error << "t curve created with " << pOCurve->GetControlPointCount() << " with l : " << pOCurve->GetLength(); bbErrorME(error.CStr()); #endif */ /* for (int i = 0 ; i < pOCurve->GetControlPointCount() ; i++) { CK2dCurvePoint* point = pOCurve->GetControlPoint(i); point->SetLinear(true); } pOCurve->Update(); beh->SetOutputParameterValue(0,&pOCurve); */ } //delete mDesc; //mDesc = NULL; } beh->ActivateOutput(0); return 0; }
/* ******************************************************************* * Function: int BehaviourFunction() * * Description : Returns the number of plugins in this DLL * * Paramters : * CKBehaviorContext& r The virtools behaviour context * * Returns : One of the many virtools return values * ******************************************************************* */ int CGBLLOGetMOStatus::BehaviourFunction(const CKBehaviorContext& behContext) { CKBehavior* beh = behContext.Behavior; CKBOOL localError = false; CGBLCOError retVal(CGBLCOError::EGBLCOErrorType::GBLCO_OK); MeasuredObjectiveControllerMgr* MOMngr = static_cast<MeasuredObjectiveControllerMgr*>(behContext.Context->GetManagerByGuid(MeasuredObjectiveControllerMgrGUID)); // Check to see if we got the manager ok if (!MOMngr) { assert(NULL); return CKBR_OK; } if (beh->IsInputActive(eBehInputStart)) { // Get the details of the MO P-In CKParameterIn *pIn = beh->GetInputParameter(eParamInputMO); CKParameter *moParam = pIn->GetRealSource(); // Ensure we read the P-In ok if (!moParam) { // Report the error CKParameterOut *pOut = beh->GetOutputParameter(eParamOutputGetError); TGBLError::SetTGBLError(pOut, CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL, GBLLO_ERROR_NO_PARAM_FROM_BB,GBLLO_ERROR_NO_DATA_FROM_BB_DESC); beh->ActivateOutput(eBehOutputError, TRUE); localError = true; } if (!localError) { // Get the data from the P-In CGBLMOData *moData = static_cast<CGBLMOData*>(moParam->GetAppData()); if (moData) { // Get the name from the MO and use this to get the // runtime MO from the controller XString moName = moData->GetName(); CGBLLOMeasuredObjective *mo=NULL; retVal=MOMngr->GetRunTimeMO(moName,mo); // See if the controller gave us the MO if((retVal==CGBLCOError::EGBLCOErrorType::GBLCO_OK)&&(mo)) { // Get the status of the MO bool moStatus=mo->GetMOStatus(); // return the status of the MO back to Virtools Dev beh->SetOutputParameterValue(eParamOutputGetStatus, &moStatus); } } else { // Report the fact that we couldnt create a runtime MO from the param CKParameterOut *pOut = beh->GetOutputParameter(eParamOutputGetError); TGBLError::SetTGBLError(pOut, CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL, GBLLO_ERROR_NO_DATA_FROM_BB,GBLLO_ERROR_NO_DATA_FROM_BB_DESC); beh->ActivateOutput(eBehOutputError, TRUE); localError = true; } } } if (localError) { // error allready dealt with } else if (retVal!=CGBLCOError::EGBLCOErrorType::GBLCO_OK) { // Report the error back to Virtools dev CKParameterOut *pOut = beh->GetOutputParameter(eParamOutputGetError); const char* errorString = retVal; TGBLError::SetTGBLError(pOut, retVal,retVal,(CKSTRING)errorString); beh->ActivateOutput(eBehOutputError, TRUE); } else { // We are ok beh->ActivateOutput(eBehOutputDone, TRUE); } 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; }
//************************************ // Method: PVWSet // FullName: PVWSet // Access: public // Returns: int // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ int PVWSet(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 : CK3dEntity *target = (CK3dEntity *) beh->GetTarget(); if( !target ) bbErrorME("No Reference Object specified"); pRigidBody *body = NULL; body = GetPMan()->getBody(target); if (!body) bbErrorME("No Reference Object specified"); pWheel *wheel = body->getWheel(target); if (!wheel)bbErrorME("pWheel object doesnt exist!"); pWheel2 *wheel2 = wheel->castWheel2(); if (!wheel2)bbErrorME("Couldnt cast a pWheel2 object"); BB_DECLARE_PIMAP; /************************************************************************/ /* engel kuehne un partner */ /************************************************************************/ /************************************************************************/ /* retrieve settings state */ /************************************************************************/ BBSParameter(bbI_XML); BBSParameter(bbI_AxleSpeed); BBSParameter(bbI_Steer); BBSParameter(bbI_MotorTorque); BBSParameter(bbI_BrakeTorque); BBSParameter(bbI_SuspensionSpring); BBSParameter(bbI_SuspensionTravel); BBSParameter(bbI_Radius); BBSParameter(bbI_WFlags); BBSParameter(bbI_WSFlags); BBSParameter(bbI_LatFunc); BBSParameter(bbI_LongFunc); /************************************************************************/ /* retrieve values */ /************************************************************************/ int xmlValue = GetInputParameterValue<int>(beh,BB_IP_INDEX(bbI_XML)); float axleVel = GetInputParameterValue<float>(beh,BB_IP_INDEX(bbI_AxleSpeed)); float steer = GetInputParameterValue<float>(beh,BB_IP_INDEX(bbI_Steer)); float mTorque = GetInputParameterValue<float>(beh,BB_IP_INDEX(bbI_MotorTorque)); float bTorque = GetInputParameterValue<float>(beh,BB_IP_INDEX(bbI_BrakeTorque)); float suspensionTravel = GetInputParameterValue<float>(beh,BB_IP_INDEX(bbI_SuspensionTravel)); int wFlags = GetInputParameterValue<int>(beh,BB_IP_INDEX(bbI_WFlags)); int wSFlags = GetInputParameterValue<int>(beh,BB_IP_INDEX(bbI_WSFlags)); pSpring sSpring; if (sbbI_SuspensionSpring) { CKParameterIn *par = beh->GetInputParameter(bbI_SuspensionSpring); if (par) { CKParameter *rPar = par->GetRealSource(); if (rPar) { sSpring = pFactory::Instance()->createSpringFromParameter(rPar); NxSpringDesc xsp; xsp.damper = sSpring.damper; xsp.spring = sSpring.spring; xsp.targetValue = sSpring.targetValue; if (xsp.isValid()) { wheel2->setSuspensionSpring(sSpring); }else bbErrorME("Invalid Spring Setings!"); } } } /************************************************************************/ /* Update Object ! */ /************************************************************************/ ////////////////////////////////////////////////////////////////////////// // load some settings from XML if(sbbI_XML) { } if (sbbI_Steer)wheel2->setAngle(steer); if (sbbI_AxleSpeed)wheel2->setAxleSpeed(axleVel); if (sbbI_MotorTorque)wheel2->setMotorTorque(mTorque); if (sbbI_BrakeTorque)wheel2->setBreakTorque(bTorque); if (sbbI_SuspensionSpring)wheel2->setSuspensionSpring(sSpring); if (sbbI_SuspensionTravel)wheel2->setSuspensionTravel(suspensionTravel); if (sbbI_WFlags) { ////////////////////////////////////////////////////////////////////////// // // wheel2->setFlags(wFlags); } if (sbbI_WSFlags) { wheel2->getWheelShape()->setWheelFlags(wSFlags); } if (sbbI_LatFunc) { CKParameterIn *par = beh->GetInputParameter(BB_IP_INDEX(bbI_LatFunc)); if (par) { CKParameter *rPar = par->GetRealSource(); if (rPar) { pTireFunction func = pFactory::Instance()->createTireFuncFromParameter(rPar); if (func.isValid()) { NxTireFunctionDesc xFn; xFn.asymptoteSlip = func.asymptoteSlip; xFn.asymptoteValue = func.asymptoteValue; xFn.extremumSlip= func.extremumSlip; xFn.extremumValue= func.extremumValue; xFn.stiffnessFactor= func.stiffnessFactor; wheel2->getWheelShape()->setLongitudalTireForceFunction(xFn); }else bbErrorME("Invalid Tire Function Settings!"); } } } if (sbbI_LongFunc) { CKParameterIn *par = beh->GetInputParameter(BB_IP_INDEX(bbI_LongFunc)); if (par) { CKParameter *rPar = par->GetRealSource(); if (rPar) { pTireFunction func = pFactory::Instance()->createTireFuncFromParameter(rPar); if (func.isValid()) { NxTireFunctionDesc xFn; xFn.asymptoteSlip = func.asymptoteSlip; xFn.asymptoteValue = func.asymptoteValue; xFn.extremumSlip= func.extremumSlip; xFn.extremumValue= func.extremumValue; xFn.stiffnessFactor= func.stiffnessFactor; wheel2->getWheelShape()->setLongitudalTireForceFunction(xFn); }else bbErrorME("Invalid Tire Function Settings!"); } } } } beh->ActivateOutput(0); return 0; }
//************************************ // Method: vt_GetInVal // FullName: vt_GetInVal // Access: public static // Returns: PyObject * // Qualifier: // Parameter: PyObject * self // Parameter: PyObject * args //************************************ static PyObject *vt_GetInVal( PyObject * self, PyObject * args ) { int size = PyTuple_Size(args); int bid, index; PyArg_ParseTuple(args, "ii", &bid, &index); CK_ID cid = bid; CKBehavior *beh = static_cast<CKBehavior*>(pym->m_Context->GetObject(cid)); if (size!=2) { pym->m_Context->OutputToConsole("PyError : This function needs 2 arguments : \n\t bid,index"); Py_RETURN_NONE; } using namespace vtTools; using namespace vtTools::Enums; CKParameterManager *pam = static_cast<CKParameterManager *>(pym->m_Context->GetParameterManager()); if (index < beh->GetInputParameterCount() ) { CKParameterIn *ciIn = beh->GetInputParameter(index); CKParameterType pType = ciIn->GetType(); vtTools::Enums::SuperType sType = ParameterTools::GetVirtoolsSuperType(pym->m_Context,pam->ParameterTypeToGuid(pType)); PyObject *val; switch (sType) { case vtSTRING: { val = PyString_FromString( vtTools::BehaviorTools::GetInputParameterValue<CKSTRING>(beh,index )); break; } case vtFLOAT: { val = PyFloat_FromDouble(static_cast<float>(vtTools::BehaviorTools::GetInputParameterValue<float>(beh,index ))); break; } case vtINTEGER: { val = PyInt_FromLong( static_cast<long>(vtTools::BehaviorTools::GetInputParameterValue<int>(beh,index ))); break; } default : XString err("wrong input parameter type: "); err << ciIn->GetName() << "Only Types derivated from Interger,Float or String are acceptable"; pym->m_Context->OutputToConsole(err.Str(),FALSE ); Py_RETURN_NONE; } if (!val) { Py_DECREF(val); } return val; } Py_RETURN_NONE; }
/* ******************************************************************* * Function: int BehaviourFunction() * * Description : Returns the number of plugins in this DLL * * Paramters : * CKBehaviorContext& r The virtools behaviour context * * Returns : One of the many virtools return values * ******************************************************************* */ int CGBLLOStopTimer::BehaviourFunction(const CKBehaviorContext& behContext) { CKBehavior* beh = behContext.Behavior; CKBOOL localError = false; CGBLCOError retVal(CGBLCOError::EGBLCOErrorType::GBLCO_OK); MeasuredObjectiveControllerMgr* MOMngr = static_cast<MeasuredObjectiveControllerMgr*>(behContext.Context->GetManagerByGuid(MeasuredObjectiveControllerMgrGUID)); // Check to see if we got the manager ok if (!MOMngr) { assert(NULL); return CKBR_OK; } if (beh->IsInputActive(eBehInputStart)) { // Get the details of the MO P-In CKParameterIn *pInMO = beh->GetInputParameter(eParamInputMO); CKParameter *moParam = pInMO->GetRealSource(); // Get the details of the Measurement P-In CKParameterIn *pInMeas= beh->GetInputParameter(eParamInputMeasurement); CKParameter *measParam = pInMeas->GetRealSource(); // Ensure we read the P-In ok if (!moParam) { // Report the error CKParameterOut *pOut = beh->GetOutputParameter(eParamOutputGetError); TGBLError::SetTGBLError(pOut, CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL, GBLLO_ERROR_NO_PARAM_FROM_BB,GBLLO_ERROR_NO_DATA_FROM_BB_DESC); beh->ActivateOutput(eBehOutputError, TRUE); localError = true; } if (!localError) { // Get the data from the P-In CGBLMOData *moData = static_cast<CGBLMOData*>(moParam->GetAppData()); if (moData) { // Get the name from the MO and use this to get the // runtime MO from the controller XString moName = moData->GetName(); CGBLLOMeasuredObjective *mo=NULL; retVal=MOMngr->GetRunTimeMO(moName,mo); // See if the controller gave us the MO if((retVal==CGBLCOError::EGBLCOErrorType::GBLCO_OK)&&(mo)) { // Get the data from the P-In CGBLMeasurementData *measData = static_cast<CGBLMeasurementData*>(measParam->GetAppData()); if (measData) { // Get the measurement XString measName = measData->GetName(); EGBLLOMeasurementType measType=measData->GetType(); CGBLMeasurement *meas=NULL; retVal=mo->GetMeasurement(measName,meas); // See if the MO gave us the measurement if((retVal==CGBLCOError::EGBLCOErrorType::GBLCO_OK)&&(meas)) { // Based on the measurement type, get the value from the P-Im // and pass the value to the measurement. switch (measType) { case eTimer: { CGBLLOMeasurementTimer *timeMeas=NULL; timeMeas=static_cast<CGBLLOMeasurementTimer*>(meas); retVal=timeMeas->StopTimer(); } break; default: { CKParameterOut *pOut = beh->GetOutputParameter(eParamOutputGetError); TGBLError::SetTGBLError(pOut, CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL, GBLLO_ERROR_TRIED_START_TIMER_NOT,GBLLO_ERROR_TRIED_START_TIMER_NOT_DESC); beh->ActivateOutput(eBehOutputError, TRUE); localError = true; } break; } } } } } else { // Report the fact that we couldnt create a runtime MO from the param CKParameterOut *pOut = beh->GetOutputParameter(eParamOutputGetError); TGBLError::SetTGBLError(pOut, CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL, GBLLO_ERROR_NO_DATA_FROM_BB,GBLLO_ERROR_NO_DATA_FROM_BB_DESC); beh->ActivateOutput(eBehOutputError, TRUE); localError = true; } } } if (localError) { // error allready dealt with } else if (retVal!=CGBLCOError::EGBLCOErrorType::GBLCO_OK) { // Report the error back to Virtools dev CKParameterOut *pOut = beh->GetOutputParameter(eParamOutputGetError); const char* errorString = retVal; TGBLError::SetTGBLError(pOut, retVal,retVal,(CKSTRING)errorString); beh->ActivateOutput(eBehOutputError, TRUE); } else { // We are ok beh->ActivateOutput(eBehOutputDone, TRUE); } return CKBR_OK; }
/* ******************************************************************* * 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: 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; } }