diff options
Diffstat (limited to 'source/gameengine/Ketsji')
42 files changed, 708 insertions, 449 deletions
diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp index 6b669bcd936..69bf4dd69ce 100644 --- a/source/gameengine/Ketsji/KX_Camera.cpp +++ b/source/gameengine/Ketsji/KX_Camera.cpp @@ -64,7 +64,7 @@ MT_Transform KX_Camera::GetWorldToCamera() const trans.setBasis(NodeGetWorldOrientation()); trans.setOrigin(NodeGetWorldPosition()); - + camtrans.invert(trans); return camtrans; @@ -95,8 +95,8 @@ const MT_Point3 KX_Camera::GetCameraLocation() //return m_trans1.getOrigin(); //return MT_Point3(0,0,0); <----- /* .... I want it in world coords */ - MT_Transform trans; - trans.setBasis(NodeGetWorldOrientation()); + //MT_Transform trans; + //trans.setBasis(NodeGetWorldOrientation()); return NodeGetWorldPosition(); } diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp index df61aaf5243..f1286de1bd4 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.cpp +++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp @@ -183,8 +183,6 @@ bool KX_CameraActuator::Update(double curtime,double deltatime) MT_Point3 lookat = ((KX_GameObject*)m_ob)->NodeGetWorldPosition(); MT_Matrix3x3 actormat = ((KX_GameObject*)m_ob)->NodeGetWorldOrientation(); - - float fp1[3], fp2[3], rc[3]; float inp, fac; //, factor = 0.0; /* some factor... */ float mindistsq, maxdistsq, distsq; diff --git a/source/gameengine/Ketsji/KX_CameraIpoSGController.h b/source/gameengine/Ketsji/KX_CameraIpoSGController.h index 029aa6d7156..d80847fa5fb 100644 --- a/source/gameengine/Ketsji/KX_CameraIpoSGController.h +++ b/source/gameengine/Ketsji/KX_CameraIpoSGController.h @@ -55,11 +55,12 @@ private: double m_ipotime; public: - KX_CameraIpoSGController() : m_ipotime(0.0), - m_modify_lens(false), - m_modify_clipstart(false), - m_modify_clipend(false), - m_modified(true) + KX_CameraIpoSGController() : + m_modify_lens(false), + m_modify_clipstart(false), + m_modify_clipend(false), + m_modified(true), + m_ipotime(0.0) {} ~KX_CameraIpoSGController(); diff --git a/source/gameengine/Ketsji/KX_ClientObjectInfo.h b/source/gameengine/Ketsji/KX_ClientObjectInfo.h index 0981463ed44..51cb19e8935 100644 --- a/source/gameengine/Ketsji/KX_ClientObjectInfo.h +++ b/source/gameengine/Ketsji/KX_ClientObjectInfo.h @@ -35,12 +35,21 @@ /** * Client Type and Additional Info. This structure can be use instead of a bare void* pointer, for safeness, and additional info for callbacks */ - struct KX_ClientObjectInfo { - int m_type; + enum { + STATIC, + ACTOR, + RESERVED1, + RADAR, + NEAR + } m_type; void* m_clientobject; void* m_auxilary_info; +public: + KX_ClientObjectInfo(void *clientobject) : + m_clientobject(clientobject) + {} }; #endif //__KX_CLIENTOBJECT_INFO_H diff --git a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp index 04bec5cb37c..e42ae59e2bb 100644 --- a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp @@ -40,8 +40,11 @@ KX_ConstraintWrapper::KX_ConstraintWrapper( PHY_ConstraintType ctype, int constraintId, - PHY_IPhysicsEnvironment* physenv,PyTypeObject *T) -: m_constraintType(ctype),m_constraintId(constraintId),m_physenv(physenv),PyObjectPlus(T) + PHY_IPhysicsEnvironment* physenv,PyTypeObject *T) : + PyObjectPlus(T), + m_constraintId(constraintId), + m_constraintType(ctype), + m_physenv(physenv) { } KX_ConstraintWrapper::~KX_ConstraintWrapper() diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h index bf40baf5594..3ed3e2bfa8f 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h @@ -32,22 +32,35 @@ #ifndef KX_CONVERTPHYSICSOBJECTS #define KX_CONVERTPHYSICSOBJECTS - +/* These are defined by the build system... */ //#define USE_SUMO_SOLID -//solid is not available yet - -#define USE_ODE +//#define USE_ODE class RAS_MeshObject; class KX_Scene; +typedef enum { + KX_BOUNDBOX, + KX_BOUNDSPHERE, + KX_BOUNDCYLINDER, + KX_BOUNDCONE, + KX_BOUNDMESH +} KX_BoundBoxClass; -struct KX_Bounds +struct KX_BoxBounds { float m_center[3]; float m_extends[3]; }; +/* Cone/Cylinder */ +struct KX_CBounds +{ + float m_radius; + float m_height; +}; + + struct KX_ObjectProperties { bool m_dyna; @@ -59,9 +72,11 @@ struct KX_ObjectProperties bool m_isactor; bool m_concave; bool m_isdeformable; - bool m_implicitsphere ; - bool m_implicitbox; - KX_Bounds m_boundingbox; + KX_BoundBoxClass m_boundclass; + union { + KX_BoxBounds box; + KX_CBounds c; + } m_boundobject; }; #ifdef USE_ODE diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp index a6e7daadb2c..96716214edc 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp @@ -29,7 +29,9 @@ * * ***** END GPL/BL DUAL LICENSE BLOCK ***** */ +#ifdef WIN32 #pragma warning (disable : 4786) +#endif // defines USE_ODE to choose physics engine #include "KX_ConvertPhysicsObject.h" @@ -63,7 +65,6 @@ // USE_SUMO_SOLID is defined in headerfile KX_ConvertPhysicsObject.h #ifdef USE_SUMO_SOLID - #include "SumoPhysicsEnvironment.h" #include "KX_SumoPhysicsController.h" @@ -83,16 +84,15 @@ void BL_RegisterSumoObject(KX_GameObject* gameobj,class SM_Scene* sumoScene,DT_S DT_ShapeHandle CreateShapeFromMesh(RAS_MeshObject* meshobj); -void KX_ConvertSumoObject( class KX_GameObject* gameobj, - class RAS_MeshObject* meshobj, - class KX_Scene* kxscene, - PHY_ShapeProps* kxshapeprops, - PHY_MaterialProps* kxmaterial, - struct KX_ObjectProperties* objprop) +void KX_ConvertSumoObject( KX_GameObject* gameobj, + RAS_MeshObject* meshobj, + KX_Scene* kxscene, + PHY_ShapeProps* kxshapeprops, + PHY_MaterialProps* kxmaterial, + struct KX_ObjectProperties* objprop) { - SM_ShapeProps* smprop = new SM_ShapeProps; smprop->m_ang_drag = kxshapeprops->m_ang_drag; @@ -105,6 +105,7 @@ void KX_ConvertSumoObject( class KX_GameObject* gameobj, smprop->m_inertia = kxshapeprops->m_inertia; smprop->m_lin_drag = kxshapeprops->m_lin_drag; smprop->m_mass = kxshapeprops->m_mass; + smprop->m_radius = objprop->m_radius; SM_MaterialProps* smmaterial = new SM_MaterialProps; @@ -116,55 +117,48 @@ void KX_ConvertSumoObject( class KX_GameObject* gameobj, smmaterial->m_friction = kxmaterial->m_friction; smmaterial->m_restitution = kxmaterial->m_restitution; - class SumoPhysicsEnvironment* sumoEnv = + SumoPhysicsEnvironment* sumoEnv = (SumoPhysicsEnvironment*)kxscene->GetPhysicsEnvironment(); SM_Scene* sceneptr = sumoEnv->GetSumoScene(); - - SM_Object* sumoObj=NULL; if (objprop->m_dyna) { - - DT_ShapeHandle shape = DT_Sphere(0.0); - - if (objprop->m_ghost) + DT_ShapeHandle shape = NULL; + switch (objprop->m_boundclass) { - - sumoObj = new SM_Object(shape,NULL,smprop,NULL); - } else - { - sumoObj = new SM_Object(shape,smmaterial,smprop,NULL); + case KX_BOUNDBOX: + shape = DT_NewBox(objprop->m_boundobject.box.m_extends[0], objprop->m_boundobject.box.m_extends[1], objprop->m_boundobject.box.m_extends[2]); + break; + case KX_BOUNDCYLINDER: + shape = DT_NewCylinder(objprop->m_radius, objprop->m_boundobject.c.m_height); + break; + case KX_BOUNDCONE: + shape = DT_NewCone(objprop->m_radius, objprop->m_boundobject.c.m_height); + break; +/* Enabling this allows you to use dynamic mesh objects. It's disabled 'cause it's really slow. */ + case KX_BOUNDMESH: + if (meshobj && meshobj->NumPolygons() > 0) + { + if ((shape = CreateShapeFromMesh(meshobj))) + break; + } + /* If CreateShapeFromMesh fails, fall through and use sphere */ + default: + case KX_BOUNDSPHERE: + shape = DT_NewSphere(objprop->m_radius); + break; + } - double radius = objprop->m_radius; + sumoObj = new SM_Object(shape, !objprop->m_ghost?smmaterial:NULL,smprop,NULL); - MT_Scalar margin = radius;//0.5; - sumoObj->setMargin(margin); + sumoObj->setRigidBody(objprop->m_angular_rigidbody?true:false); - //if (bRigidBody) - //{ - if (objprop->m_in_active_layer) - { - DT_AddObject(sumoEnv->GetSolidScene(), - sumoObj->getObjectHandle()); - } - //} - - if (objprop->m_angular_rigidbody) - { - sumoObj->setRigidBody(true); - } else - { - sumoObj->setRigidBody(false); - } - - bool isDynamic = true; - bool isActor = true; - - BL_RegisterSumoObject(gameobj,sceneptr,sumoEnv->GetSolidScene(),sumoObj,NULL,isDynamic,isActor); + objprop->m_isactor = objprop->m_dyna = true; + BL_RegisterSumoObject(gameobj,sceneptr,sumoEnv->GetSolidScene(),sumoObj,NULL,true, true); } else { @@ -172,20 +166,40 @@ void KX_ConvertSumoObject( class KX_GameObject* gameobj, if (meshobj) { int numpolys = meshobj->NumPolygons(); - { DT_ShapeHandle complexshape=0; - if (objprop->m_implicitbox) - { - complexshape = DT_Box(objprop->m_boundingbox.m_extends[0],objprop->m_boundingbox.m_extends[1],objprop->m_boundingbox.m_extends[2]); - } else + switch (objprop->m_boundclass) { - if (numpolys>0) - { - complexshape = CreateShapeFromMesh(meshobj); - } + case KX_BOUNDBOX: + complexshape = DT_NewBox(objprop->m_boundobject.box.m_extends[0], objprop->m_boundobject.box.m_extends[1], objprop->m_boundobject.box.m_extends[2]); + break; + case KX_BOUNDSPHERE: + complexshape = DT_NewSphere(objprop->m_boundobject.c.m_radius); + break; + case KX_BOUNDCYLINDER: + complexshape = DT_NewCylinder(objprop->m_boundobject.c.m_radius, objprop->m_boundobject.c.m_height); + break; + case KX_BOUNDCONE: + complexshape = DT_NewCone(objprop->m_boundobject.c.m_radius, objprop->m_boundobject.c.m_height); + break; + default: + case KX_BOUNDMESH: + if (numpolys>0) + { + complexshape = CreateShapeFromMesh(meshobj); + //std::cout << "Convert Physics Mesh: " << meshobj->GetName() << std::endl; +/* if (!complexshape) + { + // Something has to be done here - if the object has no polygons, it will not be able to have + // sensors attached to it. + DT_Vector3 pt = {0., 0., 0.}; + complexshape = DT_NewSphere(1.0); + objprop->m_ghost = evilObject = true; + } */ + } + break; } if (complexshape) @@ -209,21 +223,7 @@ void KX_ConvertSumoObject( class KX_GameObject* gameobj, } - if (objprop->m_ghost) - { - sumoObj = new SM_Object(complexshape,NULL,NULL, dynamicParent); - } else - { - sumoObj = new SM_Object(complexshape,smmaterial,NULL, dynamicParent); - } - - if (objprop->m_in_active_layer) - { - DT_AddObject(sumoEnv->GetSolidScene(), - sumoObj->getObjectHandle()); - } - - + sumoObj = new SM_Object(complexshape,!objprop->m_ghost?smmaterial:NULL,NULL, dynamicParent); const STR_String& matname=meshobj->GetMaterialName(0); @@ -232,7 +232,6 @@ void KX_ConvertSumoObject( class KX_GameObject* gameobj, matname.ReadPtr(), objprop->m_dyna, objprop->m_isactor); - } } } @@ -264,35 +263,34 @@ void BL_RegisterSumoObject(KX_GameObject* gameobj,class SM_Scene* sumoScene,DT_S KX_SumoPhysicsController* physicscontroller = new KX_SumoPhysicsController(sumoScene,solidscene,sumoObj,motionstate,isDynamic); gameobj->SetPhysicsController(physicscontroller); physicscontroller->setClientInfo(gameobj); + + if (!gameobj->getClientInfo()) + std::cout << "BL_RegisterSumoObject: WARNING: Object " << gameobj->GetName() << " has no client info" << std::endl; + sumoObj->setClientObject(gameobj->getClientInfo()); gameobj->GetSGNode()->AddSGController(physicscontroller); - //gameobj->GetClientInfo()->m_type = (isActor ? 1 : 0); + gameobj->getClientInfo()->m_type = (isActor ? KX_ClientObjectInfo::ACTOR : KX_ClientObjectInfo::STATIC); //gameobj->GetClientInfo()->m_clientobject = gameobj; // store materialname in auxinfo, needed for touchsensors - //gameobj->GetClientInfo()->m_auxilary_info = (matname? (void*)(matname+2) : NULL); + gameobj->getClientInfo()->m_auxilary_info = (matname? (void*)(matname+2) : NULL); physicscontroller->SetObject(gameobj->GetSGNode()); - + //gameobj->SetDynamicsScaling(MT_Vector3(1.0, 1.0, 1.0)); }; - - DT_ShapeHandle CreateShapeFromMesh(RAS_MeshObject* meshobj) { - DT_ShapeHandle* shapeptr = map_gamemesh_to_sumoshape[GEN_HashedPtr(meshobj)]; + DT_ShapeHandle *shapeptr = map_gamemesh_to_sumoshape[GEN_HashedPtr(meshobj)]; if (shapeptr) { return *shapeptr; } - // todo: shared meshes - DT_ShapeHandle shape = DT_NewComplexShape(); - int p=0; int numpolys = meshobj->NumPolygons(); if (!numpolys) { @@ -300,38 +298,80 @@ DT_ShapeHandle CreateShapeFromMesh(RAS_MeshObject* meshobj) } int numvalidpolys = 0; - - - for (p=0;p<meshobj->m_triangle_indices.size();p++) + for (int p=0; p<numpolys; p++) { - RAS_TriangleIndex& idx = meshobj->m_triangle_indices[p]; - + RAS_Polygon* poly = meshobj->GetPolygon(p); + // only add polygons that have the collisionflag set - if (idx.m_collider) + if (poly->IsCollider()) { - DT_Begin(); - for (int v=0;v<3;v++) - { - int num = meshobj->m_xyz_index_to_vertex_index_mapping[idx.m_index[v]].size(); - if (num != 1) - { - int i=0; - } - RAS_MatArrayIndex& vertindex = meshobj->m_xyz_index_to_vertex_index_mapping[idx.m_index[v]][0]; + numvalidpolys++; + break; + } + } + + if (numvalidpolys < 1) + return NULL; + + DT_ShapeHandle shape = DT_NewComplexShape(NULL); + + + numvalidpolys = 0; - numvalidpolys++; + for (int p2=0; p2<numpolys; p2++) + { + RAS_Polygon* poly = meshobj->GetPolygon(p2); - { - const MT_Point3& pt = meshobj->GetVertex(vertindex.m_array, - vertindex.m_index, - (RAS_IPolyMaterial*)vertindex.m_matid)->xyz(); - DT_Vertex(pt[0],pt[1],pt[2]); - } + // only add polygons that have the collisionflag set + if (poly->IsCollider()) + { /* We have to tesselate here because SOLID can only raycast triangles */ + DT_Begin(); + DT_Vector3 pt; + /* V1 */ + meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, + poly->GetVertexIndexBase().m_indexarray[0], + poly->GetMaterial()->GetPolyMaterial())->xyz().getValue(pt); + DT_Vertex(pt); + /* V2 */ + meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, + poly->GetVertexIndexBase().m_indexarray[1], + poly->GetMaterial()->GetPolyMaterial())->xyz().getValue(pt); + DT_Vertex(pt); + /* V3 */ + meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, + poly->GetVertexIndexBase().m_indexarray[2], + poly->GetMaterial()->GetPolyMaterial())->xyz().getValue(pt); + DT_Vertex(pt); + + numvalidpolys++; + DT_End(); + + if (poly->VertexCount() == 4) + { + DT_Begin(); + /* V1 */ + meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, + poly->GetVertexIndexBase().m_indexarray[0], + poly->GetMaterial()->GetPolyMaterial())->xyz().getValue(pt); + DT_Vertex(pt); + /* V3 */ + meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, + poly->GetVertexIndexBase().m_indexarray[2], + poly->GetMaterial()->GetPolyMaterial())->xyz().getValue(pt); + DT_Vertex(pt); + /* V4 */ + meshobj->GetVertex(poly->GetVertexIndexBase().m_vtxarray, + poly->GetVertexIndexBase().m_indexarray[3], + poly->GetMaterial()->GetPolyMaterial())->xyz().getValue(pt); + DT_Vertex(pt); + + numvalidpolys++; + DT_End(); } - DT_End(); + } } - + DT_EndComplexShape(); if (numvalidpolys > 0) @@ -340,7 +380,7 @@ DT_ShapeHandle CreateShapeFromMesh(RAS_MeshObject* meshobj) return shape; } - // memleak... todo: delete shape + delete shape; return NULL; } diff --git a/source/gameengine/Ketsji/KX_GameActuator.cpp b/source/gameengine/Ketsji/KX_GameActuator.cpp index b3e50359224..dcdb9b00087 100644 --- a/source/gameengine/Ketsji/KX_GameActuator.cpp +++ b/source/gameengine/Ketsji/KX_GameActuator.cpp @@ -113,6 +113,7 @@ bool KX_GameActuator::Update(double curtime, double deltatime) { STR_String exitstring = "restarting game"; m_ketsjiengine->RequestExit(KX_EXIT_REQUEST_RESTART_GAME); + m_ketsjiengine->SetNameNextGame(m_filename); m_scene->AddDebugProperty((this)->GetParent(), exitstring); } break; @@ -146,7 +147,7 @@ bool KX_GameActuator::Update(double curtime, double deltatime) PyTypeObject KX_GameActuator::Type = { PyObject_HEAD_INIT(&PyType_Type) 0, - "KX_SceneActuator", + "KX_GameActuator", sizeof(KX_GameActuator), 0, PyDestructor, @@ -177,9 +178,39 @@ PyParentObject KX_GameActuator::Parents[] = PyMethodDef KX_GameActuator::Methods[] = { + {"getFile", (PyCFunction) KX_GameActuator::sPyGetFile, METH_VARARGS, GetFile_doc}, + {"setFile", (PyCFunction) KX_GameActuator::sPySetFile, METH_VARARGS, SetFile_doc}, {NULL,NULL} //Sentinel }; +/* getFile */ +char KX_GameActuator::GetFile_doc[] = +"getFile()\n" +"get the name of the file to start.\n"; +PyObject* KX_GameActuator::PyGetFile(PyObject* self, PyObject* args, PyObject* kwds) +{ + return PyString_FromString(m_filename); +} + +/* setFile */ +char KX_GameActuator::SetFile_doc[] = +"setFile(name)\n" +"set the name of the file to start.\n"; +PyObject* KX_GameActuator::PySetFile(PyObject* self, PyObject* args, PyObject* kwds) +{ + char* new_file; + + if (!PyArg_ParseTuple(args, "s", &new_file)) + { + return NULL; + } + + m_filename = STR_String(new_file); + + Py_Return; + +} + PyObject* KX_GameActuator::_getattr(char* attr) diff --git a/source/gameengine/Ketsji/KX_GameActuator.h b/source/gameengine/Ketsji/KX_GameActuator.h index 7f2af86db42..4f197cf5841 100644 --- a/source/gameengine/Ketsji/KX_GameActuator.h +++ b/source/gameengine/Ketsji/KX_GameActuator.h @@ -78,7 +78,8 @@ class KX_GameActuator : public SCA_IActuator /* --------------------------------------------------------------------- */ virtual PyObject* _getattr(char *attr); - + KX_PYMETHOD_DOC(KX_GameActuator,GetFile); + KX_PYMETHOD_DOC(KX_GameActuator,SetFile); }; /* end of class KX_GameActuator */ diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 24f0a36b152..2f30ac645a0 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -66,14 +66,15 @@ KX_GameObject::KX_GameObject( PyTypeObject* T ) : SCA_IObject(T), - m_bUseObjectColor(false), m_bDyna(false), m_bSuspendDynamics(false), - m_pPhysicsController1(NULL), - m_bVisible(true) + m_bUseObjectColor(false), + m_bVisible(true), + m_pPhysicsController1(NULL) { m_ignore_activity_culling = false; - m_pClient_info = new KX_ClientObjectInfo(); + m_pClient_info = new KX_ClientObjectInfo(this); + m_pClient_info->m_type = KX_ClientObjectInfo::ACTOR; m_pSGNode = new SG_Node(this,sgReplicationInfo,callbacks); // define the relationship between this node and it's parent. @@ -198,7 +199,7 @@ CValue* KX_GameObject::GetReplica() // this will copy properties and so on... CValue::AddDataToReplica(replica); ProcessReplica(replica); - + return replica; } @@ -222,14 +223,11 @@ void KX_GameObject::ApplyTorque(const MT_Vector3& torque,bool local) void KX_GameObject::ApplyMovement(const MT_Vector3& dloc,bool local) { - if (this->IsDynamic()) + if (m_pPhysicsController1) // (IsDynamic()) { m_pPhysicsController1->RelativeTranslate(dloc,local); } - else - { - GetSGNode()->RelativeTranslate(dloc,GetSGNode()->GetSGParent(),local); - } + GetSGNode()->RelativeTranslate(dloc,GetSGNode()->GetSGParent(),local); } @@ -237,12 +235,14 @@ void KX_GameObject::ApplyMovement(const MT_Vector3& dloc,bool local) void KX_GameObject::ApplyRotation(const MT_Vector3& drot,bool local) { MT_Matrix3x3 rotmat(drot); + rotmat.transpose(); - if (this->IsDynamic()) //m_pPhysicsController) - m_pPhysicsController1->RelativeRotate(rotmat.transposed(),local); - else - // in worldspace - GetSGNode()->RelativeRotate(rotmat.transposed(),local); + //if (m_pPhysicsController1) // (IsDynamic()) + // m_pPhysicsController1->RelativeRotate(rotmat_,local); + // in worldspace + GetSGNode()->RelativeRotate(rotmat,local); + if (m_pPhysicsController1) + m_pPhysicsController1->setOrientation(NodeGetWorldOrientation().getRotation()); } @@ -273,7 +273,7 @@ void KX_GameObject::Bucketize() { double* fl = GetOpenGLMatrix(); - for (int i=0;i<m_meshes.size();i++) + for (size_t i=0;i<m_meshes.size();i++) m_meshes[i]->Bucketize(fl, this, m_bUseObjectColor, m_objectColor); } @@ -283,7 +283,7 @@ void KX_GameObject::RemoveMeshes() { double* fl = GetOpenGLMatrix(); - for (int i=0;i<m_meshes.size();i++) + for (size_t i=0;i<m_meshes.size();i++) m_meshes[i]->RemoveFromBuckets(fl, this); //note: meshes can be shared, and are deleted by KX_BlenderSceneConverter @@ -315,7 +315,7 @@ void KX_GameObject::UpdateTransform() void KX_GameObject::SetDebugColor(unsigned int bgra) { - for (int i=0;i<m_meshes.size();i++) + for (size_t i=0;i<m_meshes.size();i++) m_meshes[i]->DebugColor(bgra); } @@ -411,9 +411,9 @@ KX_GameObject::MarkVisible( * determined on this level. Maybe change this to mesh level * later on? */ - for (int i=0;i<m_meshes.size();i++) + double* fl = GetOpenGLMatrix(); + for (size_t i=0;i<m_meshes.size();i++) { - double* fl = GetOpenGLMatrix(); m_meshes[i]->MarkVisible(fl,this,visible,m_bUseObjectColor,m_objectColor); } } @@ -425,9 +425,9 @@ KX_GameObject::MarkVisible( void ) { - for (int i=0;i<m_meshes.size();i++) + double* fl = GetOpenGLMatrix(); + for (size_t i=0;i<m_meshes.size();i++) { - double* fl = GetOpenGLMatrix(); m_meshes[i]->MarkVisible(fl, this, m_bVisible, @@ -439,8 +439,8 @@ KX_GameObject::MarkVisible( void KX_GameObject::addLinearVelocity(const MT_Vector3& lin_vel,bool local) { -// if (m_pPhysicsController1) -// m_pPhysicsController1->AddLinearVelocity(lin_vel,local); + if (m_pPhysicsController1) + m_pPhysicsController1->SetLinearVelocity(lin_vel + m_pPhysicsController1->GetLinearVelocity(),local); } @@ -972,7 +972,6 @@ PyObject* KX_GameObject::PyGetOrientation(PyObject* self, int row,col; const MT_Matrix3x3& orient = NodeGetWorldOrientation(); - int index = 0; for (row=0;row<3;row++) { PyObject* veclist = PyList_New(3); diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index e23a9a53957..6b3101be34d 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -217,7 +217,7 @@ public: * instance allocated on the heap. Ownership of the new * object belongs with the caller. */ - CValue* + virtual CValue* GetReplica( ); @@ -225,7 +225,7 @@ public: * Inherited from CValue -- Makes sure any internal * data owned by this class is deep copied. Called internally */ - void + virtual void ProcessReplica( KX_GameObject* replica ); @@ -340,6 +340,9 @@ public: m_pSGNode = node; } + /** + * Deprecated & broken + */ bool IsDynamic( ) const { @@ -549,6 +552,7 @@ public: */ void Resume(void); + KX_ClientObjectInfo* getClientInfo() { return m_pClient_info; } /** * @section Python interface functions. */ diff --git a/source/gameengine/Ketsji/KX_IPO_SGController.cpp b/source/gameengine/Ketsji/KX_IPO_SGController.cpp index 8dfced41c1e..2152fa35cd1 100644 --- a/source/gameengine/Ketsji/KX_IPO_SGController.cpp +++ b/source/gameengine/Ketsji/KX_IPO_SGController.cpp @@ -44,17 +44,18 @@ #include "KX_IPO_SGController.h" #include "KX_ScalarInterpolator.h" #include "KX_GameObject.h" +#include "KX_IPhysicsController.h" // All objects should start on frame 1! Will we ever need an object to // start on another frame, the 1.0 should change. KX_IpoSGController::KX_IpoSGController() -: m_ipotime(1.0), - m_modify_position(false), +: m_modify_position(false), m_modify_orientation(false), m_modify_scaling(false), - m_modified(true), m_ipo_as_force(false), - m_force_ipo_acts_local(false) + m_force_ipo_acts_local(false), + m_modified(true), + m_ipotime(1.0) { m_sumo_object = NULL; m_game_object = NULL; @@ -121,6 +122,11 @@ bool KX_IpoSGController::Update(double currentTime) m_sumo_object->calcXform(); } */ + if (m_game_object && ob) { + m_game_object->GetPhysicsController()->ApplyForce(m_force_ipo_acts_local ? + ob->GetWorldOrientation() * m_ipo_xform.GetPosition() : + m_ipo_xform.GetPosition(), false); + } } else { ob->SetLocalPosition(m_ipo_xform.GetPosition()); @@ -137,6 +143,11 @@ bool KX_IpoSGController::Update(double currentTime) m_sumo_object->calcXform(); } */ + if (m_game_object && ob) { + m_game_object->ApplyTorque(m_force_ipo_acts_local ? + ob->GetWorldOrientation() * m_ipo_xform.GetEulerAngles() : + m_ipo_xform.GetEulerAngles(), false); + } } else { ob->SetLocalOrientation(MT_Matrix3x3(m_ipo_xform.GetEulerAngles())); diff --git a/source/gameengine/Ketsji/KX_IPhysicsController.cpp b/source/gameengine/Ketsji/KX_IPhysicsController.cpp index fe43261c0be..475ae0dfba8 100644 --- a/source/gameengine/Ketsji/KX_IPhysicsController.cpp +++ b/source/gameengine/Ketsji/KX_IPhysicsController.cpp @@ -38,8 +38,8 @@ KX_IPhysicsController::KX_IPhysicsController(bool dyna,void* userdata) : m_bDyna(dyna), - m_userdata(userdata), - m_suspendDynamics(false) + m_suspendDynamics(false), + m_userdata(userdata) { }; diff --git a/source/gameengine/Ketsji/KX_IpoActuator.cpp b/source/gameengine/Ketsji/KX_IpoActuator.cpp index de2b31684e0..92333329f9e 100644 --- a/source/gameengine/Ketsji/KX_IpoActuator.cpp +++ b/source/gameengine/Ketsji/KX_IpoActuator.cpp @@ -89,7 +89,6 @@ public: }; - KX_IpoActuator::KX_IpoActuator(SCA_IObject* gameobj, const STR_String& propname, float starttime, @@ -100,16 +99,16 @@ KX_IpoActuator::KX_IpoActuator(SCA_IObject* gameobj, bool force_ipo_local, PyTypeObject* T) : SCA_IActuator(gameobj,T), + m_bNegativeEvent(false), m_starttime (starttime), - m_endtime(endtime) , - m_localtime(starttime), + m_endtime(endtime), m_recurse(recurse), - m_type((IpoActType)acttype) , + m_localtime(starttime), m_direction(1), - m_bNegativeEvent(false), m_propname(propname), m_ipo_as_force(ipo_as_force), - m_force_ipo_local(force_ipo_local) + m_force_ipo_local(force_ipo_local), + m_type((IpoActType)acttype) { // intentionally empty } diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index 80a4d13c916..37f5a16de83 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -102,9 +102,10 @@ const char KX_KetsjiEngine::m_profileLabels[tc_numCategories][15] = { * Constructor of the Ketsji Engine */ KX_KetsjiEngine::KX_KetsjiEngine(KX_ISystem* system) -: m_bInitialized(false), - m_activecam(0), - m_rasterizer(NULL) +: + m_rasterizer(NULL), + m_bInitialized(false), + m_activecam(0) { m_kxsystem = system; m_bFixedTime = false; @@ -587,6 +588,8 @@ void KX_KetsjiEngine::DoSound(KX_Scene* scene) m_logger->StartLog(tc_sound, m_kxsystem->GetTimeInSeconds(), true); KX_Camera* cam = scene->GetActiveCamera(); + if (!cam) + return; MT_Point3 listenerposition = cam->NodeGetWorldPosition(); MT_Vector3 listenervelocity = cam->GetLinearVelocity(); MT_Matrix3x3 listenerorientation = cam->NodeGetWorldOrientation(); @@ -734,6 +737,9 @@ void KX_KetsjiEngine::RenderFrame(KX_Scene* scene) { float left, right, bottom, top, nearfrust, farfrust; KX_Camera* cam = scene->GetActiveCamera(); + + if (!cam) + return; m_rasterizer->DisplayFog(); @@ -998,8 +1004,8 @@ void KX_KetsjiEngine::RemoveScene(const STR_String& scenename) } else { - STR_String tmpname = scenename; - printf("warning: scene %s does not exist, not removed!\n",tmpname.Ptr()); +// STR_String tmpname = scenename; + std::cout << "warning: scene " << scenename << " does not exist, not removed!" << std::endl; } } diff --git a/source/gameengine/Ketsji/KX_LightIpoSGController.h b/source/gameengine/Ketsji/KX_LightIpoSGController.h index 459d091ce80..deba37540d5 100644 --- a/source/gameengine/Ketsji/KX_LightIpoSGController.h +++ b/source/gameengine/Ketsji/KX_LightIpoSGController.h @@ -55,11 +55,12 @@ private: double m_ipotime; public: - KX_LightIpoSGController() : m_ipotime(0.0), - m_modify_energy(false), - m_modify_color(false), - m_modify_dist(false), - m_modified(true) + KX_LightIpoSGController() : + m_modify_energy(false), + m_modify_color(false), + m_modify_dist(false), + m_modified(true), + m_ipotime(0.0) {} virtual ~KX_LightIpoSGController(); diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp index c6f41265690..4e2a731c421 100644 --- a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp +++ b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp @@ -51,6 +51,11 @@ #include "KX_Camera.h" #include "KX_MouseFocusSensor.h" +#include "KX_ClientObjectInfo.h" +#include "SM_Object.h" +#include "SM_Scene.h" +#include "SumoPhysicsEnvironment.h" + /* ------------------------------------------------------------------------- */ /* Native functions */ /* ------------------------------------------------------------------------- */ @@ -233,23 +238,23 @@ bool KX_MouseFocusSensor::ParentObjectHasFocus(void) * ignore-object. We don't ignore anything... */ KX_GameObject* thisObj = (KX_GameObject*) GetParent(); - - //SM_Object* hitSMObj = m_sumoScene->rayTest(NULL, - // frompoint3, - // topoint3, - // resultpoint, - // resultnormal); - - KX_GameObject* hitKXObj = 0; + SumoPhysicsEnvironment *spe = dynamic_cast<SumoPhysicsEnvironment* > (m_kxscene->GetPhysicsEnvironment()); + SM_Scene *sumoScene = spe->GetSumoScene(); + + SM_Object* hitSMObj = sumoScene->rayTest(NULL, + frompoint3, + topoint3, + resultpoint, + resultnormal); /* all this casting makes me nervous... */ - //SM_ClientObjectInfo* client_info - // = ( hitSMObj ? - // (SM_ClientObjectInfo*) ((SM_Object*)hitSMObj)->getClientObject() : - // NULL); - //KX_GameObject* hitKXObj = ( client_info ? - // (KX_GameObject*)client_info->m_clientobject : - // NULL); + KX_ClientObjectInfo* client_info + = ( hitSMObj ? + (KX_ClientObjectInfo*) ((SM_Object*)hitSMObj)->getClientObject() : + NULL); + KX_GameObject* hitKXObj = ( client_info ? + (KX_GameObject*)client_info->m_clientobject : + NULL); /* Is this me? In the ray test, there are a lot of extra checks diff --git a/source/gameengine/Ketsji/KX_NearSensor.cpp b/source/gameengine/Ketsji/KX_NearSensor.cpp index 8008e85843f..0b32c748646 100644 --- a/source/gameengine/Ketsji/KX_NearSensor.cpp +++ b/source/gameengine/Ketsji/KX_NearSensor.cpp @@ -38,11 +38,40 @@ #include "KX_TouchEventManager.h" #include "KX_Scene.h" // needed to create a replica +#include "SM_Object.h" + #ifdef HAVE_CONFIG_H #include <config.h> #endif +KX_NearSensor::KX_NearSensor(SCA_EventManager* eventmgr, + KX_GameObject* gameobj, + void *vshape, + double margin, + double resetmargin, + bool bFindMaterial, + const STR_String& touchedpropname, + class KX_Scene* scene, + PyTypeObject* T) + :KX_TouchSensor(eventmgr, + gameobj, + bFindMaterial, + touchedpropname, + /* scene, */ + T), + m_Margin(margin), + m_ResetMargin(resetmargin) -#ifdef PHYSICS_NOT_YET +{ + m_client_info = new KX_ClientObjectInfo(gameobj); + m_client_info->m_type = KX_ClientObjectInfo::NEAR; + + DT_ShapeHandle shape = (DT_ShapeHandle) vshape; + m_sumoObj = new SM_Object(shape,NULL,NULL,NULL); + m_sumoObj->setMargin(m_Margin); + m_sumoObj->setClientObject(m_client_info); + + SynchronizeTransform(); +} KX_NearSensor::KX_NearSensor(SCA_EventManager* eventmgr, KX_GameObject* gameobj, @@ -56,20 +85,27 @@ KX_NearSensor::KX_NearSensor(SCA_EventManager* eventmgr, gameobj, bFindMaterial, touchedpropname, - scene, + /* scene, */ T), m_Margin(margin), - m_ResetMargin(resetmargin), - m_sumoScene(sumoscene) + m_ResetMargin(resetmargin) { - m_client_info.m_type = 4; - m_client_info.m_clientobject = gameobj; - m_client_info.m_auxilary_info = NULL; - sumoObj->setClientObject(&m_client_info); + m_client_info = new KX_ClientObjectInfo(gameobj); + m_client_info->m_type = KX_ClientObjectInfo::NEAR; + m_client_info->m_auxilary_info = NULL; + + m_sumoObj = new SM_Object(DT_NewSphere(0.0),NULL,NULL,NULL); + m_sumoObj->setMargin(m_Margin); + m_sumoObj->setClientObject(m_client_info); + + SynchronizeTransform(); } - +void KX_NearSensor::RegisterSumo(KX_TouchEventManager *touchman) +{ + touchman->GetSumoScene()->addSensor(*m_sumoObj); +} CValue* KX_NearSensor::GetReplica() { @@ -82,6 +118,16 @@ CValue* KX_NearSensor::GetReplica() // this will copy properties and so on... CValue::AddDataToReplica(replica); + replica->m_client_info = new KX_ClientObjectInfo(m_client_info->m_clientobject); + replica->m_client_info->m_type = KX_ClientObjectInfo::NEAR; + replica->m_client_info->m_auxilary_info = NULL; + + replica->m_sumoObj = new SM_Object(DT_NewSphere(0.0),NULL,NULL,NULL); + replica->m_sumoObj->setMargin(m_Margin); + replica->m_sumoObj->setClientObject(replica->m_client_info); + + replica->SynchronizeTransform(); + return replica; } @@ -89,42 +135,11 @@ CValue* KX_NearSensor::GetReplica() void KX_NearSensor::ReParent(SCA_IObject* parent) { - DT_ShapeHandle shape = DT_Sphere(0.0); - - // this sumoObject is not deleted by a gameobj, so delete it ourself - // later (memleaks)! - - SM_Object* sumoObj = new SM_Object(shape,NULL,NULL,NULL); - sumoObj->setMargin(m_Margin); - - //sumoObj->setPosition(gameobj->NodeGetWorldPosition()); - //sumoobj->setPosition(m_sumoObj->getPosition()); - //sumoobj->setOrientation(m_sumoObj->getOrientation()); - //newobj->setRigidBody(this->m_sumoObj->isRigidBody()); - - m_sumoObj = sumoObj; - m_solidHandle = m_sumoObj->getObjectHandle(); - - double radius = m_sumoObj->getMargin(); - sumoObj->setMargin(m_sumoObj->getMargin()); + SCA_ISensor::ReParent(parent); - m_client_info.m_type = 4; - m_client_info.m_clientobject = parent; - m_client_info.m_auxilary_info = NULL; - sumoObj->setClientObject(&m_client_info); - - //m_sumoScene->add(*newobj); + m_client_info->m_clientobject = static_cast<KX_GameObject*>(parent); - if (m_sumoObj) - { - DT_SetObjectResponse(m_resptable, - m_sumoObj->getObjectHandle(), - collisionResponse, - DT_SIMPLE_RESPONSE, - this); - } - - SCA_ISensor::ReParent(parent); + SynchronizeTransform(); } @@ -133,19 +148,20 @@ KX_NearSensor::~KX_NearSensor() { // for nearsensor, the sensor is the 'owner' of sumoobj // for touchsensor, it's the parent - - m_sumoScene->remove(*m_sumoObj); + static_cast<KX_TouchEventManager*>(m_eventmgr)->GetSumoScene()->remove(*m_sumoObj); if (m_sumoObj) delete m_sumoObj; + + if (m_client_info) + delete m_client_info; } - bool KX_NearSensor::Evaluate(CValue* event) { bool result = false; - KX_GameObject* parent = (KX_GameObject*)GetParent(); + KX_GameObject* parent = static_cast<KX_GameObject*>(GetParent()); if (m_bTriggered != m_bLastTriggered) { @@ -172,28 +188,27 @@ bool KX_NearSensor::Evaluate(CValue* event) -void KX_NearSensor::HandleCollision(void* obj1,void* obj2,const DT_CollData * coll_data) +DT_Bool KX_NearSensor::HandleCollision(void* obj1,void* obj2,const DT_CollData * coll_data) { - KX_TouchEventManager* toucheventmgr = (KX_TouchEventManager*)m_eventmgr; - KX_GameObject* parent = (KX_GameObject*)GetParent(); - + KX_TouchEventManager* toucheventmgr = static_cast<KX_TouchEventManager*>(m_eventmgr); + KX_GameObject* parent = static_cast<KX_GameObject*>(GetParent()); + // need the mapping from SM_Objects to gameobjects now - SM_ClientObjectInfo* client_info =(SM_ClientObjectInfo*) (obj1 == m_sumoObj? + KX_ClientObjectInfo* client_info =static_cast<KX_ClientObjectInfo*> (obj1 == m_sumoObj? ((SM_Object*)obj2)->getClientObject() : ((SM_Object*)obj1)->getClientObject()); KX_GameObject* gameobj = ( client_info ? - (KX_GameObject*)client_info->m_clientobject : + static_cast<KX_GameObject*>(client_info->m_clientobject) : NULL); - + if (gameobj && (gameobj != parent)) { if (!m_colliders->SearchValue(gameobj)) m_colliders->Add(gameobj->AddRef()); - // only take valid colliders - if (client_info->m_type == 1) + if (client_info->m_type == KX_ClientObjectInfo::ACTOR) { if ((m_touchedpropname.Length() == 0) || (gameobj->GetProperty(m_touchedpropname))) @@ -202,10 +217,9 @@ void KX_NearSensor::HandleCollision(void* obj1,void* obj2,const DT_CollData * co m_hitObject = gameobj; } } - } else - { - } + + return DT_CONTINUE; } @@ -262,4 +276,3 @@ KX_NearSensor::_getattr(char* attr) _getattr_up(KX_TouchSensor); } -#endif //PHYSICS_NOT_YET diff --git a/source/gameengine/Ketsji/KX_NearSensor.h b/source/gameengine/Ketsji/KX_NearSensor.h index 2240cb0d589..335edbb97ca 100644 --- a/source/gameengine/Ketsji/KX_NearSensor.h +++ b/source/gameengine/Ketsji/KX_NearSensor.h @@ -36,8 +36,10 @@ #define KX_NEARSENSOR_H #include "KX_TouchSensor.h" +#include "KX_ClientObjectInfo.h" class KX_Scene; +class KX_ClientObjectInfo; class KX_NearSensor : public KX_TouchSensor { @@ -45,17 +47,36 @@ class KX_NearSensor : public KX_TouchSensor double m_Margin; double m_ResetMargin; KX_Scene* m_scene; + KX_ClientObjectInfo* m_client_info; +protected: + KX_NearSensor(class SCA_EventManager* eventmgr, + class KX_GameObject* gameobj, + void *shape, + double margin, + double resetmargin, + bool bFindMaterial, + const STR_String& touchedpropname, + class KX_Scene* scene, + PyTypeObject* T=&Type); public: - KX_NearSensor(class SCA_EventManager* eventmgr,class KX_GameObject* gameobj,double margin,double resetmargin,bool bFindMaterial,const STR_String& touchedpropname,class KM_Scene* scene,PyTypeObject* T=&Type); + KX_NearSensor(class SCA_EventManager* eventmgr, + class KX_GameObject* gameobj, + double margin, + double resetmargin, + bool bFindMaterial, + const STR_String& touchedpropname, + class KX_Scene* scene, + PyTypeObject* T=&Type); virtual ~KX_NearSensor(); virtual CValue* GetReplica(); virtual bool Evaluate(CValue* event); virtual void ReParent(SCA_IObject* parent); - //virtual void HandleCollision(void* obj1,void* obj2, - // const DT_CollData * coll_data); - + virtual DT_Bool HandleCollision(void* obj1,void* obj2, + const DT_CollData * coll_data); + virtual void RegisterSumo(KX_TouchEventManager *touchman); + virtual PyObject* _getattr(char *attr); }; diff --git a/source/gameengine/Ketsji/KX_ObColorIpoSGController.h b/source/gameengine/Ketsji/KX_ObColorIpoSGController.h index 2fa37a6369c..02a58ffd95a 100644 --- a/source/gameengine/Ketsji/KX_ObColorIpoSGController.h +++ b/source/gameengine/Ketsji/KX_ObColorIpoSGController.h @@ -48,9 +48,9 @@ private: double m_ipotime; public: - KX_ObColorIpoSGController() : m_ipotime(0.0), - - m_modified(true) + KX_ObColorIpoSGController() : + m_modified(true), + m_ipotime(0.0) {} virtual ~KX_ObColorIpoSGController(); virtual SG_Controller* GetReplica(class SG_Node* destnode); diff --git a/source/gameengine/Ketsji/KX_ObjectActuator.cpp b/source/gameengine/Ketsji/KX_ObjectActuator.cpp index bcbabc384e9..1d913fe6e44 100644 --- a/source/gameengine/Ketsji/KX_ObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_ObjectActuator.cpp @@ -44,7 +44,6 @@ /* Native functions */ /* ------------------------------------------------------------------------- */ - KX_ObjectActuator:: KX_ObjectActuator( SCA_IObject* gameobj, @@ -64,8 +63,8 @@ KX_ObjectActuator( m_drot(drot), m_linear_velocity(linV), m_angular_velocity(angV), - m_active_combined_velocity (false), - m_bitLocalFlag (flag) + m_bitLocalFlag (flag), + m_active_combined_velocity (false) { } @@ -83,6 +82,11 @@ bool KX_ObjectActuator::Update(double curtime,double deltatime) // it should reconcile the externally set velocity with it's // own velocity. if (m_active_combined_velocity) { + static bool update_resolve_warning = 0; + if (!update_resolve_warning) { + update_resolve_warning = 1; + std::cout << "FIXME: KX_ObjectActuator::Update ResolveCombinedVelocities undefined!" << std::endl; + } //if (parent->GetSumoObject()) { //parent->GetPhysicsController()->ResolveCombinedVelocities( // m_linear_velocity, diff --git a/source/gameengine/Ketsji/KX_PhysicsEngineEnums.h b/source/gameengine/Ketsji/KX_PhysicsEngineEnums.h index 9f6bd6d8f0b..9c1267ff34c 100644 --- a/source/gameengine/Ketsji/KX_PhysicsEngineEnums.h +++ b/source/gameengine/Ketsji/KX_PhysicsEngineEnums.h @@ -34,11 +34,12 @@ enum e_PhysicsEngine { - UseNone=1, - UseSumo, - UseODE, - UseDynamo, - NoSelection + NoSelection = -1, + UseNone = 0, + UseEnji = 1, + UseSumo = 2, + UseDynamo = 3, + UseODE = 4 }; #endif //__KX_PHYSICSENGINEENUMS diff --git a/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp b/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp index 2bba77a966a..d692af82b7a 100644 --- a/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp +++ b/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp @@ -40,8 +40,10 @@ KX_PhysicsObjectWrapper::KX_PhysicsObjectWrapper( PHY_IPhysicsController* ctrl, - PHY_IPhysicsEnvironment* physenv,PyTypeObject *T) -: m_ctrl(ctrl),m_physenv(physenv),PyObjectPlus(T) + PHY_IPhysicsEnvironment* physenv,PyTypeObject *T) : + PyObjectPlus(T), + m_ctrl(ctrl), + m_physenv(physenv) { } diff --git a/source/gameengine/Ketsji/KX_RadarSensor.cpp b/source/gameengine/Ketsji/KX_RadarSensor.cpp index 19e26b6f484..923a38cb7cc 100644 --- a/source/gameengine/Ketsji/KX_RadarSensor.cpp +++ b/source/gameengine/Ketsji/KX_RadarSensor.cpp @@ -39,11 +39,8 @@ /** * RadarSensor constructor. Creates a near-sensor derived class, with a cone collision shape. */ - -#ifdef PHYSICS_NOT_YET - -KX_RadarSensor::KX_RadarSensor(class SCA_EventManager* eventmgr, - class KX_GameObject* gameobj, +KX_RadarSensor::KX_RadarSensor(SCA_EventManager* eventmgr, + KX_GameObject* gameobj, double coneradius, double coneheight, int axis, @@ -57,20 +54,21 @@ KX_RadarSensor::KX_RadarSensor(class SCA_EventManager* eventmgr, : KX_NearSensor( eventmgr, gameobj, + DT_NewCone(coneradius,coneheight), margin, resetmargin, bFindMaterial, touchedpropname, kxscene, T), - m_coneheight(coneheight), m_coneradius(coneradius), + m_coneheight(coneheight), m_axis(axis) { - m_client_info.m_type = 3; - m_client_info.m_clientobject = gameobj; - m_client_info.m_auxilary_info = NULL; - sumoObj->setClientObject(&m_client_info); + m_client_info->m_type = KX_ClientObjectInfo::RADAR; + //m_client_info->m_clientobject = gameobj; + //m_client_info->m_auxilary_info = NULL; + //sumoObj->setClientObject(&m_client_info); } @@ -221,4 +219,3 @@ PyObject* KX_RadarSensor::PyGetConeHeight(PyObject* self, } -#endif //PHYSICS_NOT_YET diff --git a/source/gameengine/Ketsji/KX_RadarSensor.h b/source/gameengine/Ketsji/KX_RadarSensor.h index 77e085d29a3..03364ae9c29 100644 --- a/source/gameengine/Ketsji/KX_RadarSensor.h +++ b/source/gameengine/Ketsji/KX_RadarSensor.h @@ -62,18 +62,18 @@ class KX_RadarSensor : public KX_NearSensor MT_Point3 m_cone_target; public: - KX_RadarSensor(class SCA_EventManager* eventmgr, - class KX_GameObject* gameobj, + + KX_RadarSensor(SCA_EventManager* eventmgr, + KX_GameObject* gameobj, double coneradius, double coneheight, int axis, double margin, double resetmargin, - class SM_Object* sumoObj, bool bFindMaterial, const STR_String& touchedpropname, - class SM_Scene* sumoscene, - PyTypeObject* T=&Type); + class KX_Scene* kxscene, + PyTypeObject* T = &Type); KX_RadarSensor(); virtual ~KX_RadarSensor(); virtual void SynchronizeTransform(); diff --git a/source/gameengine/Ketsji/KX_RayEventManager.h b/source/gameengine/Ketsji/KX_RayEventManager.h index f5280f1fec6..7acc0b04ded 100644 --- a/source/gameengine/Ketsji/KX_RayEventManager.h +++ b/source/gameengine/Ketsji/KX_RayEventManager.h @@ -44,8 +44,8 @@ class KX_RayEventManager : public SCA_EventManager class SCA_LogicManager* m_logicmgr; public: KX_RayEventManager(class SCA_LogicManager* logicmgr) - : m_logicmgr(logicmgr), - SCA_EventManager(RAY_EVENTMGR) + : SCA_EventManager(RAY_EVENTMGR), + m_logicmgr(logicmgr) {} virtual void NextFrame(double curtime,double deltatime); virtual void RegisterSensor(SCA_ISensor* sensor); diff --git a/source/gameengine/Ketsji/KX_RaySensor.cpp b/source/gameengine/Ketsji/KX_RaySensor.cpp index 5cca436327a..c53651712a8 100644 --- a/source/gameengine/Ketsji/KX_RaySensor.cpp +++ b/source/gameengine/Ketsji/KX_RaySensor.cpp @@ -41,6 +41,9 @@ #include "KX_GameObject.h" #include "KX_Scene.h" +#include "SumoPhysicsEnvironment.h" +#include "KX_SumoPhysicsController.h" + #ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -57,10 +60,10 @@ KX_RaySensor::KX_RaySensor(class SCA_EventManager* eventmgr, m_propertyname(propname), m_bFindMaterial(bFindMaterial), m_distance(distance), + m_scene(ketsjiScene), + m_bTriggered(false), m_axis(axis), - m_ketsjiScene(ketsjiScene), m_rayHit(false), - m_bTriggered(false), m_hitObject(NULL) @@ -139,56 +142,78 @@ bool KX_RaySensor::Evaluate(CValue* event) } case 3: // -X { - todir[0] = invmat[0][0] * -1; - todir[1] = invmat[0][1] * -1; - todir[2] = invmat[0][2] * -1; + todir[0] = -invmat[0][0]; + todir[1] = -invmat[0][1]; + todir[2] = -invmat[0][2]; break; } case 4: // -Y { - todir[0] = invmat[1][0] * -1; - todir[1] = invmat[1][1] * -1; - todir[2] = invmat[1][2] * -1; + todir[0] = -invmat[1][0]; + todir[1] = -invmat[1][1]; + todir[2] = -invmat[1][2]; break; } case 5: // -Z { - todir[0] = invmat[2][0] * -1; - todir[1] = invmat[2][1] * -1; - todir[2] = invmat[2][2] * -1; + todir[0] = -invmat[2][0]; + todir[1] = -invmat[2][1]; + todir[2] = -invmat[2][2]; break; } } todir.normalize(); m_rayDirection = todir; - - MT_Point3 topoint = frompoint + (m_distance) * todir; MT_Point3 resultpoint; MT_Vector3 resultnormal; bool ready = false; - /* - do { + SumoPhysicsEnvironment *spe = dynamic_cast<SumoPhysicsEnvironment *>(m_scene->GetPhysicsEnvironment()); + SM_Scene *scene = spe->GetSumoScene(); + KX_SumoPhysicsController *spc = dynamic_cast<KX_SumoPhysicsController *>(obj->GetPhysicsController()); + KX_GameObject *parent = obj->GetParent(); + if (!spc && parent) + spc = dynamic_cast<KX_SumoPhysicsController *>(parent->GetPhysicsController()); + if (parent) + parent->Release(); + SM_Object *thisObj = spc?spc->GetSumoObject():NULL; - - - SM_Object* hitObj = m_sumoScene->rayTest(obj->GetSumoObject(), - frompoint, - topoint, - resultpoint, - resultnormal); + do { + SM_Object* hitObj = scene->rayTest(thisObj, + frompoint, + topoint, + resultpoint, + resultnormal); + if (hitObj) { - KX_ClientObjectInfo* info = (SM_ClientObjectInfo*)hitObj->getClientObject(); - SCA_IObject* hitgameobj = (SCA_IObject*)info->m_clientobject; + + KX_ClientObjectInfo* info = (KX_ClientObjectInfo*)hitObj->getClientObject(); bool bFound = false; - - if (hitgameobj == obj) + + if (!info) + { + std::cout<< "WARNING: Ray sensor " << GetName() << " cannot sense SM_Object " << hitObj << " - no client info.\n" << std::endl; + ready = true; + break; + } + + SCA_IObject *hitgameobj = (SCA_IObject*)info->m_clientobject; + + if (hitgameobj == obj || info->m_type > KX_ClientObjectInfo::ACTOR) { // false hit - MT_Scalar marg = obj->GetSumoObject()->getMargin() ; - frompoint = resultpoint + marg * todir; + KX_SumoPhysicsController *hitspc = dynamic_cast<KX_SumoPhysicsController *> (static_cast<KX_GameObject*> (hitgameobj) ->GetPhysicsController()); + if (hitspc) + { + MT_Scalar marg = hitspc->GetSumoObject()->getMargin(); + if (hitspc->GetSumoObject()->getShapeProps()) + marg += hitspc->GetSumoObject()->getShapeProps()->m_radius; + frompoint = resultpoint + marg * todir; + } else { + ready = true; + } } else { @@ -208,10 +233,7 @@ bool KX_RaySensor::Evaluate(CValue* event) } else { - if (hitgameobj->GetProperty(m_propertyname) != NULL) - { - bFound = true; - } + bFound = hitgameobj->GetProperty(m_propertyname) != NULL; } } @@ -231,7 +253,7 @@ bool KX_RaySensor::Evaluate(CValue* event) } } while (!ready); - */ + /* now pass this result to some controller */ diff --git a/source/gameengine/Ketsji/KX_RaySensor.h b/source/gameengine/Ketsji/KX_RaySensor.h index 4a783b398b4..528f52f27a7 100644 --- a/source/gameengine/Ketsji/KX_RaySensor.h +++ b/source/gameengine/Ketsji/KX_RaySensor.h @@ -44,7 +44,7 @@ class KX_RaySensor : public SCA_ISensor STR_String m_propertyname; bool m_bFindMaterial; double m_distance; - class KX_Scene* m_ketsjiScene; + class KX_Scene* m_scene; bool m_bTriggered; int m_axis; bool m_rayHit; diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp index 784a3e015df..060afe060ee 100644 --- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp @@ -135,8 +135,8 @@ KX_SCA_ReplaceMeshActuator::KX_SCA_ReplaceMeshActuator(SCA_IObject *gameobj, PyTypeObject* T) : SCA_IActuator(gameobj, T), - m_scene(scene), - m_mesh(mesh) + m_mesh(mesh), + m_scene(scene) { } /* End of constructor */ diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index c2cb001cce8..8a964e07eb5 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -73,6 +73,8 @@ #include "PHY_IPhysicsEnvironment.h" #include "KX_IPhysicsController.h" +#include "SM_Scene.h" +#include "SumoPhysicsEnvironment.h" void* KX_SceneReplicationFunc(SG_IObject* node,void* gameobj,void* scene) { @@ -95,23 +97,20 @@ SG_Callbacks KX_Scene::m_callbacks = SG_Callbacks(KX_SceneReplicationFunc,KX_Sce // (defined in KX_PythonInit.cpp) extern bool gUseVisibilityTemp; - - - KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice, class SCA_IInputDevice* mousedevice, class NG_NetworkDeviceInterface *ndi, class SND_IAudioDevice* adi, const STR_String& sceneName): - m_mousemgr(NULL), m_keyboardmgr(NULL), - m_active_camera(NULL), - m_ueberExecutionPriority(0), - m_adi(adi), + m_mousemgr(NULL), + m_physicsEnvironment(0), m_sceneName(sceneName), + m_adi(adi), m_networkDeviceInterface(ndi), - m_physicsEnvironment(0) + m_active_camera(NULL), + m_ueberExecutionPriority(0) { @@ -130,11 +129,7 @@ KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice, m_keyboardmgr = new SCA_KeyboardManager(m_logicmgr,keyboarddevice); m_mousemgr = new SCA_MouseManager(m_logicmgr,mousedevice); -// m_solidScene = DT_CreateScene(); -// m_respTable = DT_CreateRespTable(); - SCA_AlwaysEventManager* alwaysmgr = new SCA_AlwaysEventManager(m_logicmgr); - //KX_TouchEventManager* touchmgr = new KX_TouchEventManager(m_logicmgr, m_respTable, m_solidScene); SCA_PropertyEventManager* propmgr = new SCA_PropertyEventManager(m_logicmgr); SCA_RandomEventManager* rndmgr = new SCA_RandomEventManager(m_logicmgr); KX_RayEventManager* raymgr = new KX_RayEventManager(m_logicmgr); @@ -145,14 +140,11 @@ KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice, m_logicmgr->RegisterEventManager(propmgr); m_logicmgr->RegisterEventManager(m_keyboardmgr); m_logicmgr->RegisterEventManager(m_mousemgr); - //m_logicmgr->RegisterEventManager(touchmgr); m_logicmgr->RegisterEventManager(m_timemgr); m_logicmgr->RegisterEventManager(rndmgr); m_logicmgr->RegisterEventManager(raymgr); m_logicmgr->RegisterEventManager(netmgr); - //m_sumoScene = new SM_Scene(); - //m_sumoScene->setSecondaryRespTable(m_respTable); m_soundScene = new SND_Scene(adi); assert (m_networkDeviceInterface != NULL); m_networkScene = new NG_NetworkScene(m_networkDeviceInterface); @@ -169,6 +161,7 @@ KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice, KX_Scene::~KX_Scene() { + // int numobj = m_objectlist->GetCount(); //int numrootobjects = GetRootParentList()->GetCount(); @@ -708,6 +701,11 @@ void KX_Scene::NewRemoveObject(class CValue* gameobj) newobj->Release(); if (m_euthanasyobjects->RemoveValue(newobj)) newobj->Release(); + + if (newobj == m_active_camera) + { + m_active_camera = NULL; + } } @@ -979,3 +977,15 @@ void KX_Scene::SetGravity(const MT_Vector3& gravity) { GetPhysicsEnvironment()->setGravity(gravity[0],gravity[1],gravity[2]); } + +void KX_Scene::SetPhysicsEnvironment(class PHY_IPhysicsEnvironment* physEnv) +{ + SumoPhysicsEnvironment *sme = dynamic_cast<SumoPhysicsEnvironment *>(physEnv); + m_physicsEnvironment = physEnv; + if (sme) + { + KX_TouchEventManager* touchmgr = new KX_TouchEventManager(m_logicmgr, sme->GetSumoScene()); + m_logicmgr->RegisterEventManager(touchmgr); + return; + } +} diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index 818368561e6..35f2f9dbb71 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -466,10 +466,7 @@ public: return m_physicsEnvironment; } - void SetPhysicsEnvironment(class PHY_IPhysicsEnvironment* physEnv) - { - m_physicsEnvironment = physEnv; - } + void SetPhysicsEnvironment(class PHY_IPhysicsEnvironment* physEnv); void SetGravity(const MT_Vector3& gravity); }; diff --git a/source/gameengine/Ketsji/KX_SceneActuator.cpp b/source/gameengine/Ketsji/KX_SceneActuator.cpp index 4a1d8c74b77..e07719ea680 100644 --- a/source/gameengine/Ketsji/KX_SceneActuator.cpp +++ b/source/gameengine/Ketsji/KX_SceneActuator.cpp @@ -295,12 +295,9 @@ PyObject* KX_SceneActuator::PySetScene(PyObject* self, return NULL; } - if (m_KetsjiEngine->FindScene(scene_name)) - { - /* Scene switch is done by name. */ - m_nextSceneName = scene_name; - } - + /* Scene switch is done by name. */ + m_nextSceneName = scene_name; + Py_Return; } diff --git a/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp b/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp index 12b8775b5cd..57986cd7b78 100644 --- a/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp +++ b/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp @@ -1,4 +1,7 @@ + +#ifdef WIN32 #pragma warning (disable : 4786) +#endif #include "KX_SumoPhysicsController.h" #include "SG_Spatial.h" @@ -107,7 +110,7 @@ SG_Controller* KX_SumoPhysicsController::GetReplica(SG_Node* destnode) //parentcontroller is here be able to avoid collisions between parent/child PHY_IPhysicsController* parentctrl = NULL; - + if (destnode != destnode->GetRootSGParent()) { KX_GameObject* clientgameobj = (KX_GameObject*) destnode->GetRootSGParent()->GetSGClientObject(); @@ -123,7 +126,7 @@ SG_Controller* KX_SumoPhysicsController::GetReplica(SG_Node* destnode) childit!= destnode->GetSGChildren().end(); ++childit ) { - KX_GameObject* clientgameobj = static_cast<KX_GameObject*>( (*childit)->GetSGClientObject()); + KX_GameObject *clientgameobj = static_cast<KX_GameObject*>( (*childit)->GetSGClientObject()); if (clientgameobj) { parentctrl = (KX_SumoPhysicsController*)clientgameobj->GetPhysicsController(); @@ -145,8 +148,7 @@ void KX_SumoPhysicsController::SetObject (SG_IObject* object) // cheating here... KX_GameObject* gameobj = (KX_GameObject*) object->GetSGClientObject(); gameobj->SetPhysicsController(this); - - + GetSumoObject()->setClientObject(gameobj->getClientInfo()); } diff --git a/source/gameengine/Ketsji/KX_SumoPhysicsController.h b/source/gameengine/Ketsji/KX_SumoPhysicsController.h index 523e139fc69..465dd799c2a 100644 --- a/source/gameengine/Ketsji/KX_SumoPhysicsController.h +++ b/source/gameengine/Ketsji/KX_SumoPhysicsController.h @@ -1,3 +1,34 @@ +/** + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ #ifndef __KX_SUMOPHYSICSCONTROLLER_H #define __KX_SUMOPHYSICSCONTROLLER_H @@ -27,8 +58,8 @@ public: class SM_Object* sumoObj, class PHY_IMotionState* motionstate ,bool dyna) - : SumoPhysicsController(sumoScene,solidscene,sumoObj,motionstate,dyna), - KX_IPhysicsController(dyna,NULL) + : KX_IPhysicsController(dyna,NULL) , + SumoPhysicsController(sumoScene,solidscene,sumoObj,motionstate,dyna) { }; virtual ~KX_SumoPhysicsController(); diff --git a/source/gameengine/Ketsji/KX_TimeLogger.cpp b/source/gameengine/Ketsji/KX_TimeLogger.cpp index 509f7e13234..766c541b4fc 100644 --- a/source/gameengine/Ketsji/KX_TimeLogger.cpp +++ b/source/gameengine/Ketsji/KX_TimeLogger.cpp @@ -36,8 +36,10 @@ #include <config.h> #endif -KX_TimeLogger::KX_TimeLogger(unsigned int maxNumMeasurements) -: m_maxNumMeasurements(maxNumMeasurements), m_logging(false), m_logStart(0) +KX_TimeLogger::KX_TimeLogger(unsigned int maxNumMeasurements) : + m_maxNumMeasurements(maxNumMeasurements), + m_logStart(0), + m_logging(false) { } @@ -108,7 +110,7 @@ double KX_TimeLogger::GetAverage(void) const unsigned int numMeasurements = m_measurements.size(); if (numMeasurements > 1) { - for (int i = 1; i < numMeasurements; i++) { + for (unsigned int i = 1; i < numMeasurements; i++) { avg += m_measurements[i]; } avg /= (float)numMeasurements - 1; diff --git a/source/gameengine/Ketsji/KX_TouchEventManager.cpp b/source/gameengine/Ketsji/KX_TouchEventManager.cpp index 8c7f18983e5..2186c442f32 100644 --- a/source/gameengine/Ketsji/KX_TouchEventManager.cpp +++ b/source/gameengine/Ketsji/KX_TouchEventManager.cpp @@ -38,33 +38,60 @@ #include <config.h> #endif -#ifdef PHYSICS_NOT_YET +#include "SM_Object.h" KX_TouchEventManager::KX_TouchEventManager(class SCA_LogicManager* logicmgr, - DT_RespTableHandle resphandle, - DT_SceneHandle scenehandle) + SM_Scene *scene) : SCA_EventManager(TOUCH_EVENTMGR), - m_resphandle(resphandle), - m_scenehandle(scenehandle), - m_logicmgr(logicmgr) {} + m_logicmgr(logicmgr), + m_scene(scene) +{ + //m_scene->addTouchCallback(STATIC_RESPONSE, KX_TouchEventManager::collisionResponse, this); + m_scene->addTouchCallback(OBJECT_RESPONSE, KX_TouchEventManager::collisionResponse, this); + m_scene->addTouchCallback(SENSOR_RESPONSE, KX_TouchEventManager::collisionResponse, this); +} -void KX_TouchEventManager::RegisterSensor(SCA_ISensor* sensor) +DT_Bool KX_TouchEventManager::HandleCollision(void* object1,void* object2, + const DT_CollData * coll_data) { + SM_Object * obj1 = (SM_Object *) object1; + SM_Object * obj2 = (SM_Object *) object2; + + for ( vector<SCA_ISensor*>::iterator it = m_sensors.begin(); !(it==m_sensors.end()); it++) + { + KX_GameObject* gameobj = ((KX_GameObject*)((KX_TouchSensor*)*it)->GetParent()); + KX_ClientObjectInfo *client_info = (KX_ClientObjectInfo *) obj1->getClientObject(); +// Enable these printfs to create excesive debug info +// printf("KX_TEM::HC: Sensor %s\tGO: %p o1: %s (%p)", (const char *) (*it)->GetName(), gameobj, (const char *) ((KX_GameObject *) client_info->m_clientobject)->GetName(), client_info->m_clientobject); + if (client_info && client_info->m_clientobject == gameobj) + ((KX_TouchSensor*)*it)->HandleCollision(object1,object2,coll_data); + + client_info = (KX_ClientObjectInfo *) obj2->getClientObject(); +// printf(" o2: %s (%p)\n", (const char *) ((KX_GameObject *) client_info->m_clientobject)->GetName(), client_info->m_clientobject); + if (client_info && client_info->m_clientobject == gameobj) + ((KX_TouchSensor*)*it)->HandleCollision(object1,object2,coll_data); + } + + return DT_CONTINUE; +} +DT_Bool KX_TouchEventManager::collisionResponse(void *client_data, + void *object1, + void *object2, + const DT_CollData *coll_data) +{ + KX_TouchEventManager *touchmgr = (KX_TouchEventManager *) client_data; + touchmgr->HandleCollision(object1, object2, coll_data); + return DT_CONTINUE; +} + +void KX_TouchEventManager::RegisterSensor(SCA_ISensor* sensor) +{ KX_TouchSensor* touchsensor = static_cast<KX_TouchSensor*>(sensor); m_sensors.push_back(touchsensor); - touchsensor->RegisterSumo();//this,m_resphandle); - - //KX_GameObject* gameobj = ((KX_GameObject*)sensor->GetParent()); -// SM_Object* smobj = touchsensor->GetSumoObject();//gameobj->GetSumoObject(); -// if (smobj) -// { -// smobj->calcXform(); -// DT_AddObject(m_scenehandle, -// smobj->getObjectHandle()); -// } + touchsensor->RegisterSumo(this); } @@ -89,10 +116,7 @@ void KX_TouchEventManager::NextFrame(double curtime,double deltatime) vector<SCA_ISensor*>::iterator it; for (it = m_sensors.begin();!(it==m_sensors.end());it++) - ((KX_TouchSensor*)*it)->SynchronizeTransform(); - - if (DT_Test(m_scenehandle,m_resphandle)) - int i = 0; + static_cast<KX_TouchSensor*>(*it)->SynchronizeTransform(); for (it = m_sensors.begin();!(it==m_sensors.end());it++) (*it)->Activate(m_logicmgr,NULL); @@ -107,14 +131,10 @@ void KX_TouchEventManager::RemoveSensor(class SCA_ISensor* sensor) std::find(m_sensors.begin(), m_sensors.end(), sensor); if (!(i == m_sensors.end())) { - //std::swap(*i, m_sensors.back()); - //m_sensors.pop_back(); - //SM_Object* smobj = ((KX_TouchSensor*)*i)->GetSumoObject(); - //DT_RemoveObject(m_scenehandle, - // smobj->getObjectHandle()); + std::swap(*i, m_sensors.back()); + m_sensors.pop_back(); } // remove the sensor forever :) SCA_EventManager::RemoveSensor(sensor); } -#endif diff --git a/source/gameengine/Ketsji/KX_TouchEventManager.h b/source/gameengine/Ketsji/KX_TouchEventManager.h index 711a3abb996..e53dc264494 100644 --- a/source/gameengine/Ketsji/KX_TouchEventManager.h +++ b/source/gameengine/Ketsji/KX_TouchEventManager.h @@ -37,19 +37,30 @@ #include "KX_GameObject.h" #include <vector> -using namespace std; class KX_TouchEventManager : public SCA_EventManager { class SCA_LogicManager* m_logicmgr; + SM_Scene *m_scene; + + static DT_Bool KX_TouchEventManager::collisionResponse(void *client_data, + void *object1, + void *object2, + const DT_CollData *coll_data); + + virtual DT_Bool HandleCollision(void* obj1,void* obj2, + const DT_CollData * coll_data); + public: - KX_TouchEventManager(class SCA_LogicManager* logicmgr); + KX_TouchEventManager(class SCA_LogicManager* logicmgr, + SM_Scene *scene); virtual void NextFrame(double curtime,double deltatime); virtual void EndFrame(); virtual void RemoveSensor(class SCA_ISensor* sensor); virtual void RegisterSensor(SCA_ISensor* sensor); SCA_LogicManager* GetLogicManager() { return m_logicmgr;} + SM_Scene *GetSumoScene() { return m_scene; } }; #endif //__KX_TOUCHEVENTMANAGER diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp index ee2226d03ad..6ae670a842c 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.cpp +++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp @@ -37,14 +37,14 @@ #include "SCA_LogicManager.h" #include "KX_GameObject.h" #include "KX_TouchEventManager.h" +#include "SM_Object.h" +#include "KX_SumoPhysicsController.h" #include <iostream> #ifdef HAVE_CONFIG_H #include <config.h> #endif -#ifdef PHYSICS_NOT_YET - /* ------------------------------------------------------------------------- */ /* Native functions */ /* ------------------------------------------------------------------------- */ @@ -84,78 +84,81 @@ bool KX_TouchSensor::Evaluate(CValue* event) return result; } -KX_TouchSensor::KX_TouchSensor(SCA_EventManager* eventmgr,KX_GameObject* gameobj,SM_Object* sumoObj,bool bFindMaterial,const STR_String& touchedpropname,PyTypeObject* T) +KX_TouchSensor::KX_TouchSensor(SCA_EventManager* eventmgr,KX_GameObject* gameobj,/*SM_Object* sumoObj,*/bool bFindMaterial,const STR_String& touchedpropname,PyTypeObject* T) :SCA_ISensor(gameobj,eventmgr,T), m_touchedpropname(touchedpropname), m_bFindMaterial(bFindMaterial), -m_sumoObj(sumoObj), +m_eventmgr(eventmgr), +/*m_sumoObj(sumoObj),*/ m_bCollision(false), m_bTriggered(false), m_bLastTriggered(false) { - m_eventmgr = eventmgr; KX_TouchEventManager* touchmgr = (KX_TouchEventManager*) eventmgr; +// m_resptable = touchmgr->GetResponseTable(); - m_resptable = touchmgr->GetResponseTable(); - - m_solidHandle = m_sumoObj->getObjectHandle(); +// m_solidHandle = m_sumoObj->getObjectHandle(); m_hitObject = NULL; m_colliders = new CListValue(); + + KX_ClientObjectInfo *client_info = gameobj->getClientInfo(); + client_info->m_clientobject = gameobj; + client_info->m_auxilary_info = NULL; + + KX_SumoPhysicsController *sphy = dynamic_cast<KX_SumoPhysicsController *>(gameobj->GetPhysicsController()); + if (sphy) + m_sumoObj = sphy->GetSumoObject(); + } KX_TouchSensor::~KX_TouchSensor() { - DT_ClearObjectResponse(m_resptable,m_solidHandle); + //DT_ClearObjectResponse(m_resptable,m_solidHandle); m_colliders->Release(); } void KX_TouchSensor::ReParent(SCA_IObject* parent) { - - m_sumoObj = ((KX_GameObject*)parent)->GetSumoObject(); - m_solidHandle = m_sumoObj->getObjectHandle(); - - m_client_info.m_clientobject = NULL;//parent; - m_client_info.m_auxilary_info = NULL; + KX_GameObject *gameobj = static_cast<KX_GameObject *>(parent); + KX_SumoPhysicsController *sphy = dynamic_cast<KX_SumoPhysicsController *>(((KX_GameObject*)parent)->GetPhysicsController()); + if (sphy) + m_sumoObj = sphy->GetSumoObject(); + +// m_solidHandle = m_sumoObj->getObjectHandle(); + KX_ClientObjectInfo *client_info = gameobj->getClientInfo(); + client_info->m_clientobject = parent; + client_info->m_auxilary_info = NULL; SCA_ISensor::ReParent(parent); } - -void KX_TouchSensor::RegisterSumo() +void KX_TouchSensor::RegisterSumo(KX_TouchEventManager *touchman) { + if (m_sumoObj) + { + touchman->GetSumoScene()->requestCollisionCallback(*m_sumoObj); + // collision + // Deprecated - if (m_sumoObj) - { - // collision - DT_SetObjectResponse( - m_resptable, - m_solidHandle, - collisionResponse, - DT_SIMPLE_RESPONSE, - this); - - } - + } } -void KX_TouchSensor::HandleCollision(void* obj1,void* obj2,const DT_CollData * coll_data) +DT_Bool KX_TouchSensor::HandleCollision(void* obj1,void* obj2,const DT_CollData * coll_data) { KX_TouchEventManager* toucheventmgr = (KX_TouchEventManager*)m_eventmgr; KX_GameObject* parent = (KX_GameObject*)GetParent(); // need the mapping from SM_Objects to gameobjects now - SM_ClientObjectInfo* client_info =(SM_ClientObjectInfo*) (obj1 == m_sumoObj? + KX_ClientObjectInfo* client_info =(KX_ClientObjectInfo*) (obj1 == m_sumoObj? ((SM_Object*)obj2)->getClientObject() : ((SM_Object*)obj1)->getClientObject()); - KX_GameObject* gameobj = ( client_info ? (KX_GameObject*)client_info->m_clientobject : NULL); - + if (gameobj && (gameobj != parent)) { if (!m_colliders->SearchValue(gameobj)) @@ -185,12 +188,14 @@ void KX_TouchSensor::HandleCollision(void* obj1,void* obj2,const DT_CollData { m_bTriggered = true; m_hitObject = gameobj; + //printf("KX_TouchSensor::HandleCollision\n"); } } - + return DT_CONTINUE; } + /* ------------------------------------------------------------------------- */ /* Python functions */ /* ------------------------------------------------------------------------- */ @@ -322,10 +327,11 @@ PyObject* KX_TouchSensor::PyGetHitObjectList(PyObject* self, * - this also doesn't work (obviously) for multi-materials... */ KX_GameObject* gameob = (KX_GameObject*) m_colliders->GetValue(i); - SM_Object* smob = (SM_Object*) gameob->GetSumoObject(); + KX_SumoPhysicsController* spc = dynamic_cast<KX_SumoPhysicsController*>(gameob->GetPhysicsController()); + SM_Object* smob = spc?spc->GetSumoObject():NULL; if (smob) { - SM_ClientObjectInfo* cl_inf = (SM_ClientObjectInfo*) smob->getClientObject(); + KX_ClientObjectInfo* cl_inf = (KX_ClientObjectInfo*) smob->getClientObject(); if (m_touchedpropname == ((char*)cl_inf->m_auxilary_info)) { newList->Add(m_colliders->GetValue(i)->AddRef()); @@ -392,6 +398,5 @@ PyObject* KX_TouchSensor::PySetTouchMaterial(PyObject* self, PyObject* args, PyO Py_Return; } -#endif //#ifdef PHYSICS_NOT_YET /* eof */ diff --git a/source/gameengine/Ketsji/KX_TouchSensor.h b/source/gameengine/Ketsji/KX_TouchSensor.h index 35b23ecc60a..50338827694 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.h +++ b/source/gameengine/Ketsji/KX_TouchSensor.h @@ -38,8 +38,13 @@ #include "SCA_ISensor.h" #include "ListValue.h" +#include <SOLID/SOLID.h> +#include "SM_Scene.h" + #include "KX_ClientObjectInfo.h" +class KX_TouchEventManager; + class KX_TouchSensor : public SCA_ISensor { protected: @@ -52,10 +57,9 @@ protected: bool m_bFindMaterial; class SCA_EventManager* m_eventmgr; - //class SM_Object* m_sumoObj; - //DT_ObjectHandle m_solidHandle; - //SM_ClientObjectInfo m_client_info; - //DT_RespTableHandle m_resptable; + class SM_Object* m_sumoObj; + DT_ObjectHandle m_solidHandle; + DT_RespTableHandle m_resptable; bool m_bCollision; @@ -67,7 +71,7 @@ protected: public: KX_TouchSensor(class SCA_EventManager* eventmgr, class KX_GameObject* gameobj, - class SM_Object* sumoObj, + /*class SM_Object* sumoObj,*/ bool fFindMaterial, const STR_String& touchedpropname, PyTypeObject* T=&Type) ; @@ -88,25 +92,15 @@ public: virtual bool Evaluate(CValue* event); virtual void ReParent(SCA_IObject* parent); -/* static void collisionResponse(void *client_data, - void *object1, - void *object2, - const DT_CollData *coll_data) { - class KX_TouchSensor* sensor = (class KX_TouchSensor*) client_data; - sensor->HandleCollision(object1,object2,coll_data); - } - - - - void RegisterSumo(); + virtual void RegisterSumo(KX_TouchEventManager* touchman); - virtual void HandleCollision(void* obj1,void* obj2, + virtual DT_Bool HandleCollision(void* obj1,void* obj2, const DT_CollData * coll_data); - // SM_Object* GetSumoObject() { return m_sumoObj; }; + SM_Object* GetSumoObject() { return m_sumoObj; }; - */ + virtual bool IsPositiveTrigger() { bool result = m_bTriggered; @@ -115,7 +109,7 @@ public: } - void EndFrame(); + virtual void EndFrame(); // todo: put some info for collision maybe diff --git a/source/gameengine/Ketsji/KX_WorldIpoController.h b/source/gameengine/Ketsji/KX_WorldIpoController.h index 5967db42235..562a2769807 100644 --- a/source/gameengine/Ketsji/KX_WorldIpoController.h +++ b/source/gameengine/Ketsji/KX_WorldIpoController.h @@ -53,11 +53,12 @@ private: double m_ipotime; public: - KX_WorldIpoController() : m_ipotime(0.0), - m_modify_mist_color(false), - m_modify_mist_start(false), - m_modify_mist_dist(false), - m_modified(true) + KX_WorldIpoController() : + m_modify_mist_color(false), + m_modify_mist_start(false), + m_modify_mist_dist(false), + m_modified(true), + m_ipotime(0.0) {} virtual ~KX_WorldIpoController(); diff --git a/source/gameengine/Ketsji/Makefile b/source/gameengine/Ketsji/Makefile index 3884be14ded..f12e1c08ed4 100644 --- a/source/gameengine/Ketsji/Makefile +++ b/source/gameengine/Ketsji/Makefile @@ -42,7 +42,8 @@ CPPFLAGS += $(OGL_CPPFLAGS) CPPFLAGS += -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION) CPPFLAGS += -I$(NAN_STRING)/include CPPFLAGS += -I$(NAN_SOUNDSYSTEM)/include -CPPFLAGS += -I$(NAN_FUZZICS)/include -I$(NAN_SUMO)/include -I$(NAN_MOTO)/include +CPPFLAGS += -I$(NAN_FUZZICS)/include -I$(NAN_SUMO) -I$(NAN_MOTO)/include +CPPFLAGS += -I$(NAN_SOLID)/include CPPFLAGS += -I../Rasterizer -I../GameLogic -I../SceneGraph CPPFLAGS += -I../BlenderRoutines -I../Expressions CPPFLAGS += -I../../kernel/gen_system diff --git a/source/gameengine/Ketsji/SConscript b/source/gameengine/Ketsji/SConscript index fddf4762013..4789138d1c2 100644 --- a/source/gameengine/Ketsji/SConscript +++ b/source/gameengine/Ketsji/SConscript @@ -1,3 +1,5 @@ +import sys + Import ('user_options_dict') Import ('library_env') @@ -59,6 +61,7 @@ if user_options_dict['USE_PHYSICS'] == 'solid': if user_options_dict['USE_PHYSICS'] == 'ode': source_files += ['KX_OdePhysicsController.cpp'] + ketsji_env.Append (CPPPATH = user_options_dict['SOLID_INCLUDE']) ketsji_env.Append (CPPPATH = ['.', '#source/kernel/gen_system', @@ -90,7 +93,7 @@ ketsji_env.Append (CPPPATH = ['.', '#source/gameengine/Physics/common', '#source/gameengine/Physics/BlOde', '#source/gameengine/Physics/Dummy', - '#source/gameengine/Physics/Sumo/', + '#source/gameengine/Physics/Sumo', '#source/gameengine/Physics/Sumo/include', '#source/gameengine/Physics/Sumo/Fuzzics/include', '#source/gameengine/Network/LoopBackNetwork', @@ -98,6 +101,8 @@ ketsji_env.Append (CPPPATH = ['.', '#source/blender/blenloader' ]) +if sys.platform == 'win32': + ketsji_env.Append (CXXFLAGS = ['/GR']) ketsji_env.Append (CPPPATH = user_options_dict['PYTHON_INCLUDE']) ketsji_env.Library (target='#'+user_options_dict['BUILD_DIR']+'/lib/KX_ketsji', source=source_files) |