示例#1
0
void KX_ObstacleSimulation::AddObstaclesForNavMesh(KX_NavMeshObject* navmeshobj)
{	
	dtStatNavMesh* navmesh = navmeshobj->GetNavMesh();
	if (navmesh)
	{
		int npoly = navmesh->getPolyCount();
		for (int pi=0; pi<npoly; pi++)
		{
			const dtStatPoly* poly = navmesh->getPoly(pi);

			for (int i = 0, j = (int)poly->nv-1; i < (int)poly->nv; j = i++)
			{	
				if (poly->n[j]) continue;
				const float* vj = navmesh->getVertex(poly->v[j]);
				const float* vi = navmesh->getVertex(poly->v[i]);
		
				KX_Obstacle* obstacle = CreateObstacle(navmeshobj);
				obstacle->m_type = KX_OBSTACLE_NAV_MESH;
				obstacle->m_shape = KX_OBSTACLE_SEGMENT;
				obstacle->m_pos = MT_Point3(vj[0], vj[2], vj[1]);
				obstacle->m_pos2 = MT_Point3(vi[0], vi[2], vi[1]);
				obstacle->m_rad = 0;
			}
		}
	}
}
示例#2
0
void IKTree::updateBones(int i)
{
  for (int j=0; j<bone[i].numChildren; j++) {
    int k = bone[i].child[j];
    bone[k].gRot = bone[i].gRot * bone[i].lRot;
    MT_Transform rot(MT_Point3(0,0,0), bone[k].gRot);
    bone[k].pos = bone[i].pos + rot * bone[k].offset;
    updateBones(k);
  }
}
示例#3
0
void KX_KetsjiEngine::PostProcessScene(KX_Scene* scene)
{
	bool override_camera = (m_overrideCam && (scene->GetName() == m_overrideSceneName));

	SG_SetActiveStage(SG_STAGE_SCENE);

	// if there is no activecamera, or the camera is being
	// overridden we need to construct a temporarily camera
	if (!scene->GetActiveCamera() || override_camera)
	{
		KX_Camera* activecam = NULL;

		RAS_CameraData camdata = RAS_CameraData();
		if (override_camera)
		{
			camdata.m_lens = m_overrideCamLens;
			camdata.m_clipstart = m_overrideCamNear;
			camdata.m_clipend = m_overrideCamFar;
			
			camdata.m_perspective= !m_overrideCamUseOrtho;
		}
		activecam = new KX_Camera(scene,KX_Scene::m_callbacks,camdata);
		activecam->SetName("__default__cam__");
	
			// set transformation
		if (override_camera) {
			const MT_CmMatrix4x4& cammatdata = m_overrideCamViewMat;
			MT_Transform trans = MT_Transform(cammatdata.getPointer());
			MT_Transform camtrans;
			camtrans.invert(trans);
			
			activecam->NodeSetLocalPosition(camtrans.getOrigin());
			activecam->NodeSetLocalOrientation(camtrans.getBasis());
			activecam->NodeUpdateGS(0);
		} else {
			activecam->NodeSetLocalPosition(MT_Point3(0.0, 0.0, 0.0));
			activecam->NodeSetLocalOrientation(MT_Vector3(0.0, 0.0, 0.0));
			activecam->NodeUpdateGS(0);
		}

		scene->AddCamera(activecam);
		scene->SetActiveCamera(activecam);
		scene->GetObjectList()->Add(activecam->AddRef());
		scene->GetRootParentList()->Add(activecam->AddRef());
		//done with activecam
		activecam->Release();
	}
	
	scene->UpdateParents(0.0);
}
示例#4
0
SG_Spatial::
SG_Spatial(
	void* clientobj,
	void* clientinfo,
	SG_Callbacks& callbacks
): 

	SG_IObject(clientobj,clientinfo,callbacks),
	m_localPosition(0.0,0.0,0.0),
	m_localRotation(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0),
	m_localScaling(1.f,1.f,1.f),
	
	m_worldPosition(0.0,0.0,0.0),
	m_worldRotation(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0),
	m_worldScaling(1.f,1.f,1.f),

	m_parent_relation (NULL),
	
	m_bbox(MT_Point3(-1.0, -1.0, -1.0), MT_Point3(1.0, 1.0, 1.0)),
	m_radius(1.0),
	m_modified(false),
	m_ogldirty(false)
{
}
void SG_BBox::get(MT_Point3 *box, const MT_Transform &world) const
{
	*box++ = world(m_min);
	*box++ = world(MT_Point3(m_min[0], m_min[1], m_max[2]));
	*box++ = world(MT_Point3(m_min[0], m_max[1], m_min[2]));
	*box++ = world(MT_Point3(m_min[0], m_max[1], m_max[2]));
	*box++ = world(MT_Point3(m_max[0], m_min[1], m_min[2]));
	*box++ = world(MT_Point3(m_max[0], m_min[1], m_max[2]));
	*box++ = world(MT_Point3(m_max[0], m_max[1], m_min[2]));
	*box++ = world(m_max);
}
SG_BBox::SG_BBox(const SG_BBox &other, const MT_Transform &world) :
	m_min(world(other.m_min)),
	m_max(world(other.m_max))
{
	*this += world(MT_Point3(m_min[0], m_min[1], m_max[2]));
	*this += world(MT_Point3(m_min[0], m_max[1], m_min[2]));
	*this += world(MT_Point3(m_min[0], m_max[1], m_max[2]));
	*this += world(MT_Point3(m_max[0], m_min[1], m_min[2]));
	*this += world(MT_Point3(m_max[0], m_min[1], m_max[2]));
	*this += world(MT_Point3(m_max[0], m_max[1], m_min[2]));
}
SG_BBox SG_BBox::transform(const MT_Transform &world) const
{
	SG_BBox bbox(world(m_min), world(m_max));
	bbox += world(MT_Point3(m_min[0], m_min[1], m_max[2]));
	bbox += world(MT_Point3(m_min[0], m_max[1], m_min[2]));
	bbox += world(MT_Point3(m_min[0], m_max[1], m_max[2]));
	bbox += world(MT_Point3(m_max[0], m_min[1], m_min[2]));
	bbox += world(MT_Point3(m_max[0], m_min[1], m_max[2]));
	bbox += world(MT_Point3(m_max[0], m_max[1], m_min[2]));
	return bbox;
}
void SG_BBox::getaa(MT_Point3 *box, const MT_Transform &world) const
{
	const MT_Point3 min(world(m_min)), max(world(m_max));
	*box++ = min;
	*box++ = MT_Point3(min[0], min[1], max[2]);
	*box++ = MT_Point3(min[0], max[1], min[2]);
	*box++ = MT_Point3(min[0], max[1], max[2]);
	*box++ = MT_Point3(max[0], min[1], min[2]);
	*box++ = MT_Point3(max[0], min[1], max[2]);
	*box++ = MT_Point3(max[0], max[1], min[2]);
	*box++ = max;
}
示例#9
0
void	KX_BlenderSceneConverter::resetNoneDynamicObjectToIpo()
{
	if (addInitFromFrame) {		
		KX_SceneList* scenes = m_ketsjiEngine->CurrentScenes();
		int numScenes = scenes->size();
		if (numScenes>=0) {
			KX_Scene* scene = scenes->at(0);
			CListValue* parentList = scene->GetRootParentList();
			for (int ix=0;ix<parentList->GetCount();ix++) {
				KX_GameObject* gameobj = (KX_GameObject*)parentList->GetValue(ix);
				if (!gameobj->IsDynamic()) {
					Object* blenderobject = gameobj->GetBlenderObject();
					if (!blenderobject)
						continue;
					if (blenderobject->type==OB_ARMATURE)
						continue;
					float eu[3];
					mat4_to_eul(eu,blenderobject->obmat);					
					MT_Point3 pos = MT_Point3(
						blenderobject->obmat[3][0],
						blenderobject->obmat[3][1],
						blenderobject->obmat[3][2]
					);
					MT_Vector3 eulxyz = MT_Vector3(
						eu[0],
						eu[1],
						eu[2]
					);
					MT_Vector3 scale = MT_Vector3(
						blenderobject->size[0],
						blenderobject->size[1],
						blenderobject->size[2]
					);
					gameobj->NodeSetLocalPosition(pos);
					gameobj->NodeSetLocalOrientation(MT_Matrix3x3(eulxyz));
					gameobj->NodeSetLocalScale(scale);
					gameobj->NodeUpdateGS(0);
				}
			}
		}
	}
}
示例#10
0
/**
 *	Transforms the collision object. A cone is not correctly centered
 *	for usage.  */
void KX_RadarSensor::SynchronizeTransform()
{
    // Getting the parent location was commented out. Why?
    MT_Transform trans;
    trans.setOrigin(((KX_GameObject*)GetParent())->NodeGetWorldPosition());
    trans.setBasis(((KX_GameObject*)GetParent())->NodeGetWorldOrientation());
    // What is the default orientation? pointing in the -y direction?
    // is the geometry correctly converted?

    // a collision cone is oriented
    // center the cone correctly
    // depends on the radar 'axis'
    switch (m_axis)
    {
    case SENS_RADAR_X_AXIS: // +X Axis
    {
        MT_Quaternion rotquatje(MT_Vector3(0,0,1),MT_radians(90));
        trans.rotate(rotquatje);
        trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0));
        break;
    };
    case SENS_RADAR_Y_AXIS: // +Y Axis
    {
        MT_Quaternion rotquatje(MT_Vector3(1,0,0),MT_radians(-180));
        trans.rotate(rotquatje);
        trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0));
        break;
    };
    case SENS_RADAR_Z_AXIS: // +Z Axis
    {
        MT_Quaternion rotquatje(MT_Vector3(1,0,0),MT_radians(-90));
        trans.rotate(rotquatje);
        trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0));
        break;
    };
    case SENS_RADAR_NEG_X_AXIS: // -X Axis
    {
        MT_Quaternion rotquatje(MT_Vector3(0,0,1),MT_radians(-90));
        trans.rotate(rotquatje);
        trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0));
        break;
    };
    case SENS_RADAR_NEG_Y_AXIS: // -Y Axis
    {
        //MT_Quaternion rotquatje(MT_Vector3(1,0,0),MT_radians(-180));
        //trans.rotate(rotquatje);
        trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0));
        break;
    };
    case SENS_RADAR_NEG_Z_AXIS: // -Z Axis
    {
        MT_Quaternion rotquatje(MT_Vector3(1,0,0),MT_radians(90));
        trans.rotate(rotquatje);
        trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0));
        break;
    };
    default:
    {
    }
    }

    //Using a temp variable to translate MT_Point3 to float[3].
    //float[3] works better for the Python interface.
    MT_Point3 temp = trans.getOrigin();
    m_cone_origin[0] = temp[0];
    m_cone_origin[1] = temp[1];
    m_cone_origin[2] = temp[2];

    temp = trans(MT_Point3(0, -m_coneheight/2.0 ,0));
    m_cone_target[0] = temp[0];
    m_cone_target[1] = temp[1];
    m_cone_target[2] = temp[2];


    if (m_physCtrl)
    {
        PHY_IMotionState* motionState = m_physCtrl->GetMotionState();
        const MT_Point3& pos = trans.getOrigin();
        float ori[12];
        trans.getBasis().getValue(ori);
        motionState->setWorldPosition(pos[0], pos[1], pos[2]);
        motionState->setWorldOrientation(ori);
        m_physCtrl->WriteMotionStateToDynamics(true);
    }

}
float BL_ArmatureObject::GetBoneLength(Bone* bone) const
{
	return (float)(MT_Point3(bone->head) - MT_Point3(bone->tail)).length();
}
示例#12
0
void KX_Camera::ExtractFrustumSphere()
{
	if (m_set_frustum_center)
		return;

	// compute sphere for the general case and not only symmetric frustum:
	// the mirror code in ImageRender can use very asymmetric frustum.
	// We will put the sphere center on the line that goes from origin to the center of the far clipping plane
	// This is the optimal position if the frustum is symmetric or very asymmetric and probably close
	// to optimal for the general case. The sphere center position is computed so that the distance to
	// the near and far extreme frustum points are equal.

	// get the transformation matrix from device coordinate to camera coordinate
	MT_Matrix4x4 clip_camcs_matrix = m_projection_matrix;
	clip_camcs_matrix.invert();

	if (m_projection_matrix[3][3] == MT_Scalar(0.0))
	{
		// frustrum projection
		// detect which of the corner of the far clipping plane is the farthest to the origin
		MT_Vector4 nfar;    // far point in device normalized coordinate
		MT_Point3 farpoint; // most extreme far point in camera coordinate
		MT_Point3 nearpoint;// most extreme near point in camera coordinate
		MT_Point3 farcenter(0.0, 0.0, 0.0);// center of far cliping plane in camera coordinate
		MT_Scalar F=-1.0, N; // square distance of far and near point to origin
		MT_Scalar f, n;     // distance of far and near point to z axis. f is always > 0 but n can be < 0
		MT_Scalar e, s;     // far and near clipping distance (<0)
		MT_Scalar c;        // slope of center line = distance of far clipping center to z axis / far clipping distance
		MT_Scalar z;        // projection of sphere center on z axis (<0)
		// tmp value
		MT_Vector4 npoint(1.0, 1.0, 1.0, 1.0);
		MT_Vector4 hpoint;
		MT_Point3 point;
		MT_Scalar len;
		for (int i=0; i<4; i++)
		{
			hpoint = clip_camcs_matrix*npoint;
			point.setValue(hpoint[0]/hpoint[3], hpoint[1]/hpoint[3], hpoint[2]/hpoint[3]);
			len = point.dot(point);
			if (len > F)
			{
				nfar = npoint;
				farpoint = point;
				F = len;
			}
			// rotate by 90 degree along the z axis to walk through the 4 extreme points of the far clipping plane
			len = npoint[0];
			npoint[0] = -npoint[1];
			npoint[1] = len;
			farcenter += point;
		}
		// the far center is the average of the far clipping points
		farcenter *= 0.25;
		// the extreme near point is the opposite point on the near clipping plane
		nfar.setValue(-nfar[0], -nfar[1], -1.0, 1.0);
		nfar = clip_camcs_matrix*nfar;
		nearpoint.setValue(nfar[0]/nfar[3], nfar[1]/nfar[3], nfar[2]/nfar[3]);
		// this is a frustrum projection
		N = nearpoint.dot(nearpoint);
		e = farpoint[2];
		s = nearpoint[2];
		// projection on XY plane for distance to axis computation
		MT_Point2 farxy(farpoint[0], farpoint[1]);
		// f is forced positive by construction
		f = farxy.length();
		// get corresponding point on the near plane
		farxy *= s/e;
		// this formula preserve the sign of n
		n = f*s/e - MT_Point2(nearpoint[0]-farxy[0], nearpoint[1]-farxy[1]).length();
		c = MT_Point2(farcenter[0], farcenter[1]).length()/e;
		// the big formula, it simplifies to (F-N)/(2(e-s)) for the symmetric case
		z = (F-N)/(2.0*(e-s+c*(f-n)));
		m_frustum_center = MT_Point3(farcenter[0]*z/e, farcenter[1]*z/e, z);
		m_frustum_radius = m_frustum_center.distance(farpoint);
	}
	else
	{
		// orthographic projection
		// The most extreme points on the near and far plane. (normalized device coords)
		MT_Vector4 hnear(1.0, 1.0, 1.0, 1.0), hfar(-1.0, -1.0, -1.0, 1.0);
		
		// Transform to hom camera local space
		hnear = clip_camcs_matrix*hnear;
		hfar = clip_camcs_matrix*hfar;
		
		// Tranform to 3d camera local space.
		MT_Point3 nearpoint(hnear[0]/hnear[3], hnear[1]/hnear[3], hnear[2]/hnear[3]);
		MT_Point3 farpoint(hfar[0]/hfar[3], hfar[1]/hfar[3], hfar[2]/hfar[3]);
		
		// just use mediant point
		m_frustum_center = (farpoint + nearpoint)*0.5;
		m_frustum_radius = m_frustum_center.distance(farpoint);
	}
	// Transform to world space.
	m_frustum_center = GetCameraToWorld()(m_frustum_center);
	m_frustum_radius /= fabs(NodeGetWorldScaling()[NodeGetWorldScaling().closestAxis()]);
	
	m_set_frustum_center = true;
}
示例#13
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;
}
示例#14
0
MT_Point3 MT_CmMatrix4x4::GetPos() const
{
	return MT_Point3(m_V[3][0], m_V[3][1], m_V[3][2]);
}
示例#15
0
void IK_QJacobianSolver::ConstrainPoleVector(IK_QSegment *root, std::list<IK_QTask *>& tasks)
{
	// this function will be called before and after solving. calling it before
	// solving gives predictable solutions by rotating towards the solution,
	// and calling it afterwards ensures the solution is exact.

	if (!m_poleconstraint)
		return;
	
	// disable pole vector constraint in case of multiple position tasks
	std::list<IK_QTask *>::iterator task;
	int positiontasks = 0;

	for (task = tasks.begin(); task != tasks.end(); task++)
		if ((*task)->PositionTask())
			positiontasks++;
	
	if (positiontasks >= 2) {
		m_poleconstraint = false;
		return;
	}

	// get positions and rotations
	root->UpdateTransform(m_rootmatrix);

	const MT_Vector3 rootpos = root->GlobalStart();
	const MT_Vector3 endpos = m_poletip->GlobalEnd();
	const MT_Matrix3x3& rootbasis = root->GlobalTransform().getBasis();

	// construct "lookat" matrices (like gluLookAt), based on a direction and
	// an up vector, with the direction going from the root to the end effector
	// and the up vector going from the root to the pole constraint position.
	MT_Vector3 dir = normalize(endpos - rootpos);
	MT_Vector3 rootx = rootbasis.getColumn(0);
	MT_Vector3 rootz = rootbasis.getColumn(2);
	MT_Vector3 up = rootx * cos(m_poleangle) + rootz *sin(m_poleangle);

	// in post, don't rotate towards the goal but only correct the pole up
	MT_Vector3 poledir = (m_getpoleangle) ? dir : normalize(m_goal - rootpos);
	MT_Vector3 poleup = normalize(m_polegoal - rootpos);

	MT_Matrix3x3 mat, polemat;

	mat[0] = normalize(MT_cross(dir, up));
	mat[1] = MT_cross(mat[0], dir);
	mat[2] = -dir;

	polemat[0] = normalize(MT_cross(poledir, poleup));
	polemat[1] = MT_cross(polemat[0], poledir);
	polemat[2] = -poledir;

	if (m_getpoleangle) {
		// we compute the pole angle that to rotate towards the target
		m_poleangle = angle(mat[1], polemat[1]);

		if (rootz.dot(mat[1] * cos(m_poleangle) + mat[0] * sin(m_poleangle)) > 0.0)
			m_poleangle = -m_poleangle;

		// solve again, with the pole angle we just computed
		m_getpoleangle = false;
		ConstrainPoleVector(root, tasks);
	}
	else {
		// now we set as root matrix the difference between the current and
		// desired rotation based on the pole vector constraint. we use
		// transpose instead of inverse because we have orthogonal matrices
		// anyway, and in case of a singular matrix we don't get NaN's.
		MT_Transform trans(MT_Point3(0, 0, 0), polemat.transposed() * mat);
		m_rootmatrix = trans * m_rootmatrix;
	}
}
示例#16
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);
				}
			}
		}
	}
}
/** \file gameengine/GameLogic/SCA_IObject.cpp
 *  \ingroup gamelogic
 */

#include <iostream>
#include <algorithm>

#include "SCA_IObject.h"
#include "SCA_ISensor.h"
#include "SCA_IController.h"
#include "SCA_IActuator.h"
#include "MT_Point3.h"
#include "EXP_ListValue.h"

MT_Point3 SCA_IObject::m_sDummy=MT_Point3(0,0,0);
SG_QList SCA_IObject::m_activeBookmarkedControllers;

SCA_IObject::SCA_IObject():
	CValue(),
	m_initState(0),
	m_state(0),
	m_firstState(NULL)
{
	m_suspended = false;
}

SCA_IObject::~SCA_IObject()
{
	SCA_SensorList::iterator its;
	for (its = m_sensors.begin(); !(its == m_sensors.end()); ++its)
示例#18
0
void	KX_MotionState::setWorldPosition(float posX,float posY,float posZ)
{
	m_node->SetLocalPosition(MT_Point3(posX,posY,posZ));
	//m_node->SetWorldPosition(MT_Point3(posX,posY,posZ));
}
	bool
KX_BoneParentRelation::
UpdateChildCoordinates(
	SG_Spatial * child,
	const SG_Spatial * parent,
	bool& parentUpdated
) {
	MT_assert(child != NULL);
	
	// This way of accessing child coordinates is a bit cumbersome
	// be nice to have non constant reference access to these values.

	const MT_Vector3 & child_scale = child->GetLocalScale();
	const MT_Point3 & child_pos = child->GetLocalPosition();
	const MT_Matrix3x3 & child_rotation = child->GetLocalOrientation();
	// we don't know if the armature has been updated or not, assume yes
	parentUpdated = true;

	// the childs world locations which we will update.
	
	MT_Vector3 child_w_scale;
	MT_Point3 child_w_pos;
	MT_Matrix3x3 child_w_rotation;
	
	bool valid_parent_transform = false;
	
	if (parent)
	{
		BL_ArmatureObject *armature = (BL_ArmatureObject*)(parent->GetSGClientObject());
		if (armature)
		{
			MT_Matrix4x4 parent_matrix;
			if (armature->GetBoneMatrix(m_bone, parent_matrix))
			{
				// Get the child's transform, and the bone matrix.
				MT_Matrix4x4 child_transform ( 
					MT_Transform(child_pos + MT_Vector3(0.0f, armature->GetBoneLength(m_bone), 0.0f), 
						child_rotation.scaled(
							child_scale[0], 
							child_scale[1], 
							child_scale[2])));
				
				// The child's world transform is parent * child
				parent_matrix = parent->GetWorldTransform() * parent_matrix;
				child_transform = parent_matrix * child_transform;
				
				// Recompute the child transform components from the transform.
				child_w_scale.setValue( 
					MT_Vector3(child_transform[0][0], child_transform[0][1], child_transform[0][2]).length(),
					MT_Vector3(child_transform[1][0], child_transform[1][1], child_transform[1][2]).length(),
					MT_Vector3(child_transform[2][0], child_transform[2][1], child_transform[2][2]).length());
				child_w_rotation.setValue(child_transform[0][0], child_transform[0][1], child_transform[0][2], 
					child_transform[1][0], child_transform[1][1], child_transform[1][2], 
					child_transform[2][0], child_transform[2][1], child_transform[2][2]);
				child_w_rotation.scale(1.0f/child_w_scale[0], 1.0f/child_w_scale[1], 1.0f/child_w_scale[2]);
					
				child_w_pos = MT_Point3(child_transform[0][3], child_transform[1][3], child_transform[2][3]);
					
				valid_parent_transform = true;
			}
		}
	} 
	
	if (valid_parent_transform)
	{
		child->SetWorldScale(child_w_scale);
		child->SetWorldPosition(child_w_pos);
		child->SetWorldOrientation(child_w_rotation);
	}
	else {
		child->SetWorldFromLocalTransform();
	}
	child->ClearModified();
	// this node must always be updated, so reschedule it for next time
	child->ActivateRecheduleUpdateCallback();
	return valid_parent_transform;
}
示例#20
0
PyObject *KX_VertexProxy::PyGetXYZ()
{
	return PyObjectFrom(MT_Point3(m_vertex->getXYZ()));
}