mirror of
https://github.com/bulletphysics/bullet3
synced 2024-12-13 21:30:09 +00:00
Merge pull request #952 from YunfeiBai/master
Add depth image when using hardware renderer.
This commit is contained in:
commit
32b15d7aee
@ -36,6 +36,9 @@ struct CommonCameraInterface
|
||||
|
||||
virtual void setAspectRatio(float ratio) = 0;
|
||||
virtual float getAspectRatio() const = 0;
|
||||
|
||||
virtual float getCameraFrustumFar() const = 0;
|
||||
virtual float getCameraFrustumNear() const = 0;
|
||||
};
|
||||
|
||||
#endif //COMMON_CAMERA_INTERFACE_H
|
||||
|
@ -437,10 +437,15 @@ void OpenGLGuiHelper::copyCameraImageData(const float viewMatrix[16], const floa
|
||||
int bytesPerPixel = 4; //RGBA
|
||||
|
||||
int sourcePixelIndex = (xIndex+yIndex*sourceWidth)*bytesPerPixel;
|
||||
int sourceDepthIndex = xIndex+yIndex*sourceWidth;
|
||||
|
||||
m_data->m_rgbaPixelBuffer1[(i+j*destinationWidth)*4+0] = sourceRgbaPixelBuffer[sourcePixelIndex+0];
|
||||
m_data->m_rgbaPixelBuffer1[(i+j*destinationWidth)*4+1] = sourceRgbaPixelBuffer[sourcePixelIndex+1];
|
||||
m_data->m_rgbaPixelBuffer1[(i+j*destinationWidth)*4+2] = sourceRgbaPixelBuffer[sourcePixelIndex+2];
|
||||
m_data->m_rgbaPixelBuffer1[(i+j*destinationWidth)*4+3] = 255;
|
||||
|
||||
m_data->m_depthBuffer1[i+j*destinationWidth] = sourceDepthBuffer[sourceDepthIndex];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -456,7 +461,7 @@ void OpenGLGuiHelper::copyCameraImageData(const float viewMatrix[16], const floa
|
||||
{
|
||||
for (int i=0;i<numRequestedPixels;i++)
|
||||
{
|
||||
depthBuffer[i] = m_data->m_depthBuffer1[i];
|
||||
depthBuffer[i] = m_data->m_depthBuffer1[i+startPixelIndex];
|
||||
}
|
||||
}
|
||||
if (numPixelsCopied)
|
||||
|
@ -383,3 +383,13 @@ float SimpleCamera::getAspectRatio() const
|
||||
{
|
||||
return m_data->m_aspect;
|
||||
}
|
||||
|
||||
float SimpleCamera::getCameraFrustumFar() const
|
||||
{
|
||||
return m_data->m_frustumZFar;
|
||||
}
|
||||
|
||||
float SimpleCamera::getCameraFrustumNear() const
|
||||
{
|
||||
return m_data->m_frustumZNear;
|
||||
}
|
||||
|
@ -47,6 +47,9 @@ struct SimpleCamera : public CommonCameraInterface
|
||||
|
||||
virtual void setAspectRatio(float ratio);
|
||||
virtual float getAspectRatio() const;
|
||||
|
||||
virtual float getCameraFrustumFar() const;
|
||||
virtual float getCameraFrustumNear() const;
|
||||
};
|
||||
|
||||
#endif //SIMPLE_CAMERA_H
|
@ -958,7 +958,16 @@ void TinyRendererVisualShapeConverter::copyCameraImageData(unsigned char* pixels
|
||||
{
|
||||
if (depthBuffer)
|
||||
{
|
||||
depthBuffer[i] = m_data->m_depthBuffer[i+startPixelIndex];
|
||||
float distance = -m_data->m_depthBuffer[i+startPixelIndex];
|
||||
float farPlane = m_data->m_camera.getCameraFrustumFar();
|
||||
float nearPlane = m_data->m_camera.getCameraFrustumNear();
|
||||
|
||||
btClamp(distance,nearPlane,farPlane);
|
||||
|
||||
// the depth buffer value is between 0 and 1
|
||||
float a = farPlane / (farPlane - nearPlane);
|
||||
float b = farPlane * nearPlane / (nearPlane - farPlane);
|
||||
depthBuffer[i] = a + b / distance;
|
||||
}
|
||||
if (segmentationMaskBuffer)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user