[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24422] branches/physics25: Physics: sketched physics integration code after discussion with Brecht.
Arystanbek Dyussenov
arystan.d at gmail.com
Mon Nov 9 16:59:01 CET 2009
Revision: 24422
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24422
Author: kazanbas
Date: 2009-11-09 16:59:01 +0100 (Mon, 09 Nov 2009)
Log Message:
-----------
Physics: sketched physics integration code after discussion with Brecht.
Improved integration design doc is here: http://wiki.blender.org/index.php/User:Kazanbas/Bullet_Proposal#Integration.
Note, code won't compile for now.
Modified Paths:
--------------
branches/physics25/extern/bullet2/src/BulletDynamics/Dynamics/Bullet-C-API.cpp
branches/physics25/source/blender/blenkernel/intern/scene.c
branches/physics25/source/blender/makesdna/DNA_group_types.h
branches/physics25/source/blender/makesdna/DNA_object_types.h
Added Paths:
-----------
branches/physics25/source/blender/blenkernel/intern/rigidbody.c
Modified: branches/physics25/extern/bullet2/src/BulletDynamics/Dynamics/Bullet-C-API.cpp
===================================================================
--- branches/physics25/extern/bullet2/src/BulletDynamics/Dynamics/Bullet-C-API.cpp 2009-11-09 13:55:04 UTC (rev 24421)
+++ branches/physics25/extern/bullet2/src/BulletDynamics/Dynamics/Bullet-C-API.cpp 2009-11-09 15:59:01 UTC (rev 24422)
@@ -394,3 +394,34 @@
return -1.0f;
}
+typedef void *(GetTransformFunc)(btScalar m[4][4]);
+typedef void *(SetTransformFunc)(btScalar m[4][4]);
+void set_motion_state(GetTransformFunc *get, SetTransformFunc *set);
+
+void set_motion_state(plRigidBodyHandle r, GetTransformFunc *get, SetTransformFunc *set)
+{
+
+}
+
+class CustomMotionState : public btMotionState {
+private:
+ GetTransformFunc *get;
+ SetTransformFunc *set;
+
+public:
+ CustomMotionState(GetTransformFunc *get, SetTransformFunc *set) : get(get), set(set) { }
+
+ virtual void getWorldTransform(btTransform& t) const
+ {
+ btScalar m[4][4];
+ this->get(m);
+ t.setFromOpenGLSubMatrix((btScalar*)m);
+ }
+
+ virtual void setWorldTransform(const btTransform& t)
+ {
+ btScalar m[4][4];
+ t.getOpenGLMatrix((btScalar*)m);
+ this->set(m);
+ }
+};
Added: branches/physics25/source/blender/blenkernel/intern/rigidbody.c
===================================================================
--- branches/physics25/source/blender/blenkernel/intern/rigidbody.c (rev 0)
+++ branches/physics25/source/blender/blenkernel/intern/rigidbody.c 2009-11-09 15:59:01 UTC (rev 24422)
@@ -0,0 +1,89 @@
+/*
+ *
+ * $Id$
+ *
+ * ***** BEGIN GPL 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.
+ *
+ * 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) Blender Foundation
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Arystanbek Dyussenov.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include "Bullet-C-Api.h"
+
+static plPhysicsSdkHandle bullet_sdk; /* XXX global var */
+
+/* void object_to_rigidbody(); */
+static plCollisionShapeHandle create_shape(Object *ob);
+
+/*
+ Q: use motionstates?
+ Q: how to update rigid body mass as it changes in Object
+ Q: how to update collision shape when mesh changes?
+*/
+void rigidbody_group_step(Group *group)
+{
+ GroupObject *go;
+ Object *ob;
+ plDynamicsWorldHandle world;
+
+ static int prevframe= 0;
+ int frame= scene->r.cfra, startframe= scene->r.sfra;
+ float delta;
+
+ if (!bullet_sdk)
+ bullet_sdk= plNewBulletSdk();
+
+ if (!group->physics_world)
+ group->physics_world= plCreateDynamicsWorld(bullet_sdk);
+
+ world= group->physics_world;
+
+ for(go= group->gobject.first; go; go= go->next) {
+ ob= go->ob;
+ if (!ob->rigid) {
+ ob->rigid= plCreateRigidBody(NULL, ob->mass, create_shape(ob));
+
+ plRemoveRigidBody(world, ob->rigid);
+
+ plAddRigidBody(world, ob->rigid);
+ }
+ }
+
+ if (frame == startframe) {
+ /* start frame - reset positions */
+ }
+
+ delta= FRA2TIME(frame) - FRA2TIME(prevframe);
+
+ if (delta <= 0.0f) {
+ prevframe= frame;
+ return;
+ }
+
+ plStepSimulation(world, delta);
+}
+
+static plCollisionShapeHandle create_shape(Object *ob)
+{
+ #error write shape code
+}
Property changes on: branches/physics25/source/blender/blenkernel/intern/rigidbody.c
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: branches/physics25/source/blender/blenkernel/intern/scene.c
===================================================================
--- branches/physics25/source/blender/blenkernel/intern/scene.c 2009-11-09 13:55:04 UTC (rev 24421)
+++ branches/physics25/source/blender/blenkernel/intern/scene.c 2009-11-09 15:59:01 UTC (rev 24422)
@@ -774,6 +774,8 @@
{
Base *base;
Object *ob;
+ Group *group;
+ GroupObject *go;
float ctime = frame_to_float(sce, sce->r.cfra);
if(sce->theDag==NULL)
@@ -788,7 +790,21 @@
* such as Scene->World->MTex/Texture) can still get correctly overridden.
*/
BKE_animsys_evaluate_all_animation(G.main, ctime);
-
+
+ /* update physics objects first */
+ for(group= G.main->group.first; group; group= group->id.next) {
+ if(group->flag & GR_PHYSICS) {
+
+ /* evaluate transform first */
+ for(go= group->gobject.first; go; go= go->next) {
+ object_handle_update(sce, go->ob);
+ }
+
+ /* now perform sim. step */
+ rigidbody_group_step(group);
+ }
+ }
+
for(base= sce->base.first; base; base= base->next) {
ob= base->object;
Modified: branches/physics25/source/blender/makesdna/DNA_group_types.h
===================================================================
--- branches/physics25/source/blender/makesdna/DNA_group_types.h 2009-11-09 13:55:04 UTC (rev 24421)
+++ branches/physics25/source/blender/makesdna/DNA_group_types.h 2009-11-09 15:59:01 UTC (rev 24422)
@@ -58,10 +58,13 @@
int flag;
int pad;
+
+ void *physics_world; /* not saved to file */
+ int pad;
} Group;
/* Group flags */
-#define GR_PHYSICS 1 /* group rigid bodies */
+#define GR_PHYSICS 1 /* group rigid bodies */
#endif
Modified: branches/physics25/source/blender/makesdna/DNA_object_types.h
===================================================================
--- branches/physics25/source/blender/makesdna/DNA_object_types.h 2009-11-09 13:55:04 UTC (rev 24421)
+++ branches/physics25/source/blender/makesdna/DNA_object_types.h 2009-11-09 15:59:01 UTC (rev 24422)
@@ -248,6 +248,8 @@
ListBase gpulamp; /* runtime, for lamps only */
ListBase pc_ids;
ListBase *duplilist; /* for temporary dupli list storage, only for use by RNA API */
+
+ void *rigid; /* rigid body pointer, not saved to file */
} Object;
/* Warning, this is not used anymore because hooks are now modifiers */
More information about the Bf-blender-cvs
mailing list