fix flipped tinyrenderer image

This commit is contained in:
Erwin Coumans
2016-06-09 12:12:46 -07:00
parent e0c3392cee
commit 98d2f91f3c
3 changed files with 13 additions and 9 deletions

View File

@@ -631,7 +631,7 @@ void PhysicsClientExample::stepSimulation(float deltaTime)
int bytesPerPixel = 4; int bytesPerPixel = 4;
int pixelIndex = (xIndex+yIndex*imageData.m_pixelWidth)*bytesPerPixel; int pixelIndex = (xIndex+yIndex*imageData.m_pixelWidth)*bytesPerPixel;
m_canvas->setPixel(m_canvasIndex,i,camVisualizerHeight-1-j, m_canvas->setPixel(m_canvasIndex,i,j,
imageData.m_rgbColorData[pixelIndex], imageData.m_rgbColorData[pixelIndex],
imageData.m_rgbColorData[pixelIndex+1], imageData.m_rgbColorData[pixelIndex+1],

View File

@@ -580,7 +580,9 @@ void TinyRendererVisualShapeConverter::render(const float viewMat[16], const flo
} }
} }
//printf("write tga \n"); //printf("write tga \n");
m_data->m_rgbColorBuffer.write_tga_file("camera.tga"); //m_data->m_rgbColorBuffer.write_tga_file("camera.tga");
// printf("flipped!\n");
m_data->m_rgbColorBuffer.flip_vertically();
} }

View File

@@ -459,15 +459,16 @@ static PyObject* pybullet_renderImage(PyObject* self, PyObject* args)
} }
Py_DECREF(seq); Py_DECREF(seq);
if (valid)
{ {
b3SharedMemoryCommandHandle command; b3SharedMemoryCommandHandle command;
command = b3InitRequestCameraImage(sm); command = b3InitRequestCameraImage(sm);
if (valid)
{
//printf("set b3RequestCameraImageSetCameraMatrices\n"); //printf("set b3RequestCameraImageSetCameraMatrices\n");
b3RequestCameraImageSetCameraMatrices(command, viewMatrix, projectionMatrix); b3RequestCameraImageSetCameraMatrices(command, viewMatrix, projectionMatrix);
}
b3RequestCameraImageSetPixelResolution(command,width,height); b3RequestCameraImageSetPixelResolution(command,width,height);
if (b3CanSubmitCommand(sm)) if (b3CanSubmitCommand(sm))
@@ -489,24 +490,25 @@ static PyObject* pybullet_renderImage(PyObject* self, PyObject* args)
PyObject *pylistPos; PyObject *pylistPos;
PyObject* pylistDep; PyObject* pylistDep;
int i,j,p;
//printf("image width = %d, height = %d\n", imageData.m_pixelWidth, imageData.m_pixelHeight); //printf("image width = %d, height = %d\n", imageData.m_pixelWidth, imageData.m_pixelHeight);
{ {
PyObject *item; PyObject *item;
int bytesPerPixel = 3;//Red, Green, Blue, each 8 bit values int bytesPerPixel = 4;//Red, Green, Blue, each 8 bit values
int num=bytesPerPixel*imageData.m_pixelWidth*imageData.m_pixelHeight; int num=bytesPerPixel*imageData.m_pixelWidth*imageData.m_pixelHeight;
pylistPos = PyTuple_New(num); pylistPos = PyTuple_New(num);
pylistDep = PyTuple_New(imageData.m_pixelWidth*imageData.m_pixelHeight); pylistDep = PyTuple_New(imageData.m_pixelWidth*imageData.m_pixelHeight);
for (int i=0;i<imageData.m_pixelWidth;i++) for (i=0;i<imageData.m_pixelWidth;i++)
{ {
for (int j=0;j<imageData.m_pixelHeight;j++) for (j=0;j<imageData.m_pixelHeight;j++)
{ {
int depIndex = i+j*imageData.m_pixelWidth; int depIndex = i+j*imageData.m_pixelWidth;
item = PyFloat_FromDouble(imageData.m_depthValues[depIndex]); item = PyFloat_FromDouble(imageData.m_depthValues[depIndex]);
PyTuple_SetItem(pylistDep, depIndex, item); PyTuple_SetItem(pylistDep, depIndex, item);
for (int p=0;p<bytesPerPixel;p++) for (p=0;p<bytesPerPixel;p++)
{ {
int pixelIndex = bytesPerPixel*(i+j*imageData.m_pixelWidth)+p; int pixelIndex = bytesPerPixel*(i+j*imageData.m_pixelWidth)+p;
item = PyInt_FromLong(imageData.m_rgbColorData[pixelIndex]); item = PyInt_FromLong(imageData.m_rgbColorData[pixelIndex]);