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:
authorMitchell Stokes <mogurijin@gmail.com>2012-11-05 00:56:02 +0400
committerMitchell Stokes <mogurijin@gmail.com>2012-11-05 00:56:02 +0400
commitf840bd4a9f89815ca213d8398c99865fc6d64e4c (patch)
treeb2c27e3ec22ac337120ab6f8db47b5071b6c49cb /source/gameengine/Physics
parentcc77001416b385b289e7824cd5d71cad2bddfefb (diff)
BGE: This patch adds a character wrapper (similar to the already implemented vehicle wrapper) to control character physics options. Currently supported options are:
* jump() -- causes the character to jump * onGround -- specifies whether or not the character is on the ground * gravity -- controls the "gravity" that the character physics uses for the character More options could be added (such as jump speed, step height, make fall speed, max slope, etc).
Diffstat (limited to 'source/gameengine/Physics')
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp40
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h2
-rw-r--r--source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h6
-rw-r--r--source/gameengine/Physics/common/CMakeLists.txt1
-rw-r--r--source/gameengine/Physics/common/PHY_ICharacter.h30
-rw-r--r--source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h4
6 files changed, 83 insertions, 0 deletions
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
index 687fc116234..486411d7e35 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
@@ -37,6 +37,7 @@ subject to the following restrictions:
#include "PHY_IMotionState.h"
+#include "PHY_ICharacter.h"
#include "KX_GameObject.h"
#include "RAS_MeshObject.h"
#include "RAS_Polygon.h"
@@ -266,6 +267,36 @@ public:
};
#endif //NEW_BULLET_VEHICLE_SUPPORT
+class CharacterWrapper : public PHY_ICharacter
+{
+private:
+ btKinematicCharacterController* m_controller;
+
+public:
+ CharacterWrapper(btKinematicCharacterController* cont)
+ : m_controller(cont)
+ {}
+
+ virtual void Jump()
+ {
+ m_controller->jump();
+ }
+
+ virtual bool OnGround()
+ {
+ return m_controller->onGround();
+ }
+
+ virtual float GetGravity()
+ {
+ return m_controller->getGravity();
+ }
+ virtual void SetGravity(float gravity)
+ {
+ m_controller->setGravity(gravity);
+ }
+};
+
class CcdOverlapFilterCallBack : public btOverlapFilterCallback
{
private:
@@ -2285,6 +2316,15 @@ PHY_IVehicle* CcdPhysicsEnvironment::getVehicleConstraint(int constraintId)
#endif //NEW_BULLET_VEHICLE_SUPPORT
+PHY_ICharacter* CcdPhysicsEnvironment::getCharacterController(KX_GameObject *ob)
+{
+ CcdPhysicsController* controller = (CcdPhysicsController*)ob->GetPhysicsController()->GetUserData();
+ if (controller->GetCharacterController())
+ return new CharacterWrapper(controller->GetCharacterController());
+
+ return NULL;
+}
+
int currentController = 0;
int numController = 0;
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
index 350ecd2588a..18ce0550498 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
@@ -184,6 +184,8 @@ protected:
return 0;
}
#endif /* NEW_BULLET_VEHICLE_SUPPORT */
+ // Character physics wrapper
+ virtual PHY_ICharacter* getCharacterController(class KX_GameObject* ob);
btTypedConstraint* getConstraintById(int constraintId);
diff --git a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h
index 70de9c25553..233c4412d9e 100644
--- a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h
+++ b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h
@@ -72,6 +72,12 @@ public:
return 0;
}
+ // Character physics wrapper
+ virtual PHY_ICharacter* getCharacterController(class KX_GameObject* ob)
+ {
+ return 0;
+ }
+
virtual PHY_IPhysicsController* rayTest(PHY_IRayCastFilterCallback &filterCallback, float fromX,float fromY,float fromZ, float toX,float toY,float toZ);
virtual bool cullingTest(PHY_CullingCallback callback, void* userData, PHY__Vector4* planes, int nplanes, int occlusionRes, const int *viewport, double modelview[16], double projection[16]) { return false; }
diff --git a/source/gameengine/Physics/common/CMakeLists.txt b/source/gameengine/Physics/common/CMakeLists.txt
index ceb7a8ba548..400e475f8a2 100644
--- a/source/gameengine/Physics/common/CMakeLists.txt
+++ b/source/gameengine/Physics/common/CMakeLists.txt
@@ -41,6 +41,7 @@ set(SRC
PHY_IVehicle.cpp
PHY_DynamicTypes.h
+ PHY_ICharacter.h
PHY_IController.h
PHY_IGraphicController.h
PHY_IMotionState.h
diff --git a/source/gameengine/Physics/common/PHY_ICharacter.h b/source/gameengine/Physics/common/PHY_ICharacter.h
new file mode 100644
index 00000000000..e2fc5e45125
--- /dev/null
+++ b/source/gameengine/Physics/common/PHY_ICharacter.h
@@ -0,0 +1,30 @@
+
+/** \file PHY_ICharacter.h
+ * \ingroup phys
+ */
+
+#ifndef __PHY_ICHARACTER_H__
+#define __PHY_ICHARACTER_H__
+
+//PHY_ICharacter provides a generic interface for "character" controllers
+
+#ifdef WITH_CXX_GUARDEDALLOC
+#include "MEM_guardedalloc.h"
+#endif
+
+class PHY_ICharacter
+{
+public:
+
+ virtual void Jump()= 0;
+ virtual bool OnGround()= 0;
+
+ virtual float GetGravity()= 0;
+ virtual void SetGravity(float gravity)= 0;
+
+#ifdef WITH_CXX_GUARDEDALLOC
+ MEM_CXX_CLASS_ALLOC_FUNCS("GE:PHY_ICharacter")
+#endif
+};
+
+#endif //__PHY_ICHARACTER_H__
diff --git a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h
index 66ca037aa47..077d225903c 100644
--- a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h
+++ b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h
@@ -40,6 +40,7 @@
#endif
class PHY_IVehicle;
+class PHY_ICharacter;
class RAS_MeshObject;
class PHY_IPhysicsController;
@@ -156,6 +157,9 @@ class PHY_IPhysicsEnvironment
//complex constraint for vehicles
virtual PHY_IVehicle* getVehicleConstraint(int constraintId) =0;
+ // Character physics wrapper
+ virtual PHY_ICharacter* getCharacterController(class KX_GameObject* ob) =0;
+
virtual PHY_IPhysicsController* rayTest(PHY_IRayCastFilterCallback &filterCallback, float fromX,float fromY,float fromZ, float toX,float toY,float toZ)=0;
//culling based on physical broad phase