Add API to get dynamic info.

This commit is contained in:
yunfeibai 2017-05-07 22:21:38 -07:00
parent e363e12ea4
commit 5fe4c6bb5b
7 changed files with 83 additions and 6 deletions

View File

@ -1214,9 +1214,30 @@ int b3GetJointInfo(b3PhysicsClientHandle physClient, int bodyIndex, int jointInd
return cl->getJointInfo(bodyIndex, jointIndex, *info);
}
int b3GetDynamicInfo(b3PhysicsClientHandle physClient, int bodyUniqueId, int linkIndex, struct b3DynamicInfo* info)
b3SharedMemoryCommandHandle b3GetDynamicInfoCommandInit(b3PhysicsClientHandle physClient, int bodyUniqueId, int linkIndex)
{
return 0;
PhysicsClient* cl = (PhysicsClient* ) physClient;
b3Assert(cl);
b3Assert(cl->canSubmitCommand());
struct SharedMemoryCommand* command = cl->getAvailableSharedMemoryCommand();
b3Assert(command);
command->m_type = CMD_GET_DYNAMIC_INFO;
command->m_getDynamicInfoArgs.m_bodyUniqueId = bodyUniqueId;
command->m_getDynamicInfoArgs.m_linkIndex = linkIndex;
return (b3SharedMemoryCommandHandle) command;
}
int b3GetDynamicInfo(b3SharedMemoryStatusHandle statusHandle, struct b3DynamicInfo* info)
{
const SharedMemoryStatus* status = (const SharedMemoryStatus* ) statusHandle;
const b3DynamicInfo &dynamicInfo = status->m_dynamicInfo;
btAssert(status->m_type == CMD_GET_DYNAMIC_INFO);
if (status->m_type != CMD_GET_DYNAMIC_INFO_COMPLETED)
return false;
info->m_mass = dynamicInfo.m_mass;
info->m_lateralFrictionCoeff = dynamicInfo.m_lateralFrictionCoeff;
return true;
}
b3SharedMemoryCommandHandle b3InitResetDynamicInfo(b3PhysicsClientHandle physClient)

View File

@ -77,8 +77,9 @@ int b3GetNumJoints(b3PhysicsClientHandle physClient, int bodyIndex);
///given a body and joint index, return the joint information. See b3JointInfo in SharedMemoryPublic.h
int b3GetJointInfo(b3PhysicsClientHandle physClient, int bodyIndex, int jointIndex, struct b3JointInfo* info);
b3SharedMemoryCommandHandle b3GetDynamicInfoCommandInit(b3PhysicsClientHandle physClient, int bodyUniqueId, int linkIndex);
///given a body unique id and link index, return the dynamic information. See b3DynamicInfo in SharedMemoryPublic.h
int b3GetDynamicInfo(b3PhysicsClientHandle physClient, int bodyUniqueId, int linkIndex, struct b3DynamicInfo* info);
int b3GetDynamicInfo(b3SharedMemoryStatusHandle statusHandle, struct b3DynamicInfo* info);
b3SharedMemoryCommandHandle b3InitResetDynamicInfo(b3PhysicsClientHandle physClient);
int b3ResetDynamicInfoSetMass(b3SharedMemoryCommandHandle commandHandle, int bodyUniqueId, int linkIndex, double mass);

View File

@ -54,8 +54,8 @@ protected:
int m_canvasDepthIndex;
int m_canvasSegMaskIndex;
float m_lightPos[3];
float m_specularCoeff;
btScalar m_lightPos[3];
btScalar m_specularCoeff;
void createButton(const char* name, int id, bool isTrigger );
@ -281,7 +281,11 @@ void PhysicsClientExample::prepareAndSubmitCommand(int commandId)
b3RequestCameraImageSetCameraMatrices(commandHandle, viewMatrix,projectionMatrix);
b3RequestCameraImageSetPixelResolution(commandHandle, camVisualizerWidth,camVisualizerHeight);
b3RequestCameraImageSetLightDirection(commandHandle, m_lightPos);
float lightPos[3];
lightPos[0] = m_lightPos[0];
lightPos[1] = m_lightPos[1];
lightPos[2] = m_lightPos[2];
b3RequestCameraImageSetLightDirection(commandHandle, lightPos);
b3RequestCameraImageSetLightSpecularCoeff(commandHandle, m_specularCoeff);
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
break;

View File

@ -1039,6 +1039,15 @@ const SharedMemoryStatus* PhysicsClientSharedMemory::processServerStatus() {
b3Warning("Removing body failed");
break;
}
case CMD_GET_DYNAMIC_INFO_COMPLETED:
{
break;
}
case CMD_GET_DYNAMIC_INFO_FAILED:
{
b3Warning("Request dynamic info failed");
break;
}
default: {
b3Error("Unknown server status %d\n", serverCmd.m_type);
btAssert(0);

View File

@ -3955,6 +3955,38 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
break;
};
case CMD_GET_DYNAMIC_INFO:
{
int bodyUniqueId = clientCmd.m_getDynamicInfoArgs.m_bodyUniqueId;
int linkIndex = clientCmd.m_getDynamicInfoArgs.m_linkIndex;
InteralBodyData* body = m_data->m_bodyHandles.getHandle(bodyUniqueId);
if (body && body->m_multiBody)
{
SharedMemoryStatus& serverCmd = serverStatusOut;
serverCmd.m_type = CMD_GET_DYNAMIC_INFO_COMPLETED;
btMultiBody* mb = body->m_multiBody;
if (linkIndex == -1)
{
serverCmd.m_dynamicInfo.m_mass = mb->getBaseMass();
serverCmd.m_dynamicInfo.m_lateralFrictionCoeff = mb->getBaseCollider()->getFriction();
}
else
{
serverCmd.m_dynamicInfo.m_mass = mb->getLinkMass(linkIndex);
serverCmd.m_dynamicInfo.m_lateralFrictionCoeff = mb->getLinkCollider(linkIndex)->getFriction();
}
hasStatus = true;
}
else
{
b3Warning("The dynamic info requested is not available");
SharedMemoryStatus& serverCmd = serverStatusOut;
serverCmd.m_type = CMD_GET_DYNAMIC_INFO_FAILED;
hasStatus = true;
}
break;
}
case CMD_SEND_PHYSICS_SIMULATION_PARAMETERS:
{
BT_PROFILE("CMD_SEND_PHYSICS_SIMULATION_PARAMETERS");

View File

@ -122,6 +122,12 @@ struct ResetDynamicInfoArgs
double m_lateralFriction;
};
struct GetDynamicInfoArgs
{
int m_bodyUniqueId;
int m_linkIndex;
};
struct SetJointFeedbackArgs
{
int m_bodyUniqueId;
@ -739,6 +745,7 @@ struct SharedMemoryCommand
struct FileArgs m_fileArguments;
struct SdfRequestInfoArgs m_sdfRequestInfoArgs;
struct ResetDynamicInfoArgs m_resetDynamicInfoArgs;
struct GetDynamicInfoArgs m_getDynamicInfoArgs;
struct InitPoseArgs m_initPoseArgs;
struct SendPhysicsSimulationParameters m_physSimParamArgs;
struct BulletDataStreamArgs m_dataStreamArguments;

View File

@ -57,6 +57,7 @@ enum EnumSharedMemoryClientCommand
CMD_REQUEST_OPENGL_VISUALIZER_CAMERA,
CMD_REMOVE_BODY,
CMD_RESET_DYNAMIC_INFO,
CMD_GET_DYNAMIC_INFO,
CMD_PROFILE_TIMING,
//don't go beyond this command!
CMD_MAX_CLIENT_COMMANDS,
@ -141,6 +142,8 @@ enum EnumSharedMemoryServerStatus
CMD_REQUEST_OPENGL_VISUALIZER_CAMERA_COMPLETED,
CMD_REMOVE_BODY_COMPLETED,
CMD_REMOVE_BODY_FAILED,
CMD_GET_DYNAMIC_INFO_COMPLETED,
CMD_GET_DYNAMIC_INFO_FAILED,
//don't go beyond 'CMD_MAX_SERVER_COMMANDS!
CMD_MAX_SERVER_COMMANDS
};