static PyObject* gPyGetCharacter(PyObject* self,
                                 PyObject* args,
                                 PyObject* kwds)
{
	PyObject* pyob;
	KX_GameObject *ob;

	if (!PyArg_ParseTuple(args,"O", &pyob))
		return NULL;

	if (!ConvertPythonToGameObject(pyob, &ob, false, "bge.constraints.getCharacter(value)"))
		return NULL;

	if (PHY_GetActiveEnvironment())
	{
			
		PHY_ICharacter* character= PHY_GetActiveEnvironment()->getCharacterController(ob);
		if (character)
		{
			KX_CharacterWrapper* pyWrapper = new KX_CharacterWrapper(character);
			return pyWrapper->NewProxy(true);
		}

	}

	Py_RETURN_NONE;
}
static PyObject *gPyGetAppliedImpulse(PyObject *self,
                                      PyObject *args,
                                      PyObject *kwds)
{
	float	appliedImpulse = 0.f;

#if defined(_WIN64)
	__int64 constraintid;
	if (PyArg_ParseTuple(args,"L",&constraintid))
#else
	long constraintid;
	if (PyArg_ParseTuple(args,"l",&constraintid))
#endif
	{
		if (PHY_GetActiveEnvironment())
		{
			appliedImpulse = PHY_GetActiveEnvironment()->getAppliedImpulse(constraintid);
		}
	}
	else {
		return NULL;
	}

	return PyFloat_FromDouble(appliedImpulse);
}
static PyObject *gPyGetVehicleConstraint(PyObject *self,
                                         PyObject *args,
                                         PyObject *kwds)
{
#if defined(_WIN64)
	__int64 constraintid;
	if (PyArg_ParseTuple(args,"L",&constraintid))
#else
	long constraintid;
	if (PyArg_ParseTuple(args,"l",&constraintid))
#endif
	{
		if (PHY_GetActiveEnvironment())
		{
			
			PHY_IVehicle* vehicle = PHY_GetActiveEnvironment()->getVehicleConstraint(constraintid);
			if (vehicle)
			{
				KX_VehicleWrapper* pyWrapper = new KX_VehicleWrapper(vehicle,PHY_GetActiveEnvironment());
				return pyWrapper->NewProxy(true);
			}

		}
	}
	else {
		return NULL;
	}

	Py_RETURN_NONE;
}
static PyObject *gPyExportBulletFile(PyObject *, PyObject *args)
{
	char* filename;
	if (!PyArg_ParseTuple(args,"s:exportBulletFile",&filename))
		return NULL;

	if (PHY_GetActiveEnvironment())
	{
		PHY_GetActiveEnvironment()->exportFile(filename);
	}
	Py_RETURN_NONE;
}
static PyObject *gPyCreateConstraint(PyObject *self,
                                     PyObject *args,
                                     PyObject *kwds)
{
	/* FIXME - physicsid is a long being cast to a pointer, should at least use PyCapsule */
	unsigned long long physicsid = 0, physicsid2 = 0;
	int constrainttype = 0;
	int flag = 0;
	float pivotX = 0.0f, pivotY = 0.0f, pivotZ = 0.0f, axisX = 0.0f, axisY = 0.0f, axisZ = 0.0f;

	static const char *kwlist[] = {"physicsid_1", "physicsid_2", "constraint_type", "pivot_x", "pivot_y", "pivot_z",
	                               "axis_X", "axis_y", "axis_z", "flag", NULL};

	if (!PyArg_ParseTupleAndKeywords(args, kwds, "KKi|ffffffi:createConstraint", (char **)kwlist,
	                                 &physicsid, &physicsid2, &constrainttype,
	                                 &pivotX, &pivotY, &pivotZ, &axisX, &axisY, &axisZ, &flag))
	{
		return NULL;
	}

	if (PHY_GetActiveEnvironment()) {
		PHY_IPhysicsController *physctrl = (PHY_IPhysicsController*)physicsid;
		PHY_IPhysicsController *physctrl2 = (PHY_IPhysicsController*)physicsid2;
		if (physctrl) { //TODO:check for existence of this pointer!
			//convert from euler angle into axis
			const float deg2rad = 0.017453292f;

			//we need to pass a full constraint frame, not just axis
			//localConstraintFrameBasis
			MT_Matrix3x3 localCFrame(MT_Vector3(deg2rad*axisX, deg2rad*axisY, deg2rad*axisZ));
			MT_Vector3 axis0 = localCFrame.getColumn(0);
			MT_Vector3 axis1 = localCFrame.getColumn(1);
			MT_Vector3 axis2 = localCFrame.getColumn(2);

			int constraintid = PHY_GetActiveEnvironment()->CreateConstraint(
			        physctrl, physctrl2, (enum PHY_ConstraintType)constrainttype, pivotX, pivotY, pivotZ,
			        (float)axis0.x(), (float)axis0.y(), (float)axis0.z(),
			        (float)axis1.x(), (float)axis1.y(), (float)axis1.z(),
			        (float)axis2.x(), (float)axis2.y(), (float)axis2.z(), flag);

			KX_ConstraintWrapper *wrap = new KX_ConstraintWrapper(
			        (enum PHY_ConstraintType)constrainttype, constraintid, PHY_GetActiveEnvironment());

			return wrap->NewProxy(true);
		}
	}
	Py_RETURN_NONE;
}
static PyObject *gPySetGravity(PyObject *self,
                               PyObject *args,
                               PyObject *kwds)
{
	float x,y,z;
	if (PyArg_ParseTuple(args,"fff",&x,&y,&z))
	{
		if (PHY_GetActiveEnvironment())
			PHY_GetActiveEnvironment()->setGravity(x,y,z);
	}
	else {
		return NULL;
	}
	
	Py_RETURN_NONE;
}
static PyObject *gPySetSolverType(PyObject *self,
                                  PyObject *args,
                                  PyObject *kwds)
{
	int	solverType;
	if (PyArg_ParseTuple(args,"i",&solverType))
	{
		if (PHY_GetActiveEnvironment())
		{
			PHY_GetActiveEnvironment()->setSolverType(solverType);
		}
	}
	else {
		return NULL;
	}
	Py_RETURN_NONE;
}
static PyObject *gPySetUseEpa(PyObject *self,
                              PyObject *args,
                              PyObject *kwds)
{
	int	epa;
	if (PyArg_ParseTuple(args,"i",&epa))
	{
		if (PHY_GetActiveEnvironment())
		{
			PHY_GetActiveEnvironment()->setUseEpa(epa);
		}
	}
	else {
		return NULL;
	}
	Py_RETURN_NONE;
}
static PyObject *gPySetLinearAirDamping(PyObject *self,
                                        PyObject *args,
                                        PyObject *kwds)
{
	float damping;
	if (PyArg_ParseTuple(args,"f",&damping))
	{
		if (PHY_GetActiveEnvironment())
		{
			PHY_GetActiveEnvironment()->setLinearAirDamping( damping);
		}
	}
	else {
		return NULL;
	}
	Py_RETURN_NONE;
}
static PyObject *gPySetSorConstant(PyObject *self,
                                   PyObject *args,
                                   PyObject *kwds)
{
	float sor;
	if (PyArg_ParseTuple(args,"f",&sor))
	{
		if (PHY_GetActiveEnvironment())
		{
			PHY_GetActiveEnvironment()->setSolverSorConstant( sor);
		}
	}
	else {
		return NULL;
	}
	Py_RETURN_NONE;
}
static PyObject *gPySetCcdMode(PyObject *self,
                               PyObject *args,
                               PyObject *kwds)
{
	float ccdMode;
	if (PyArg_ParseTuple(args,"f",&ccdMode))
	{
		if (PHY_GetActiveEnvironment())
		{
			PHY_GetActiveEnvironment()->setCcdMode( ccdMode);
		}
	}
	else {
		return NULL;
	}
	Py_RETURN_NONE;
}
static PyObject *gPySetContactBreakingTreshold(PyObject *self,
                                               PyObject *args,
                                               PyObject *kwds)
{
	float contactBreakingTreshold;
	if (PyArg_ParseTuple(args,"f",&contactBreakingTreshold))
	{
		if (PHY_GetActiveEnvironment())
		{
			PHY_GetActiveEnvironment()->setContactBreakingTreshold( contactBreakingTreshold);
		}
	}
	else {
		return NULL;
	}
	Py_RETURN_NONE;
}
static PyObject *gPySetDeactivationAngularTreshold(PyObject *self,
                                                   PyObject *args,
                                                   PyObject *kwds)
{
	float angularDeactivationTreshold;
	if (PyArg_ParseTuple(args,"f",&angularDeactivationTreshold))
	{
		if (PHY_GetActiveEnvironment())
		{
			PHY_GetActiveEnvironment()->setDeactivationAngularTreshold( angularDeactivationTreshold);
		}
	}
	else {
		return NULL;
	}
	Py_RETURN_NONE;
}
static PyObject *gPySetDeactivationTime(PyObject *self,
                                        PyObject *args,
                                        PyObject *kwds)
{
	float deactive_time;
	if (PyArg_ParseTuple(args,"f",&deactive_time))
	{
		if (PHY_GetActiveEnvironment())
		{
			PHY_GetActiveEnvironment()->setDeactivationTime(deactive_time);
		}
	}
	else {
		return NULL;
	}
	Py_RETURN_NONE;
}
static PyObject *gPySetNumIterations(PyObject *self,
                                     PyObject *args,
                                     PyObject *kwds)
{
	int iter;
	if (PyArg_ParseTuple(args,"i",&iter))
	{
		if (PHY_GetActiveEnvironment())
		{
			PHY_GetActiveEnvironment()->setNumIterations(iter);
		}
	}
	else {
		return NULL;
	}
	Py_RETURN_NONE;
}
static PyObject *gPySetNumTimeSubSteps(PyObject *self,
                                       PyObject *args,
                                       PyObject *kwds)
{
	int substep;
	if (PyArg_ParseTuple(args,"i",&substep))
	{
		if (PHY_GetActiveEnvironment())
		{
			PHY_GetActiveEnvironment()->setNumTimeSubSteps(substep);
		}
	}
	else {
		return NULL;
	}
	Py_RETURN_NONE;
}
static PyObject *gPySetSolverTau(PyObject *self,
                                 PyObject *args,
                                 PyObject *kwds)
{
	float tau;
	if (PyArg_ParseTuple(args,"f",&tau))
	{
		if (PHY_GetActiveEnvironment())
		{
			PHY_GetActiveEnvironment()->setSolverTau( tau);
		}
	}
	else {
		return NULL;
	}
	Py_RETURN_NONE;
}
static PyObject *gPySetDebugMode(PyObject *self,
                                 PyObject *args,
                                 PyObject *kwds)
{
	int mode;
	if (PyArg_ParseTuple(args,"i",&mode))
	{
		if (PHY_GetActiveEnvironment())
		{
			PHY_GetActiveEnvironment()->setDebugMode(mode);
			
		}
		
	}
	else {
		return NULL;
	}
	
	Py_RETURN_NONE;
}
static PyObject *gPyRemoveConstraint(PyObject *self,
                                     PyObject *args,
                                     PyObject *kwds)
{
#if defined(_WIN64)
	__int64 constraintid;
	if (PyArg_ParseTuple(args,"L",&constraintid))
#else
	long constraintid;
	if (PyArg_ParseTuple(args,"l",&constraintid))
#endif
	{
		if (PHY_GetActiveEnvironment())
		{
			PHY_GetActiveEnvironment()->removeConstraint(constraintid);
		}
	}
	else {
		return NULL;
	}
	
	Py_RETURN_NONE;
}
Example #20
0
static PyObject* gPyCreateConstraint(PyObject* self,
										 PyObject* args, 
										 PyObject* kwds)
{
	int physicsid=0,physicsid2 = 0,constrainttype=0,extrainfo=0;
	int len = PyTuple_Size(args);
	int success = 1;
	int flag = 0;

	float pivotX=1,pivotY=1,pivotZ=1,axisX=0,axisY=0,axisZ=1;
	if (len == 3)
	{
		success = PyArg_ParseTuple(args,"iii",&physicsid,&physicsid2,&constrainttype);
	}
	else
	if (len ==6)
	{
		success = PyArg_ParseTuple(args,"iiifff",&physicsid,&physicsid2,&constrainttype,
			&pivotX,&pivotY,&pivotZ);
	}
	else if (len == 9)
	{
		success = PyArg_ParseTuple(args,"iiiffffff",&physicsid,&physicsid2,&constrainttype,
			&pivotX,&pivotY,&pivotZ,&axisX,&axisY,&axisZ);
	}
	else if (len == 10)
	{
		success = PyArg_ParseTuple(args,"iiiffffffi",&physicsid,&physicsid2,&constrainttype,
			&pivotX,&pivotY,&pivotZ,&axisX,&axisY,&axisZ,&flag);
	}
	else if (len==4)
	{
		success = PyArg_ParseTuple(args,"iiii",&physicsid,&physicsid2,&constrainttype,&extrainfo);
		pivotX=extrainfo;
	}
	
	if (success)
	{
		if (PHY_GetActiveEnvironment())
		{
			
			PHY_IPhysicsController* physctrl = (PHY_IPhysicsController*) physicsid;
			PHY_IPhysicsController* physctrl2 = (PHY_IPhysicsController*) physicsid2;
			if (physctrl) //TODO:check for existence of this pointer!
			{
				PHY_ConstraintType ct = (PHY_ConstraintType) constrainttype;
				int constraintid =0;

				if (ct == PHY_GENERIC_6DOF_CONSTRAINT)
				{
					//convert from euler angle into axis
					float radsPerDeg = 6.283185307179586232f / 360.f;

					//we need to pass a full constraint frame, not just axis
					//localConstraintFrameBasis
					MT_Matrix3x3 localCFrame(MT_Vector3(radsPerDeg*axisX,radsPerDeg*axisY,radsPerDeg*axisZ));
					MT_Vector3 axis0 = localCFrame.getColumn(0);
					MT_Vector3 axis1 = localCFrame.getColumn(1);
					MT_Vector3 axis2 = localCFrame.getColumn(2);
						
					constraintid = PHY_GetActiveEnvironment()->createConstraint(physctrl,physctrl2,(enum PHY_ConstraintType)constrainttype,
						pivotX,pivotY,pivotZ,
						(float)axis0.x(),(float)axis0.y(),(float)axis0.z(),
						(float)axis1.x(),(float)axis1.y(),(float)axis1.z(),
						(float)axis2.x(),(float)axis2.y(),(float)axis2.z(),flag);

				} else
				{
					constraintid = PHY_GetActiveEnvironment()->createConstraint(physctrl,physctrl2,(enum PHY_ConstraintType)constrainttype,pivotX,pivotY,pivotZ,axisX,axisY,axisZ,0);
				}
				
				KX_ConstraintWrapper* wrap = new KX_ConstraintWrapper((enum PHY_ConstraintType)constrainttype,constraintid,PHY_GetActiveEnvironment());
				

				return wrap->NewProxy(true);
			}
			
			
		}
	}
	else {
		return NULL;
	}

	Py_RETURN_NONE;
}
static PyObject *gPyCreateConstraint(PyObject *self,
                                     PyObject *args,
                                     PyObject *kwds)
{
	/* FIXME - physicsid is a long being cast to a pointer, should at least use PyCapsule */
#if defined(_WIN64)
	__int64 physicsid=0,physicsid2 = 0;
#else
	long physicsid=0,physicsid2 = 0;
#endif
	int constrainttype=0, extrainfo=0;
	int len = PyTuple_Size(args);
	int success = 1;
	int flag = 0;

	float pivotX=1,pivotY=1,pivotZ=1,axisX=0,axisY=0,axisZ=1;
	if (len == 3)
	{
#if defined(_WIN64)
		success = PyArg_ParseTuple(args,"LLi",&physicsid,&physicsid2,&constrainttype);
#else
		success = PyArg_ParseTuple(args,"lli",&physicsid,&physicsid2,&constrainttype);
#endif
	}
	else if (len == 6)
	{
#if defined(_WIN64)
		success = PyArg_ParseTuple(args,"LLifff",&physicsid,&physicsid2,&constrainttype,
		                           &pivotX,&pivotY,&pivotZ);
#else
		success = PyArg_ParseTuple(args,"llifff",&physicsid,&physicsid2,&constrainttype,
		                           &pivotX,&pivotY,&pivotZ);
#endif
	}
	else if (len == 9)
	{
#if defined(_WIN64)
		success = PyArg_ParseTuple(args,"LLiffffff",&physicsid,&physicsid2,&constrainttype,
		                           &pivotX,&pivotY,&pivotZ,&axisX,&axisY,&axisZ);
#else
		success = PyArg_ParseTuple(args,"lliffffff",&physicsid,&physicsid2,&constrainttype,
		                           &pivotX,&pivotY,&pivotZ,&axisX,&axisY,&axisZ);
#endif
	}
	else if (len == 10)
	{
#if defined(_WIN64)
		success = PyArg_ParseTuple(args,"LLiffffffi",&physicsid,&physicsid2,&constrainttype,
		                           &pivotX,&pivotY,&pivotZ,&axisX,&axisY,&axisZ,&flag);
#else
		success = PyArg_ParseTuple(args,"lliffffffi",&physicsid,&physicsid2,&constrainttype,
		                           &pivotX,&pivotY,&pivotZ,&axisX,&axisY,&axisZ,&flag);
#endif
	}

	/* XXX extrainfo seems to be nothing implemented. right now it works as a pivot with [X,0,0] */
	else if (len == 4)
	{
#if defined(_WIN64)
		success = PyArg_ParseTuple(args,"LLii",&physicsid,&physicsid2,&constrainttype,&extrainfo);
#else
		success = PyArg_ParseTuple(args,"llii",&physicsid,&physicsid2,&constrainttype,&extrainfo);
#endif
		pivotX=extrainfo;
	}

	if (success)
	{
		if (PHY_GetActiveEnvironment())
		{
			
			PHY_IPhysicsController* physctrl = (PHY_IPhysicsController*) physicsid;
			PHY_IPhysicsController* physctrl2 = (PHY_IPhysicsController*) physicsid2;
			if (physctrl) //TODO:check for existence of this pointer!
			{
				PHY_ConstraintType ct = (PHY_ConstraintType) constrainttype;
				int constraintid =0;

				if (ct == PHY_GENERIC_6DOF_CONSTRAINT)
				{
					//convert from euler angle into axis
					float radsPerDeg = 6.283185307179586232f / 360.f;

					//we need to pass a full constraint frame, not just axis
					//localConstraintFrameBasis
					MT_Matrix3x3 localCFrame(MT_Vector3(radsPerDeg*axisX,radsPerDeg*axisY,radsPerDeg*axisZ));
					MT_Vector3 axis0 = localCFrame.getColumn(0);
					MT_Vector3 axis1 = localCFrame.getColumn(1);
					MT_Vector3 axis2 = localCFrame.getColumn(2);

					constraintid = PHY_GetActiveEnvironment()->createConstraint(physctrl,physctrl2,(enum PHY_ConstraintType)constrainttype,
					                                                            pivotX,pivotY,pivotZ,
					                                                            (float)axis0.x(),(float)axis0.y(),(float)axis0.z(),
					                                                            (float)axis1.x(),(float)axis1.y(),(float)axis1.z(),
					                                                            (float)axis2.x(),(float)axis2.y(),(float)axis2.z(),flag);
				}
				else {
					constraintid = PHY_GetActiveEnvironment()->createConstraint(physctrl,physctrl2,(enum PHY_ConstraintType)constrainttype,pivotX,pivotY,pivotZ,axisX,axisY,axisZ,0);
				}
				
				KX_ConstraintWrapper* wrap = new KX_ConstraintWrapper((enum PHY_ConstraintType)constrainttype,constraintid,PHY_GetActiveEnvironment());

				return wrap->NewProxy(true);
			}
			
			
		}
	}
	else {
		return NULL;
	}

	Py_RETURN_NONE;
}