diff --git a/examples/OpenGLWindow/SimpleCamera.cpp b/examples/OpenGLWindow/SimpleCamera.cpp index 76992ef90..db54b19fb 100644 --- a/examples/OpenGLWindow/SimpleCamera.cpp +++ b/examples/OpenGLWindow/SimpleCamera.cpp @@ -64,6 +64,20 @@ SimpleCamera::~SimpleCamera() void SimpleCamera::setVRCamera(const float viewMat[16], const float projectionMatrix[16]) { m_data->m_enableVR = true; + + b3Matrix3x3 vm; + vm.setValue(viewMat[0],viewMat[4],viewMat[8], + viewMat[1],viewMat[5],viewMat[9], + viewMat[2],viewMat[6],viewMat[10]); + + b3Vector3 vp = b3MakeVector3(viewMat[12],viewMat[13],viewMat[14]); + b3Transform tr; + tr.setBasis(vm); + tr.setOrigin(vp); + b3Transform cp = tr.inverse(); + m_data->m_cameraPosition = cp.getOrigin(); + + for (int i=0;i<16;i++) { m_data->m_viewMatrixVR[i] = viewMat[i]; diff --git a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp index 47d3b36b8..a459137b3 100644 --- a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp +++ b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp @@ -3509,17 +3509,50 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm int* segmentationMaskBuffer = (int*)(bufferServerToClient+numRequestedPixels*8); serverStatusOut.m_numDataStreamBytes = numRequestedPixels * totalBytesPerPixel; + float viewMat[16]; + float projMat[16]; + for (int i=0;i<16;i++) + { + viewMat[i] = clientCmd.m_requestPixelDataArguments.m_viewMatrix[i]; + projMat[i] = clientCmd.m_requestPixelDataArguments.m_projectionMatrix[i]; + } + if ((clientCmd.m_updateFlags & REQUEST_PIXEL_ARGS_HAS_CAMERA_MATRICES)==0) + { + b3OpenGLVisualizerCameraInfo tmpCamResult; + bool result = this->m_data->m_guiHelper->getCameraInfo( + &tmpCamResult.m_width, + &tmpCamResult.m_height, + tmpCamResult.m_viewMatrix, + tmpCamResult.m_projectionMatrix, + tmpCamResult.m_camUp, + tmpCamResult.m_camForward, + tmpCamResult.m_horizontal, + tmpCamResult.m_vertical, + &tmpCamResult.m_yaw, + &tmpCamResult.m_pitch, + &tmpCamResult.m_dist, + tmpCamResult.m_target); + if (result) + { + for (int i=0;i<16;i++) + { + viewMat[i] = tmpCamResult.m_viewMatrix[i]; + projMat[i] = tmpCamResult.m_projectionMatrix[i]; + } + } + } if ((clientCmd.m_updateFlags & ER_BULLET_HARDWARE_OPENGL)!=0) { - m_data->m_guiHelper->copyCameraImageData(clientCmd.m_requestPixelDataArguments.m_viewMatrix, - clientCmd.m_requestPixelDataArguments.m_projectionMatrix,pixelRGBA,numRequestedPixels, + + m_data->m_guiHelper->copyCameraImageData(viewMat, + projMat,pixelRGBA,numRequestedPixels, depthBuffer,numRequestedPixels, segmentationMaskBuffer, numRequestedPixels, startPixelIndex,width,height,&numPixelsCopied); - m_data->m_guiHelper->debugDisplayCameraImageData(clientCmd.m_requestPixelDataArguments.m_viewMatrix, - clientCmd.m_requestPixelDataArguments.m_projectionMatrix,pixelRGBA,numRequestedPixels, + m_data->m_guiHelper->debugDisplayCameraImageData(viewMat, + projMat,pixelRGBA,numRequestedPixels, depthBuffer,numRequestedPixels, 0, numRequestedPixels, startPixelIndex,width,height,&numPixelsCopied); diff --git a/examples/SharedMemory/TinyRendererVisualShapeConverter.cpp b/examples/SharedMemory/TinyRendererVisualShapeConverter.cpp index ee49f47d5..61ba6f719 100644 --- a/examples/SharedMemory/TinyRendererVisualShapeConverter.cpp +++ b/examples/SharedMemory/TinyRendererVisualShapeConverter.cpp @@ -46,6 +46,8 @@ struct MyTexture2 struct TinyRendererObjectArray { btAlignedObjectArray< TinyRenderObjectData*> m_renderObjects; + int m_objectUniqueId; + int m_linkIndex; }; #define START_WIDTH 640 @@ -596,8 +598,11 @@ void TinyRendererVisualShapeConverter::convertVisualShapes( m_data->m_swRenderInstances.insert(colObj,new TinyRendererObjectArray); } visualsPtr = m_data->m_swRenderInstances[colObj]; + btAssert(visualsPtr); TinyRendererObjectArray* visuals = *visualsPtr; + visuals->m_objectUniqueId = bodyUniqueId; + visuals->m_linkIndex = linkIndex; b3VisualShapeData visualShape; visualShape.m_objectUniqueId = bodyUniqueId; @@ -699,37 +704,41 @@ int TinyRendererVisualShapeConverter::getVisualShapesData(int bodyUniqueId, int return 0; } + + void TinyRendererVisualShapeConverter::changeRGBAColor(int bodyUniqueId, int linkIndex, const double rgbaColor[4]) { - int start = -1; - for (int i = 0; i < m_data->m_visualShapes.size(); i++) - { - if (m_data->m_visualShapes[i].m_objectUniqueId == bodyUniqueId && m_data->m_visualShapes[i].m_linkIndex == linkIndex) - { - start = i; + int start = -1; + for (int i = 0; i < m_data->m_visualShapes.size(); i++) + { + if (m_data->m_visualShapes[i].m_objectUniqueId == bodyUniqueId && m_data->m_visualShapes[i].m_linkIndex == linkIndex) + { m_data->m_visualShapes[i].m_rgbaColor[0] = rgbaColor[0]; m_data->m_visualShapes[i].m_rgbaColor[1] = rgbaColor[1]; m_data->m_visualShapes[i].m_rgbaColor[2] = rgbaColor[2]; m_data->m_visualShapes[i].m_rgbaColor[3] = rgbaColor[3]; - break; } - } - if (start>=0) + } + + for (int i=0;im_swRenderInstances.size();i++) { - TinyRendererObjectArray** visualArrayPtr = m_data->m_swRenderInstances.getAtIndex(start); - TinyRendererObjectArray* visualArray = *visualArrayPtr; - - btHashPtr colObjHash = m_data->m_swRenderInstances.getKeyAtIndex(start); - const btCollisionObject* colObj = (btCollisionObject*) colObjHash.getPointer(); - - float rgba[4] = {rgbaColor[0], rgbaColor[1], rgbaColor[2], rgbaColor[3]}; - for (int v=0;vm_renderObjects.size();v++) + TinyRendererObjectArray** ptrptr = m_data->m_swRenderInstances.getAtIndex(i); + if (ptrptr && *ptrptr) { - visualArray->m_renderObjects[v]->m_model->setColorRGBA(rgba); + float rgba[4] = {rgbaColor[0], rgbaColor[1], rgbaColor[2], rgbaColor[3]}; + TinyRendererObjectArray* visuals = *ptrptr; + if ((bodyUniqueId == visuals->m_objectUniqueId) && (linkIndex == visuals->m_linkIndex)) + { + for (int q=0;qm_renderObjects.size();q++) + { + visuals->m_renderObjects[q]->m_model->setColorRGBA(rgba); + } + } } } } + void TinyRendererVisualShapeConverter::setUpAxis(int axis) { m_data->m_upAxis = axis;