forked from bartvdbraak/blender
BGE: linear velocity and angular velocity are attributes now
... what lead me to wonder if we should remove obj.setAngularVelocity, obj.setLinearVelocity, obj.getLinearVelocity and obj.getAngularVelocity. * this was so Copy and Paste ... anyways tests are welcome (I never used those methods in python myself).
This commit is contained in:
parent
61d7e4a51e
commit
2541429ded
@ -1244,6 +1244,10 @@ void KX_GameObject::Relink(GEN_Map<GEN_HashedPtr, void*> *map_parameter)
|
||||
#define MATHUTILS_VEC_CB_SCALE_GLOBAL 4
|
||||
#define MATHUTILS_VEC_CB_INERTIA_LOCAL 5
|
||||
#define MATHUTILS_VEC_CB_OBJECT_COLOR 6
|
||||
#define MATHUTILS_VEC_CB_LINVEL_LOCAL 7
|
||||
#define MATHUTILS_VEC_CB_LINVEL_GLOBAL 8
|
||||
#define MATHUTILS_VEC_CB_ANGVEL_LOCAL 9
|
||||
#define MATHUTILS_VEC_CB_ANGVEL_GLOBAL 10
|
||||
|
||||
static int mathutils_kxgameob_vector_cb_index= -1; /* index for our callbacks */
|
||||
|
||||
@ -1282,6 +1286,23 @@ static int mathutils_kxgameob_vector_get(PyObject *self_v, int subtype, float *v
|
||||
case MATHUTILS_VEC_CB_OBJECT_COLOR:
|
||||
self->GetObjectColor().getValue(vec_from);
|
||||
break;
|
||||
case MATHUTILS_VEC_CB_LINVEL_LOCAL:
|
||||
if(!self->GetPhysicsController()) return 0;
|
||||
self->GetLinearVelocity(true).getValue(vec_from);
|
||||
break;
|
||||
case MATHUTILS_VEC_CB_LINVEL_GLOBAL:
|
||||
if(!self->GetPhysicsController()) return 0;
|
||||
self->GetLinearVelocity(false).getValue(vec_from);
|
||||
break;
|
||||
case MATHUTILS_VEC_CB_ANGVEL_LOCAL:
|
||||
if(!self->GetPhysicsController()) return 0;
|
||||
self->GetAngularVelocity(true).getValue(vec_from);
|
||||
break;
|
||||
case MATHUTILS_VEC_CB_ANGVEL_GLOBAL:
|
||||
if(!self->GetPhysicsController()) return 0;
|
||||
self->GetAngularVelocity(false).getValue(vec_from);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return 1;
|
||||
@ -1314,6 +1335,18 @@ static int mathutils_kxgameob_vector_set(PyObject *self_v, int subtype, float *v
|
||||
case MATHUTILS_VEC_CB_OBJECT_COLOR:
|
||||
self->SetObjectColor(MT_Vector4(vec_to));
|
||||
break;
|
||||
case MATHUTILS_VEC_CB_LINVEL_LOCAL:
|
||||
self->setLinearVelocity(MT_Point3(vec_to),true);
|
||||
break;
|
||||
case MATHUTILS_VEC_CB_LINVEL_GLOBAL:
|
||||
self->setLinearVelocity(MT_Point3(vec_to),false);
|
||||
break;
|
||||
case MATHUTILS_VEC_CB_ANGVEL_LOCAL:
|
||||
self->setAngularVelocity(MT_Point3(vec_to),true);
|
||||
break;
|
||||
case MATHUTILS_VEC_CB_ANGVEL_GLOBAL:
|
||||
self->setAngularVelocity(MT_Point3(vec_to),false);
|
||||
break;
|
||||
}
|
||||
|
||||
return 1;
|
||||
@ -1484,6 +1517,12 @@ PyAttributeDef KX_GameObject::Attributes[] = {
|
||||
KX_PYATTRIBUTE_RW_FUNCTION("worldPosition", KX_GameObject, pyattr_get_worldPosition, pyattr_set_worldPosition),
|
||||
KX_PYATTRIBUTE_RW_FUNCTION("localScale", KX_GameObject, pyattr_get_localScaling, pyattr_set_localScaling),
|
||||
KX_PYATTRIBUTE_RO_FUNCTION("worldScale", KX_GameObject, pyattr_get_worldScaling),
|
||||
KX_PYATTRIBUTE_RW_FUNCTION("linearVelocity", KX_GameObject, pyattr_get_localLinearVelocity, pyattr_set_worldLinearVelocity),
|
||||
KX_PYATTRIBUTE_RW_FUNCTION("localLinearVelocity", KX_GameObject, pyattr_get_localLinearVelocity, pyattr_set_localLinearVelocity),
|
||||
KX_PYATTRIBUTE_RW_FUNCTION("worldLinearVelocity", KX_GameObject, pyattr_get_worldLinearVelocity, pyattr_set_worldLinearVelocity),
|
||||
KX_PYATTRIBUTE_RW_FUNCTION("angularVelocity", KX_GameObject, pyattr_get_localAngularVelocity, pyattr_set_worldAngularVelocity),
|
||||
KX_PYATTRIBUTE_RW_FUNCTION("localAngularVelocity", KX_GameObject, pyattr_get_localAngularVelocity, pyattr_set_localAngularVelocity),
|
||||
KX_PYATTRIBUTE_RW_FUNCTION("worldAngularVelocity", KX_GameObject, pyattr_get_worldAngularVelocity, pyattr_set_worldAngularVelocity),
|
||||
KX_PYATTRIBUTE_RO_FUNCTION("children", KX_GameObject, pyattr_get_children),
|
||||
KX_PYATTRIBUTE_RO_FUNCTION("childrenRecursive", KX_GameObject, pyattr_get_children_recursive),
|
||||
KX_PYATTRIBUTE_RO_FUNCTION("attrDict", KX_GameObject, pyattr_get_attrDict),
|
||||
@ -1976,6 +2015,96 @@ int KX_GameObject::pyattr_set_localScaling(void *self_v, const KX_PYATTRIBUTE_DE
|
||||
return PY_SET_ATTR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
PyObject* KX_GameObject::pyattr_get_worldLinearVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
||||
{
|
||||
#ifdef USE_MATHUTILS
|
||||
return newVectorObject_cb(BGE_PROXY_FROM_REF(self_v), 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_LINVEL_GLOBAL);
|
||||
#else
|
||||
KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
|
||||
return PyObjectFrom(GetLinearVelocity(false));
|
||||
#endif
|
||||
}
|
||||
|
||||
int KX_GameObject::pyattr_set_worldLinearVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
||||
{
|
||||
KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
|
||||
MT_Vector3 velocity;
|
||||
if (!PyVecTo(value, velocity))
|
||||
return PY_SET_ATTR_FAIL;
|
||||
|
||||
self->setLinearVelocity(velocity, false);
|
||||
|
||||
return PY_SET_ATTR_SUCCESS;
|
||||
}
|
||||
|
||||
PyObject* KX_GameObject::pyattr_get_localLinearVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
||||
{
|
||||
#ifdef USE_MATHUTILS
|
||||
return newVectorObject_cb(BGE_PROXY_FROM_REF(self_v), 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_LINVEL_LOCAL);
|
||||
#else
|
||||
KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
|
||||
return PyObjectFrom(GetLinearVelocity(true));
|
||||
#endif
|
||||
}
|
||||
|
||||
int KX_GameObject::pyattr_set_localLinearVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
||||
{
|
||||
KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
|
||||
MT_Vector3 velocity;
|
||||
if (!PyVecTo(value, velocity))
|
||||
return PY_SET_ATTR_FAIL;
|
||||
|
||||
self->setLinearVelocity(velocity, true);
|
||||
|
||||
return PY_SET_ATTR_SUCCESS;
|
||||
}
|
||||
|
||||
PyObject* KX_GameObject::pyattr_get_worldAngularVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
||||
{
|
||||
#ifdef USE_MATHUTILS
|
||||
return newVectorObject_cb(BGE_PROXY_FROM_REF(self_v), 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_ANGVEL_GLOBAL);
|
||||
#else
|
||||
KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
|
||||
return PyObjectFrom(GetAngularVelocity(false));
|
||||
#endif
|
||||
}
|
||||
|
||||
int KX_GameObject::pyattr_set_worldAngularVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
||||
{
|
||||
KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
|
||||
MT_Vector3 velocity;
|
||||
if (!PyVecTo(value, velocity))
|
||||
return PY_SET_ATTR_FAIL;
|
||||
|
||||
self->setAngularVelocity(velocity, false);
|
||||
|
||||
return PY_SET_ATTR_SUCCESS;
|
||||
}
|
||||
|
||||
PyObject* KX_GameObject::pyattr_get_localAngularVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
||||
{
|
||||
#ifdef USE_MATHUTILS
|
||||
return newVectorObject_cb(BGE_PROXY_FROM_REF(self_v), 3, mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_ANGVEL_LOCAL);
|
||||
#else
|
||||
KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
|
||||
return PyObjectFrom(GetAngularVelocity(true));
|
||||
#endif
|
||||
}
|
||||
|
||||
int KX_GameObject::pyattr_set_localAngularVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
||||
{
|
||||
KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
|
||||
MT_Vector3 velocity;
|
||||
if (!PyVecTo(value, velocity))
|
||||
return PY_SET_ATTR_FAIL;
|
||||
|
||||
self->setAngularVelocity(velocity, true);
|
||||
|
||||
return PY_SET_ATTR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
PyObject* KX_GameObject::pyattr_get_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
||||
{
|
||||
KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
|
||||
|
@ -877,6 +877,14 @@ public:
|
||||
static PyObject* pyattr_get_worldScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
|
||||
static PyObject* pyattr_get_localScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
|
||||
static int pyattr_set_localScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
|
||||
static PyObject* pyattr_get_worldLinearVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
|
||||
static int pyattr_set_worldLinearVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
|
||||
static PyObject* pyattr_get_localLinearVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
|
||||
static int pyattr_set_localLinearVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
|
||||
static PyObject* pyattr_get_worldAngularVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
|
||||
static int pyattr_set_worldAngularVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
|
||||
static PyObject* pyattr_get_localAngularVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
|
||||
static int pyattr_set_localAngularVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
|
||||
static PyObject* pyattr_get_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
|
||||
static int pyattr_set_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
|
||||
static PyObject* pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
|
||||
|
Loading…
Reference in New Issue
Block a user