SG_Controller*	KX_IpoSGController::GetReplica(class SG_Node* destnode)
{
	KX_IpoSGController* iporeplica = new KX_IpoSGController(*this);
	// clear object that ipo acts on in the replica.
	iporeplica->ClearObject();
	iporeplica->SetGameObject((KX_GameObject*)destnode->GetSGClientObject());

	// dirty hack, ask Gino for a better solution in the ipo implementation
	// hacken en zagen, in what we call datahiding, not written for replication :(

	T_InterpolatorList oldlist = m_interpolators;
	iporeplica->m_interpolators.clear();

	T_InterpolatorList::iterator i;
	for (i = oldlist.begin(); !(i == oldlist.end()); ++i) {
		KX_ScalarInterpolator* copyipo = new KX_ScalarInterpolator(*((KX_ScalarInterpolator*)*i));
		iporeplica->AddInterpolator(copyipo);

		MT_Scalar* scaal = ((KX_ScalarInterpolator*)*i)->GetTarget();
		uint_ptr orgbase = (uint_ptr)&m_ipo_xform;
		uint_ptr orgloc = (uint_ptr)scaal;
		uint_ptr offset = orgloc-orgbase;
		uint_ptr newaddrbase = (uint_ptr)&iporeplica->m_ipo_xform;
		newaddrbase += offset;
		MT_Scalar* blaptr = (MT_Scalar*) newaddrbase;
		copyipo->SetNewTarget((MT_Scalar*)blaptr);
	}
	
	return iporeplica;
}
Пример #2
0
void BL_ConvertIpos(struct Object* blenderobject,KX_GameObject* gameobj,KX_BlenderSceneConverter *converter)
{
	if (blenderobject->adt) {

		KX_IpoSGController* ipocontr = new KX_IpoSGController();
		gameobj->GetSGNode()->AddSGController(ipocontr);
		ipocontr->SetObject(gameobj->GetSGNode());
		
		// For ipo_as_force, we need to know which SM object and Scene the
		// object associated with this ipo is in. Is this already known here?
		// I think not.... then it must be done later :(
//		ipocontr->SetSumoReference(gameobj->GetSumoScene(), 
//								   gameobj->GetSumoObject());

		ipocontr->SetGameObject(gameobj);

		ipocontr->GetIPOTransform().SetPosition(
			MT_Point3(
			blenderobject->loc[0]/*+blenderobject->dloc[0]*/,
			blenderobject->loc[1]/*+blenderobject->dloc[1]*/,
			blenderobject->loc[2]/*+blenderobject->dloc[2]*/
			)
		);
		ipocontr->GetIPOTransform().SetEulerAngles(
			MT_Vector3(
			blenderobject->rot[0],
			blenderobject->rot[1],
			blenderobject->rot[2]
			)
		);
		ipocontr->GetIPOTransform().SetScaling(
			MT_Vector3(
			blenderobject->size[0],
			blenderobject->size[1],
			blenderobject->size[2]
			)
		);

		const char *rotmode, *drotmode;

		switch(blenderobject->rotmode)
		{
		case ROT_MODE_AXISANGLE:
			rotmode = "rotation_axis_angle";
			drotmode = "delta_rotation_axis_angle";
		case ROT_MODE_QUAT:
			rotmode = "rotation_quaternion";
			drotmode = "delta_rotation_quaternion";
		default:
			rotmode = "rotation_euler";
			drotmode = "delta_rotation_euler";
		}

		BL_InterpolatorList *adtList= GetAdtList(blenderobject->adt, converter);
		
		// For each active channel in the adtList add an
		// interpolator to the game object.
		
		KX_IInterpolator *interpolator;
		KX_IScalarInterpolator *interp;
		
		for(int i=0; i<3; i++) {
			if ((interp = adtList->GetScalarInterpolator("location", i))) {
				interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetPosition()[i]), interp);
				ipocontr->AddInterpolator(interpolator);
				ipocontr->SetIPOChannelActive(OB_LOC_X+i, true);
			}
		}
		for(int i=0; i<3; i++) {
			if ((interp = adtList->GetScalarInterpolator("delta_location", i))) {
				interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetDeltaPosition()[i]), interp);
				ipocontr->AddInterpolator(interpolator);
				ipocontr->SetIPOChannelActive(OB_DLOC_X+i, true);
			}
		}
		for(int i=0; i<3; i++) {
			if ((interp = adtList->GetScalarInterpolator(rotmode, i))) {
				interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetEulerAngles()[i]), interp);
				ipocontr->AddInterpolator(interpolator);
				ipocontr->SetIPOChannelActive(OB_ROT_X+i, true);
			}
		}
		for(int i=0; i<3; i++) {
			if ((interp = adtList->GetScalarInterpolator(drotmode, i))) {
				interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetDeltaEulerAngles()[i]), interp);
				ipocontr->AddInterpolator(interpolator);
				ipocontr->SetIPOChannelActive(OB_DROT_X+i, true);
			}
		}
		for(int i=0; i<3; i++) {
			if ((interp = adtList->GetScalarInterpolator("scale", i))) {
				interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetScaling()[i]), interp);
				ipocontr->AddInterpolator(interpolator);
				ipocontr->SetIPOChannelActive(OB_SIZE_X+i, true);
			}
		}
		for(int i=0; i<3; i++) {
			if ((interp = adtList->GetScalarInterpolator("delta_scale", i))) {
				interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetDeltaScaling()[i]), interp);
				ipocontr->AddInterpolator(interpolator);
				ipocontr->SetIPOChannelActive(OB_DSIZE_X+i, true);
			}
		}
		
		{
			KX_ObColorIpoSGController* ipocontr_obcol=NULL;
			
			for(int i=0; i<4; i++) {
				if ((interp = adtList->GetScalarInterpolator("color", i))) {
					if (!ipocontr_obcol) {
						ipocontr_obcol = new KX_ObColorIpoSGController();
						gameobj->GetSGNode()->AddSGController(ipocontr_obcol);
						ipocontr_obcol->SetObject(gameobj->GetSGNode());
					}
					interpolator= new KX_ScalarInterpolator(&ipocontr_obcol->m_rgba[i], interp);
					ipocontr_obcol->AddInterpolator(interpolator);
				}
			}
		}
	}
}
Пример #3
0
SG_Controller *BL_CreateIPO(struct bAction *action, KX_GameObject* gameobj, KX_BlenderSceneConverter *converter)
{
	KX_IpoSGController* ipocontr = new KX_IpoSGController();
	ipocontr->SetGameObject(gameobj);

	Object* blenderobject = gameobj->GetBlenderObject();

	ipocontr->GetIPOTransform().SetPosition(MT_Point3(blenderobject->loc));
	ipocontr->GetIPOTransform().SetEulerAngles(MT_Vector3(blenderobject->rot));
	ipocontr->GetIPOTransform().SetScaling(MT_Vector3(blenderobject->size));

	const char *rotmode, *drotmode;

	switch(blenderobject->rotmode) {
	case ROT_MODE_AXISANGLE:
		rotmode = "rotation_axis_angle";
		drotmode = "delta_rotation_axis_angle";
		break;
	case ROT_MODE_QUAT:
		rotmode = "rotation_quaternion";
		drotmode = "delta_rotation_quaternion";
		break;
	default:
		rotmode = "rotation_euler";
		drotmode = "delta_rotation_euler";
		break;
	}

	BL_InterpolatorList *adtList= GetAdtList(action, converter);
		
	// For each active channel in the adtList add an
	// interpolator to the game object.
		
	KX_IInterpolator *interpolator;
	KX_IScalarInterpolator *interp;
		
	for(int i=0; i<3; i++) {
		if ((interp = adtList->GetScalarInterpolator("location", i))) {
			interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetPosition()[i]), interp);
			ipocontr->AddInterpolator(interpolator);
			ipocontr->SetIPOChannelActive(OB_LOC_X+i, true);
		}
	}
	for(int i=0; i<3; i++) {
		if ((interp = adtList->GetScalarInterpolator("delta_location", i))) {
			interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetDeltaPosition()[i]), interp);
			ipocontr->AddInterpolator(interpolator);
			ipocontr->SetIPOChannelActive(OB_DLOC_X+i, true);
		}
	}
	for(int i=0; i<3; i++) {
		if ((interp = adtList->GetScalarInterpolator(rotmode, i))) {
			interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetEulerAngles()[i]), interp);
			ipocontr->AddInterpolator(interpolator);
			ipocontr->SetIPOChannelActive(OB_ROT_X+i, true);
		}
	}
	for(int i=0; i<3; i++) {
		if ((interp = adtList->GetScalarInterpolator(drotmode, i))) {
			interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetDeltaEulerAngles()[i]), interp);
			ipocontr->AddInterpolator(interpolator);
			ipocontr->SetIPOChannelActive(OB_DROT_X+i, true);
		}
	}
	for(int i=0; i<3; i++) {
		if ((interp = adtList->GetScalarInterpolator("scale", i))) {
			interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetScaling()[i]), interp);
			ipocontr->AddInterpolator(interpolator);
			ipocontr->SetIPOChannelActive(OB_SIZE_X+i, true);
		}
	}
	for(int i=0; i<3; i++) {
		if ((interp = adtList->GetScalarInterpolator("delta_scale", i))) {
			interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetDeltaScaling()[i]), interp);
			ipocontr->AddInterpolator(interpolator);
			ipocontr->SetIPOChannelActive(OB_DSIZE_X+i, true);
		}
	}
		
	{
		KX_ObColorIpoSGController* ipocontr_obcol=NULL;
			
		for(int i=0; i<4; i++) {
			if ((interp = adtList->GetScalarInterpolator("color", i))) {
				if (!ipocontr_obcol) {
					ipocontr_obcol = new KX_ObColorIpoSGController();
					gameobj->GetSGNode()->AddSGController(ipocontr_obcol);
					ipocontr_obcol->SetObject(gameobj->GetSGNode());
				}
				interpolator= new KX_ScalarInterpolator(&ipocontr_obcol->m_rgba[i], interp);
				ipocontr_obcol->AddInterpolator(interpolator);
			}
		}
	}

	return ipocontr;
}