Revision: 19714
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19714
Author: campbellbarton
Date: 2009-04-14 14:34:39 +0200 (Tue, 14 Apr 2009)
Log Message:
-----------
BGE Physics
Clamp objects min/max velocity.
Accessed with bullet physics from the advanced button with dynamic and rigid
body objects.
- useful for preventing unstable physics in cases where objects move too fast.
- can add linear velocity with the motion actuator to give smooth motion
transitions, without moving too fast.
- minimum velocity means objects don't stop moving.
- python scripts can adjust these values speedup or throttle velocity in the
existing direction.
Also made copy properties from an object with no properties work (in case you
want to clear all props)
Modified Paths:
--------------
trunk/blender/source/blender/makesdna/DNA_object_types.h
trunk/blender/source/blender/src/buttons_logic.c
trunk/blender/source/blender/src/editobject.c
trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.h
trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
trunk/blender/source/gameengine/Ketsji/KX_IPhysicsController.h
trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.h
trunk/blender/source/gameengine/Physics/common/PHY_IPhysicsController.h
trunk/blender/source/gameengine/Physics/common/PHY_Pro.h
trunk/blender/source/gameengine/PyDoc/KX_GameObject.py
Modified: trunk/blender/source/blender/makesdna/DNA_object_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_object_types.h 2009-04-14
11:53:41 UTC (rev 19713)
+++ trunk/blender/source/blender/makesdna/DNA_object_types.h 2009-04-14
12:34:39 UTC (rev 19714)
@@ -157,7 +157,9 @@
float formfactor;
float rdamping, sizefac;
float margin;
- int pad3;
+ float max_vel; /* clamp the maximum velocity 0.0 is disabled */
+ float min_vel; /* clamp the maximum velocity 0.0 is disabled */
+ float pad3; /* clamp the maximum velocity 0.0 is disabled */
char dt, dtx;
char totcol; /* copy of mesh or curve or meta */
Modified: trunk/blender/source/blender/src/buttons_logic.c
===================================================================
--- trunk/blender/source/blender/src/buttons_logic.c 2009-04-14 11:53:41 UTC
(rev 19713)
+++ trunk/blender/source/blender/src/buttons_logic.c 2009-04-14 12:34:39 UTC
(rev 19714)
@@ -3139,6 +3139,7 @@
uiDefButF(block, NUM, 0, "Margin",
xco, yco, 180, 19, &ob->margin, 0.001,
1.0, 1, 0,
"Collision margin");
+
yco -= 20;
if (ob->gameflag & OB_RIGID_BODY)
@@ -3166,7 +3167,24 @@
uiDefButBitI(block, TOG,
OB_LOCK_RIGID_BODY_Z_ROT_AXIS, 0, "Lock Z Rot Axis",
xco+=180, yco, 180, 19, &ob->gameflag2,
0, 0, 0, 0,
"Disable simulation of angular motion
along the Z axis");
+ yco -= 20;
}
+ xco = 0;
+
+ uiBlockEndAlign(block);
+
+ uiDefBut(block, LABEL, 0, "Clamp Velocity (zero
disables)", xco, yco, 180*2, 19, NULL, 0, 0, 0, 0, "");
+
+ uiBlockBeginAlign(block);
+
+ uiDefButF(block, NUM, 0, "Min",
+ xco+=180, yco, 90, 19, &ob->min_vel, 0.0,
1000.0, 1, 0,
+ "Clamp velocity to this minimum speed (except
when totally still)");
+ uiDefButF(block, NUM, 0, "Max",
+ xco+=90, yco, 90, 19, &ob->max_vel, 0.0,
1000.0, 1, 0,
+ "Clamp velocity to this maximum speed");
+ uiBlockEndAlign(block);
+
/*
uiDefButBitI(block, TOG, OB_BSB_COL_CL_RS, 0, "Cluster
Collision RS",
xco, yco, 180, 19, &ob->bsoft->collisionflags,
0, 0, 0, 0,
Modified: trunk/blender/source/blender/src/editobject.c
===================================================================
--- trunk/blender/source/blender/src/editobject.c 2009-04-14 11:53:41 UTC
(rev 19713)
+++ trunk/blender/source/blender/src/editobject.c 2009-04-14 12:34:39 UTC
(rev 19714)
@@ -3205,14 +3205,12 @@
prop= prop->next;
}
- if(tot==0) {
- error("No properties in the active object to copy");
- return;
- }
-
str= MEM_callocN(50 + 33*tot, "copymenu prop");
- strcpy(str, "Copy Property %t|Replace All|Merge All|%l");
+ if (tot)
+ strcpy(str, "Copy Property %t|Replace All|Merge All|%l");
+ else
+ strcpy(str, "Copy Property %t|Clear All (no properties on
active)");
tot= 0;
prop= ob->prop.first;
@@ -3526,7 +3524,8 @@
base->object->formfactor =
ob->formfactor;
base->object->damping= ob->damping;
base->object->rdamping= ob->rdamping;
- base->object->mass= ob->mass;
+ base->object->min_vel= ob->min_vel;
+ base->object->max_vel= ob->max_vel;
if (ob->gameflag & OB_BOUNDS) {
base->object->boundtype =
ob->boundtype;
}
Modified: trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
2009-04-14 11:53:41 UTC (rev 19713)
+++ trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
2009-04-14 12:34:39 UTC (rev 19714)
@@ -1107,6 +1107,10 @@
shapeProps->m_do_fh = (blenderobject->gameflag & OB_DO_FH) != 0;
shapeProps->m_do_rot_fh = (blenderobject->gameflag & OB_ROT_FH) != 0;
+// velocity clamping XXX
+ shapeProps->m_clamp_vel_min = blenderobject->min_vel;
+ shapeProps->m_clamp_vel_max = blenderobject->max_vel;
+
return shapeProps;
}
Modified: trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
2009-04-14 11:53:41 UTC (rev 19713)
+++ trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
2009-04-14 12:34:39 UTC (rev 19714)
@@ -59,6 +59,24 @@
}
+float KX_BulletPhysicsController::GetLinVelocityMin()
+{
+ return (float)CcdPhysicsController::GetLinVelocityMin();
+}
+void KX_BulletPhysicsController::SetLinVelocityMin(float val)
+{
+ CcdPhysicsController::SetLinVelocityMin(val);
+}
+
+float KX_BulletPhysicsController::GetLinVelocityMax()
+{
+ return (float)CcdPhysicsController::GetLinVelocityMax();
+}
+void KX_BulletPhysicsController::SetLinVelocityMax(float val)
+{
+ CcdPhysicsController::SetLinVelocityMax(val);
+}
+
void KX_BulletPhysicsController::SetObject (SG_IObject* object)
{
SG_Controller::SetObject(object);
@@ -73,6 +91,10 @@
}
+MT_Scalar KX_BulletPhysicsController::GetRadius()
+{
+ return MT_Scalar(CcdPhysicsController::GetRadius());
+}
void KX_BulletPhysicsController::setMargin (float collisionMargin)
{
@@ -176,11 +198,6 @@
return inertia;
}
-MT_Scalar KX_BulletPhysicsController::GetRadius()
-{
- return MT_Scalar(CcdPhysicsController::GetRadius());
-}
-
MT_Vector3 KX_BulletPhysicsController::getReactionForce()
{
assert(0);
Modified: trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.h
2009-04-14 11:53:41 UTC (rev 19713)
+++ trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.h
2009-04-14 12:34:39 UTC (rev 19714)
@@ -56,8 +56,12 @@
virtual SG_Controller* GetReplica(class SG_Node* destnode);
virtual MT_Scalar GetRadius();
+
+ virtual float GetLinVelocityMin();
+ virtual void SetLinVelocityMin(float val);
+ virtual float GetLinVelocityMax();
+ virtual void SetLinVelocityMax(float val);
-
virtual void SetSumoTransform(bool nondynaonly);
// todo: remove next line !
virtual void SetSimulatedTime(double time);
Modified: trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
2009-04-14 11:53:41 UTC (rev 19713)
+++ trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
2009-04-14 12:34:39 UTC (rev 19714)
@@ -801,6 +801,8 @@
ci.m_gravity = btVector3(0,0,0);
ci.m_localInertiaTensor =btVector3(0,0,0);
ci.m_mass = objprop->m_dyna ? shapeprops->m_mass : 0.f;
+ ci.m_clamp_vel_min = shapeprops->m_clamp_vel_min;
+ ci.m_clamp_vel_max = shapeprops->m_clamp_vel_max;
ci.m_margin = objprop->m_margin;
shapeInfo->m_radius = objprop->m_radius;
isbulletdyna = objprop->m_dyna;
Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp 2009-04-14
11:53:41 UTC (rev 19713)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp 2009-04-14
12:34:39 UTC (rev 19714)
@@ -1086,6 +1086,8 @@
KX_PYATTRIBUTE_RO_FUNCTION("name", KX_GameObject,
pyattr_get_name),
KX_PYATTRIBUTE_RO_FUNCTION("parent", KX_GameObject,
pyattr_get_parent),
KX_PYATTRIBUTE_RW_FUNCTION("mass", KX_GameObject,
pyattr_get_mass, pyattr_set_mass),
+ KX_PYATTRIBUTE_RW_FUNCTION("linVelocityMin", KX_GameObject,
pyattr_get_lin_vel_min, pyattr_set_lin_vel_min),
+ KX_PYATTRIBUTE_RW_FUNCTION("linVelocityMax", KX_GameObject,
pyattr_get_lin_vel_max, pyattr_set_lin_vel_max),
KX_PYATTRIBUTE_RW_FUNCTION("visible", KX_GameObject,
pyattr_get_visible, pyattr_set_visible),
KX_PYATTRIBUTE_BOOL_RW ("occlusion", KX_GameObject, m_bOccluder),
KX_PYATTRIBUTE_RW_FUNCTION("position", KX_GameObject,
pyattr_get_position, pyattr_set_position),
@@ -1364,6 +1366,53 @@
return 0;
}
+PyObject* KX_GameObject::pyattr_get_lin_vel_min(void *self_v, const
KX_PYATTRIBUTE_DEF *attrdef)
+{
+ KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
+ KX_IPhysicsController *spc = self->GetPhysicsController();
+ return PyFloat_FromDouble(spc ? spc->GetLinVelocityMax() : 0.0f);
+}
+
+int KX_GameObject::pyattr_set_lin_vel_min(void *self_v, const
KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+ KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
+ KX_IPhysicsController *spc = self->GetPhysicsController();
+ MT_Scalar val = PyFloat_AsDouble(value);
+ if (val < 0.0f) { /* also accounts for non float */
+ PyErr_SetString(PyExc_AttributeError, "expected a float zero or
above");
+ return 1;
+ }
+
+ if (spc)
+ spc->SetLinVelocityMin(val);
+
+ return 0;
+}
+
+PyObject* KX_GameObject::pyattr_get_lin_vel_max(void *self_v, const
KX_PYATTRIBUTE_DEF *attrdef)
+{
+ KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
+ KX_IPhysicsController *spc = self->GetPhysicsController();
+ return PyFloat_FromDouble(spc ? spc->GetLinVelocityMax() : 0.0f);
+}
+
+int KX_GameObject::pyattr_set_lin_vel_max(void *self_v, const
KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+ KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
+ KX_IPhysicsController *spc = self->GetPhysicsController();
+ MT_Scalar val = PyFloat_AsDouble(value);
+ if (val < 0.0f) { /* also accounts for non float */
+ PyErr_SetString(PyExc_AttributeError, "expected a float zero or
above");
+ return 1;
+ }
+
+ if (spc)
+ spc->SetLinVelocityMax(val);
+
+ return 0;
+}
+
+
PyObject* KX_GameObject::pyattr_get_visible(void *self_v, const
KX_PYATTRIBUTE_DEF *attrdef)
{
KX_GameObject* self= static_cast<KX_GameObject*>(self_v);
Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.h 2009-04-14
11:53:41 UTC (rev 19713)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.h 2009-04-14
12:34:39 UTC (rev 19714)
@@ -960,6 +960,10 @@
static PyObject* pyattr_get_mass(void *self_v, const
KX_PYATTRIBUTE_DEF *attrdef);
static int pyattr_set_mass(void *self_v, const
KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+ static PyObject* pyattr_get_lin_vel_min(void *self_v, const
KX_PYATTRIBUTE_DEF *attrdef);
+ static int pyattr_set_lin_vel_min(void *self_v,
const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs