BGE: Committing patch [#32697] "New BGE gravity API" by HG1.
authorMitchell Stokes <mogurijin@gmail.com>
Sat, 10 Nov 2012 03:11:18 +0000 (03:11 +0000)
committerMitchell Stokes <mogurijin@gmail.com>
Sat, 10 Nov 2012 03:11:18 +0000 (03:11 +0000)
This patch adds a gravity attribute to KX_Scene.

doc/python_api/rst/bge.types.rst
source/gameengine/Ketsji/KX_Scene.cpp
source/gameengine/Ketsji/KX_Scene.h
source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.cpp
source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h
source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h

index fdaeb61173fc0b6a7d4ee854f729d97f9fbdafdf..431b264ba7362da1fd12f682b62bf3c72544cba3 100644 (file)
@@ -3113,6 +3113,12 @@ Types
 
       :type: list
 
+   .. attribute:: gravity
+
+      The scene gravity using the world x, y and z axis.
+
+      :type: list [fx, fy, fz]
+
    .. method:: addObject(object, other, time=0)
 
       Adds an object to the scene like the Add Object Actuator would.
index 96b4a21a36c2ad1b0d164d64baaaceafe823f6ae..72be5f57b950def14050ab21259a5e885ad8a501 100644 (file)
@@ -55,7 +55,7 @@
 #include "SCA_BasicEventManager.h"
 #include "KX_Camera.h"
 #include "SCA_JoystickManager.h"
-
+#include "KX_PyMath.h"
 #include "RAS_MeshObject.h"
 
 #include "RAS_IRasterizer.h"
@@ -1706,6 +1706,17 @@ void     KX_Scene::SetGravity(const MT_Vector3& gravity)
        GetPhysicsEnvironment()->setGravity(gravity[0],gravity[1],gravity[2]);
 }
 
+MT_Vector3 KX_Scene::GetGravity()
+{
+       PHY__Vector3 gravity;
+       MT_Vector3 vec;
+
+       GetPhysicsEnvironment()->getGravity(gravity);
+       vec = gravity.m_vec;
+
+       return vec;
+}
+
 void KX_Scene::SetSceneConverter(class KX_BlenderSceneConverter* sceneConverter)
 {
        m_sceneConverter = sceneConverter;
@@ -2270,6 +2281,25 @@ int KX_Scene::pyattr_set_drawing_callback_post(void *self_v, const KX_PYATTRIBUT
        return PY_SET_ATTR_SUCCESS;
 }
 
+PyObject *KX_Scene::pyattr_get_gravity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+       KX_Scene* self = static_cast<KX_Scene*>(self_v);
+
+       return PyObjectFrom(self->GetGravity());
+}
+
+int KX_Scene::pyattr_set_gravity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+       KX_Scene* self = static_cast<KX_Scene*>(self_v);
+
+       MT_Vector3 vec;
+       if (!PyVecTo(value, vec))
+               return PY_SET_ATTR_FAIL;
+
+       self->SetGravity(vec);
+       return PY_SET_ATTR_SUCCESS;
+}
+
 PyAttributeDef KX_Scene::Attributes[] = {
        KX_PYATTRIBUTE_RO_FUNCTION("name",                              KX_Scene, pyattr_get_name),
        KX_PYATTRIBUTE_RO_FUNCTION("objects",                   KX_Scene, pyattr_get_objects),
@@ -2280,6 +2310,7 @@ PyAttributeDef KX_Scene::Attributes[] = {
        KX_PYATTRIBUTE_RW_FUNCTION("active_camera",             KX_Scene, pyattr_get_active_camera, pyattr_set_active_camera),
        KX_PYATTRIBUTE_RW_FUNCTION("pre_draw",                  KX_Scene, pyattr_get_drawing_callback_pre, pyattr_set_drawing_callback_pre),
        KX_PYATTRIBUTE_RW_FUNCTION("post_draw",                 KX_Scene, pyattr_get_drawing_callback_post, pyattr_set_drawing_callback_post),
+       KX_PYATTRIBUTE_RW_FUNCTION("gravity",                   KX_Scene, pyattr_get_gravity, pyattr_set_gravity),
        KX_PYATTRIBUTE_BOOL_RO("suspended",                             KX_Scene, m_suspend),
        KX_PYATTRIBUTE_BOOL_RO("activity_culling",              KX_Scene, m_activity_culling),
        KX_PYATTRIBUTE_FLOAT_RW("activity_culling_radius", 0.5f, FLT_MAX, KX_Scene, m_activity_box_radius),
index c2e468e6da6e7ac0a36887f1919584e954f6195d..29473949535d4c2e838d9355acaceb34f377ca6f 100644 (file)
@@ -573,6 +573,7 @@ public:
        void SetPhysicsEnvironment(class PHY_IPhysicsEnvironment*       physEnv);
 
        void    SetGravity(const MT_Vector3& gravity);
+       MT_Vector3 GetGravity();
 
        short GetAnimationFPS();
        
@@ -616,6 +617,8 @@ public:
        static int                      pyattr_set_drawing_callback_pre(void *selv_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
        static PyObject*        pyattr_get_drawing_callback_post(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
        static int                      pyattr_set_drawing_callback_post(void *selv_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+       static PyObject*        pyattr_get_gravity(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+       static int                      pyattr_set_gravity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
 
        virtual PyObject *py_repr(void) { return PyUnicode_From_STR_String(GetName()); }
        
index d1a8143fa883c4b3823e425426b572b8bcf86bc9..d1fabba18f963615712fe2a9396d19f0b1be63bf 100644 (file)
@@ -85,8 +85,9 @@ void DummyPhysicsEnvironment::setGravity(float x,float y,float z)
 {
 }
 
-
-
+void DummyPhysicsEnvironment::getGravity(PHY__Vector3& grav)
+{
+}
 
 
 
index 233c4412d9e108ffff203e8ed6f61c9f0d67b2ad..5ce34bdf7cf588d446d018deef1d55969d1f2f3e 100644 (file)
@@ -56,6 +56,7 @@ public:
        virtual float           getFixedTimeStep();
 
        virtual void            setGravity(float x,float y,float z);
+       virtual void            getGravity(PHY__Vector3& grav);
 
        virtual int                     createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
                        float pivotX,float pivotY,float pivotZ,
index 077d225903ca395a126f9bc2ddc8190ec049d151..bfbe570ad0c25aa3ec9dc54ebaec514daf206940 100644 (file)
@@ -143,6 +143,7 @@ class PHY_IPhysicsEnvironment
                virtual void            setUseEpa(bool epa) {}
 
                virtual void            setGravity(float x,float y,float z)=0;
+               virtual void            getGravity(PHY__Vector3& grav) = 0;
 
                virtual int                     createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
                        float pivotX,float pivotY,float pivotZ,