add compute softbody com

This commit is contained in:
Chuyuan Fu
2019-10-24 19:09:08 -07:00
committed by Xuchen Han
parent 618c85325c
commit 74571d79e7
2 changed files with 14 additions and 3 deletions

View File

@@ -7257,6 +7257,7 @@ bool PhysicsServerCommandProcessor::processRequestActualStateCommand(const struc
serverCmd.m_numDataStreamBytes = sizeof(SendActualStateSharedMemoryStorage); serverCmd.m_numDataStreamBytes = sizeof(SendActualStateSharedMemoryStorage);
serverCmd.m_sendActualStateArgs.m_stateDetails = 0; serverCmd.m_sendActualStateArgs.m_stateDetails = 0;
serverCmd.m_sendActualStateArgs.m_rootLocalInertialFrame[0] = serverCmd.m_sendActualStateArgs.m_rootLocalInertialFrame[0] =
body->m_rootLocalInertialFrame.getOrigin()[0]; body->m_rootLocalInertialFrame.getOrigin()[0];
serverCmd.m_sendActualStateArgs.m_rootLocalInertialFrame[1] = serverCmd.m_sendActualStateArgs.m_rootLocalInertialFrame[1] =
@@ -7273,11 +7274,12 @@ bool PhysicsServerCommandProcessor::processRequestActualStateCommand(const struc
serverCmd.m_sendActualStateArgs.m_rootLocalInertialFrame[6] = serverCmd.m_sendActualStateArgs.m_rootLocalInertialFrame[6] =
body->m_rootLocalInertialFrame.getRotation()[3]; body->m_rootLocalInertialFrame.getRotation()[3];
btVector3 center_of_mass(sb->getCenterOfMass());
btTransform tr = sb->getWorldTransform(); btTransform tr = sb->getWorldTransform();
//base position in world space, cartesian //base position in world space, cartesian
stateDetails->m_actualStateQ[0] = tr.getOrigin()[0]; stateDetails->m_actualStateQ[0] = center_of_mass[0];
stateDetails->m_actualStateQ[1] = tr.getOrigin()[1]; stateDetails->m_actualStateQ[1] = center_of_mass[1];
stateDetails->m_actualStateQ[2] = tr.getOrigin()[2]; stateDetails->m_actualStateQ[2] = center_of_mass[2];
//base orientation, quaternion x,y,z,w, in world space, cartesian //base orientation, quaternion x,y,z,w, in world space, cartesian
stateDetails->m_actualStateQ[3] = tr.getRotation()[0]; stateDetails->m_actualStateQ[3] = tr.getRotation()[0];

View File

@@ -20,6 +20,7 @@ subject to the following restrictions:
#include "LinearMath/btAlignedObjectArray.h" #include "LinearMath/btAlignedObjectArray.h"
#include "LinearMath/btTransform.h" #include "LinearMath/btTransform.h"
#include "LinearMath/btIDebugDraw.h" #include "LinearMath/btIDebugDraw.h"
#include "LinearMath/btVector3.h"
#include "BulletDynamics/Dynamics/btRigidBody.h" #include "BulletDynamics/Dynamics/btRigidBody.h"
#include "BulletCollision/CollisionShapes/btConcaveShape.h" #include "BulletCollision/CollisionShapes/btConcaveShape.h"
@@ -973,6 +974,14 @@ public:
/* Return the volume */ /* Return the volume */
btScalar getVolume() const; btScalar getVolume() const;
/* Cluster count */ /* Cluster count */
btVector3 getCenterOfMass() const{
btVector3 com(0,0,0);
for(int i = 0; i<m_nodes.size(); i++){
com += m_nodes[i].m_x;
}
com/=m_nodes.size();
return com;
}
int clusterCount() const; int clusterCount() const;
/* Cluster center of mass */ /* Cluster center of mass */
static btVector3 clusterCom(const Cluster* cluster); static btVector3 clusterCom(const Cluster* cluster);