From 90b6befe3d29ea8e89ffb5fbe1a47967e6462a46 Mon Sep 17 00:00:00 2001 From: erwincoumans Date: Wed, 14 Mar 2018 17:33:51 -0700 Subject: [PATCH] add missing implementation of b3RobotSimulatorClientAPI_NoGUI::getCameraImage Fixes Issue 1602 --- .../b3RobotSimulatorClientAPI_NoGUI.cpp | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/examples/RobotSimulator/b3RobotSimulatorClientAPI_NoGUI.cpp b/examples/RobotSimulator/b3RobotSimulatorClientAPI_NoGUI.cpp index 8beeed506..49b8524da 100644 --- a/examples/RobotSimulator/b3RobotSimulatorClientAPI_NoGUI.cpp +++ b/examples/RobotSimulator/b3RobotSimulatorClientAPI_NoGUI.cpp @@ -1106,6 +1106,72 @@ void b3RobotSimulatorClientAPI_NoGUI::getMouseEvents(b3MouseEventsData* mouseEve } +bool b3RobotSimulatorClientAPI_NoGUI::getCameraImage(int width, int height, struct b3RobotSimulatorGetCameraImageArgs args, struct b3CameraImageData &imageData) +{ + if (!isConnected()) { + b3Warning("Not connected"); + return false; + } + + b3SharedMemoryCommandHandle command; + + command = b3InitRequestCameraImage(m_data->m_physicsClientHandle); + + b3RequestCameraImageSetPixelResolution(command, width, height); + + // Check and apply optional arguments + if (args.m_viewMatrix && args.m_projectionMatrix) { + b3RequestCameraImageSetCameraMatrices(command, args.m_viewMatrix, args.m_projectionMatrix); + } + + if (args.m_lightDirection != NULL) { + b3RequestCameraImageSetLightDirection(command, args.m_lightDirection); + } + + if (args.m_lightColor != NULL) { + b3RequestCameraImageSetLightColor(command, args.m_lightColor); + } + + if (args.m_lightDistance>=0) { + b3RequestCameraImageSetLightDistance(command, args.m_lightDistance); + } + + if (args.m_hasShadow>=0) { + b3RequestCameraImageSetShadow(command, args.m_hasShadow); + } + + if (args.m_lightAmbientCoeff>=0) { + b3RequestCameraImageSetLightAmbientCoeff(command, args.m_lightAmbientCoeff); + } + + if (args.m_lightDiffuseCoeff>=0) { + b3RequestCameraImageSetLightDiffuseCoeff(command, args.m_lightDiffuseCoeff); + } + + if (args.m_lightSpecularCoeff>=0) { + b3RequestCameraImageSetLightSpecularCoeff(command, args.m_lightSpecularCoeff); + } + + if (args.m_renderer>=0) { + b3RequestCameraImageSelectRenderer(command, args.m_renderer); + } + + // Actually retrieve the image + if (b3CanSubmitCommand(m_data->m_physicsClientHandle)) { + b3SharedMemoryStatusHandle statusHandle; + int statusType; + + statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command); + statusType = b3GetStatusType(statusHandle); + if (statusType == CMD_CAMERA_IMAGE_COMPLETED) { + b3GetCameraImageData(m_data->m_physicsClientHandle, &imageData); + } + } else { + return false; + } + return true; +} + bool b3RobotSimulatorClientAPI_NoGUI::calculateInverseDynamics(int bodyUniqueId, double *jointPositions, double *jointVelocities, double *jointAccelerations, double *jointForcesOutput) {