Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErwin Coumans <blender@erwincoumans.com>2006-02-13 09:28:35 +0300
committerErwin Coumans <blender@erwincoumans.com>2006-02-13 09:28:35 +0300
commitf55e45f855250a5693455fe0f7e13fe0f35c7814 (patch)
tree3b98f46c92068f3dd6c1acb45887b0b16175878c /source/gameengine/Ketsji
parente4790aef46f7ca0b4ab01c34f043be9e7b1fa7f1 (diff)
more vehicle preparation and some bullet collision detection bugfixes (related to collision margin)
Diffstat (limited to 'source/gameengine/Ketsji')
-rw-r--r--source/gameengine/Ketsji/KX_KetsjiEngine.cpp19
-rw-r--r--source/gameengine/Ketsji/KX_VehicleWrapper.cpp150
-rw-r--r--source/gameengine/Ketsji/KX_VehicleWrapper.h18
3 files changed, 182 insertions, 5 deletions
diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
index 8be153ecb60..e9d10f785b0 100644
--- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
+++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
@@ -333,6 +333,13 @@ void KX_KetsjiEngine::NextFrame()
m_clockTime = m_kxsystem->GetTimeInSeconds();
double deltatime = m_clockTime - m_frameTime;
+ if (deltatime<0.f)
+ {
+ printf("problem with clock\n");
+ deltatime = 0.f;
+ m_clockTime = 0.f;
+ m_frameTime = 0.f;
+ }
// Compute the number of logic frames to do each update (fixed tic bricks)
int frames =int(deltatime*m_ticrate);
@@ -341,9 +348,21 @@ void KX_KetsjiEngine::NextFrame()
// PIL_sleep_ms(4);
KX_SceneList::iterator sceneit;
+ int frameOut = 5;
+ if (frames>frameOut)
+ {
+ printf("framedOut: %d\n",frames);
+ m_frameTime+=(frames-frameOut)*(1.0/m_ticrate);
+ frames = frameOut;
+ }
+
while (frames)
{
+ if (frames > frameOut)
+ {
+ printf ("what happened\n");
+ }
m_frameTime += 1.0/m_ticrate;
diff --git a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp
index 299a2d1f180..9745af028d5 100644
--- a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp
+++ b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp
@@ -4,6 +4,9 @@
#include "KX_VehicleWrapper.h"
#include "PHY_IPhysicsEnvironment.h"
#include "PHY_IVehicle.h"
+#include "KX_PyMath.h"
+#include "KX_GameObject.h"
+#include "KX_MotionState.h"
#ifdef HAVE_CONFIG_H
#include <config.h>
@@ -20,6 +23,13 @@ KX_VehicleWrapper::KX_VehicleWrapper(
KX_VehicleWrapper::~KX_VehicleWrapper()
{
+ int numMotion = m_motionStates.size();
+ for (int i=0;i<numMotion;i++)
+ {
+ PHY_IMotionState* motionState = m_motionStates[i];
+ delete motionState;
+ }
+ m_motionStates.clear();
}
@@ -27,18 +37,92 @@ PyObject* KX_VehicleWrapper::PyAddWheel(PyObject* self,
PyObject* args,
PyObject* kwds)
{
+
+ PyObject* pylistPos,*pylistDir,*pylistAxleDir;
+ PyObject* wheelGameObject;
+ float suspensionRestLength,wheelRadius;
+ int hasSteering;
+
+
+ if (PyArg_ParseTuple(args,"OOOOffi",&wheelGameObject,&pylistPos,&pylistDir,&pylistAxleDir,&suspensionRestLength,&wheelRadius,&hasSteering))
+ {
+ KX_GameObject* gameOb = (KX_GameObject*) wheelGameObject;
+
+ PHY_IMotionState* motionState = new KX_MotionState(gameOb->GetSGNode());
+
+ MT_Vector3 attachPos,attachDir,attachAxle;
+ PyVecTo(pylistPos,attachPos);
+ PyVecTo(pylistDir,attachDir);
+ PyVecTo(pylistAxleDir,attachAxle);
+ PHY__Vector3 aPos,aDir,aAxle;
+ aPos[0] = attachPos[0];
+ aPos[1] = attachPos[1];
+ aPos[2] = attachPos[2];
+ aDir[0] = attachDir[0];
+ aDir[1] = attachDir[1];
+ aDir[2] = attachDir[2];
+ aAxle[0] = attachAxle[0];
+ aAxle[1] = attachAxle[1];
+ aAxle[2] = attachAxle[2];
+
+ printf("attempt for addWheel: suspensionRestLength%f wheelRadius %f, hasSteering:%d\n",suspensionRestLength,wheelRadius,hasSteering);
+ m_vehicle->AddWheel(motionState,aPos,aDir,aAxle,suspensionRestLength,wheelRadius,hasSteering);
+
+ }
Py_INCREF(Py_None);
return Py_None;
}
-PyObject* KX_VehicleWrapper::PyGetWheelsTransform(PyObject* self,
+
+PyObject* KX_VehicleWrapper::PyGetWheelPosition(PyObject* self,
PyObject* args,
PyObject* kwds)
{
- assert(0);
- return PyInt_FromLong(m_vehicle->GetNumWheels());
+
+ int wheelIndex;
+
+ if (PyArg_ParseTuple(args,"i",&wheelIndex))
+ {
+ float position[3];
+ m_vehicle->GetWheelPosition(wheelIndex,position[0],position[1],position[2]);
+ MT_Vector3 pos(position[0],position[1],position[2]);
+ return PyObjectFrom(pos);
+ }
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+PyObject* KX_VehicleWrapper::PyGetWheelRotation(PyObject* self,
+ PyObject* args,
+ PyObject* kwds)
+{
+ int wheelIndex;
+ if (PyArg_ParseTuple(args,"i",&wheelIndex))
+ {
+ return PyFloat_FromDouble(m_vehicle->GetWheelRotation(wheelIndex));
+ }
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+PyObject* KX_VehicleWrapper::PyGetWheelOrientationQuaternion(PyObject* self,
+ PyObject* args,
+ PyObject* kwds)
+{
+ int wheelIndex;
+ if (PyArg_ParseTuple(args,"i",&wheelIndex))
+ {
+ float orn[4];
+ m_vehicle->GetWheelOrientationQuaternion(wheelIndex,orn[0],orn[1],orn[2],orn[3]);
+ MT_Quaternion quatorn(orn[0],orn[1],orn[2],orn[3]);
+ MT_Matrix3x3 ornmat(quatorn);
+ return PyObjectFrom(ornmat);
+ }
+ Py_INCREF(Py_None);
+ return Py_None;
+
}
@@ -57,6 +141,58 @@ PyObject* KX_VehicleWrapper::PyGetConstraintId(PyObject* self,
return PyInt_FromLong(m_vehicle->GetUserConstraintId());
}
+
+
+PyObject* KX_VehicleWrapper::PyApplyEngineForce(PyObject* self,
+ PyObject* args,
+ PyObject* kwds)
+{
+ float force;
+ int wheelIndex;
+
+ if (PyArg_ParseTuple(args,"fi",&force,&wheelIndex))
+ {
+ m_vehicle->ApplyEngineForce(force,wheelIndex);
+ }
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+
+PyObject* KX_VehicleWrapper::PyApplyBraking(PyObject* self,
+ PyObject* args,
+ PyObject* kwds)
+{
+ float braking;
+ int wheelIndex;
+
+ if (PyArg_ParseTuple(args,"fi",&braking,&wheelIndex))
+ {
+ m_vehicle->ApplyBraking(braking,wheelIndex);
+ }
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+
+
+
+PyObject* KX_VehicleWrapper::PySetSteeringValue(PyObject* self,
+ PyObject* args,
+ PyObject* kwds)
+{
+ float steeringValue;
+ int wheelIndex;
+
+ if (PyArg_ParseTuple(args,"fi",&steeringValue,&wheelIndex))
+ {
+ m_vehicle->SetSteeringValue(steeringValue,wheelIndex);
+ }
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+
PyObject* KX_VehicleWrapper::PyGetConstraintType(PyObject* self,
PyObject* args,
PyObject* kwds)
@@ -67,6 +203,7 @@ PyObject* KX_VehicleWrapper::PyGetConstraintType(PyObject* self,
+
//python specific stuff
PyTypeObject KX_VehicleWrapper::Type = {
PyObject_HEAD_INIT(&PyType_Type)
@@ -130,9 +267,14 @@ int KX_VehicleWrapper::_setattr(const STR_String& attr,PyObject* pyobj)
PyMethodDef KX_VehicleWrapper::Methods[] = {
{"addWheel",(PyCFunction) KX_VehicleWrapper::sPyAddWheel, METH_VARARGS},
{"getNumWheels",(PyCFunction) KX_VehicleWrapper::sPyGetNumWheels, METH_VARARGS},
- {"getWheelsTransform",(PyCFunction) KX_VehicleWrapper::sPyGetWheelsTransform, METH_VARARGS},
+ {"getWheelOrientationQuaternion",(PyCFunction) KX_VehicleWrapper::sPyGetWheelOrientationQuaternion, METH_VARARGS},
+ {"getWheelRotation",(PyCFunction) KX_VehicleWrapper::sPyGetWheelRotation, METH_VARARGS},
+ {"getWheelPosition",(PyCFunction) KX_VehicleWrapper::sPyGetWheelPosition, METH_VARARGS},
{"getConstraintId",(PyCFunction) KX_VehicleWrapper::sPyGetConstraintId, METH_VARARGS},
{"getConstraintType",(PyCFunction) KX_VehicleWrapper::sPyGetConstraintType, METH_VARARGS},
+ {"setSteeringValue",(PyCFunction) KX_VehicleWrapper::sPySetSteeringValue, METH_VARARGS},
+ {"applyEngineForce",(PyCFunction) KX_VehicleWrapper::sPyApplyEngineForce, METH_VARARGS},
+ {"applyBraking",(PyCFunction) KX_VehicleWrapper::sPyApplyBraking, METH_VARARGS},
{NULL,NULL} //Sentinel
};
diff --git a/source/gameengine/Ketsji/KX_VehicleWrapper.h b/source/gameengine/Ketsji/KX_VehicleWrapper.h
index ebdf1b0fa2f..22b8f186f4a 100644
--- a/source/gameengine/Ketsji/KX_VehicleWrapper.h
+++ b/source/gameengine/Ketsji/KX_VehicleWrapper.h
@@ -4,6 +4,9 @@
#include "Value.h"
#include "PHY_DynamicTypes.h"
class PHY_IVehicle;
+class PHY_IMotionState;
+
+#include <vector>
///Python interface to physics vehicles (primarily 4-wheel cars and 2wheel bikes)
class KX_VehicleWrapper : public PyObjectPlus
@@ -11,6 +14,9 @@ class KX_VehicleWrapper : public PyObjectPlus
Py_Header;
virtual PyObject* _getattr(const STR_String& attr);
virtual int _setattr(const STR_String& attr, PyObject *value);
+
+ std::vector<PHY_IMotionState*> m_motionStates;
+
public:
KX_VehicleWrapper(PHY_IVehicle* vehicle,class PHY_IPhysicsEnvironment* physenv,PyTypeObject *T = &Type);
virtual ~KX_VehicleWrapper ();
@@ -19,11 +25,21 @@ public:
KX_PYMETHOD(KX_VehicleWrapper,AddWheel);
KX_PYMETHOD(KX_VehicleWrapper,GetNumWheels);
- KX_PYMETHOD(KX_VehicleWrapper,GetWheelsTransform);
+ KX_PYMETHOD(KX_VehicleWrapper,GetWheelOrientationQuaternion);
+ KX_PYMETHOD(KX_VehicleWrapper,GetWheelRotation);
+
+ KX_PYMETHOD(KX_VehicleWrapper,GetWheelPosition);
KX_PYMETHOD(KX_VehicleWrapper,GetConstraintId);
KX_PYMETHOD(KX_VehicleWrapper,GetConstraintType);
+ KX_PYMETHOD(KX_VehicleWrapper,SetSteeringValue);
+
+ KX_PYMETHOD(KX_VehicleWrapper,ApplyEngineForce);
+
+ KX_PYMETHOD(KX_VehicleWrapper,ApplyBraking);
+
+
private:
PHY_IVehicle* m_vehicle;