Beispiel #1
0
//************************************
// Method:    PClothDestroy
// FullName:  PClothDestroy
// Access:    public 
// Returns:   int
// Qualifier:
// Parameter: const CKBehaviorContext& behcontext
//************************************
int PClothDestroy(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 ) return CKBR_OWNERERROR;
		//////////////////////////////////////////////////////////////////////////
		pCloth *cloth  = GetPMan()->getCloth(target->GetID());
		if (!cloth)
		{
			beh->ActivateOutput(0);
			return CKBR_PARAMETERERROR;
		}

		pWorld *world = cloth->getWorld();
		world->destroyCloth(target->GetID());

		beh->ActivateOutput(0);
	}
	return 0;
}
Beispiel #2
0
//************************************
// Method:    PCIgnorePair
// FullName:  PCIgnorePair
// Access:    public 
// Returns:   int
// Qualifier:
// Parameter: const CKBehaviorContext& behcontext
//************************************
int PCIgnorePair(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;


		CK3dEntity *targetA = (CK3dEntity *) beh->GetInputParameterObject(0);
		CK3dEntity *targetB = (CK3dEntity *) beh->GetInputParameterObject(1);
		int ignore = GetInputParameterValue<int>(beh,2);
		//////////////////////////////////////////////////////////////////////////
		// the world :  
		pWorld *world=GetPMan()->getWorld(target); 
		
		if(world){
			world->cIgnorePair(targetA,targetB,ignore);
		}
		
		beh->ActivateInput(0,FALSE);
		beh->ActivateOutput(0);
	}
	return 0;
}
Beispiel #3
0
//************************************
// Method:    JDestroy
// FullName:  JDestroy
// Access:    public 
// Returns:   int
// Qualifier:
// Parameter: const CKBehaviorContext& behcontext
//************************************
int JDestroy(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: 
	
		int jointType = GetInputParameterValue<int>(beh,1); 

		CK3dEntity *target = (CK3dEntity *) beh->GetTarget();
		CK3dEntity *targetB = (CK3dEntity *) beh->GetInputParameterObject(0);
		
		if (!pFactory::Instance()->jointCheckPreRequisites(target,targetB,jointType))
		{
			return CK_OK;
		}
	
		
		// the world :  
		pWorld *worldA=GetPMan()->getWorldByBody(target); 
		pWorld *worldB=GetPMan()->getWorldByBody(targetB); 
		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);

		if(bodyA || bodyB)
		{

			pJoint *joint = worldA->getJoint(target,targetB,(JType)jointType);
			if (joint)
			{
				worldA->deleteJoint(joint);
			}
		}

		beh->ActivateOutput(0);
	}
	return 0;
}
Beispiel #4
0
//************************************
// Method:    PBSetTriggerMask
// FullName:  PBSetTriggerMask
// Access:    public 
// Returns:   int
// Qualifier:
// Parameter: const CKBehaviorContext& behcontext
//************************************
int PBSetTriggerMask(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 ) return CKBR_OWNERERROR;


		//////////////////////////////////////////////////////////////////////////
		// the world :  
		
		pWorld *world  = GetPMan()->getWorldByShapeReference(target);
		if (!world)
		{
			beh->ActivateOutput(0);
			return 0;
		}

		if (world)
		{
			NxShape *shape  = world->getShapeByEntityID(target->GetID());
			if (shape)
			{

				int onEnter = GetInputParameterValue<int>(beh,bbI_OnEnter);
				int onStay = GetInputParameterValue<int>(beh,bbI_OnStay);
				int onLeave = GetInputParameterValue<int>(beh,bbI_OnLeave);

				shape->setFlag(NX_TRIGGER_ON_ENTER,onEnter);
				shape->setFlag(NX_TRIGGER_ON_STAY,onStay);
				shape->setFlag(NX_TRIGGER_ON_LEAVE,onLeave);

			}
		}
			
		beh->ActivateOutput(0);
	}
	return 0;
}
Beispiel #5
0
//************************************
// Method:    PClothDetachFromShape
// FullName:  PClothDetachFromShape
// Access:    public 
// Returns:   int
// Qualifier:
// Parameter: const CKBehaviorContext& behcontext
//************************************
int PClothDetachFromShape(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 ) return CKBR_OWNERERROR;

		
		//////////////////////////////////////////////////////////////////////////

		CK3dEntity*shapeReference  = (CK3dEntity *) beh->GetInputParameterObject(bbI_ShapeReference);
		if (!shapeReference)
		{
			beh->ActivateOutput(0);
			return CKBR_PARAMETERERROR;
		}

		pCloth *cloth  = GetPMan()->getCloth(target->GetID());
		if (!cloth)
		{
			beh->ActivateOutput(0);
			return CKBR_PARAMETERERROR;
		}

		
		NxShape *shape  = cloth->getWorld()->getShapeByEntityID(shapeReference->GetID());
		if(shape)
		{
			cloth->detachFromShape((CKBeObject*)shapeReference);
		}

		
		beh->ActivateOutput(0);


		beh->ActivateOutput(0);
	}
	return 0;
}
//************************************
// Method:    PClothAttachVertexToPosition
// FullName:  PClothAttachVertexToPosition
// Access:    public 
// Returns:   int
// Qualifier:
// Parameter: const CKBehaviorContext& behcontext
//************************************
int PClothAttachVertexToPosition(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 ) return CKBR_OWNERERROR;

		
		//////////////////////////////////////////////////////////////////////////

		pWorld *world  = GetPMan()->getDefaultWorld();
		if (!world)
		{
			beh->ActivateOutput(0);
			return CKBR_PARAMETERERROR;
		}
		
		pCloth *cloth  = world->getCloth(target);
		if (!cloth)
		{
			beh->ActivateOutput(0);
			return CKBR_PARAMETERERROR;
		}

		int vertexIndex = GetInputParameterValue<int>(beh,bbI_VertexIndex);
		VxVector localPosition = GetInputParameterValue<VxVector>(beh,bbI_GlobalPosition);

		cloth->attachVertexToGlobalPosition(vertexIndex,localPosition);

		beh->ActivateOutput(0);
	}
	return 0;
}
Beispiel #7
0
int SetZoom(const CKBehaviorContext& behcontext)
{
	CKBehavior* beh = behcontext.Behavior;

	CKCamera *cam = (CKCamera *) beh->GetTarget();
  if( !cam ) return CKBR_OWNERERROR;

  float zoom = 50; // Zoom in mm
  beh->GetInputParameterValue(0, &zoom);

  float fov = 2.0f * atanf(18.0f / zoom);
  cam->SetFov( fov );

  beh->ActivateInput(0, FALSE);
	beh->ActivateOutput(0);

	return CKBR_OK;
}
//************************************
// Method:    PClothAddForceAtVertex
// FullName:  PClothAddForceAtVertex
// Access:    public 
// Returns:   int
// Qualifier:
// Parameter: const CKBehaviorContext& behcontext
//************************************
int PClothAddForceAtVertex(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 ) return CKBR_OWNERERROR;

		
		//////////////////////////////////////////////////////////////////////////
		pCloth *cloth  = GetPMan()->getCloth(target->GetID());
		if (!cloth)
		{
			beh->ActivateOutput(0);
			return CKBR_PARAMETERERROR;
		}
		
		int vertexIndex = GetInputParameterValue<int>(beh,bbI_VertexIndex);
		VxVector force = GetInputParameterValue<VxVector>(beh,bbI_Force);
		int forceMode = GetInputParameterValue<int>(beh,bbI_ForceMode);

		cloth->addForceAtVertex(force,vertexIndex,(ForceMode)forceMode);



		beh->ActivateOutput(0);
	}
	return 0;
}
Beispiel #9
0
//************************************
// Method:    PVGet
// FullName:  PVGet
// Access:    public 
// Returns:   int
// Qualifier:
// Parameter: const CKBehaviorContext& behcontext
//************************************
int PVGet(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);

		CK3dEntity *target = (CK3dEntity *) beh->GetTarget();
		if( !target ) 	bbErrorME("No Reference Object specified");

		
		pRigidBody *body = NULL;

		body = GetPMan()->getBody(target);
		if (!body)
			bbSErrorME(E_PE_NoBody);


		pVehicle *v = body->getVehicle();
		if (!v)
		{
			bbSErrorME(E_PE_NoVeh);
		}

		BB_DECLARE_PMAP;


		/************************************************************************/
		/* retrieve settings state  */
		/*****
		*******************************************************************/

		BBSParameter(O_StateFlags);
		BBSParameter(O_Acceleration);
		BBSParameter(O_Steering);
		BBSParameter(O_MTorque);
		BBSParameter(O_MPH);
		BBSParameter(O_RPM);
		BBSParameter(O_MRPM);
		BBSParameter(O_WRPM);
		BBSParameter(O_Gear);
		/************************************************************************/
		/*                                                                      */
		/************************************************************************/

		BB_O_SET_VALUE_IF(int,O_StateFlags,v->getStateFlags());
		BB_O_SET_VALUE_IF(float,O_Acceleration,v->_cAcceleration);
		BB_O_SET_VALUE_IF(float,O_Steering,v->_cSteering);
		BB_O_SET_VALUE_IF(float,O_MPH,v->getMPH());

		float wRPM = v->_computeRpmFromWheels();
		BB_O_SET_VALUE_IF(float,O_WRPM,wRPM);

		//----------------------------------------------------------------
		//
		// output new engine values
		//
		if (v->isValidEngine())
		{
			BB_O_SET_VALUE_IF(float,O_MTorque,v->getEngine()->GetEngineTorque());
			BB_O_SET_VALUE_IF(float,O_RPM,v->getRPM());
			BB_O_SET_VALUE_IF(int,O_Gear,v->getGear());
		}
Beispiel #10
0
//************************************
// 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;
}
Beispiel #11
0
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;
}
Beispiel #12
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;
}
Beispiel #13
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 CGBLFileSystem::BehaviourFunction(const CKBehaviorContext& behContext)
{
	BOOL error = FALSE;

	// Quick bit of error checking
	CKBehavior* beh = behContext.Behavior;
	CKBeObject* beObject = beh->GetTarget();
	int fileSystemBrowseMode = 0;

    if (!beObject)
	{
       error = TRUE;
	}

	if (!error)
	{
		// Reset On input, if active
		if (beh->IsInputActive(eBehInputOn)) 
		{
			beh->ActivateInput(eBehInputOn, FALSE);

			// Clear error message output
			beh->SetOutputParameterValue(eParamOutputErrorMsg, EMPTY_STRING);
		}

		// see which mode we are in
		beh->GetInputParameterValue(eParamInputMode, &fileSystemBrowseMode);
	}

	if (!error)
	{
		// See if we have the special case
		char *currentFolder = NULL;
		currentFolder = (char*)(beh->GetInputParameterReadDataPtr(eParamInputCurrentFolder));

		XString scannedFolder = currentFolder;

		if (currentFolder) 
		{
			// special case takes priority over FILES / FOLDER mode
			if (strcmp(currentFolder,SPECIAL_CASE)==0)
			{
				beh->SetOutputParameterValue(eParamOutputScannedFolder, scannedFolder.CStr(),scannedFolder.Length()+1 );
				if (fileSystemBrowseMode == eFolder)
				{			
					if (GetLogicalDrives(beh))
					{
						// Everythings gone ok we have a list of the logical drives
						beh->ActivateOutput(eBehOutputDone, TRUE);
					}
					else
					{
						// Something went wrong
						beh->SetOutputParameterValue(eParamOutputErrorMsg, "Failed To Scan The Logical Drives");
						beh->ActivateOutput(eBehOutputError, TRUE);
					}
				}
				else
				{
					//  Cant scan for files in the SPECIAL_CASE
					// Get the destination data array and clear it out
					CKDataArray* dataArray = static_cast<CKDataArray*>(beh->GetInputParameterObject(eParamInputDataArray));
					if (!dataArray)
					{
						CGBLWidget::OutputBBErrorMsg(beh, "Please attatch an array to the BB");
					}
					else
					{
						dataArray->Clear();
						dataArray->AddRow();
						int currentRow = dataArray->GetRowCount()-1; // 0 index
						dataArray->SetElementStringValue(currentRow,NAME_COLUMN,NOT_FOUND);
						beh->ActivateOutput(eBehOutputDone, TRUE);
					}
					
				}
			}
			else
			{
				// add a "\" to the end, it makes the ouput consistent.
				int len = strlen (scannedFolder.CStr());
				if ((scannedFolder[len-1])!=SINGLE_SEPERATOR)
				{
					scannedFolder << SINGLE_SEPERATOR;
				}

				// Try to scan the passed folder
				if (GetData(beh,fileSystemBrowseMode)==FALSE)
				{
					// Error Handling we can handle errors here
					// We most likely got here because the user doesnt have access to the folder.
					if (fileSystemBrowseMode == eFile)
					{
						beh->SetOutputParameterValue(eParamOutputErrorMsg, "Failed To Scan Files");
					}
					else
					{
						beh->SetOutputParameterValue(eParamOutputErrorMsg, "Failed To Scan Folders");
					}
					
					beh->ActivateOutput(eBehOutputDone, TRUE);
					// Handleable, recoverable errors, so dont set the error flag
					//beh->ActivateOutput(eBehOutputError, TRUE);
				}
				else
				{
					// No errors
					beh->SetOutputParameterValue(eParamOutputScannedFolder, scannedFolder.CStr(), scannedFolder.Length() + 1);
					beh->ActivateOutput(eBehOutputDone, TRUE);
				}
			}
		}	
		else
		{
			// Dont think we can ever get here becuase "" is a valid folder.
			// Just in case though.
			beh->SetOutputParameterValue(eParamOutputErrorMsg, "Please Supply a Folder To Scan");
			beh->ActivateOutput(eBehOutputError, TRUE);
		}
	}

	return CKBR_OK;
}
Beispiel #14
0
//************************************
// 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;
}
Beispiel #15
0
//************************************
// 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;
}
Beispiel #16
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;
}
Beispiel #17
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;
}
Beispiel #18
0
CKERROR LogEntryCB(const CKBehaviorContext& behcontext)
{
	CKBehavior* beh = behcontext.Behavior;
	CKBeObject *beo = (CKBeObject *)beh->GetTarget();
	
	if (behcontext.CallbackMessage==CKM_BEHAVIOREDITED) 
	{
	/*	CKParameterIn* pin = beh->GetInputParameter(0);
		if (!pin) {
			CKBehavior* pbeh = beh;
			XString name;
			while ((pbeh=pbeh->GetParent())) {
				name << pbeh->GetName() << "->";
			}
			name << beh->GetName();

			XString str;
			str << '[' << name << "] : failed to retrieve first input parameter";
			behcontext.Context->OutputToConsole(str.Str(),TRUE);
			return CKBR_PARAMETERERROR;
		}
		
		if (pin->GetGUID()!=CKPGUID_MESSAGE) {
			pin->SetGUID(CKPGUID_MESSAGE,FALSE);

			CKBehavior* pbeh = beh;
			XString name;
			while ((pbeh=pbeh->GetParent())) {
				name << pbeh->GetName() << "->";
			}
			name << beh->GetName();

			XString str;
			str << '[' << name << "] : first input parameter type must be \"Message\"!";
			behcontext.Context->OutputToConsole(str.Str(),TRUE);
		}

		pin = beh->GetInputParameter(1);
		if (!pin) {
			CKBehavior* pbeh = beh;
			XString name;
			while ((pbeh=pbeh->GetParent())) {
				name << pbeh->GetName() << "->";
			}
			name << beh->GetName();

			XString str;
			str << '[' << name << "] : failed to retrieve second input parameter";
			behcontext.Context->OutputToConsole(str.Str(),TRUE);
			return CKBR_PARAMETERERROR;
		}
	
		if (!behcontext.ParameterManager->IsDerivedFrom(pin->GetGUID(),CKPGUID_OBJECT)) {
			pin->SetGUID(CKPGUID_BEOBJECT,FALSE);

			CKBehavior* pbeh = beh;
			XString name;
			while ((pbeh=pbeh->GetParent())) {
				name << pbeh->GetName() << "->";
			}
			name << beh->GetName();

			XString str;
			str << '[' << name << "] : second input parameter type must derived from \"BeObject\"!";
			behcontext.Context->OutputToConsole(str.Str(),TRUE);
		}*/
	}

	return CKBR_OK;
}
Beispiel #19
0
//************************************
// Method:    PBSetHard
// FullName:  PBSetHard
// Access:    public
// Returns:   int
// Qualifier:
// Parameter: const CKBehaviorContext& behcontext
//************************************
int PBSetHard(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;

		//////////////////////////////////////////////////////////////////////////
		// the world :  
		pWorld *world=GetPMan()->getWorldByBody(target); 
		if (!world)
		{
			if (!body)	bbErrorME("No valid world object found");
		}


		body = GetPMan()->getBody(target);
		if (!body)	bbErrorME("No Reference Object specified");

		BB_DECLARE_PIMAP;

		/************************************************************************/
		/* retrieve settings state  */
		/************************************************************************/
		BBSParameter(bbI_Vel);
		BBSParameter(bbI_AVel);
		BBSParameter(bbI_Torque);
		BBSParameter(bbI_Momentum);
		BBSParameter(bbI_Pos);
		BBSParameter(bbI_Rotation);
		
	
	
		if (sbbI_Vel)
		{
			VxVector velocity= GetInputParameterValue<VxVector>(beh,BB_IP_INDEX(bbI_Vel));
			body->setLinearVelocity(velocity);
		}

		if (sbbI_AVel)
		{
			VxVector aVelocity= GetInputParameterValue<VxVector>(beh,BB_IP_INDEX(bbI_AVel));
			body->setAngularVelocity(aVelocity);
		}

		if (sbbI_Torque)
		{
			VxVector torque= GetInputParameterValue<VxVector>(beh,BB_IP_INDEX(bbI_Torque));
			body->setAngularMomentum(torque);
		}
		if (sbbI_Momentum)
		{
			VxVector momentum= GetInputParameterValue<VxVector>(beh,BB_IP_INDEX(bbI_Momentum));
			body->setLinearMomentum(momentum);
		}

		
		if (sbbI_Pos)
		{
			VxVector pos= GetInputParameterValue<VxVector>(beh,BB_IP_INDEX(bbI_Pos));
			body->setPosition(pos,target);
		}
		if (sbbI_Rotation)
		{
			VxQuaternion rot= GetInputParameterValue<VxQuaternion>(beh,BB_IP_INDEX(bbI_Rotation));
			body->setRotation(rot,target);
		}

	}
	beh->ActivateOutput(0);
	return 0;
}
Beispiel #20
0
//************************************
// Method:    PBPhysicalizeEx
// FullName:  PBPhysicalizeEx
// Access:    public 
// Returns:   int
// Qualifier:
// Parameter: const CKBehaviorContext& behcontext
//************************************
int PBPhysicalizeEx(const CKBehaviorContext& behcontext)
{

	using namespace vtTools::BehaviorTools;
	using namespace vtTools;
	using namespace vtTools::AttributeTools;
	using namespace vtTools::ParameterTools;


	//////////////////////////////////////////////////////////////////////////	//////////////////////////////////////////////////////////////////////////
	//
	//	objects		
	//
	
	CKBehavior* beh = behcontext.Behavior;
  	CKContext* ctx = behcontext.Context;
	PhysicManager *pm = GetPMan();
	pFactory *pf = pFactory::Instance();

	//the object :
	CK3dEntity *target = (CK3dEntity *) beh->GetTarget();
	if( !target ) 	bbErrorME("No Reference Object specified");

	//the world reference, optional used
	CK3dEntity*worldRef = NULL;

	//the world object, only used when reference has been specified
	pWorld *world = NULL;

	//final object description 
	pObjectDescr *oDesc = new pObjectDescr();

	pRigidBody *body = NULL;
	XString errMesg;

	//----------------------------------------------------------------
	//
	// sanity checks 
	//


	// rigid body 
	 GetPMan()->getBody(target);
	if( body){
		errMesg.Format("Object %s already registered.",target->GetName());
		bbErrorME(errMesg.Str());

	}
    
	//----------------------------------------------------------------
	//
	// 
	//
	if (!GetPMan()->isValid())
		GetPMan()->performInitialization();

	//////////////////////////////////////////////////////////////////////////	//////////////////////////////////////////////////////////////////////////
	//
	//		Collecting data. Stores all settings in a pObjectDescr.
	//

	//get the parameter array
	BB_DECLARE_PIMAP;

	//----------------------------------------------------------------
	//
	// generic settings
	//
	oDesc->hullType = (HullType)GetInputParameterValue<int>(beh,bbI_HullType);
	oDesc->flags = (BodyFlags)GetInputParameterValue<int>(beh,bbI_Flags);
	oDesc->density  = GetInputParameterValue<float>(beh,bbI_Density);

	//----------------------------------------------------------------
	//	optional
	//		world		  
	//
	BBSParameterM(bbI_World,BB_SSTART);
	if (sbbI_World)
	{
		worldRef = (CK3dEntity *) beh->GetInputParameterObject(BB_IP_INDEX(bbI_World));
		if (worldRef)
		{
			world  =  GetPMan()->getWorld(worldRef,target); 
			if (!world)
			{
				xLogger::xLog(ELOGERROR,E_LI_MANAGER,"World reference has been specified but no valid world object found. Switching to default world");
				goto errorFound;
			}
		}
	}
    
	//----------------------------------------------------------------
	//	optional
	//		Pivot
	//
	BBSParameterM(bbI_Pivot,BB_SSTART);
	if (sbbI_Pivot)
	{
		CKParameter*pivotParameter = beh->GetInputParameter(BB_IP_INDEX(bbI_Pivot))->GetRealSource();
		if (pivotParameter)
		{
	
			IParameter::Instance()->copyTo(oDesc->pivot,pivotParameter);
			oDesc->mask |= OD_Pivot;

		}
	}
	//----------------------------------------------------------------
	//	optional
	//		mass
	//
	BBSParameterM(bbI_Mass,BB_SSTART);
	if (sbbI_Mass)
	{

		CKParameter*massParameter = beh->GetInputParameter(BB_IP_INDEX(bbI_Mass))->GetRealSource();
		if (massParameter)
		{
		
			IParameter::Instance()->copyTo(oDesc->mass,massParameter);
			oDesc->mask |= OD_Mass;
		}
	
	}

	//----------------------------------------------------------------
	//	optional
	//		collision
	//
	BBSParameterM(bbI_Collision , BB_SSTART);
	if (sbbI_Collision)
	{

		CKParameter*par = beh->GetInputParameter(BB_IP_INDEX(bbI_Collision))->GetRealSource();
		if (par)
		{
			oDesc->collisionGroup = GetValueFromParameterStruct<int>(par,PS_BC_GROUP,false);

			CKParameterOut* maskPar = GetParameterFromStruct(par,PS_BC_GROUPSMASK);
			if (maskPar)
			{
				oDesc->groupsMask.bits0  = GetValueFromParameterStruct<int>(maskPar,0);
				oDesc->groupsMask.bits1  = GetValueFromParameterStruct<int>(maskPar,1);
				oDesc->groupsMask.bits2  = GetValueFromParameterStruct<int>(maskPar,2);
				oDesc->groupsMask.bits3  = GetValueFromParameterStruct<int>(maskPar,3);
			}
			
			oDesc->skinWidth = GetValueFromParameterStruct<float>(par,PS_BC_SKINWITDH,false);

			IParameter::Instance()->copyTo(oDesc->collision,par);
			oDesc->mask |= OD_Collision;
		}
	}

	//----------------------------------------------------------------
	//	optional
	//		collision : CCD 
	//
	BBSParameterM(bbI_CCD, BB_SSTART);
	if (sbbI_CCD)
	{
		CKParameter*par = beh->GetInputParameter(BB_IP_INDEX(bbI_CCD))->GetRealSource();
		if (par)
		{
			IParameter::Instance()->copyTo(oDesc->ccd,par);
			oDesc->mask |= OD_CCD;
		}
	}
	//----------------------------------------------------------------
	//	optional
	//		optimization
	//
	BBSParameterM(bbI_Optimization, BB_SSTART);
	if (sbbI_Optimization)
	{

		CKParameter*par = beh->GetInputParameter(BB_IP_INDEX(bbI_Optimization))->GetRealSource();
		if (par)
		{
			IParameter::Instance()->copyTo(oDesc->optimization,par);
			oDesc->mask |= OD_Optimization;
			
		}
	}

	//----------------------------------------------------------------
	//	optional
	//		Material
	//
	BBSParameterM(bbI_Material, BB_SSTART);
	if (sbbI_Material)
	{
		CKParameter*par = beh->GetInputParameter(BB_IP_INDEX(bbI_Material))->GetRealSource();
		if (par)
		{
			pFactory::Instance()->copyTo(oDesc->material,par);
			oDesc->mask |= OD_Material;
		}
	}

	//----------------------------------------------------------------
	//	optional
	//		capsule
	//
	BBSParameterM(bbI_Capsule, BB_SSTART);
	if (sbbI_Capsule)
	{
		if (oDesc->hullType == HT_Capsule)
		{
			CKParameter*par = beh->GetInputParameter(BB_IP_INDEX(bbI_Capsule))->GetRealSource();
			if (par)
			{
				IParameter::Instance()->copyTo(oDesc->capsule,par);
				oDesc->mask |= OD_Capsule;
			}
		}else{
			errMesg.Format("You attached a capsule parameter but the hull type is not capsule");
			bbWarning(errMesg.Str());
		}
	}

	//----------------------------------------------------------------
	//	optional
	//		convex cylinder
	//
	BBSParameterM(bbI_CCylinder, BB_SSTART);
	if (sbbI_CCylinder)
	{
		if (oDesc->hullType == HT_ConvexCylinder)
		{
			CKParameter*par = beh->GetInputParameter(BB_IP_INDEX(bbI_CCylinder))->GetRealSource();
			if (par)
			{
				pFactory::Instance()->copyTo(oDesc->convexCylinder,par,true);
				oDesc->mask |= OD_ConvexCylinder;
			}
		}else{
			errMesg.Format("You attached a convex cylinder parameter but the hull type is not a convex cylinder");
			bbWarning(errMesg.Str());
		}
	}

	
	oDesc->version = pObjectDescr::E_OD_VERSION::OD_DECR_V1;

	//////////////////////////////////////////////////////////////////////////	//////////////////////////////////////////////////////////////////////////
	//
	//	body creation
	//
	if (!body)
	{

		if(! (oDesc->flags & BF_SubShape) )
		{
			body  = pFactory::Instance()->createRigidBody(target,*oDesc);
		}
	}

	if (!body)
	{
		SAFE_DELETE(oDesc);
		bbErrorME("No Reference Object specified");
	}
	//////////////////////////////////////////////////////////////////////////	//////////////////////////////////////////////////////////////////////////
	//
	//	attribute creation, attach settings 		
	//
	if (oDesc->flags & BF_AddAttributes )
	{
		//body->saveToAttributes(oDesc);
		GetPMan()->copyToAttributes(*oDesc,target);
	}

	//----------------------------------------------------------------
	//
	// update input parameters
	//
	if (sbbI_Material)
	{
		CKParameterOut *par = (CKParameterOut*)beh->GetInputParameter(BB_IP_INDEX(bbI_Material))->GetRealSource();
		if (par)
		{
			pFactory::Instance()->copyTo(par,oDesc->material);
		}
	}
	//----------------------------------------------------------------
	//
	// cleanup 
	//
	//SAFE_DELETE(oDesc);

	//----------------------------------------------------------------
	//
	// error out
	//
	errorFound:
	{
		beh->ActivateOutput(0);
		return CKBR_GENERICERROR;
	}

	//----------------------------------------------------------------
	//
	// All ok
	//
	allOk:
	{
		beh->ActivateOutput(0);
		return CKBR_OK;
	}

	return 0;
}
Beispiel #21
0
/*
 *******************************************************************
 * 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 BehaviourFunction() 
 *
 * Description :
 *		
 * Paramters :
 *    CKBehaviorContext& r The virtools behaviour context
 *
 * Returns : One of the many virtools return values
 *
 *******************************************************************
 */
int CGBLLOStringBuilder::BehaviourFunction(const CKBehaviorContext& behContext)
{
	CKBehavior* beh = behContext.Behavior;
	CKBeObject* beObject = beh->GetTarget();
	CKBOOL error = FALSE;
	XString outString = NULL;

    // error check to ensure virtools is working ok
	if (!beObject)
	{
		error = TRUE;
		CKParameterOut *parameterOutError = beh->GetOutputParameter(EGBLStringBuilderParamOutputs::eParamGetError);
		TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_FATAL,LOI_ERROR_NO_BEHAVIOUR_STATE,LOI_ERROR_NO_BEHAVIOUR_DESC);
		beh->SetOutputParameterValue(eParamGetError, parameterOutError);
		beh->ActivateOutput(eBehOutputError, TRUE);
	}

	int lengthOfSource = 0;
	int lengthOfInsert = 0;
	int insertPosition = 0;
	if (!error)
	{
		// Reset On input, if active
		if (beh->IsInputActive(eBehInputOn)) 
		{
			beh->ActivateInput(eBehInputOn, FALSE);
		}

		// get the BB params into variables to work with
		XString sourceString = NULL;
		sourceString = (CKSTRING)(beh->GetInputParameterReadDataPtr(eParamSetSourceString));

		XString insertString = NULL;
		insertString = (CKSTRING)(beh->GetInputParameterReadDataPtr(eParamSetInsertString));

		
		beh->GetInputParameterValue(eParamSetInsertPosition,&insertPosition);

		

		lengthOfSource = strlen(sourceString.Str());
		lengthOfInsert = strlen(insertString.Str());

		// Simple bounds checking and error recovery
		if (insertPosition<0)
		{
			insertPosition=0;
		}
		if (insertPosition>lengthOfSource)
		{
			outString = sourceString;
			outString += insertString;
		}
		else
		{
			// a little more error checking and simple recovery
			// deal with the special cases first
			if (lengthOfSource<=0)
			{
				// an empty source
				outString = insertString;
			}
			else if (insertPosition == 0)
			{
				outString = insertString;
				outString += sourceString;
			}
			else
			{
				//  build up the new string
				XString start = NULL;
				XString end = NULL;
				start = sourceString.Substring(0,insertPosition);
				end = sourceString.Substring(insertPosition,lengthOfSource);
				outString  = start ;
				outString += insertString;
				outString += end;
			}
		}
	}

	if (!error)
	{
		int newCartPos = insertPosition+lengthOfInsert;
		beh->SetOutputParameterValue(eParamGetCarretPosition,&newCartPos);
		beh->SetOutputParameterValue(eParamGetNewText, outString.CStr(), outString.Length() + 1);
		beh->ActivateOutput(eBehOutputDone, TRUE);
	}

	return CKBR_OK;
}
Beispiel #23
0
//************************************
// Method:    JD6SetParameters
// FullName:  JD6SetParameters
// Access:    public 
// Returns:   int
// Qualifier:
// Parameter: const CKBehaviorContext& behcontext
//************************************
int JD6SetParameters(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(0);
		
		if (!pFactory::Instance()->jointCheckPreRequisites(target,targetB,JT_D6))
		{

			return CK_OK;
		}
		
		
		
		// the world :  
		pWorld *worldA=GetPMan()->getWorldByBody(target); 
		pWorld *worldB=GetPMan()->getWorldByBody(targetB); 
		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);

		if(bodyA || bodyB)
		{

			pJointD6 *joint =static_cast<pJointD6*>(worldA->getJoint(target,targetB,JT_D6));
			VxVector linVel = GetInputParameterValue<VxVector>(beh,1); 
			VxVector aVel = GetInputParameterValue<VxVector>(beh,2); 
			VxVector pos = GetInputParameterValue<VxVector>(beh,3); 
			VxQuaternion rot = GetInputParameterValue<VxQuaternion>(beh,4); 

			float ratio = GetInputParameterValue<float>(beh,5); 
			
			
			joint->setDriveLinearVelocity(linVel);
			joint->setDriveAngularVelocity(aVel);
			joint->setRatio(ratio);
			
			joint->setDrivePosition(pos);
			joint->setDriveRotation(rot);



		}
	
		beh->ActivateOutput(0);
	}
	return 0;
}
Beispiel #24
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;
}