Example #1
0
int AddNodalLink(const CKBehaviorContext& behcontext)
{
	CKBehavior* beh = behcontext.Behavior;
	CKContext* ctx = behcontext.Context;
	CKAttributeManager* attman = ctx->GetAttributeManager();
	beh->ActivateInput(0,FALSE);
	beh->ActivateOutput(0);

	CKGroup* group = (CKGroup*)beh->GetInputParameterObject(0);			
	CKParameterOut* param = group->GetAttributeParameter(attman->GetAttributeTypeByName(Network3dName));
	if(!param) throw "Given Group isn't a Network";
	N3DGraph* graph;
	param->GetValue(&graph);

	CK3dEntity* s = (CK3dEntity*)beh->GetInputParameterObject(1);
	CK3dEntity* e = (CK3dEntity*)beh->GetInputParameterObject(2);
	float b;
	beh->GetInputParameterValue(3,&b);
	graph->InsertEdge(s,e,b);
	beh->ActivateOutput(0);





	return CKBR_OK;
}
Example #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;
}
Example #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;
}
Example #4
0
int TextureSinus(const CKBehaviorContext& behcontext)
{
    CKBehavior* beh = behcontext.Behavior;

    // we get the amount value
    float xamp=0.1f;
    beh->GetInputParameterValue(0, &xamp);

    // we get the amount value
    float yamp=0.1f;
    beh->GetInputParameterValue(1, &yamp);

    float l= 1.0f;
    beh->GetInputParameterValue(2, &l);

    // we get the saved uv's
    VxUV* savedUV = (VxUV*) beh->GetLocalParameterReadDataPtr(0);

    // we get the interpolated mesh
    CKMesh *mesh = (CKMesh*) beh->GetInputParameterObject(4);

    int channel = -1;
    beh->GetInputParameterValue(3, &channel);
    int channelcount = mesh->GetChannelCount();
    if (channel < -1 || channel >= channelcount) {
        beh->ActivateInput(0, FALSE);
        beh->ActivateOutput(0);
        return CKBR_PARAMETERERROR;
    }

    CKDWORD Stride;
    VxUV *uvarray = (VxUV*) mesh->GetModifierUVs(&Stride,channel);
    int pointsNumber = mesh->GetModifierUVCount(channel);

    float time;
    beh->GetLocalParameterValue(1, &time);

    float t;
    for( int i=0 ; i<pointsNumber ; i++, uvarray =(VxUV *)((BYTE *)uvarray + Stride)) {
        t = ((float)i/pointsNumber-0.5f)*4.0f+time*l;
        uvarray->u = savedUV[i].u + ( 0.5f - savedUV[i].u ) * xamp * cosf(t);
        uvarray->v = savedUV[i].v + ( 0.5f - savedUV[i].v ) * yamp * sinf(t);
    }
    mesh->ModifierUVMove(channel);

    float pi = 3.1415926535f;
    time += behcontext.DeltaTime * 0.001f;

    if(l*time > 2*pi)
        time -= (2*pi / l);

    beh->SetLocalParameterValue(1, &time);

    beh->ActivateInput(0, FALSE);
    beh->ActivateOutput(0);
    return CKBR_OK;
}
Example #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;
}
/*
 *******************************************************************
 * Function: int BehaviourFunction( const CKBehaviorContext& behaviorContext )
 *
 * Description : The execution function is the function that will be called 
 *               during the process loop of the behavior engine, if the behavior 
 *               is defined as using an execution function. This function is not 
 *               called if the behavior is defined as a graph. This function is the 
 *               heart of the behavior: it should compute the essence of the behavior, 
 *               in an incremental way. The minimum amount of computing should be 
 *               done at each call, to leave time for the other behaviors to run. 
 *               The function receives the delay in milliseconds that has elapsed 
 *               since the last behavioral process, and should rely on this value to 
 *               manage the amount of effect it has on its computation, if the effect 
 *               of this computation relies on time.
 *
 * Paramters :
 *    behaviourContext    r   Behavior context reference, which gives access to 
 *                            frequently used global objects ( context, level, manager, etc... )
 *
 * Returns : int, If it is done, it should return CKBR_OK. If it returns 
 *                CKBR_ACTIVATENEXTFRAME, the behavior will again be called 
 *                during the next process loop.
 *
 *******************************************************************
 */
int CGBLCHChatMoveHomogeneous::BehaviourFunction( const CKBehaviorContext& behaviorContext )
{
	CKBehavior *beh = behaviorContext.Behavior;
	CKContext *ctx = behaviorContext.Context;
	

	CK2dEntity *chatFrame = (CK2dEntity *)beh->GetInputParameterObject(0);

	if (chatFrame)
	{
		float left, top, right, bottom;

		beh->GetInputParameterValue(3, &left);
		beh->GetInputParameterValue(3, &top);
		beh->GetInputParameterValue(2, &right);
		right += left;
		beh->GetInputParameterValue(1, &bottom);
		bottom += top;

		VxRect rect(left, top, right, bottom);
		chatFrame->SetHomogeneousCoordinates ( 1 );
		int res = chatFrame->SetHomogeneousRect ( rect );
		if (res == 0)
		{
			beh->ActivateInput (0, 0);
			beh->ActivateOutput (0);
		}
		else
		{
			beh->ActivateInput (0, 0);
			beh->ActivateOutput (1);
		}
	}
	else
	{
		beh->ActivateInput (0, 0);
		beh->ActivateOutput (1);
	}
		
    return CKBR_OK;
}
Example #7
0
CKERROR TextureSinusCallBackObject(const CKBehaviorContext& behcontext)
{
    CKBehavior* beh = behcontext.Behavior;

    switch(behcontext.CallbackMessage) {

#ifdef macintosh
    case CKM_BEHAVIORLOAD:
    {


        CKMesh *mesh = (CKMesh*) beh->GetInputParameterObject(4);
        if(!mesh)
            return 0;
        int nbvert = mesh->GetModifierUVCount();
        // we get the saved uv's
        DWORD *savedUV = (DWORD *) beh->GetLocalParameterWriteDataPtr(0);

        for(int i=0; i<nbvert*2; i++) {
            savedUV[i] = ENDIANSWAP32(savedUV[i]);
        }
    }
    break;
#endif

    case CKM_BEHAVIORATTACH:
    {
        // we get the mesh vertices
        CKMesh *mesh = (CKMesh*) beh->GetInputParameterObject(4);
        if(!mesh) return 0;

        CKDWORD Stride;
        VxUV *uvarray = (VxUV*) mesh->GetModifierUVs(&Stride);
        int nbvert = mesh->GetModifierUVCount();

        VxUV *savedUV;
        savedUV = new VxUV[nbvert];

        for(int i=0 ; i<nbvert ; i++, uvarray = (VxUV*)((BYTE*)uvarray + Stride) ) {
            savedUV[i] = *uvarray;
        }

        beh->SetLocalParameterValue(0, savedUV, nbvert * sizeof(VxUV) );

        delete[] savedUV;
    }
    break;
    case CKM_BEHAVIORDETACH:
    {
        // we get the mesh vertices
        if(!beh) return 0;
        CKMesh *mesh = (CKMesh*) beh->GetInputParameterObject(4);
        if(!mesh) return 0;

        CKDWORD Stride;
        VxUV *uvarray = (VxUV*) mesh->GetModifierUVs(&Stride);
        int nbvert = mesh->GetModifierUVCount();

        VxUV *savePos = (VxUV*) beh->GetLocalParameterWriteDataPtr(0);
        if(!savePos) return 0;

        for(int i=0 ; i<nbvert ; i++, uvarray = (VxUV*)((BYTE*)uvarray + Stride) ) {
            *uvarray = savePos[i];
        }
        mesh->ModifierUVMove();
    }

    }
    return CKBR_OK;
}
Example #8
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;
}
Example #9
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;
}
/*
*******************************************************************
* Function: int BehaviourFunction( const CKBehaviorContext& behaviorContext )
*
* Description : The execution function is the function that will be called 
*               during the process loop of the behavior engine, if the behavior 
*               is defined as using an execution function. This function is not 
*               called if the behavior is defined as a graph. This function is the 
*               heart of the behavior: it should compute the essence of the behavior, 
*               in an incremental way. The minimum amount of computing should be 
*               done at each call, to leave time for the other behaviors to run. 
*               The function receives the delay in milliseconds that has elapsed 
*               since the last behavioral process, and should rely on this value to 
*               manage the amount of effect it has on its computation, if the effect 
*               of this computation relies on time.
*
* Parameters :
*    behaviourContext    r   Behavior context reference, which gives access to 
*                            frequently used global objects ( context, level, manager, etc... )
*
* Returns : int, If it is done, it should return CKBR_OK. If it returns 
*                CKBR_ACTIVATENEXTFRAME, the behavior will again be called 
*                during the next process loop.
*
*******************************************************************
*/
int CGBLCHPopulateAvailableRecipients::BehaviourFunction( const CKBehaviorContext& behaviorContext )
{
    enum 
    {
        GETACTIVEPLAYERSARRAY_COLUMN_VIRTOOLSUSERID,
        GETACTIVEPLAYERSARRAY_COLUMN_USERNAME,
        GETACTIVEPLAYERSARRAY_COLUMN_GBLTEAMID
    };
   
    enum 
    {
        AVAILABLERECIPIENTSARRAY_COLUMN_USERNAME,
        AVAILABLERECIPIENTSARRAY_COLUMN_VIRTOOLSUSERID,
        AVAILABLERECIPIENTSARRAY_COLUMN_GBLTEAMID
    };

    CKBehavior *beh = behaviorContext.Behavior;
    CGBLCOError localError(CGBLCOError::EGBLCOErrorType::GBLCO_OK);

    if (!beh)
    {
        assert(NULL);
        return CKBR_BEHAVIORERROR;
    }

    // Get profile controller
    CGBLProfileManager* profileManager = static_cast<CGBLProfileManager*>(beh->GetCKContext()->GetManagerByGuid(GBLProfileManagerGUID));
    if (!profileManager)
    {
        assert(NULL);
        return CKBR_BEHAVIORERROR;
    }

    // Get GBL Loader manager
    GBLLDManager* loaderManager = static_cast<GBLLDManager*>(beh->GetCKContext()->GetManagerByGuid(GBLLDManagerGUID));
    if (!profileManager)
    {
        assert(NULL);
        return CKBR_BEHAVIORERROR;
    }

    // Check we have been passed an array
    CKDataArray* availableRecipientsArray = static_cast<CKDataArray*>(beh->GetInputParameterObject(eParamInputAvailableRecipientsArray));
    if (!availableRecipientsArray)
    {
        return CKBR_BEHAVIORERROR;
    }

    // Clear array and set up structure
    availableRecipientsArray->Clear();
    while (availableRecipientsArray->GetColumnCount())
        availableRecipientsArray->RemoveColumn(0);

    availableRecipientsArray->InsertColumn(-1, CKARRAYTYPE_STRING, "Name");
    availableRecipientsArray->InsertColumn(-1, CKARRAYTYPE_INT, "VirtoolsUserID");
    availableRecipientsArray->InsertColumn(-1, CKARRAYTYPE_PARAMETER, "GBLTeamID", GUID_TEAM_ID);

    // Create a temporary array of active players to be filled in by the Profile Controller
    CKDataArray* tmpActivePlayersArray = (CKDataArray*)beh->GetCKContext()->CreateObject(CKCID_DATAARRAY,
                                    "CGBLCHPopulateAvailableRecipients temp array", 
                                    CK_OBJECTCREATION_DYNAMIC);
    if (!tmpActivePlayersArray)
    {
        assert(NULL);
        return CKBR_BEHAVIORERROR;
    }

    // Create temporary array for team names to be filled in by the Profile Controller
    CKDataArray* tmpTeamNameArray = (CKDataArray*)beh->GetCKContext()->CreateObject(CKCID_DATAARRAY,
                                    "CGBLCHPopulateAvailableRecipients temp array 2", 
                                    CK_OBJECTCREATION_DYNAMIC);
    if (!tmpTeamNameArray)
    {
        assert(NULL);
        return CKBR_BEHAVIORERROR;
    }

    // Get active players
    localError = profileManager->GetActivePlayers(tmpActivePlayersArray);
    if (localError != CGBLCOError::EGBLCOErrorType::GBLCO_OK)
    {
        localError.SetCode(GBLCH_ERRORCODE_UNABLETOGETPROFILEINFORMATION);
        localError.SetDescription((XString)"An error occurred while attempting to retrieve profile information: " + (const char*)localError);
    }
    else
    {
        // Collate Team IDs into local array
        CGBLTeamID teamID;
        XArray<CGBLTeamID> arrayOfTeamIDs;
        XArray<XString> arrayOfTeamNames;
        char* stringBuffer = NULL;

        for (int row = 0;row < tmpActivePlayersArray->GetRowCount();row++)
        {
            // Get Team ID
            teamID = 0;
            if (tmpActivePlayersArray->GetElementValue(row, GETACTIVEPLAYERSARRAY_COLUMN_GBLTEAMID, &teamID))
            {
                if ((int)teamID)
                {
                    // Have we already got this team ID in the array?
                    if (arrayOfTeamIDs.End() == arrayOfTeamIDs.Find(teamID))
                    {
                        // No, add it to the array
                        arrayOfTeamIDs.PushBack(teamID);
                    }
                }
            }
        }

        // Copy team IDs and names into AvailableRecipients array
        for (int team = 0;team < arrayOfTeamIDs.Size();team++)
        {
            availableRecipientsArray->AddRow();
            int row = availableRecipientsArray->GetRowCount() - 1;

            assert(row == team);

            // Get team name
            teamID = arrayOfTeamIDs[team];
            localError = profileManager->GetProfileField((const)teamID, "Name", tmpTeamNameArray);
            if (localError != CGBLCOError::EGBLCOErrorType::GBLCO_OK) {
                localError.SetCode(GBLCH_ERRORCODE_UNABLETOGETPROFILEINFORMATION);
                localError.SetDescription((XString)"An error occurred while attempting to retrieve profile information: " + (const char*)localError);
                break;
            }

            // Place team name into destination array
            stringBuffer = new char[tmpTeamNameArray->GetElementStringValue(0, 0, NULL) + 1];
            tmpTeamNameArray->GetElementStringValue(0, 0, stringBuffer);

            availableRecipientsArray->SetElementStringValue(row, AVAILABLERECIPIENTSARRAY_COLUMN_USERNAME, stringBuffer);

            delete stringBuffer;
            stringBuffer = NULL;

            // Set user ID as 0
            int virtoolsUserID = 0;
            availableRecipientsArray->SetElementValue(row, AVAILABLERECIPIENTSARRAY_COLUMN_VIRTOOLSUSERID, &virtoolsUserID);

            // Set team ID
            availableRecipientsArray->SetElementValue(row, AVAILABLERECIPIENTSARRAY_COLUMN_GBLTEAMID, &arrayOfTeamIDs[team]);
        }
    }
    if (localError == CGBLCOError::EGBLCOErrorType::GBLCO_OK)
    {
        CGBLTeamID teamID;
        char* stringBuffer = NULL;
        int virtoolsUserID;

        // Now copy players (which includes facilitators) into the destination array
        for (int row = 0;row < tmpActivePlayersArray->GetRowCount();row++)
        {
            // Get User ID
            virtoolsUserID = 0;
            if (tmpActivePlayersArray->GetElementValue(row, GETACTIVEPLAYERSARRAY_COLUMN_VIRTOOLSUSERID, &virtoolsUserID))
            {
                // Check this user ID valid
                if (virtoolsUserID)
                {
                    // Add new row to destination array
                    availableRecipientsArray->AddRow();
                    int row = availableRecipientsArray->GetRowCount() - 1;

                    // Set Virtools user ID
                    availableRecipientsArray->SetElementValue(row, AVAILABLERECIPIENTSARRAY_COLUMN_VIRTOOLSUSERID, &virtoolsUserID);

                    // Get name and put into dest array
                    stringBuffer = new char[tmpActivePlayersArray->GetElementStringValue(row, GETACTIVEPLAYERSARRAY_COLUMN_USERNAME, NULL) + 1];
                    tmpActivePlayersArray->GetElementStringValue(row, GETACTIVEPLAYERSARRAY_COLUMN_USERNAME, stringBuffer);
                    
                    availableRecipientsArray->SetElementStringValue(row, AVAILABLERECIPIENTSARRAY_COLUMN_USERNAME, stringBuffer);
                    delete stringBuffer;
                    stringBuffer = NULL;

                    // Set team ID to 0
                    teamID = 0;
                    availableRecipientsArray->SetElementValue(row, AVAILABLERECIPIENTSARRAY_COLUMN_GBLTEAMID, &teamID);
                }
            }
        }
    }
    if (localError == CGBLCOError::EGBLCOErrorType::GBLCO_OK)
    {
        // Remove the current user from the array

        // Get current Virtools User ID from GBL Loader
        int currentVirtoolsUserID = loaderManager->GetVirtoolsUserID();        

        for (int row = availableRecipientsArray->GetRowCount() - 1;row >= 0;row--)
        {
            int virtoolsUserId = 0;
            availableRecipientsArray->GetElementValue(row, AVAILABLERECIPIENTSARRAY_COLUMN_VIRTOOLSUSERID, &virtoolsUserId);

            if (virtoolsUserId == currentVirtoolsUserID)
            {
                // This row is the current user. Remove it
                availableRecipientsArray->RemoveRow(row);
            }
        }
    }

    // Free temporary arrays
    beh->GetCKContext()->DestroyObject(tmpActivePlayersArray);
    beh->GetCKContext()->DestroyObject(tmpTeamNameArray);

    // Did an error occur?
    if (localError == CGBLCOError::EGBLCOErrorType::GBLCO_OK)
    {
        // Output success
        beh->ActivateOutput(eBehOutputDone);
    }
    else
    {
        // Output the error
        TGBLError::SetTGBLError(beh->GetOutputParameter(eParamOutputError), localError, localError, (CKSTRING)(const char*)localError);
        beh->ActivateOutput(eBehOutputError);
    }

    // All done
    return CKBR_OK;
}
Example #11
0
int DOUserValueModified(const CKBehaviorContext& behcontext)
{
	CKBehavior* beh = behcontext.Behavior;
	CKMessageManager* mm = behcontext.MessageManager;
	CKContext* ctx = behcontext.Context;

	//////////////////////////////////////////////////////////////////////////
	//connection id : 
	int connectionID = vtTools::BehaviorTools::GetInputParameterValue<int>(beh,0);





	if (beh->IsInputActive(1))
	{
		beh->ActivateInput(1,FALSE);
		beh->ActivateOutput(1);
		return 0;
	}



	//////////////////////////////////////////////////////////////////////////
	//the object :
	CK3dEntity *obj= (CK3dEntity*)beh->GetInputParameterObject(1);
	if (!obj)
	{
		beh->ActivateOutput(3);
		return CKBR_ACTIVATENEXTFRAME;
	}

	//////////////////////////////////////////////////////////////////////////
	//network ok  ? 
	xNetInterface *cin  = GetNM()->GetClientNetInterface();
	if (!cin)
	{
		CKParameterOut *pout = beh->GetOutputParameter(2);
		XString errorMesg("distributed object creation failed,no network connection !");
		pout->SetStringValue(errorMesg.Str());
		beh->ActivateOutput(3);
		return CKBR_ACTIVATENEXTFRAME;
	}

	//use objects name, if not specified : 
	CKSTRING name= obj->GetName();
	
	IDistributedObjects*doInterface  = cin->getDistObjectInterface();
	IDistributedClasses*cInterface = cin->getDistributedClassInterface();
    
	XString className((CKSTRING) beh->GetLocalParameterReadDataPtr(0));
	XString parameterName((CKSTRING) beh->GetLocalParameterReadDataPtr(1));

	xDistributedClass *_class = cInterface->get(className.CStr());
	
	
	//////////////////////////////////////////////////////////////////////////
	//dist class ok  ? 
	if (_class==NULL)
	{
		beh->ActivateOutput(3);
		ctx->OutputToConsoleEx("Distributed Class doesn't exists : %s",className.CStr());
		return CKBR_ACTIVATENEXTFRAME;
	}
	const char * cNAme  = _class->getClassName().getString();

	int classType  = _class->getEnitityType();
	int bcount = beh->GetInputParameterCount();

	//////////////////////////////////////////////////////////////////////////
	//we come in by input 0 : 

	

	xDistributedObject *dobjDummy = NULL;
	xDistributedObject *dobj = doInterface->getByEntityID(obj->GetID());
	if (!dobj)
	{
		beh->ActivateOutput(3);
		return CKBR_ACTIVATENEXTFRAME;
	}

	if (dobj)
	{
		xDistributedProperty * prop  = dobj->getUserProperty(parameterName.CStr());
		if (prop)
		{
			if ( dobj->getGhostUpdateBits().testStrict(1 << prop->getBlockIndex()))
			{
				CKParameterManager *pam = static_cast<CKParameterManager *>(ctx->GetParameterManager());
				CKParameterOut *ciIn = beh->GetOutputParameter(1);
				CKParameterType pType  = ciIn->GetType();

				int sType = vtTools::ParameterTools::GetVirtoolsSuperType(ctx,pam->ParameterTypeToGuid(pType));	
				int userType = xDistTools::ValueTypeToSuperType(prop->getPropertyInfo()->mValueType);
				if ( userType ==sType )
				{
					beh->ActivateOutput(2);
					dobj->getGhostUpdateBits().set(1 << prop->getBlockIndex(),false);
					switch(xDistTools::ValueTypeToSuperType(prop->getPropertyInfo()->mValueType))
					{
						case vtFLOAT:
						{
							xDistributedPoint1F *propValue  = static_cast<xDistributedPoint1F*>(prop);
							if (propValue)
							{
								float ovalue = propValue->mLastServerValue;
								beh->SetOutputParameterValue(1,&ovalue);
								break;
							}
						}

						case vtVECTOR2D:
						{
							xDistributedPoint2F *propValue  = static_cast<xDistributedPoint2F*>(prop);
							if (propValue)
							{
								Point2F ovalue = propValue->mLastServerValue;
								Vx2DVector ovaluex(ovalue.x,ovalue.y);
								beh->SetOutputParameterValue(1,&ovaluex);
								break;
							}
						}
						case vtVECTOR:
						{
							xDistributedPoint3F *propValue  = static_cast<xDistributedPoint3F*>(prop);
							if (propValue)
							{
								Point3F ovalue = propValue->mLastServerValue;
								VxVector ovaluex(ovalue.x,ovalue.y,ovalue.z);
								beh->SetOutputParameterValue(1,&ovaluex);
								break;
							}
						}
						case vtQUATERNION:
						{
							xDistributedQuatF*propValue  = static_cast<xDistributedQuatF*>(prop);
							if (propValue)
							{
								QuatF ovalue = propValue->mLastServerValue;
								VxQuaternion ovaluex(ovalue.x,ovalue.y,ovalue.z,ovalue.w);
								beh->SetOutputParameterValue(1,&ovaluex);
								break;
							}
						}
						case vtSTRING:
						{
							xDistributedString*propValue  = static_cast<xDistributedString*>(prop);
							if (propValue)
							{
								TNL::StringPtr ovalue = propValue->mCurrentValue;
								CKParameterOut *pout = beh->GetOutputParameter(1);
								XString errorMesg(ovalue.getString());
								pout->SetStringValue(errorMesg.Str());
								break;
							}
						}
						case vtINTEGER:
						{
							xDistributedInteger*propValue  = static_cast<xDistributedInteger*>(prop);
							if (propValue)
							{
								int ovalue = propValue->mLastServerValue;
								beh->SetOutputParameterValue(1,&ovalue);
								break;
							}
						}
					}
				}
			}
		}
	}

	return CKBR_ACTIVATENEXTFRAME;
	if (beh->IsInputActive(0))
	{
		beh->ActivateOutput(0);
	}



	/*
	//////////////////////////////////////////////////////////////////////////
	//we come in by input 0 : 
	if (beh->IsInputActive(0))
	{
		beh->ActivateOutput(0);

	
		for (int i = BEH_IN_INDEX_MIN_COUNT  ; i < beh->GetInputParameterCount() ; i++ )
		{
			beh->ActivateInput(0,FALSE);

			xDistributedObject *dobj = doInterface->get(name);
			if (!dobj)
			{
				beh->ActivateOutput(0);
				return 0;
			}

			CKParameterIn *ciIn = beh->GetInputParameter(i);
			CKParameterType pType  = ciIn->GetType();
			int sType = vtTools::ParameterTools::GetVirtoolsSuperType(ctx,pam->ParameterTypeToGuid(pType));	
			xDistributedPropertyArrayType &props = *dobj->getDistributedPorperties();
			
			int propID = _class->getInternalUserFieldIndex(i - BEH_IN_INDEX_MIN_COUNT);
			if (propID==-1 ||  propID > props.size() )
			{
				beh->ActivateOutput(1);
				return 0;
			}
			
			xDistributedProperty *prop  = props[propID];
			if (prop)
			{
				xDistributedPropertyInfo*propInfo  = prop->getPropertyInfo();
				if (propInfo)
				{
					
					if (xDistTools::ValueTypeToSuperType(propInfo->mValueType) ==sType )
					{
						TNL::U32 currentTime = TNL::Platform::getRealMilliseconds();

						switch(propInfo->mValueType)
						{
							case E_DC_PTYPE_3DVECTOR:
							{

								xDistributedPoint3F * dpoint3F  = (xDistributedPoint3F*)prop;
								if (dpoint3F)
								{
									VxVector vvalue;
									beh->GetInputParameterValue(i,&vvalue);
									bool update = dpoint3F->updateValue(xMath::getFrom(vvalue),currentTime);
								}
                                break;
							}

							case E_DC_PTYPE_FLOAT:
								{

									xDistributedPoint1F * dpoint3F  = (xDistributedPoint1F*)prop;
									if (dpoint3F)
									{
										float vvalue;
										beh->GetInputParameterValue(i,&vvalue);
										bool update = dpoint3F->updateValue(vvalue,currentTime);
									}
									break;
								}
						}
					}
				}
			}
		}
			
		beh->ActivateOutput(0);
	}

	
	*/
	//////////////////////////////////////////////////////////////////////////
	//we come in by loop : 
	return 0;
}
Example #12
0
/*
  *******************************************************************
  * Function: RenderCallback()
  *
  * Description : Is called from Virtools every frame. We draw the widget's visual elements in this function.
  *
  * Parameters :
  *    Passed in from Virtools. See Virtools SDK documentation:
  *    *renderContext, rw:
  *    renderObject, rw:
  *    *iArg, rw:
  *
  * Returns :  Return TRUE for success or FALSE for failure. The implications of returning FALSE are not documented in the Virtools
  * SDK documentation. Let's hope it doesn't format the user's hard disk.
  *
  *******************************************************************
*/
CKBOOL CGBLListBox::RenderCallback(CKRenderContext *renderContext, CKRenderObject* renderObject, void *iArg)
{
    const int cFixedStringBufferSize = 256;
	static VxRect fullUVRect(0.0f, 0.0f, 1.0f, 1.0f);

	CKContext* context = renderContext->GetCKContext();
	CK2dEntity* ent = CK2dEntity::Cast(renderObject);

	// Sanity check
	if (!ent) 
    {
		assert(NULL);
		return FALSE;
	}

	// Get a pointer to the building block behaviour
	CKBehavior* beh = (CKBehavior*)context->GetObject(reinterpret_cast<CK_ID>(iArg));
	if (!beh) 
		return FALSE;

	// Use clipping class to manage the clipping for us
	CGBLRenderClipper cRenderClipper(renderContext, ent);

	// Get client rectangle
	VxRect clientRect;
	ent->GetExtents(fullUVRect, clientRect);

    // Get the font from the base helper class
    VirtoolsSource::CKTextureFont* font = CGBLWidget::GetFont(context, beh);
    if (!font) 
    {
        // Don't output an error - we check for a font in the behavioural function
        return FALSE;
    }

    // Get material
    CKMaterial* material = (CKMaterial*)beh->GetInputParameterObject(eParamInputMaterial);
    if (!material) 
    {
        return FALSE;
    }

    // Are we using proportional scaling?
    CKBOOL isPropScaling = CGBLWidget::IsProportionalScaling(beh);

    // Get the font height
    float fontHeight = CGBLWidget::GetFontHeight(font, renderContext, isPropScaling);

    // Render down arrow
    CKBOOL isDownButtonPressed = FALSE;
    beh->GetLocalParameterValue(eLocalParamIsScrollDownButtonPressed, &isDownButtonPressed);

    VxRect buttonRect = GetRectDownArrow(clientRect, fontHeight);
    CGBLWidget::DrawMaterialRectangle(renderContext, material, buttonRect, 
        isDownButtonPressed ? CGBLWidgetsTheme::GetListBoxRegionDownArrowPressed() : CGBLWidgetsTheme::GetListBoxRegionDownArrowUnpressed(), 
        clientRect);
    
    // Render up arrow
    CKBOOL isUpButtonPressed = FALSE;
    beh->GetLocalParameterValue(eLocalParamIsScrollUpButtonPressed, &isUpButtonPressed);

    buttonRect = GetRectUpArrow(clientRect, fontHeight);
    CGBLWidget::DrawMaterialRectangle(renderContext, material, buttonRect, 
        isUpButtonPressed ? CGBLWidgetsTheme::GetListBoxRegionUpArrowPressed() : CGBLWidgetsTheme::GetListBoxRegionUpArrowUnpressed(), 
        clientRect);

    // Render headings if present

    // Get columns array
    CKDataArray* columnsArray = static_cast<CKDataArray*>(beh->GetInputParameterObject(eParamInputColumnsArray));
    int numColumns = columnsArray ? columnsArray->GetRowCount() : 1;

    // If we have at least one row in the columns array, we are drawing headings
    if (columnsArray && (columnsArray->GetRowCount() >= 1)) 
    {
        VxRect headingsRect = GetRectHeadings(clientRect, fontHeight, columnsArray);

        VxRect headingRect = headingsRect;
        for (int column = 0;column < numColumns;column++) 
        {
            headingRect.right = headingRect.left + GetColumnWidth(beh, columnsArray, column) * headingsRect.GetWidth() / 100.0f;

            // Draw heading background
            CGBLWidget::DrawMaterialRectangle(renderContext, material, headingRect, 
                CGBLWidgetsTheme::GetListBoxRegionHeadingBackground(), headingsRect);

            // Draw heading text
            CKCHAR fixedBuffer[cFixedStringBufferSize];
            CKSTRING headingText = NULL;
            int labelLength =  columnsArray->GetElementStringValue(column, eColumnsArrayColumnHeading, NULL);
            if (labelLength > cFixedStringBufferSize)
                headingText = new CKCHAR[labelLength];
            else
                headingText = fixedBuffer;

            if (headingText) 
            {
                columnsArray->GetElementStringValue(column, eColumnsArrayColumnHeading, headingText);
            	
                int textOptions = TEXT_CLIP;
                if (isPropScaling)
                    textOptions |= TEXT_SCREEN;

                VxRect clippedHeadingRect = headingRect;
                clippedHeadingRect.Clip(headingsRect);

                // Use margin
                clippedHeadingRect.left += CGBLWidgetsTheme::GetStringListBoxTextMargin() * fontHeight;

                font->DrawCKText(renderContext, ent, headingText, VALIGN_BOTTOM | HALIGN_LEFT, clippedHeadingRect, NULL, textOptions, TRUE);

                // Delete the buffer?
                if (headingText != fixedBuffer)
                    delete[] headingText;
            }                

            // Move to next heading
            headingRect.left = headingRect.right;
        }
    }

    // Get data array and output error if we don't have one
    CKDataArray* stringListArray = static_cast<CKDataArray*>(beh->GetInputParameterObject(eParamInputStringListArray));
    if (!stringListArray) 
        return FALSE;

    // Get space for list box strings area
    VxRect stringListRect = GetRectStringList(clientRect, fontHeight, columnsArray);

    // Draw columns backgrounds now
    VxRect columnRect = stringListRect;
    for (int column = 0;column < numColumns;column++) 
    {
        columnRect.right = columnRect.left + GetColumnWidth(beh, columnsArray, column) * stringListRect.GetWidth() / 100.0f;

        // Draw column background
        CGBLWidget::DrawMaterialRectangle(renderContext, material, columnRect, 
            CGBLWidgetsTheme::GetListBoxRegionColumnBackground(), stringListRect);

        // Move to next column
        columnRect.left = columnRect.right;
    }

    // Get the scroll offset
    int scrollOffset = 0;
    beh->GetLocalParameterValue(eLocalParamScrollOffset, &scrollOffset);

    // Range check the scroll offset
    int nRowsVisible = static_cast<int>(stringListRect.GetHeight() / fontHeight + 0.01);    // Add fudge factor to avoid rounding down errors

    if ((scrollOffset + nRowsVisible - 1) >= stringListArray->GetRowCount())
        scrollOffset = stringListArray->GetRowCount() - nRowsVisible;
    if (scrollOffset < 0)
        scrollOffset = 0;

    // Re-set scroll offset local param
    beh->SetLocalParameterValue(eLocalParamScrollOffset, &scrollOffset);

    // Draw any selection highlights
    VxRect rowRect;
    for (int row = scrollOffset; 
        CGBLWidget::GetListRowRect(stringListRect, row, scrollOffset, stringListArray->GetRowCount(), fontHeight, &rowRect); row++) 
    {
        CKBOOL rowSelected = FALSE;

        stringListArray->GetElementValue(row, CGBLWidget::eStringListArrayColumnSelected, &rowSelected);
        if (rowSelected) 
            CGBLWidget::DrawMaterialRectangle(renderContext, material, rowRect, CGBLWidgetsTheme::GetListBoxRegionSelectedBackground());
    }

    // Draw column strings now
    columnRect = stringListRect;
    for (int column = 0;column < numColumns;column++) 
    {
        columnRect.right = columnRect.left + GetColumnWidth(beh, columnsArray, column) * stringListRect.GetWidth() / 100.0f;

        // Select which column to pick from the string list array
        int arrayColumn;
        if (column) 
            arrayColumn = column + CGBLWidget::eStringListArrayColumnAdditionalLabels - 1;
        else
            arrayColumn = column;

        VxRect clippedColumnRect = columnRect;
        clippedColumnRect.Clip(stringListRect);

        CGBLWidget::DrawStringListColumn(renderContext, ent, font, isPropScaling, stringListArray, 
            arrayColumn, clippedColumnRect, scrollOffset, column == 0);

        // Move to next column
        columnRect.left = columnRect.right;
    }

    // Disable the scroll buttons?
    if (scrollOffset == 0)
        CGBLWidget::DrawDisabledRectangle(renderContext, GetRectUpArrow(clientRect, fontHeight), clientRect);

    if ((scrollOffset + nRowsVisible) > (stringListArray->GetRowCount() - 1) )
        CGBLWidget::DrawDisabledRectangle(renderContext, GetRectDownArrow(clientRect, fontHeight), clientRect);


   	CKBOOL isFocussed = CGBLWidget::IsWidgetFocussed(beh);

	// If we're focussed, draw a focus rectangle around our focussed item
	if (isFocussed) 
    {
        int focussedItem = 0;
        beh->GetLocalParameterValue(eLocalParamFocussedItem, &focussedItem);

        if (CGBLWidget::GetListRowRect(stringListRect, focussedItem, scrollOffset, stringListArray->GetRowCount(), fontHeight, &rowRect))
		{
		    // draw focus around the selected item
			CGBLWidget::DrawFocusHighlight(renderContext, beh, rowRect, FALSE);
		}
		else
		{
			// see if the list is empty
			if ((!stringListArray)||(stringListArray->GetRowCount()<=0))
			{
				// Draw focus around the full list box
				CGBLWidget::DrawFocusHighlight(renderContext, beh, clientRect, FALSE);
			}
			else
			{
				// The list isnt empty but the current item is unselectable
			}
		}
	}

    // If widget is disabled, draw whole widget area disabled
    if (!CGBLWidget::IsWidgetEnabled(beh)) 
    {
        CGBLWidget::DrawDisabledRectangle(renderContext, GetRectUpArrow(clientRect, fontHeight), clientRect);
        CGBLWidget::DrawDisabledRectangle(renderContext, GetRectDownArrow(clientRect, fontHeight), clientRect);
        CGBLWidget::DrawDisabledRectangle(renderContext, GetRectHeadings(clientRect, fontHeight, columnsArray), clientRect);
        CGBLWidget::DrawDisabledRectangle(renderContext, GetRectStringList(clientRect, fontHeight, columnsArray), clientRect);
	}

    return TRUE;
}
Example #13
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;
}
Example #14
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;
}
Example #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;
}
Example #16
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;
}
int ARTPlusPatternTransformation(const CKBehaviorContext& BehContext)
{
	CKBehavior* beh = BehContext.Behavior;
	CKBOOL detected = FALSE;
	int patternID = -1;
	int markerId = -1;
	float buffer[16];
	float patternWidth = 8.0f;
	CK3dEntity* Object = NULL;
	VxQuaternion quat = VxQuaternion();
	VxVector pos = VxVector();
	VxVector scale = VxVector();

	float gl_para[4][4] = { {1.0f, 0.0f, 0.0f, 0.0f},
							{0.0f, 1.0f, 0.0f, 0.0f},
							{0.0f, 0.0f, 1.0f, 0.0f},
							{0.0f, 0.0f, 0.0f, 1.0f} };

	float gl_tmp[4][4] =  { {0.0f, 0.0f, 0.0f, 0.0f},
							{0.0f, 0.0f, 0.0f, 0.0f},
							{0.0f, 0.0f, 0.0f, 0.0f},
							{0.0f, 0.0f, 0.0f, 0.0f} };

	float koordSys[4][4] = { {1.0f, 0.0f, 0.0f, 0.0f},
							 {0.0f, 0.0f, 1.0f, 0.0f},
							 {0.0f, 1.0f, 0.0f, 0.0f},
							 {0.0f, 0.0f, 0.0f, 1.0f} };
 
	float koordSys2[4][4] = { {1.0f, 0.0f, 0.0f, 0.0f},
							  {0.0f, -1.0f, 0.0f, 0.0f},
							  {0.0f, 0.0f, 1.0f, 0.0f},
							  {0.0f, 0.0f, 0.0f, 1.0f} };

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

	if(ARTPlusInitialized == true)
	{
		// get object
		Object = CK3dEntity::Cast(beh->GetInputParameterObject(IN_OBJECT));
		if(Object==NULL)  return CKBR_BEHAVIORERROR;

		if(markerInfo!=NULL && numMarkers>0)
		{
			// Get pattern id
			beh->GetInputParameterValue(IN_PATTERN_NUMBER, &patternID);

			// Get pattern width
			beh->GetInputParameterValue(IN_PATTERN_WIDTH, &patternWidth);

			// define size of the marker
			tracker->setPatternWidth(patternWidth);

			markerId = findMarker(patternID);
			if(	markerId>=0 && markerInfo[markerId].id==patternID)
			{
				ARFloat	patt_center[2] = {0.0f, 0.0f};
				tracker->calcOpenGLMatrixFromMarker(&markerInfo[markerId], patt_center, patternWidth, (float *)buffer);

				detected = TRUE;

				for( int j = 0; j < 4; j++ )
				{
					for( int i = 0; i < 4; i++ )
					{
						gl_para[j][i] = buffer[j*4+i];
					}
				}

				for( int j = 0; j < 4; j++ )
				{
					for( int i = 0; i < 4; i++ )
					{
						gl_tmp[j][i] = 0.0;
						for(int k=0 ; k<4 ; k++)
						{
							gl_tmp[j][i] += koordSys[j][k]*gl_para[k][i];
						}
					}
				}

				for( int j = 0; j < 4; j++ )
				{
					for( int i = 0; i < 4; i++ )
					{
						gl_para[j][i] = 0.0;
						for(int k=0 ; k<4 ; k++)
						{
							gl_para[j][i] += gl_tmp[j][k]*koordSys2[k][i];
						}
					}
				}
			}
		}

		VxMatrix mat = VxMatrix(gl_para);
		Vx3DDecomposeMatrix(mat, quat, pos, scale);

		// Set true, if marker is detected
		beh->SetOutputParameterValue(OUT_DETECTED, &detected, 0);

		// Set marker id
		beh->SetOutputParameterValue(OUT_MARKERID, &patternID, 0);

		// Set Position
		beh->SetOutputParameterValue(OUT_POSITION, &pos, 0);

		// Set quaternion
		beh->SetOutputParameterValue(OUT_QUATERNION, &quat, 0);

		// Set matrix
		beh->SetOutputParameterValue(OUT_TRANSFORM_MATRIX, &mat, 0);

		//Check object visibility
		if(detected==TRUE)
		{
			// Transform object
			Object->SetPosition(&pos, NULL, FALSE);
			Object->SetQuaternion(&quat, NULL, FALSE, FALSE);
			Object->Show(CKSHOW);
		}
		else
		{
			Object->Show(CKHIERARCHICALHIDE);
		}
	}

	return CKBR_OK;
}
Example #18
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( const CKBehaviorContext& behaviorContext )
 *
 * Description : The execution function is the function that will be called 
 *               during the process loop of the behavior engine, if the behavior 
 *               is defined as using an execution function. This function is not 
 *               called if the behavior is defined as a graph. This function is the 
 *               heart of the behavior: it should compute the essence of the behavior, 
 *               in an incremental way. The minimum amount of computing should be 
 *               done at each call, to leave time for the other behaviors to run. 
 *               The function receives the delay in milliseconds that has elapsed 
 *               since the last behavioral process, and should rely on this value to 
 *               manage the amount of effect it has on its computation, if the effect 
 *               of this computation relies on time.
 *
 * Parameters :
 *    behaviourContext    r   Behavior context reference, which gives access to 
 *                            frequently used global objects ( context, level, manager, etc... )
 *
 * Returns : int, If it is done, it should return CKBR_OK. If it returns 
 *                CKBR_ACTIVATENEXTFRAME, the behavior will again be called 
 *                during the next process loop.
 *
 *******************************************************************
 */
int GBLCIGetCIS_IDList(const CKBehaviorContext& behcontext)
{

	////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
	//						Retrieving min data : 

	CKBehavior* beh = behcontext.Behavior;
	CKContext* ctx = behcontext.Context;
		
	beh->ActivateInput(0,false);



	//						required managers		
	CGBLCIConfigurationController* cman=static_cast<CGBLCIConfigurationController*>(ctx->GetManagerByGuid(CONFIGURATION_MAN_GUID));
	IGBLCIManageInterface *cisFac   =  cman->GetCISFactoryInterface();

	CGBLSMStorageManager *storageManager = static_cast<CGBLSMStorageManager *>(ctx->GetManagerByGuid(GBLSMStorageManagerGUID));
	IGBLSMConfigurationAccess* smCIS = storageManager->GetConfigurationInterface();


	//get LAID from bb : 
	CKParameter *parameterINGetLAID = beh->GetInputParameter(BEH_IN_INDEX_LAID)->GetRealSource();
	using namespace GBLCommon::ParameterTools;
	
	//contruct c rep of the LAID : 
	CGBLLAID laID( 
			GetValueFromParameterStruct<int>(parameterINGetLAID,0,false), 
			GetValueFromParameterStruct<int>(parameterINGetLAID,1,false)
		);


    
	// get inout array  : 
	CKDataArray * resultArray = static_cast<CKDataArray*>(beh->GetInputParameterObject(BEH_IN_INDEX_TARGETARRAY));
	if(resultArray == NULL)
	{
		beh->ActivateOutput(1, true);
		CKParameterOut *pOut = beh->GetOutputParameter(0);
		CGBLCOError::EGBLCOErrorType tType;
		tType= CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL;
		TGBLError::SetTGBLError(pOut, tType , 19021, "Missing or incorrect parameter provided");
		return CKBR_OK;
	}

	//get error parameter
	CKParameterOut *parameterOutError = beh->GetOutputParameter(BEH_OUT_INDEX_ERROR);
	

	// get cis list 
	CGBLCOError returnValue = smCIS->RetrieveCISIDList(laID,resultArray);
			
	// check results and output error
	if (returnValue == CGBLCOError::EGBLCOErrorType::GBLCO_OK)
	{
		TGBLError::SetTGBLError(parameterOutError,returnValue.GetType(),returnValue.GetCode(),(CKSTRING)returnValue.GetDescription());
		beh->ActivateOutput(BEH_PIN_OUT_INDEX_SUCCESS, true);
	}
	else
	{
		
		CGBLCOError::EGBLCOErrorType tType = CGBLCOError::EGBLCOErrorType::GBLCO_OK;
		switch((CGBLCOError::EGBLCOErrorType)returnValue)
		{
			case 0:
				tType = CGBLCOError::EGBLCOErrorType::GBLCO_OK;
				break;
			case 1:
				tType = CGBLCOError::EGBLCOErrorType::GBLCO_FATAL;
				break;
			case 2:
				tType = CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL;
				break;
			case 3:
				tType = CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL;
				break;
		}
		TGBLError::SetTGBLError(parameterOutError,tType,returnValue.GetCode(),(CKSTRING)returnValue.GetDescription());
		beh->ActivateOutput(BEH_PIN_OUT_INDEX_ERROR, true);
	}

	
	return CKBR_OK;
}
Example #20
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;
}
Example #21
0
int DOOwnerChanged(const CKBehaviorContext& behcontext)
{
    CKBehavior* beh = behcontext.Behavior;
    CKMessageManager* mm = behcontext.MessageManager;
    CKContext* ctx = behcontext.Context;

    //////////////////////////////////////////////////////////////////////////
    //connection id :
    int connectionID = vtTools::BehaviorTools::GetInputParameterValue<int>(beh,0);

    //////////////////////////////////////////////////////////////////////////
    //we come in by input 0 :
    if (beh->IsInputActive(0))
    {
        beh->ActivateOutput(0);
        beh->ActivateInput(0,FALSE);
    }

    if (beh->IsInputActive(1))
    {
        beh->ActivateOutput(1);
        beh->ActivateInput(1,FALSE);
        return 0;
    }

    //////////////////////////////////////////////////////////////////////////
    //the object :
    CK3dEntity *obj= (CK3dEntity*)beh->GetInputParameterObject(1);
    if (!obj)
    {
        beh->ActivateOutput(4);
        return CKBR_ACTIVATENEXTFRAME;
    }

    //////////////////////////////////////////////////////////////////////////
    //network ok  ?
    xNetInterface *cin  = GetNM()->GetClientNetInterface();
    if (!cin)
    {
        CKParameterOut *pout = beh->GetOutputParameter(1);
        XString errorMesg("distributed object creation failed,no network connection !");
        pout->SetStringValue(errorMesg.Str());
        beh->ActivateOutput(4);
        return CKBR_ACTIVATENEXTFRAME;
    }


    IDistributedObjects*doInterface  = cin->getDistObjectInterface();
    //////////////////////////////////////////////////////////////////////////
    //we come in by input 0 :
    xDistributedObject *dobj = doInterface->getByEntityID(obj->GetID());
    if (!dobj)
    {
        CKParameterOut *pout = beh->GetOutputParameter(1);
        XString errorMesg("There is no such an object");
        pout->SetStringValue(errorMesg.Str());
        beh->ActivateOutput(4);
    } else
    {
        if (dobj->getOwnershipState().test(1 << E_DO_OS_RELEASED) && dobj->getOwnershipState().test( 1 << E_DO_OS_OWNERCHANGED) )
        {
            beh->ActivateOutput(3);
        }

        if (dobj->getOwnershipState().testStrict(1 << E_DO_OS_OWNERCHANGED))
        {
            dobj->getOwnershipState().set( 1<<E_DO_OS_OWNERCHANGED ,false );
            int newCLientID   = dobj->getUserID();
            beh->SetOutputParameterValue(0,&newCLientID);
            beh->ActivateOutput(2);
        }
    }
    return CKBR_ACTIVATENEXTFRAME;
}