[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15668] trunk/blender/source/gameengine: BGE patch: Optimization of bullet adaptation layer - part 1.

Benoit Bolsee benoit.bolsee at online.be
Mon Jul 21 14:37:28 CEST 2008


Revision: 15668
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15668
Author:   ben2610
Date:     2008-07-21 14:37:27 +0200 (Mon, 21 Jul 2008)

Log Message:
-----------
BGE patch: Optimization of bullet adaptation layer - part 1.

First batch of optimizaton of the bullet adaptation layer in the BGE.
- remove circular motion state update.
- optimization of physic adaptation layer for bullet: bypass
  unecessary conversion of rotation matrix to quaternion and back.
- remove double updates during object replication.

Modified Paths:
--------------
    trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
    trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.h
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
    trunk/blender/source/gameengine/Ketsji/KX_IPhysicsController.h
    trunk/blender/source/gameengine/Ketsji/KX_OdePhysicsController.cpp
    trunk/blender/source/gameengine/Ketsji/KX_OdePhysicsController.h
    trunk/blender/source/gameengine/Ketsji/KX_RadarSensor.cpp
    trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp
    trunk/blender/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp
    trunk/blender/source/gameengine/Ketsji/KX_SumoPhysicsController.h
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.h

Modified: trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp	2008-07-21 11:21:49 UTC (rev 15667)
+++ trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp	2008-07-21 12:37:27 UTC (rev 15668)
@@ -133,9 +133,10 @@
 	CcdPhysicsController::getOrientation(myorn[0],myorn[1],myorn[2],myorn[3]);
 	orn = MT_Quaternion(myorn[0],myorn[1],myorn[2],myorn[3]);
 }
-void KX_BulletPhysicsController::setOrientation(const MT_Quaternion& orn)
+void KX_BulletPhysicsController::setOrientation(const MT_Matrix3x3& orn)
 {
-	CcdPhysicsController::setOrientation(orn.x(),orn.y(),orn.z(),orn.w());
+	btMatrix3x3 btmat(orn[0][0], orn[0][1], orn[1][2], orn[1][0], orn[1][1], orn[1][2], orn[2][0], orn[2][1], orn[2][2]);
+	CcdPhysicsController::setWorldOrientation(btmat);
 }
 void KX_BulletPhysicsController::setPosition(const MT_Point3& pos)
 {

Modified: trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.h	2008-07-21 11:21:49 UTC (rev 15667)
+++ trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.h	2008-07-21 12:37:27 UTC (rev 15668)
@@ -35,7 +35,7 @@
 	virtual void	SetAngularVelocity(const MT_Vector3& ang_vel,bool local);
 	virtual void	SetLinearVelocity(const MT_Vector3& lin_vel,bool local);
 	virtual	void	getOrientation(MT_Quaternion& orn);
-	virtual	void setOrientation(const MT_Quaternion& orn);
+	virtual	void setOrientation(const MT_Matrix3x3& orn);
 	virtual	void setPosition(const MT_Point3& pos);
 	virtual	void setScaling(const MT_Vector3& scaling);
 	virtual	MT_Scalar	GetMass();

Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp	2008-07-21 11:21:49 UTC (rev 15667)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp	2008-07-21 12:37:27 UTC (rev 15668)
@@ -744,7 +744,7 @@
 	if (m_pPhysicsController1 && (!GetSGNode() || !GetSGNode()->GetSGParent()))
 	{
 		// see note above
-		m_pPhysicsController1->setOrientation(rot.getRotation());
+		m_pPhysicsController1->setOrientation(rot);
 	}
 	if (GetSGNode())
 		GetSGNode()->SetLocalOrientation(rot);

Modified: trunk/blender/source/gameengine/Ketsji/KX_IPhysicsController.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_IPhysicsController.h	2008-07-21 11:21:49 UTC (rev 15667)
+++ trunk/blender/source/gameengine/Ketsji/KX_IPhysicsController.h	2008-07-21 12:37:27 UTC (rev 15668)
@@ -71,7 +71,8 @@
 	virtual void	resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ) = 0;
 
 	virtual	void	getOrientation(MT_Quaternion& orn)=0;
-	virtual	void setOrientation(const MT_Quaternion& orn)=0;
+	virtual	void setOrientation(const MT_Matrix3x3& orn)=0;
+	//virtual	void setOrientation(const MT_Quaternion& orn)=0;
 	virtual	void setPosition(const MT_Point3& pos)=0;
 	virtual	void setScaling(const MT_Vector3& scaling)=0;
 	virtual	MT_Scalar	GetMass()=0;

Modified: trunk/blender/source/gameengine/Ketsji/KX_OdePhysicsController.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_OdePhysicsController.cpp	2008-07-21 11:21:49 UTC (rev 15667)
+++ trunk/blender/source/gameengine/Ketsji/KX_OdePhysicsController.cpp	2008-07-21 12:37:27 UTC (rev 15668)
@@ -133,8 +133,9 @@
 	ODEPhysicsController::SetLinearVelocity(lin_vel[0],lin_vel[1],lin_vel[2],local);
 }
 
-void KX_OdePhysicsController::setOrientation(const MT_Quaternion& orn)
+void KX_OdePhysicsController::setOrientation(const MT_Matrix3x3& rot)
 {
+	MT_Quaternion orn = rot.getRotation();
 	ODEPhysicsController::setOrientation(orn[0],orn[1],orn[2],orn[3]);
 }
 

Modified: trunk/blender/source/gameengine/Ketsji/KX_OdePhysicsController.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_OdePhysicsController.h	2008-07-21 11:21:49 UTC (rev 15667)
+++ trunk/blender/source/gameengine/Ketsji/KX_OdePhysicsController.h	2008-07-21 12:37:27 UTC (rev 15668)
@@ -67,7 +67,7 @@
 	virtual void	SetLinearVelocity(const MT_Vector3& lin_vel,bool local);
 	virtual void		resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ);
 	virtual	void		getOrientation(MT_Quaternion& orn);
-	virtual	void setOrientation(const MT_Quaternion& orn);
+	virtual	void setOrientation(const MT_Matrix3x3& orn);
 	virtual	void setPosition(const MT_Point3& pos);
 	virtual	void setScaling(const MT_Vector3& scaling);
 	virtual	MT_Scalar	GetMass();

Modified: trunk/blender/source/gameengine/Ketsji/KX_RadarSensor.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_RadarSensor.cpp	2008-07-21 11:21:49 UTC (rev 15667)
+++ trunk/blender/source/gameengine/Ketsji/KX_RadarSensor.cpp	2008-07-21 12:37:27 UTC (rev 15668)
@@ -176,8 +176,10 @@
 
 	if (m_physCtrl)
 	{
-		m_physCtrl->setPosition(trans.getOrigin().x(),trans.getOrigin().y(),trans.getOrigin().z());
-		m_physCtrl->setOrientation(trans.getRotation().x(),trans.getRotation().y(),trans.getRotation().z(),trans.getRotation().w());
+		MT_Quaternion orn = trans.getRotation();
+		MT_Point3 pos = trans.getOrigin();
+		m_physCtrl->setPosition(pos[0],pos[1],pos[2]);
+		m_physCtrl->setOrientation(orn[0],orn[1],orn[2],orn[3]);
 		m_physCtrl->calcXform();
 	}
 

Modified: trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp	2008-07-21 11:21:49 UTC (rev 15667)
+++ trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp	2008-07-21 12:37:27 UTC (rev 15668)
@@ -712,8 +712,12 @@
 
 		if (replica->GetPhysicsController())
 		{
-			replica->GetPhysicsController()->setPosition(newpos);
-			replica->GetPhysicsController()->setOrientation(newori.getRotation());
+			// not required, already done in NodeSetLocalOrientation..
+			//replica->GetPhysicsController()->setPosition(newpos);
+			//replica->GetPhysicsController()->setOrientation(newori.getRotation());
+			// Scaling has been set relatively hereabove, this does not 
+			// set the scaling of the controller. I don't know why it's just the
+			// relative scale and not the full scale that has to be put here...
 			replica->GetPhysicsController()->setScaling(newscale);
 		}
 
@@ -843,8 +847,9 @@
 
 	if (replica->GetPhysicsController())
 	{
-		replica->GetPhysicsController()->setPosition(newpos);
-		replica->GetPhysicsController()->setOrientation(newori.getRotation());
+		// not needed, already done in NodeSetLocalPosition()
+		//replica->GetPhysicsController()->setPosition(newpos);
+		//replica->GetPhysicsController()->setOrientation(newori.getRotation());
 		replica->GetPhysicsController()->setScaling(newscale);
 	}
 

Modified: trunk/blender/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp	2008-07-21 11:21:49 UTC (rev 15667)
+++ trunk/blender/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp	2008-07-21 12:37:27 UTC (rev 15668)
@@ -170,8 +170,9 @@
 }
 
 
-void KX_SumoPhysicsController::setOrientation(const MT_Quaternion& orn)
+void KX_SumoPhysicsController::setOrientation(const MT_Matrix3x3& rot)
 {
+	MT_Quaternion orn = rot.getRotation();
 	SumoPhysicsController::setOrientation(
 		orn[0],orn[1],orn[2],orn[3]);
 

Modified: trunk/blender/source/gameengine/Ketsji/KX_SumoPhysicsController.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_SumoPhysicsController.h	2008-07-21 11:21:49 UTC (rev 15667)
+++ trunk/blender/source/gameengine/Ketsji/KX_SumoPhysicsController.h	2008-07-21 12:37:27 UTC (rev 15668)
@@ -79,7 +79,7 @@
 	void	SuspendDynamics(bool);
 	void	RestoreDynamics();
 	virtual	void	getOrientation(MT_Quaternion& orn);
-	virtual	void setOrientation(const MT_Quaternion& orn);
+	virtual	void setOrientation(const MT_Matrix3x3& orn);
 	
 	virtual	void setPosition(const MT_Point3& pos);
 	virtual	void setScaling(const MT_Vector3& scaling);

Modified: trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
===================================================================
--- trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp	2008-07-21 11:21:49 UTC (rev 15667)
+++ trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp	2008-07-21 12:37:27 UTC (rev 15668)
@@ -337,16 +337,37 @@
 		{
 			m_body->setCollisionFlags(m_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
 		}
-
-		m_MotionState->setWorldOrientation(quatImag0,quatImag1,quatImag2,quatReal);
+		// not required
+		//m_MotionState->setWorldOrientation(quatImag0,quatImag1,quatImag2,quatReal);
 		btTransform xform  = m_body->getCenterOfMassTransform();
 		xform.setRotation(btQuaternion(quatImag0,quatImag1,quatImag2,quatReal));
 		m_body->setCenterOfMassTransform(xform);
-		m_bulletMotionState->setWorldTransform(xform);
+		// not required
+		//m_bulletMotionState->setWorldTransform(xform);
 	}
 
 }
 
+void CcdPhysicsController::setWorldOrientation(const btMatrix3x3& orn)
+{
+	if (m_body)
+	{
+		m_body->activate(true);
+		if (m_body->isStaticObject())
+		{
+			m_body->setCollisionFlags(m_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+		}
+		// not required
+		//m_MotionState->setWorldOrientation(quatImag0,quatImag1,quatImag2,quatReal);
+		btTransform xform  = m_body->getCenterOfMassTransform();
+		xform.setBasis(orn);
+		m_body->setCenterOfMassTransform(xform);
+		// not required
+		//m_bulletMotionState->setWorldTransform(xform);
+	}
+
+}
+
 void		CcdPhysicsController::setPosition(float posX,float posY,float posZ)
 {
 	if (m_body)
@@ -356,12 +377,13 @@
 		{
 			m_body->setCollisionFlags(m_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
 		}
-		
-		m_MotionState->setWorldPosition(posX,posY,posZ);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list