remove some warnings

This commit is contained in:
Erwin Coumans
2014-08-21 13:31:12 -07:00
parent 590504bf72
commit 4af9c5a4c9
24 changed files with 1136 additions and 1104 deletions

View File

@@ -124,7 +124,8 @@ static int loadCurrentDemoEntry(const char* startFileName)
FILE* f = fopen(startFileName,"r"); FILE* f = fopen(startFileName,"r");
if (f) if (f)
{ {
fscanf(f,"%d",&currentEntry); int result;
result = fscanf(f,"%d",&currentEntry);
fclose(f); fclose(f);
} }
return currentEntry; return currentEntry;

View File

@@ -5,7 +5,7 @@
#include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h" #include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
#define MSTRINGIFY(A) #A #define MSTRINGIFY(A) #A
static char* particleKernelsString = static const char* particleKernelsString =
#include "ParticleKernels.cl" #include "ParticleKernels.cl"
#define INTEROPKERNEL_SRC_PATH "demo/gpudemo/ParticleKernels.cl" #define INTEROPKERNEL_SRC_PATH "demo/gpudemo/ParticleKernels.cl"
@@ -40,7 +40,7 @@ static char* particleKernelsString =
//#define NUM_PARTICLES_Y 30 //#define NUM_PARTICLES_Y 30
//#define NUM_PARTICLES_Z 30 //#define NUM_PARTICLES_Z 30
B3_ATTRIBUTE_ALIGNED16(struct) b3SimParams B3_ATTRIBUTE_ALIGNED16(struct) b3SimParams
{ {
@@ -48,7 +48,7 @@ B3_ATTRIBUTE_ALIGNED16(struct) b3SimParams
b3Vector3 m_gravity; b3Vector3 m_gravity;
float m_worldMin[4]; float m_worldMin[4];
float m_worldMax[4]; float m_worldMax[4];
float m_particleRad; float m_particleRad;
float m_globalDamping; float m_globalDamping;
float m_boundaryDamping; float m_boundaryDamping;
@@ -59,7 +59,7 @@ B3_ATTRIBUTE_ALIGNED16(struct) b3SimParams
float m_attraction; float m_attraction;
float m_dummy; float m_dummy;
b3SimParams() b3SimParams()
{ {
m_gravity.setValue(0,-.3,0.f); m_gravity.setValue(0,-.3,0.f);
@@ -83,7 +83,7 @@ B3_ATTRIBUTE_ALIGNED16(struct) b3SimParams
struct ParticleInternalData struct ParticleInternalData
{ {
cl_kernel m_updatePositionsKernel; cl_kernel m_updatePositionsKernel;
cl_kernel m_updatePositionsKernel2; cl_kernel m_updatePositionsKernel2;
@@ -92,7 +92,7 @@ struct ParticleInternalData
cl_kernel m_collideParticlesKernel; cl_kernel m_collideParticlesKernel;
b3GpuSapBroadphase* m_broadphaseGPU; b3GpuSapBroadphase* m_broadphaseGPU;
cl_mem m_clPositionBuffer; cl_mem m_clPositionBuffer;
@@ -102,7 +102,7 @@ struct ParticleInternalData
b3AlignedObjectArray<b3SimParams> m_simParamCPU; b3AlignedObjectArray<b3SimParams> m_simParamCPU;
b3OpenCLArray<b3SimParams>* m_simParamGPU; b3OpenCLArray<b3SimParams>* m_simParamGPU;
ParticleInternalData() ParticleInternalData()
: :
@@ -144,7 +144,7 @@ void ParticleDemo::exitCL()
clReleaseKernel(m_data->m_updateAabbsKernel); clReleaseKernel(m_data->m_updateAabbsKernel);
clReleaseKernel(m_data->m_collideParticlesKernel); clReleaseKernel(m_data->m_collideParticlesKernel);
} }
GpuDemo::exitCL(); GpuDemo::exitCL();
} }
@@ -158,12 +158,12 @@ void ParticleDemo::setupScene(const ConstructionInfo& ci)
{ {
initCL(ci.preferredOpenCLDeviceIndex,ci.preferredOpenCLPlatformIndex); initCL(ci.preferredOpenCLDeviceIndex,ci.preferredOpenCLPlatformIndex);
int numParticles = NUM_PARTICLES_X*NUM_PARTICLES_Y*NUM_PARTICLES_Z; int numParticles = NUM_PARTICLES_X*NUM_PARTICLES_Y*NUM_PARTICLES_Z;
int maxObjects = NUM_PARTICLES_X*NUM_PARTICLES_Y*NUM_PARTICLES_Z+1024; int maxObjects = NUM_PARTICLES_X*NUM_PARTICLES_Y*NUM_PARTICLES_Z+1024;
int maxPairsSmallProxy = 32; int maxPairsSmallProxy = 32;
float radius = m_data->m_simParamCPU[0].m_particleRad; float radius = m_data->m_simParamCPU[0].m_particleRad;
@@ -219,15 +219,15 @@ void ParticleDemo::setupScene(const ConstructionInfo& ci)
float position[4] = {0,0,0,0}; float position[4] = {0,0,0,0};
float quaternion[4] = {0,0,0,1}; float quaternion[4] = {0,0,0,1};
float scaling[4] = {radius,radius,radius,1}; float scaling[4] = {radius,radius,radius,1};
int userIndex = 0; int userIndex = 0;
int totalParticles = NUM_PARTICLES_X*NUM_PARTICLES_Y*NUM_PARTICLES_Z; int totalParticles = NUM_PARTICLES_X*NUM_PARTICLES_Y*NUM_PARTICLES_Z;
int curColor = 0; int curColor = 0;
b3Vector4 colors[4] = b3Vector4 colors[4] =
{ {
b3MakeVector4(1,1,1,1), b3MakeVector4(1,1,1,1),
b3MakeVector4(1,1,0.3,1), b3MakeVector4(1,1,0.3,1),
@@ -241,9 +241,9 @@ void ParticleDemo::setupScene(const ConstructionInfo& ci)
float angle = b3RandRange(-B3_PI, B3_PI); float angle = b3RandRange(-B3_PI, B3_PI);
for (int ii=0;ii<totalParticles;ii++) for (int ii=0;ii<totalParticles;ii++)
{ {
float arg = b3RandRange(-B3_PI,B3_PI); float arg = b3RandRange(-B3_PI,B3_PI);
float rad = m_data->m_simParamCPU[0].m_particleRad; float rad = m_data->m_simParamCPU[0].m_particleRad;
position[0] = arg*b3Cos(arg + angle); position[0] = arg*b3Cos(arg + angle);
position[1] = 3.0f + arg; position[1] = 3.0f + arg;
@@ -255,8 +255,8 @@ void ParticleDemo::setupScene(const ConstructionInfo& ci)
int id = m_instancingRenderer->registerGraphicsInstance(shapeId,position,quaternion,color,scaling); int id = m_instancingRenderer->registerGraphicsInstance(shapeId,position,quaternion,color,scaling);
void* userPtr = (void*)userIndex;
int collidableIndex = userIndex; int collidableIndex = userIndex;
b3Vector3 aabbMin,aabbMax; b3Vector3 aabbMin,aabbMax;
b3Vector3 particleRadius=b3MakeVector3(rad,rad,rad); b3Vector3 particleRadius=b3MakeVector3(rad,rad,rad);
@@ -268,7 +268,7 @@ void ParticleDemo::setupScene(const ConstructionInfo& ci)
angle += b3RandRange(-(float)B3_PI, (float)B3_PI); angle += b3RandRange(-(float)B3_PI, (float)B3_PI);
} }
} }
m_data->m_broadphaseGPU->writeAabbsToGpu(); m_data->m_broadphaseGPU->writeAabbsToGpu();
@@ -291,7 +291,7 @@ void ParticleDemo::exitPhysics()
void ParticleDemo::renderScene() void ParticleDemo::renderScene()
{ {
if (m_instancingRenderer) if (m_instancingRenderer)
{ {
m_instancingRenderer->renderScene(); m_instancingRenderer->renderScene();
@@ -315,7 +315,7 @@ void ParticleDemo::clientMoveAndDisplay()
assert(err==GL_NO_ERROR); assert(err==GL_NO_ERROR);
glFinish(); glFinish();
#if 1 #if 1
@@ -326,10 +326,10 @@ void ParticleDemo::clientMoveAndDisplay()
bool useCpu = false; bool useCpu = false;
if (useCpu) if (useCpu)
{ {
float* posBuffer = (float*)hostPtr; float* posBuffer = (float*)hostPtr;
for (int i=0;i<numParticles;i++) for (int i=0;i<numParticles;i++)
{ {
posBuffer[i*4+1] += 0.1; posBuffer[i*4+1] += 0.1;
@@ -350,19 +350,19 @@ void ParticleDemo::clientMoveAndDisplay()
); );
clFinish(m_clData->m_clQueue); clFinish(m_clData->m_clQueue);
} }
if (0) if (0)
{ {
b3BufferInfoCL bInfo[] = { b3BufferInfoCL bInfo[] = {
b3BufferInfoCL( m_data->m_velocitiesGPU->getBufferCL(), true ), b3BufferInfoCL( m_data->m_velocitiesGPU->getBufferCL(), true ),
b3BufferInfoCL( m_data->m_clPositionBuffer) b3BufferInfoCL( m_data->m_clPositionBuffer)
}; };
b3LauncherCL launcher(m_clData->m_clQueue, m_data->m_updatePositionsKernel,"m_updatePositionsKernel" ); b3LauncherCL launcher(m_clData->m_clQueue, m_data->m_updatePositionsKernel,"m_updatePositionsKernel" );
launcher.setBuffers( bInfo, sizeof(bInfo)/sizeof(b3BufferInfoCL) ); launcher.setBuffers( bInfo, sizeof(bInfo)/sizeof(b3BufferInfoCL) );
@@ -370,18 +370,18 @@ void ParticleDemo::clientMoveAndDisplay()
launcher.launch1D( numParticles); launcher.launch1D( numParticles);
clFinish(m_clData->m_clQueue); clFinish(m_clData->m_clQueue);
} }
if (1) if (1)
{ {
b3BufferInfoCL bInfo[] = { b3BufferInfoCL bInfo[] = {
b3BufferInfoCL( m_data->m_clPositionBuffer), b3BufferInfoCL( m_data->m_clPositionBuffer),
b3BufferInfoCL( m_data->m_velocitiesGPU->getBufferCL() ), b3BufferInfoCL( m_data->m_velocitiesGPU->getBufferCL() ),
b3BufferInfoCL( m_data->m_simParamGPU->getBufferCL(),true) b3BufferInfoCL( m_data->m_simParamGPU->getBufferCL(),true)
}; };
b3LauncherCL launcher(m_clData->m_clQueue, m_data->m_updatePositionsKernel2 ,"m_updatePositionsKernel2"); b3LauncherCL launcher(m_clData->m_clQueue, m_data->m_updatePositionsKernel2 ,"m_updatePositionsKernel2");
launcher.setConst( numParticles); launcher.setConst( numParticles);
@@ -391,21 +391,21 @@ void ParticleDemo::clientMoveAndDisplay()
launcher.launch1D( numParticles); launcher.launch1D( numParticles);
clFinish(m_clData->m_clQueue); clFinish(m_clData->m_clQueue);
} }
if (0) if (0)
{ {
b3BufferInfoCL bInfo[] = { b3BufferInfoCL bInfo[] = {
b3BufferInfoCL( m_data->m_clPositionBuffer), b3BufferInfoCL( m_data->m_clPositionBuffer),
b3BufferInfoCL( m_data->m_broadphaseGPU->getAabbBufferWS()), b3BufferInfoCL( m_data->m_broadphaseGPU->getAabbBufferWS()),
}; };
b3LauncherCL launcher(m_clData->m_clQueue, m_data->m_updateAabbsKernel,"m_updateAabbsKernel" ); b3LauncherCL launcher(m_clData->m_clQueue, m_data->m_updateAabbsKernel,"m_updateAabbsKernel" );
launcher.setBuffers( bInfo, sizeof(bInfo)/sizeof(b3BufferInfoCL) ); launcher.setBuffers( bInfo, sizeof(bInfo)/sizeof(b3BufferInfoCL) );
launcher.setConst( m_data->m_simParamCPU[0].m_particleRad); launcher.setConst( m_data->m_simParamCPU[0].m_particleRad);
launcher.setConst( numParticles); launcher.setConst( numParticles);
launcher.launch1D( numParticles); launcher.launch1D( numParticles);
clFinish(m_clData->m_clQueue); clFinish(m_clData->m_clQueue);
} }
@@ -422,12 +422,12 @@ void ParticleDemo::clientMoveAndDisplay()
if (numPairsGPU) if (numPairsGPU)
{ {
b3BufferInfoCL bInfo[] = { b3BufferInfoCL bInfo[] = {
b3BufferInfoCL( m_data->m_clPositionBuffer), b3BufferInfoCL( m_data->m_clPositionBuffer),
b3BufferInfoCL( m_data->m_velocitiesGPU->getBufferCL() ), b3BufferInfoCL( m_data->m_velocitiesGPU->getBufferCL() ),
b3BufferInfoCL( m_data->m_broadphaseGPU->getOverlappingPairBuffer(),true), b3BufferInfoCL( m_data->m_broadphaseGPU->getOverlappingPairBuffer(),true),
}; };
b3LauncherCL launcher(m_clData->m_clQueue, m_data->m_collideParticlesKernel,"m_collideParticlesKernel"); b3LauncherCL launcher(m_clData->m_clQueue, m_data->m_collideParticlesKernel,"m_collideParticlesKernel");
launcher.setBuffers( bInfo, sizeof(bInfo)/sizeof(b3BufferInfoCL) ); launcher.setBuffers( bInfo, sizeof(bInfo)/sizeof(b3BufferInfoCL) );
launcher.setConst( numPairsGPU); launcher.setConst( numPairsGPU);
@@ -450,15 +450,15 @@ void ParticleDemo::clientMoveAndDisplay()
//clReleaseMemObject(clBuffer); //clReleaseMemObject(clBuffer);
clFinish(m_clData->m_clQueue); clFinish(m_clData->m_clQueue);
} }
} }
#endif #endif
glUnmapBuffer( GL_ARRAY_BUFFER); glUnmapBuffer( GL_ARRAY_BUFFER);
glFlush(); glFlush();
} }

View File

@@ -94,7 +94,8 @@ static int loadCurrentDemoEntry(const char* startFileName)
FILE* f = fopen(startFileName,"r"); FILE* f = fopen(startFileName,"r");
if (f) if (f)
{ {
fscanf(f,"%d",&currentEntry); int bytesScanned;
bytesScanned = fscanf(f,"%d",&currentEntry);
fclose(f); fclose(f);
} }
return currentEntry; return currentEntry;
@@ -130,20 +131,20 @@ int selectedDemo = 1;
GpuDemo::CreateFunc* allDemos[]= GpuDemo::CreateFunc* allDemos[]=
{ {
//ConcaveCompound2Scene::MyCreateFunc, //ConcaveCompound2Scene::MyCreateFunc,
//ConcaveSphereScene::MyCreateFunc, //ConcaveSphereScene::MyCreateFunc,
// ConcaveSphereScene::MyCreateFunc, // ConcaveSphereScene::MyCreateFunc,
ConcaveScene::MyCreateFunc, ConcaveScene::MyCreateFunc,
GpuBoxPlaneScene::MyCreateFunc, GpuBoxPlaneScene::MyCreateFunc,
GpuConstraintsDemo::MyCreateFunc, GpuConstraintsDemo::MyCreateFunc,
//GpuConvexPlaneScene::MyCreateFunc, //GpuConvexPlaneScene::MyCreateFunc,
@@ -155,14 +156,14 @@ GpuDemo::CreateFunc* allDemos[]=
GpuSphereScene::MyCreateFunc, GpuSphereScene::MyCreateFunc,
ConcaveSphereScene::MyCreateFunc, ConcaveSphereScene::MyCreateFunc,
ConcaveCompoundScene::MyCreateFunc, ConcaveCompoundScene::MyCreateFunc,
//GpuTetraScene::MyCreateFunc, //GpuTetraScene::MyCreateFunc,
@@ -170,7 +171,7 @@ GpuDemo::CreateFunc* allDemos[]=
Bullet2FileDemo::MyCreateFunc, Bullet2FileDemo::MyCreateFunc,
PairBench::MyCreateFunc, PairBench::MyCreateFunc,
GpuRaytraceScene::MyCreateFunc, GpuRaytraceScene::MyCreateFunc,
@@ -534,7 +535,7 @@ FILE* defaultOutput = stdout;
void myprintf(const char* msg) void myprintf(const char* msg)
{ {
fprintf(defaultOutput,msg); fprintf(defaultOutput,"%s",msg);
} }
@@ -560,7 +561,7 @@ void writeTextureToPng(int textureWidth, int textureHeight, const char* fileName
char* pixels = (char*)malloc(textureWidth*textureHeight*numComponents); char* pixels = (char*)malloc(textureWidth*textureHeight*numComponents);
err=glGetError(); err=glGetError();
assert(err==GL_NO_ERROR); assert(err==GL_NO_ERROR);
for (int j=0;j<textureHeight;j++) for (int j=0;j<textureHeight;j++)
{ {
for (int i=0;i<textureWidth;i++) for (int i=0;i<textureWidth;i++)
@@ -576,7 +577,7 @@ void writeTextureToPng(int textureWidth, int textureHeight, const char* fileName
{ {
//swap the pixels //swap the pixels
unsigned char tmp; unsigned char tmp;
for (int j=0;j<textureHeight/2;j++) for (int j=0;j<textureHeight/2;j++)
{ {
for (int i=0;i<textureWidth;i++) for (int i=0;i<textureWidth;i++)
@@ -591,9 +592,9 @@ void writeTextureToPng(int textureWidth, int textureHeight, const char* fileName
} }
} }
} }
stbi_write_png(fileName, textureWidth,textureHeight, numComponents, pixels, textureWidth*numComponents); stbi_write_png(fileName, textureWidth,textureHeight, numComponents, pixels, textureWidth*numComponents);
free(pixels); free(pixels);
free(orgPixels); free(orgPixels);
@@ -615,7 +616,7 @@ int main(int argc, char* argv[])
int sz6 = sizeof(b3Transform); int sz6 = sizeof(b3Transform);
//b3OpenCLUtils::setCachePath("/Users/erwincoumans/develop/mycache"); //b3OpenCLUtils::setCachePath("/Users/erwincoumans/develop/mycache");
b3SetCustomEnterProfileZoneFunc(b3ProfileManager::Start_Profile); b3SetCustomEnterProfileZoneFunc(b3ProfileManager::Start_Profile);
b3SetCustomLeaveProfileZoneFunc(b3ProfileManager::Stop_Profile); b3SetCustomLeaveProfileZoneFunc(b3ProfileManager::Stop_Profile);
@@ -699,7 +700,7 @@ int main(int argc, char* argv[])
gDebugForceLoadingFromSource = args.CheckCmdLineFlag("load_cl_kernels_from_disk"); gDebugForceLoadingFromSource = args.CheckCmdLineFlag("load_cl_kernels_from_disk");
gDebugSkipLoadingBinary = args.CheckCmdLineFlag("disable_cached_cl_kernels"); gDebugSkipLoadingBinary = args.CheckCmdLineFlag("disable_cached_cl_kernels");
#ifndef B3_NO_PROFILE #ifndef B3_NO_PROFILE
b3ProfileManager::Reset(); b3ProfileManager::Reset();
@@ -719,7 +720,7 @@ int main(int argc, char* argv[])
window->setWindowTitle("Bullet 3.x GPU Rigid Body http://bulletphysics.org"); window->setWindowTitle("Bullet 3.x GPU Rigid Body http://bulletphysics.org");
printf("-----------------------------------------------------\n"); printf("-----------------------------------------------------\n");
#ifndef __APPLE__ #ifndef __APPLE__
@@ -732,7 +733,7 @@ int main(int argc, char* argv[])
GLPrimitiveRenderer prim(g_OpenGLWidth,g_OpenGLHeight); GLPrimitiveRenderer prim(g_OpenGLWidth,g_OpenGLHeight);
stash = initFont(&prim); stash = initFont(&prim);
@@ -782,7 +783,7 @@ int main(int argc, char* argv[])
glClearColor(1,1,1,1); glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);//|GL_STENCIL_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);//|GL_STENCIL_BUFFER_BIT);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
sth_begin_draw(stash); sth_begin_draw(stash);
//sth_draw_text(stash, droidRegular,12.f, dx, dy-50, "How does this OpenGL True Type font look? ", &dx,width,height); //sth_draw_text(stash, droidRegular,12.f, dx, dy-50, "How does this OpenGL True Type font look? ", &dx,width,height);
int spacing = 0;//g_OpenGLHeight; int spacing = 0;//g_OpenGLHeight;
@@ -820,13 +821,13 @@ int main(int argc, char* argv[])
for (int i=0;i<nummsg;i++) for (int i=0;i<nummsg;i++)
{ {
char txt[512]; char txt[512];
sprintf(txt,msg[i]); sprintf(txt,"%s",msg[i]);
//sth_draw_text(stash, droidRegular,i, 10, dy-spacing, txt, &dx,g_OpenGLWidth,g_OpenGLHeight); //sth_draw_text(stash, droidRegular,i, 10, dy-spacing, txt, &dx,g_OpenGLWidth,g_OpenGLHeight);
sth_draw_text(stash, droidRegular,fontSize, 10, spacing, txt, &dx,g_OpenGLWidth,g_OpenGLHeight); sth_draw_text(stash, droidRegular,fontSize, 10, spacing, txt, &dx,g_OpenGLWidth,g_OpenGLHeight);
spacing+=fontSize; spacing+=fontSize;
fontSize = 32; fontSize = 32;
} }
sth_end_draw(stash); sth_end_draw(stash);
sth_flush_draw(stash); sth_flush_draw(stash);
window->endRendering(); window->endRendering();
@@ -852,7 +853,7 @@ int main(int argc, char* argv[])
// demo->myinit(); // demo->myinit();
bool useGpu = false; bool useGpu = false;
//int maxObjectCapacity=128*1024; //int maxObjectCapacity=128*1024;
int maxObjectCapacity=1024*1024; int maxObjectCapacity=1024*1024;
maxObjectCapacity = b3Max(maxObjectCapacity,ci.arraySizeX*ci.arraySizeX*ci.arraySizeX+10); maxObjectCapacity = b3Max(maxObjectCapacity,ci.arraySizeX*ci.arraySizeX*ci.arraySizeX+10);
@@ -874,7 +875,7 @@ int main(int argc, char* argv[])
printf("-----------------------------------------------------\n"); printf("-----------------------------------------------------\n");
@@ -883,14 +884,14 @@ int main(int argc, char* argv[])
if (benchmark) if (benchmark)
{ {
char prefixFileName[1024]; char prefixFileName[1024];
char csvFileName[1024]; char csvFileName[1024];
char detailsFileName[1024]; char detailsFileName[1024];
b3OpenCLDeviceInfo info; b3OpenCLDeviceInfo info;
b3OpenCLUtils::getDeviceInfo(demo->getInternalData()->m_clDevice,&info); b3OpenCLUtils::getDeviceInfo(demo->getInternalData()->m_clDevice,&info);
//todo: move this time stuff into the Platform/Window class //todo: move this time stuff into the Platform/Window class
#ifdef _WIN32 #ifdef _WIN32
SYSTEMTIME time; SYSTEMTIME time;
@@ -906,11 +907,11 @@ int main(int argc, char* argv[])
} }
sprintf(prefixFileName,"%s_%s_%s_%d_%d_%d_date_%d-%d-%d_time_%d-%d-%d",info.m_deviceName,buf,demoNames[selectedDemo],ci.arraySizeX,ci.arraySizeY,ci.arraySizeZ,time.wDay,time.wMonth,time.wYear,time.wHour,time.wMinute,time.wSecond); sprintf(prefixFileName,"%s_%s_%s_%d_%d_%d_date_%d-%d-%d_time_%d-%d-%d",info.m_deviceName,buf,demoNames[selectedDemo],ci.arraySizeX,ci.arraySizeY,ci.arraySizeZ,time.wDay,time.wMonth,time.wYear,time.wHour,time.wMinute,time.wSecond);
#else #else
timeval now; timeval now;
gettimeofday(&now,0); gettimeofday(&now,0);
struct tm* ptm; struct tm* ptm;
ptm = localtime (&now.tv_sec); ptm = localtime (&now.tv_sec);
char buf[1024]; char buf[1024];
@@ -926,7 +927,7 @@ int main(int argc, char* argv[])
ptm->tm_hour, ptm->tm_hour,
ptm->tm_min, ptm->tm_min,
ptm->tm_sec); ptm->tm_sec);
#endif #endif
sprintf(csvFileName,"%s.csv",prefixFileName); sprintf(csvFileName,"%s.csv",prefixFileName);
@@ -944,7 +945,7 @@ int main(int argc, char* argv[])
// fprintf(f,"%s (%dx%dx%d=%d),\n", g_deviceName,ci.arraySizeX,ci.arraySizeY,ci.arraySizeZ,ci.arraySizeX*ci.arraySizeY*ci.arraySizeZ); // fprintf(f,"%s (%dx%dx%d=%d),\n", g_deviceName,ci.arraySizeX,ci.arraySizeY,ci.arraySizeZ,ci.arraySizeX*ci.arraySizeY*ci.arraySizeZ);
} }
fprintf(defaultOutput,"Demo settings:\n"); fprintf(defaultOutput,"Demo settings:\n");
fprintf(defaultOutput," SelectedDemo=%d, demoname = %s\n", selectedDemo, demo->getName()); fprintf(defaultOutput," SelectedDemo=%d, demoname = %s\n", selectedDemo, demo->getName());
fprintf(defaultOutput," x_dim=%d, y_dim=%d, z_dim=%d\n",ci.arraySizeX,ci.arraySizeY,ci.arraySizeZ); fprintf(defaultOutput," x_dim=%d, y_dim=%d, z_dim=%d\n",ci.arraySizeX,ci.arraySizeY,ci.arraySizeZ);
@@ -971,7 +972,7 @@ int main(int argc, char* argv[])
if (exportFrame || exportMovie) if (exportFrame || exportMovie)
{ {
if (!renderTexture) if (!renderTexture)
{ {
renderTexture = new GLRenderToTexture(); renderTexture = new GLRenderToTexture();
@@ -993,10 +994,10 @@ int main(int argc, char* argv[])
renderTexture->init(g_OpenGLWidth,g_OpenGLHeight,renderTextureId, RENDERTEXTURE_COLOR); renderTexture->init(g_OpenGLWidth,g_OpenGLHeight,renderTextureId, RENDERTEXTURE_COLOR);
} }
bool result = renderTexture->enable(); bool result = renderTexture->enable();
} }
err = glGetError(); err = glGetError();
assert(err==GL_NO_ERROR); assert(err==GL_NO_ERROR);
@@ -1052,10 +1053,10 @@ int main(int argc, char* argv[])
} }
*/ */
if (exportFrame || exportMovie) if (exportFrame || exportMovie)
{ {
char fileName[1024]; char fileName[1024];
sprintf(fileName,"screenShot%d.png",frameIndex++); sprintf(fileName,"screenShot%d.png",frameIndex++);
writeTextureToPng(g_OpenGLWidth,g_OpenGLHeight,fileName); writeTextureToPng(g_OpenGLWidth,g_OpenGLHeight,fileName);
@@ -1085,7 +1086,7 @@ int main(int argc, char* argv[])
B3_PROFILE("glFinish"); B3_PROFILE("glFinish");
} }
if (dump_timings) if (dump_timings)
{ {
@@ -1147,7 +1148,7 @@ int main(int argc, char* argv[])
{ {
delete gui; delete gui;
gui=0; gui=0;

View File

@@ -27,7 +27,7 @@ extern bool enableExperimentalCpuConcaveCollision;
#include "Bullet3OpenCL/RigidBody/b3GpuRigidBodyPipeline.h" #include "Bullet3OpenCL/RigidBody/b3GpuRigidBodyPipeline.h"
#include "Bullet3OpenCL/RigidBody/b3GpuNarrowPhase.h" #include "Bullet3OpenCL/RigidBody/b3GpuNarrowPhase.h"
///work-in-progress ///work-in-progress
///This ReadBulletSample is kept as simple as possible without dependencies to the Bullet SDK. ///This ReadBulletSample is kept as simple as possible without dependencies to the Bullet SDK.
///It can be used to load .bullet data for other physics SDKs ///It can be used to load .bullet data for other physics SDKs
///For a more complete example how to load and convert Bullet data using the Bullet SDK check out ///For a more complete example how to load and convert Bullet data using the Bullet SDK check out
@@ -66,23 +66,23 @@ void createScene( GLInstancingRenderer& renderer,b3GpuNarrowPhase& np, b3GpuRigi
//const char* fileName="../../bin/1000 convex.bullet"; //const char* fileName="../../bin/1000 convex.bullet";
//const char* fileName="../../bin/1000 stack.bullet"; //const char* fileName="../../bin/1000 stack.bullet";
//const char* fileName="../../bin/3000 fall.bullet"; //const char* fileName="../../bin/3000 fall.bullet";
//const char* fileName="../../bin/testFile.bullet"; //const char* fileName="../../bin/testFile.bullet";
FILE* f = fopen(fileName,"rb"); FILE* f = fopen(fileName,"rb");
if (f) if (f)
{ {
fclose(f); fclose(f);
bool verboseDumpAllTypes = false; bool verboseDumpAllTypes = false;
bParse::b3BulletFile* bulletFile2 = new bParse::b3BulletFile(fileName); bParse::b3BulletFile* bulletFile2 = new bParse::b3BulletFile(fileName);
bool ok = (bulletFile2->getFlags()& bParse::FD_OK)!=0; bool ok = (bulletFile2->getFlags()& bParse::FD_OK)!=0;
if (ok) if (ok)
bulletFile2->parse(verboseDumpAllTypes); bulletFile2->parse(verboseDumpAllTypes);
else else
@@ -99,7 +99,7 @@ void createScene( GLInstancingRenderer& renderer,b3GpuNarrowPhase& np, b3GpuRigi
printf("Error parsing file %s.\n",fileName); printf("Error parsing file %s.\n",fileName);
exit(0); exit(0);
} }
if (verboseDumpAllTypes) if (verboseDumpAllTypes)
{ {
bulletFile2->dumpChunks(bulletFile2->getFileDNA()); bulletFile2->dumpChunks(bulletFile2->getFileDNA());
@@ -107,7 +107,7 @@ void createScene( GLInstancingRenderer& renderer,b3GpuNarrowPhase& np, b3GpuRigi
b3BulletDataExtractor extractor(renderer,np,rbWorld); b3BulletDataExtractor extractor(renderer,np,rbWorld);
extractor.convertAllObjects(bulletFile2); extractor.convertAllObjects(bulletFile2);
delete bulletFile2; delete bulletFile2;
return; return;
@@ -163,7 +163,7 @@ CONCAVE_SHAPES_START_HERE,
GIMPACT_SHAPE_PROXYTYPE, GIMPACT_SHAPE_PROXYTYPE,
///Multimaterial mesh ///Multimaterial mesh
MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE, MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE,
EMPTY_SHAPE_PROXYTYPE, EMPTY_SHAPE_PROXYTYPE,
STATIC_PLANE_PROXYTYPE, STATIC_PLANE_PROXYTYPE,
CUSTOM_CONCAVE_SHAPE_TYPE, CUSTOM_CONCAVE_SHAPE_TYPE,
@@ -177,7 +177,7 @@ CONCAVE_SHAPES_END_HERE,
INVALID_SHAPE_PROXYTYPE, INVALID_SHAPE_PROXYTYPE,
MAX_BROADPHASE_COLLISION_TYPES MAX_BROADPHASE_COLLISION_TYPES
}; };
b3BulletDataExtractor::b3BulletDataExtractor(GLInstancingRenderer& renderer, b3GpuNarrowPhase& np, b3GpuRigidBodyPipeline& rbWorld) b3BulletDataExtractor::b3BulletDataExtractor(GLInstancingRenderer& renderer, b3GpuNarrowPhase& np, b3GpuRigidBodyPipeline& rbWorld)
@@ -214,7 +214,7 @@ void b3BulletDataExtractor::convertAllObjects(bParse::b3BulletFile* bulletFile2)
for (i=0;i<bulletFile2->m_rigidBodies.size();i++) for (i=0;i<bulletFile2->m_rigidBodies.size();i++)
{ {
Bullet3SerializeBullet2::b3RigidBodyFloatData* colObjData = (Bullet3SerializeBullet2::b3RigidBodyFloatData*)bulletFile2->m_rigidBodies[i]; Bullet3SerializeBullet2::b3RigidBodyFloatData* colObjData = (Bullet3SerializeBullet2::b3RigidBodyFloatData*)bulletFile2->m_rigidBodies[i];
Bullet3SerializeBullet2::b3CollisionShapeData* shapeData = (Bullet3SerializeBullet2::b3CollisionShapeData*)colObjData->m_collisionObjectData.m_collisionShape; Bullet3SerializeBullet2::b3CollisionShapeData* shapeData = (Bullet3SerializeBullet2::b3CollisionShapeData*)colObjData->m_collisionObjectData.m_collisionShape;
for (int j=0;j<m_instanceGroups.size();j++) for (int j=0;j<m_instanceGroups.size();j++)
@@ -237,7 +237,7 @@ void b3BulletDataExtractor::convertAllObjects(bParse::b3BulletFile* bulletFile2)
for (int j=0;j<m_instanceGroups[i]->m_rigidBodies.size();j++) for (int j=0;j<m_instanceGroups[i]->m_rigidBodies.size();j++)
{ {
Bullet3SerializeBullet2::b3RigidBodyFloatData* colObjData = (Bullet3SerializeBullet2::b3RigidBodyFloatData*)m_instanceGroups[i]->m_rigidBodies[j]; Bullet3SerializeBullet2::b3RigidBodyFloatData* colObjData = (Bullet3SerializeBullet2::b3RigidBodyFloatData*)m_instanceGroups[i]->m_rigidBodies[j];
b3Matrix3x3 mat; b3Matrix3x3 mat;
mat.deSerializeFloat((const b3Matrix3x3FloatData&)colObjData->m_collisionObjectData.m_worldTransform.m_basis); mat.deSerializeFloat((const b3Matrix3x3FloatData&)colObjData->m_collisionObjectData.m_worldTransform.m_basis);
b3Quaternion orn; b3Quaternion orn;
@@ -259,23 +259,23 @@ void b3BulletDataExtractor::convertAllObjects(bParse::b3BulletFile* bulletFile2)
} }
if (keepStaticObjects || colObjData->m_inverseMass!=0.f) if (keepStaticObjects || colObjData->m_inverseMass!=0.f)
{ {
m_rbPipeline.registerPhysicsInstance(mass,pos,quaternion,m_instanceGroups[i]->m_collisionShapeIndex,0,true); m_rbPipeline.registerPhysicsInstance(mass,pos,quaternion,m_instanceGroups[i]->m_collisionShapeIndex,0,true);
m_renderer.registerGraphicsInstance(m_instanceGroups[i]->m_collisionShapeIndex,pos,quaternion,color,m_graphicsShapes[i]->m_scaling); m_renderer.registerGraphicsInstance(m_instanceGroups[i]->m_collisionShapeIndex,pos,quaternion,color,m_graphicsShapes[i]->m_scaling);
} }
} }
} }
} }
for (i=0;i<bulletFile2->m_collisionObjects.size();i++) for (i=0;i<bulletFile2->m_collisionObjects.size();i++)
{ {
} }
m_rbPipeline.writeAllInstancesToGpu(); m_rbPipeline.writeAllInstancesToGpu();
} }
@@ -303,7 +303,7 @@ int b3BulletDataExtractor::convertCollisionShape( Bullet3SerializeBullet2::b3Co
case CONVEX_HULL_SHAPE_PROXYTYPE: case CONVEX_HULL_SHAPE_PROXYTYPE:
{ {
Bullet3SerializeBullet2::b3ConvexInternalShapeData* bsd = (Bullet3SerializeBullet2::b3ConvexInternalShapeData*)shapeData; Bullet3SerializeBullet2::b3ConvexInternalShapeData* bsd = (Bullet3SerializeBullet2::b3ConvexInternalShapeData*)shapeData;
switch (shapeData->m_shapeType) switch (shapeData->m_shapeType)
{ {
case BOX_SHAPE_PROXYTYPE: case BOX_SHAPE_PROXYTYPE:
@@ -331,7 +331,7 @@ int b3BulletDataExtractor::convertCollisionShape( Bullet3SerializeBullet2::b3Co
b3Vector3 pt = b3MakeVector3(convexData->m_unscaledPointsFloatPtr[i].m_floats[0], b3Vector3 pt = b3MakeVector3(convexData->m_unscaledPointsFloatPtr[i].m_floats[0],
convexData->m_unscaledPointsFloatPtr[i].m_floats[1], convexData->m_unscaledPointsFloatPtr[i].m_floats[1],
convexData->m_unscaledPointsFloatPtr[i].m_floats[2]);//convexData->m_unscaledPointsFloatPtr[i].m_floats[3]); convexData->m_unscaledPointsFloatPtr[i].m_floats[2]);//convexData->m_unscaledPointsFloatPtr[i].m_floats[3]);
tmpPoints.push_back(pt*localScaling); tmpPoints.push_back(pt*localScaling);
} }
} }
@@ -378,7 +378,7 @@ int b3BulletDataExtractor::convertCollisionShape( Bullet3SerializeBullet2::b3Co
} }
}; };
break; break;
} }
case CYLINDER_SHAPE_PROXYTYPE: case CYLINDER_SHAPE_PROXYTYPE:
@@ -408,9 +408,9 @@ int b3BulletDataExtractor::convertCollisionShape( Bullet3SerializeBullet2::b3Co
} }
}; };
break; break;
} }
case MULTI_SPHERE_SHAPE_PROXYTYPE: case MULTI_SPHERE_SHAPE_PROXYTYPE:
@@ -426,7 +426,7 @@ int b3BulletDataExtractor::convertCollisionShape( Bullet3SerializeBullet2::b3Co
shape = new b3MultiSphereShape(&tmpPos[0],&radii[0],numSpheres); shape = new b3MultiSphereShape(&tmpPos[0],&radii[0],numSpheres);
break; break;
} }
#endif #endif
default: default:
@@ -453,13 +453,13 @@ int b3BulletDataExtractor::convertCollisionShape( Bullet3SerializeBullet2::b3Co
//dat. //dat.
} }
///trimesh->m_meshInterface.m_meshPartsPtr ///trimesh->m_meshInterface.m_meshPartsPtr
//trimesh->m_meshInterface.m_scaling //trimesh->m_meshInterface.m_scaling
} }
//trimesh->m_meshInterface //trimesh->m_meshInterface
//b3TriangleIndexVertexArray* meshInterface = createMeshInterface(trimesh->m_meshInterface); //b3TriangleIndexVertexArray* meshInterface = createMeshInterface(trimesh->m_meshInterface);
//scaling //scaling
//b3Vector3 scaling; scaling.deSerializeFloat(trimesh->m_meshInterface.m_scaling); //b3Vector3 scaling; scaling.deSerializeFloat(trimesh->m_meshInterface.m_scaling);
@@ -489,7 +489,7 @@ int b3BulletDataExtractor::convertCollisionShape( Bullet3SerializeBullet2::b3Co
{ {
printf("error: couldn't create childShape for compoundShape\n"); printf("error: couldn't create childShape for compoundShape\n");
} }
} }
shape = compoundShape; shape = compoundShape;
@@ -519,7 +519,7 @@ int b3BulletDataExtractor::convertCollisionShape( Bullet3SerializeBullet2::b3Co
{ {
return 0; return 0;
} }
#endif #endif
default: default:
{ {
printf("unsupported shape type (%d)\n",shapeData->m_shapeType); printf("unsupported shape type (%d)\n",shapeData->m_shapeType);
@@ -527,7 +527,7 @@ int b3BulletDataExtractor::convertCollisionShape( Bullet3SerializeBullet2::b3Co
} }
return shapeIndex; return shapeIndex;
} }
int b3BulletDataExtractor::createBoxShape( const Bullet3SerializeBullet2::b3Vector3FloatData& halfDimensions, const Bullet3SerializeBullet2::b3Vector3FloatData& localScaling, float collisionMargin) int b3BulletDataExtractor::createBoxShape( const Bullet3SerializeBullet2::b3Vector3FloatData& halfDimensions, const Bullet3SerializeBullet2::b3Vector3FloatData& localScaling, float collisionMargin)
@@ -544,7 +544,7 @@ int b3BulletDataExtractor::createBoxShape( const Bullet3SerializeBullet2::b3Vect
{ {
int numVertices = sizeof(cube_vertices)/strideInBytes; int numVertices = sizeof(cube_vertices)/strideInBytes;
int numIndices = sizeof(cube_indices)/sizeof(int); int numIndices = sizeof(cube_indices)/sizeof(int);
GraphicsShape* gfxShape = new GraphicsShape; GraphicsShape* gfxShape = new GraphicsShape;
gfxShape->m_vertices = cube_vertices; gfxShape->m_vertices = cube_vertices;
gfxShape->m_numvertices = numVertices; gfxShape->m_numvertices = numVertices;
@@ -569,7 +569,7 @@ int b3BulletDataExtractor::createSphereShape( float radius, const Bullet3Seriali
int b3BulletDataExtractor::createPlaneShape( const Bullet3SerializeBullet2::b3Vector3FloatData& planeNormal, float planeConstant, const Bullet3SerializeBullet2::b3Vector3FloatData& localScaling) int b3BulletDataExtractor::createPlaneShape( const Bullet3SerializeBullet2::b3Vector3FloatData& planeNormal, float planeConstant, const Bullet3SerializeBullet2::b3Vector3FloatData& localScaling)
{ {
printf("createPlaneShape with normal %f,%f,%f and planeConstant\n",planeNormal.m_floats[0], planeNormal.m_floats[1],planeNormal.m_floats[2],planeConstant); printf("createPlaneShape with normal %f,%f,%f and planeConstant %f\n",planeNormal.m_floats[0], planeNormal.m_floats[1],planeNormal.m_floats[2],planeConstant);
return -1; return -1;
} }
@@ -582,7 +582,7 @@ GraphicsShape* b3BulletDataExtractor::createGraphicsShapeFromConvexHull(const b3
b3ConvexUtility* utilPtr = new b3ConvexUtility(); b3ConvexUtility* utilPtr = new b3ConvexUtility();
bool merge = true; bool merge = true;
utilPtr->initializePolyhedralFeatures(tmpPoints,numPoints,merge); utilPtr->initializePolyhedralFeatures(tmpPoints,numPoints,merge);
b3AlignedObjectArray<GraphicsVertex>* vertices = new b3AlignedObjectArray<GraphicsVertex>; b3AlignedObjectArray<GraphicsVertex>* vertices = new b3AlignedObjectArray<GraphicsVertex>;
{ {
int numVertices = utilPtr->m_vertices.size(); int numVertices = utilPtr->m_vertices.size();
@@ -594,7 +594,7 @@ GraphicsShape* b3BulletDataExtractor::createGraphicsShapeFromConvexHull(const b3
b3Vector3 normal=b3MakeVector3(face.m_plane[0],face.m_plane[1],face.m_plane[2]); b3Vector3 normal=b3MakeVector3(face.m_plane[0],face.m_plane[1],face.m_plane[2]);
if (face.m_indices.size()>2) if (face.m_indices.size()>2)
{ {
GraphicsVertex vtx; GraphicsVertex vtx;
const b3Vector3& orgVertex = utilPtr->m_vertices[face.m_indices[0]]; const b3Vector3& orgVertex = utilPtr->m_vertices[face.m_indices[0]];
vtx.xyzw[0] = orgVertex[0];vtx.xyzw[1] = orgVertex[1];vtx.xyzw[2] = orgVertex[2];vtx.xyzw[3] = 0.f; vtx.xyzw[0] = orgVertex[0];vtx.xyzw[1] = orgVertex[1];vtx.xyzw[2] = orgVertex[2];vtx.xyzw[3] = 0.f;
@@ -602,7 +602,7 @@ GraphicsShape* b3BulletDataExtractor::createGraphicsShapeFromConvexHull(const b3
vtx.uv[0] = 0.5f;vtx.uv[1] = 0.5f; vtx.uv[0] = 0.5f;vtx.uv[1] = 0.5f;
int newvtxindex0 = vertices->size(); int newvtxindex0 = vertices->size();
vertices->push_back(vtx); vertices->push_back(vtx);
for (int j=1;j<face.m_indices.size()-1;j++) for (int j=1;j<face.m_indices.size()-1;j++)
{ {
indicesPtr->push_back(newvtxindex0); indicesPtr->push_back(newvtxindex0);
@@ -630,15 +630,15 @@ GraphicsShape* b3BulletDataExtractor::createGraphicsShapeFromConvexHull(const b3
} }
} }
} }
GraphicsShape* gfxShape = new GraphicsShape; GraphicsShape* gfxShape = new GraphicsShape;
gfxShape->m_vertices = &vertices->at(0).xyzw[0]; gfxShape->m_vertices = &vertices->at(0).xyzw[0];
gfxShape->m_numvertices = vertices->size(); gfxShape->m_numvertices = vertices->size();
gfxShape->m_indices = &indicesPtr->at(0); gfxShape->m_indices = &indicesPtr->at(0);
gfxShape->m_numIndices = indicesPtr->size(); gfxShape->m_numIndices = indicesPtr->size();
for (int i=0;i<4;i++) for (int i=0;i<4;i++)
gfxShape->m_scaling[i] = 1;//bake the scaling into the vertices gfxShape->m_scaling[i] = 1;//bake the scaling into the vertices
return gfxShape; return gfxShape;
} }
} }

View File

@@ -27,13 +27,13 @@
GLInstanceGraphicsShape* createGraphicsShapeFromWavefrontObj(std::vector<tinyobj::shape_t>& shapes) GLInstanceGraphicsShape* createGraphicsShapeFromWavefrontObj(std::vector<tinyobj::shape_t>& shapes)
{ {
b3AlignedObjectArray<GLInstanceVertex>* vertices = new b3AlignedObjectArray<GLInstanceVertex>; b3AlignedObjectArray<GLInstanceVertex>* vertices = new b3AlignedObjectArray<GLInstanceVertex>;
{ {
// int numVertices = obj->vertexCount; // int numVertices = obj->vertexCount;
// int numIndices = 0; // int numIndices = 0;
b3AlignedObjectArray<int>* indicesPtr = new b3AlignedObjectArray<int>; b3AlignedObjectArray<int>* indicesPtr = new b3AlignedObjectArray<int>;
for (int s=0;s<shapes.size();s++) for (int s=0;s<shapes.size();s++)
{ {
tinyobj::shape_t& shape = shapes[s]; tinyobj::shape_t& shape = shapes[s];
@@ -42,18 +42,18 @@ GLInstanceGraphicsShape* createGraphicsShapeFromWavefrontObj(std::vector<tinyobj
for (int f=0;f<faceCount;f+=3) for (int f=0;f<faceCount;f+=3)
{ {
//b3Vector3 normal(face.m_plane[0],face.m_plane[1],face.m_plane[2]); //b3Vector3 normal(face.m_plane[0],face.m_plane[1],face.m_plane[2]);
if (1) if (1)
{ {
b3Vector3 normal=b3MakeVector3(0,1,0); b3Vector3 normal=b3MakeVector3(0,1,0);
int vtxBaseIndex = vertices->size(); int vtxBaseIndex = vertices->size();
indicesPtr->push_back(vtxBaseIndex); indicesPtr->push_back(vtxBaseIndex);
indicesPtr->push_back(vtxBaseIndex+1); indicesPtr->push_back(vtxBaseIndex+1);
indicesPtr->push_back(vtxBaseIndex+2); indicesPtr->push_back(vtxBaseIndex+2);
GLInstanceVertex vtx0; GLInstanceVertex vtx0;
vtx0.xyzw[0] = shape.mesh.positions[shape.mesh.indices[f]*3+0]; vtx0.xyzw[0] = shape.mesh.positions[shape.mesh.indices[f]*3+0];
vtx0.xyzw[1] = shape.mesh.positions[shape.mesh.indices[f]*3+1]; vtx0.xyzw[1] = shape.mesh.positions[shape.mesh.indices[f]*3+1];
@@ -101,15 +101,15 @@ GLInstanceGraphicsShape* createGraphicsShapeFromWavefrontObj(std::vector<tinyobj
} }
} }
} }
GLInstanceGraphicsShape* gfxShape = new GLInstanceGraphicsShape; GLInstanceGraphicsShape* gfxShape = new GLInstanceGraphicsShape;
gfxShape->m_vertices = vertices; gfxShape->m_vertices = vertices;
gfxShape->m_numvertices = vertices->size(); gfxShape->m_numvertices = vertices->size();
gfxShape->m_indices = indicesPtr; gfxShape->m_indices = indicesPtr;
gfxShape->m_numIndices = indicesPtr->size(); gfxShape->m_numIndices = indicesPtr->size();
for (int i=0;i<4;i++) for (int i=0;i<4;i++)
gfxShape->m_scaling[i] = 1;//bake the scaling into the vertices gfxShape->m_scaling[i] = 1;//bake the scaling into the vertices
return gfxShape; return gfxShape;
} }
} }
@@ -117,15 +117,15 @@ GLInstanceGraphicsShape* createGraphicsShapeFromWavefrontObj(std::vector<tinyobj
void ConcaveScene::createConcaveMesh(const ConstructionInfo& ci, const char* fileName, const b3Vector3& shift, const b3Vector3& scaling) void ConcaveScene::createConcaveMesh(const ConstructionInfo& ci, const char* fileName, const b3Vector3& shift, const b3Vector3& scaling)
{ {
char relativeFileName[1024]; char relativeFileName[1024];
const char* prefix[]={"./data/","../data/","../../data/","../../../data/","../../../../data/"}; const char* prefix[]={"./data/","../data/","../../data/","../../../data/","../../../../data/"};
int prefixIndex=-1; int prefixIndex=-1;
{ {
int numPrefixes = sizeof(prefix)/sizeof(char*); int numPrefixes = sizeof(prefix)/sizeof(char*);
for (int i=0;i<numPrefixes;i++) for (int i=0;i<numPrefixes;i++)
@@ -145,7 +145,7 @@ void ConcaveScene::createConcaveMesh(const ConstructionInfo& ci, const char* fil
if (prefixIndex<0) if (prefixIndex<0)
return; return;
int index=10; int index=10;
{ {
@@ -154,7 +154,7 @@ void ConcaveScene::createConcaveMesh(const ConstructionInfo& ci, const char* fil
std::string err = tinyobj::LoadObj(shapes, relativeFileName, prefix[prefixIndex]); std::string err = tinyobj::LoadObj(shapes, relativeFileName, prefix[prefixIndex]);
GLInstanceGraphicsShape* shape = createGraphicsShapeFromWavefrontObj(shapes); GLInstanceGraphicsShape* shape = createGraphicsShapeFromWavefrontObj(shapes);
b3AlignedObjectArray<b3Vector3> verts; b3AlignedObjectArray<b3Vector3> verts;
for (int i=0;i<shape->m_numvertices;i++) for (int i=0;i<shape->m_numvertices;i++)
@@ -167,9 +167,9 @@ void ConcaveScene::createConcaveMesh(const ConstructionInfo& ci, const char* fil
shape->m_vertices->at(i).xyzw[2]); shape->m_vertices->at(i).xyzw[2]);
verts.push_back(vtx*scaling); verts.push_back(vtx*scaling);
} }
int colIndex = m_data->m_np->registerConcaveMesh(&verts,shape->m_indices,b3MakeVector3(1,1,1)); int colIndex = m_data->m_np->registerConcaveMesh(&verts,shape->m_indices,b3MakeVector3(1,1,1));
{ {
int strideInBytes = 9*sizeof(float); int strideInBytes = 9*sizeof(float);
int numVertices = sizeof(cube_vertices)/strideInBytes; int numVertices = sizeof(cube_vertices)/strideInBytes;
@@ -180,10 +180,10 @@ void ConcaveScene::createConcaveMesh(const ConstructionInfo& ci, const char* fil
int shapeId = ci.m_instancingRenderer->registerShape(&shape->m_vertices->at(0).xyzw[0], shape->m_numvertices, &shape->m_indices->at(0), shape->m_numIndices); int shapeId = ci.m_instancingRenderer->registerShape(&shape->m_vertices->at(0).xyzw[0], shape->m_numvertices, &shape->m_indices->at(0), shape->m_numIndices);
b3Quaternion orn(0,0,0,1); b3Quaternion orn(0,0,0,1);
b3Vector4 color=b3MakeVector4(0.3,0.3,1,1.f);//0.5);//1.f b3Vector4 color=b3MakeVector4(0.3,0.3,1,1.f);//0.5);//1.f
{ {
float mass = 0.f; float mass = 0.f;
b3Vector3 position=b3MakeVector3(0,0,0); b3Vector3 position=b3MakeVector3(0,0,0);
@@ -200,8 +200,8 @@ void ConcaveScene::createConcaveMesh(const ConstructionInfo& ci, const char* fil
} }
} }
} }
@@ -218,11 +218,11 @@ void ConcaveScene::setupScene(const ConstructionInfo& ci)
//char* fileName = "teddy.obj";//"plane.obj"; //char* fileName = "teddy.obj";//"plane.obj";
// char* fileName = "sponza_closed.obj";//"plane.obj"; // char* fileName = "sponza_closed.obj";//"plane.obj";
//char* fileName = "leoTest1.obj"; //char* fileName = "leoTest1.obj";
char* fileName = "samurai_monastry.obj"; const char* fileName = "samurai_monastry.obj";
// char* fileName = "teddy2_VHACD_CHs.obj"; // char* fileName = "teddy2_VHACD_CHs.obj";
b3Vector3 shift1=b3MakeVector3(0,0,0);//0,230,80);//150,-100,-120); b3Vector3 shift1=b3MakeVector3(0,0,0);//0,230,80);//150,-100,-120);
b3Vector4 scaling=b3MakeVector4(10,10,10,1); b3Vector4 scaling=b3MakeVector4(10,10,10,1);
// createConcaveMesh(ci,"plane100.obj",shift1,scaling); // createConcaveMesh(ci,"plane100.obj",shift1,scaling);
@@ -233,8 +233,8 @@ void ConcaveScene::setupScene(const ConstructionInfo& ci)
// b3Vector3 shift3(130,-150,-75);//0,230,80);//150,-100,-120); // b3Vector3 shift3(130,-150,-75);//0,230,80);//150,-100,-120);
// createConcaveMesh(ci,"leoTest1.obj",shift3,scaling); // createConcaveMesh(ci,"leoTest1.obj",shift3,scaling);
createConcaveMesh(ci,fileName,shift1,scaling); createConcaveMesh(ci,fileName,shift1,scaling);
} else } else
{ {
@@ -250,17 +250,17 @@ void ConcaveScene::setupScene(const ConstructionInfo& ci)
int colIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling); int colIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
b3Vector3 position=b3MakeVector3(0,-2,0); b3Vector3 position=b3MakeVector3(0,-2,0);
b3Quaternion orn(0,0,0,1); b3Quaternion orn(0,0,0,1);
b3Vector4 color=b3MakeVector4(0,0,1,1); b3Vector4 color=b3MakeVector4(0,0,1,1);
int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling); int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling);
int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(0.f,position,orn,colIndex,index,false); int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(0.f,position,orn,colIndex,index,false);
} }
} }
createDynamicObjects(ci); createDynamicObjects(ci);
m_data->m_rigidBodyPipeline->writeAllInstancesToGpu(); m_data->m_rigidBodyPipeline->writeAllInstancesToGpu();
float camPos[4]={0,0,0,0};//65.5,4.5,65.5,0}; float camPos[4]={0,0,0,0};//65.5,4.5,65.5,0};
@@ -285,15 +285,15 @@ void ConcaveScene::createDynamicObjects(const ConstructionInfo& ci)
int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices); int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
int group=1; int group=1;
int mask=1; int mask=1;
int index=0; int index=0;
if (1) if (1)
{ {
int curColor = 0; int curColor = 0;
b3Vector4 colors[4] = b3Vector4 colors[4] =
{ {
b3MakeVector4(1,1,1,1), b3MakeVector4(1,1,1,1),
b3MakeVector4(1,1,0.3,1), b3MakeVector4(1,1,0.3,1),
@@ -345,14 +345,14 @@ void ConcaveScene::createDynamicObjects(const ConstructionInfo& ci)
23+j*CONCAVE_GAPY, 23+j*CONCAVE_GAPY,
-(ci.arraySizeZ/2)*CONCAVE_GAPZ+k*CONCAVE_GAPZ); -(ci.arraySizeZ/2)*CONCAVE_GAPZ+k*CONCAVE_GAPZ);
b3Quaternion orn(0,0,0,1); b3Quaternion orn(0,0,0,1);
b3Vector4 color = colors[curColor]; b3Vector4 color = colors[curColor];
curColor++; curColor++;
curColor&=3; curColor&=3;
int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling); int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling);
int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(mass,position,orn,colIndex,index,false); int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(mass,position,orn,colIndex,index,false);
index++; index++;
} }
} }
@@ -377,10 +377,10 @@ void ConcaveCompoundScene::setupScene(const ConstructionInfo& ci)
void ConcaveCompound2Scene::createDynamicObjects(const ConstructionInfo& ci) void ConcaveCompound2Scene::createDynamicObjects(const ConstructionInfo& ci)
{ {
char* fileName = "teddy2_VHACD_CHs.obj"; const char* fileName = "teddy2_VHACD_CHs.obj";
//char* fileName = "cube_offset.obj"; //char* fileName = "cube_offset.obj";
b3Vector3 shift=b3MakeVector3(0,0,0);//0,230,80);//150,-100,-120); b3Vector3 shift=b3MakeVector3(0,0,0);//0,230,80);//150,-100,-120);
b3Vector4 scaling=b3MakeVector4(1,1,1,1); b3Vector4 scaling=b3MakeVector4(1,1,1,1);
const char* prefix[]={"./data/","../data/","../../data/","../../../data/","../../../../data/"}; const char* prefix[]={"./data/","../data/","../../data/","../../../data/","../../../../data/"};
@@ -388,12 +388,12 @@ void ConcaveCompound2Scene::createDynamicObjects(const ConstructionInfo& ci)
char relativeFileName[1024]; char relativeFileName[1024];
{ {
int numPrefixes = sizeof(prefix)/sizeof(char*); int numPrefixes = sizeof(prefix)/sizeof(char*);
for (int i=0;i<numPrefixes;i++) for (int i=0;i<numPrefixes;i++)
{ {
sprintf(relativeFileName,"%s%s",prefix[i],fileName); sprintf(relativeFileName,"%s%s",prefix[i],fileName);
FILE* f = 0; FILE* f = 0;
f = fopen(relativeFileName,"r"); f = fopen(relativeFileName,"r");
@@ -422,7 +422,7 @@ void ConcaveCompound2Scene::createDynamicObjects(const ConstructionInfo& ci)
b3AlignedObjectArray<GLInstanceVertex> vertexArray; b3AlignedObjectArray<GLInstanceVertex> vertexArray;
b3AlignedObjectArray<int> indexArray; b3AlignedObjectArray<int> indexArray;
//int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices); //int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
@@ -436,8 +436,8 @@ void ConcaveCompound2Scene::createDynamicObjects(const ConstructionInfo& ci)
b3Assert(stride2 == strideInBytes); b3Assert(stride2 == strideInBytes);
{ {
b3AlignedObjectArray<b3GpuChildShape> childShapes; b3AlignedObjectArray<b3GpuChildShape> childShapes;
int numChildShapes = shapes.size(); int numChildShapes = shapes.size();
@@ -455,7 +455,7 @@ void ConcaveCompound2Scene::createDynamicObjects(const ConstructionInfo& ci)
//for now, only support polyhedral child shapes //for now, only support polyhedral child shapes
b3GpuChildShape child; b3GpuChildShape child;
b3Vector3 pos=b3MakeVector3(0,0,0); b3Vector3 pos=b3MakeVector3(0,0,0);
b3Quaternion orn(0,0,0,1); b3Quaternion orn(0,0,0,1);
for (int v=0;v<4;v++) for (int v=0;v<4;v++)
@@ -463,21 +463,21 @@ void ConcaveCompound2Scene::createDynamicObjects(const ConstructionInfo& ci)
child.m_childPosition[v] = pos[v]; child.m_childPosition[v] = pos[v];
child.m_childOrientation[v] = orn[v]; child.m_childOrientation[v] = orn[v];
} }
b3Transform tr; b3Transform tr;
tr.setIdentity(); tr.setIdentity();
tr.setOrigin(pos); tr.setOrigin(pos);
tr.setRotation(orn); tr.setRotation(orn);
int baseIndex = vertexArray.size(); int baseIndex = vertexArray.size();
for (int f=0;f<numFaces;f++) for (int f=0;f<numFaces;f++)
{ {
for (int i=0;i<3;i++) for (int i=0;i<3;i++)
{ {
indexArray.push_back(baseIndex+shape.mesh.indices[f*3+i]); indexArray.push_back(baseIndex+shape.mesh.indices[f*3+i]);
} }
} }
b3Vector3 center=b3MakeVector3(0,0,0); b3Vector3 center=b3MakeVector3(0,0,0);
@@ -488,8 +488,8 @@ void ConcaveCompound2Scene::createDynamicObjects(const ConstructionInfo& ci)
for (int v=0;v<numVertices;v++) for (int v=0;v<numVertices;v++)
{ {
GLInstanceVertex vert; GLInstanceVertex vert;
vert.uv[0] = 0.5f; vert.uv[0] = 0.5f;
vert.uv[1] = 0.5f; vert.uv[1] = 0.5f;
@@ -540,20 +540,20 @@ void ConcaveCompound2Scene::createDynamicObjects(const ConstructionInfo& ci)
colIndex = childColIndex; colIndex = childColIndex;
} }
colIndex= m_data->m_np->registerCompoundShape(&childShapes); colIndex= m_data->m_np->registerCompoundShape(&childShapes);
} }
//int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices); //int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
int shapeId = ci.m_instancingRenderer->registerShape(&vertexArray[0].xyzw[0],vertexArray.size(),&indexArray[0],indexArray.size()); int shapeId = ci.m_instancingRenderer->registerShape(&vertexArray[0].xyzw[0],vertexArray.size(),&indexArray[0],indexArray.size());
b3Vector4 colors[4] = b3Vector4 colors[4] =
{ {
b3MakeVector4(1,0,0,1), b3MakeVector4(1,0,0,1),
b3MakeVector4(0,1,0,1), b3MakeVector4(0,1,0,1),
b3MakeVector4(0,0,1,1), b3MakeVector4(0,0,1,1),
b3MakeVector4(0,1,1,1), b3MakeVector4(0,1,1,1),
}; };
int curColor = 0; int curColor = 0;
for (int i=0;i<1;i++)//ci.arraySizeX;i++) for (int i=0;i<1;i++)//ci.arraySizeX;i++)
{ {
@@ -569,14 +569,14 @@ void ConcaveCompound2Scene::createDynamicObjects(const ConstructionInfo& ci)
// b3Quaternion orn(0,0,0,1); // b3Quaternion orn(0,0,0,1);
b3Quaternion orn(b3MakeVector3(0,0,1),1.8); b3Quaternion orn(b3MakeVector3(0,0,1),1.8);
b3Vector4 color = colors[curColor]; b3Vector4 color = colors[curColor];
curColor++; curColor++;
curColor&=3; curColor&=3;
b3Vector4 scaling=b3MakeVector4(1,1,1,1); b3Vector4 scaling=b3MakeVector4(1,1,1,1);
int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling); int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling);
int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(mass,position,orn,colIndex,index,false); int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(mass,position,orn,colIndex,index,false);
index++; index++;
} }
} }
@@ -588,14 +588,14 @@ void ConcaveCompound2Scene::createDynamicObjects(const ConstructionInfo& ci)
void ConcaveCompoundScene::createDynamicObjects(const ConstructionInfo& ci) void ConcaveCompoundScene::createDynamicObjects(const ConstructionInfo& ci)
{ {
int strideInBytes = 9*sizeof(float); int strideInBytes = 9*sizeof(float);
int numVertices = sizeof(cube_vertices)/strideInBytes; int numVertices = sizeof(cube_vertices)/strideInBytes;
int numIndices = sizeof(cube_indices)/sizeof(int); int numIndices = sizeof(cube_indices)/sizeof(int);
b3AlignedObjectArray<GLInstanceVertex> vertexArray; b3AlignedObjectArray<GLInstanceVertex> vertexArray;
b3AlignedObjectArray<int> indexArray; b3AlignedObjectArray<int> indexArray;
//int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices); //int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
int group=1; int group=1;
@@ -610,14 +610,14 @@ void ConcaveCompoundScene::createDynamicObjects(const ConstructionInfo& ci)
{ {
int childColIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling); int childColIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
b3Vector3 childPositions[3] = { b3Vector3 childPositions[3] = {
b3MakeVector3(0,-2,0), b3MakeVector3(0,-2,0),
b3MakeVector3(0,0,0), b3MakeVector3(0,0,0),
b3MakeVector3(0,0,2) b3MakeVector3(0,0,2)
}; };
b3AlignedObjectArray<b3GpuChildShape> childShapes; b3AlignedObjectArray<b3GpuChildShape> childShapes;
int numChildShapes = 3; int numChildShapes = 3;
for (int i=0;i<numChildShapes;i++) for (int i=0;i<numChildShapes;i++)
@@ -657,20 +657,20 @@ b3Vector3 childPositions[3] = {
} }
colIndex= m_data->m_np->registerCompoundShape(&childShapes); colIndex= m_data->m_np->registerCompoundShape(&childShapes);
} }
//int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices); //int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
int shapeId = ci.m_instancingRenderer->registerShape(&vertexArray[0].xyzw[0],vertexArray.size(),&indexArray[0],indexArray.size()); int shapeId = ci.m_instancingRenderer->registerShape(&vertexArray[0].xyzw[0],vertexArray.size(),&indexArray[0],indexArray.size());
b3Vector4 colors[4] = b3Vector4 colors[4] =
{ {
b3MakeVector4(1,0,0,1), b3MakeVector4(1,0,0,1),
b3MakeVector4(0,1,0,1), b3MakeVector4(0,1,0,1),
b3MakeVector4(0,0,1,1), b3MakeVector4(0,0,1,1),
b3MakeVector4(0,1,1,1), b3MakeVector4(0,1,1,1),
}; };
int curColor = 0; int curColor = 0;
for (int i=0;i<ci.arraySizeX;i++) for (int i=0;i<ci.arraySizeX;i++)
{ {
@@ -684,14 +684,14 @@ b3Vector3 childPositions[3] = {
b3Vector3 position=b3MakeVector3((-ci.arraySizeX/2+i)*ci.gapX,50+j*ci.gapY,(-ci.arraySizeZ/2+k)*ci.gapZ); b3Vector3 position=b3MakeVector3((-ci.arraySizeX/2+i)*ci.gapX,50+j*ci.gapY,(-ci.arraySizeZ/2+k)*ci.gapZ);
//b3Quaternion orn(0,0,0,1); //b3Quaternion orn(0,0,0,1);
b3Quaternion orn(b3MakeVector3(1,0,0),0.7); b3Quaternion orn(b3MakeVector3(1,0,0),0.7);
b3Vector4 color = colors[curColor]; b3Vector4 color = colors[curColor];
curColor++; curColor++;
curColor&=3; curColor&=3;
b3Vector4 scaling=b3MakeVector4(1,1,1,1); b3Vector4 scaling=b3MakeVector4(1,1,1,1);
int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling); int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling);
int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(mass,position,orn,colIndex,index,false); int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(mass,position,orn,colIndex,index,false);
index++; index++;
} }
} }
@@ -714,7 +714,7 @@ void ConcaveSphereScene::setupScene(const ConstructionInfo& ci)
void ConcaveSphereScene::createDynamicObjects(const ConstructionInfo& ci) void ConcaveSphereScene::createDynamicObjects(const ConstructionInfo& ci)
{ {
b3Vector4 colors[4] = b3Vector4 colors[4] =
{ {
b3MakeVector4(1,0,0,1), b3MakeVector4(1,0,0,1),
b3MakeVector4(0,1,0,1), b3MakeVector4(0,1,0,1),
@@ -737,20 +737,20 @@ void ConcaveSphereScene::createDynamicObjects(const ConstructionInfo& ci)
{ {
float mass = 1.f; float mass = 1.f;
b3Vector3 position=b3MakeVector3(-(ci.arraySizeX/2)*8+i*8,50+j*8,-(ci.arraySizeZ/2)*8+k*8); b3Vector3 position=b3MakeVector3(-(ci.arraySizeX/2)*8+i*8,50+j*8,-(ci.arraySizeZ/2)*8+k*8);
//b3Vector3 position(0,-41,0);//0,0,0);//i*radius*3,-41+j*radius*3,k*radius*3); //b3Vector3 position(0,-41,0);//0,0,0);//i*radius*3,-41+j*radius*3,k*radius*3);
b3Quaternion orn(0,0,0,1); b3Quaternion orn(0,0,0,1);
b3Vector4 color = colors[curColor]; b3Vector4 color = colors[curColor];
curColor++; curColor++;
curColor&=3; curColor&=3;
b3Vector4 scaling=b3MakeVector4(radius,radius,radius,1); b3Vector4 scaling=b3MakeVector4(radius,radius,radius,1);
int id = ci.m_instancingRenderer->registerGraphicsInstance(prevGraphicsShapeIndex,position,orn,color,scaling); int id = ci.m_instancingRenderer->registerGraphicsInstance(prevGraphicsShapeIndex,position,orn,color,scaling);
int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(mass,position,orn,colIndex,index,false); int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(mass,position,orn,colIndex,index,false);
index++; index++;
} }
} }

View File

@@ -142,25 +142,25 @@ void URDFvisual2BulletCollisionShape(my_shared_ptr<const Link> link, GraphicsPhy
{ {
printf("processing a cylinder\n"); printf("processing a cylinder\n");
urdf::Cylinder* cyl = (urdf::Cylinder*)visual->geometry.get(); urdf::Cylinder* cyl = (urdf::Cylinder*)visual->geometry.get();
btAlignedObjectArray<btVector3> vertices; btAlignedObjectArray<btVector3> vertices;
//int numVerts = sizeof(barrel_vertices)/(9*sizeof(float)); //int numVerts = sizeof(barrel_vertices)/(9*sizeof(float));
int numSteps = 32; int numSteps = 32;
for (int i=0;i<numSteps;i++) for (int i=0;i<numSteps;i++)
{ {
btVector3 vert(cyl->radius*btSin(SIMD_2_PI*(float(i)/numSteps)),cyl->radius*btCos(SIMD_2_PI*(float(i)/numSteps)),cyl->length/2.); btVector3 vert(cyl->radius*btSin(SIMD_2_PI*(float(i)/numSteps)),cyl->radius*btCos(SIMD_2_PI*(float(i)/numSteps)),cyl->length/2.);
vertices.push_back(vert); vertices.push_back(vert);
vert[2] = -cyl->length/2.; vert[2] = -cyl->length/2.;
vertices.push_back(vert); vertices.push_back(vert);
} }
btConvexHullShape* cylZShape = new btConvexHullShape(&vertices[0].x(), vertices.size(), sizeof(btVector3)); btConvexHullShape* cylZShape = new btConvexHullShape(&vertices[0].x(), vertices.size(), sizeof(btVector3));
cylZShape->initializePolyhedralFeatures(); cylZShape->initializePolyhedralFeatures();
//btVector3 halfExtents(cyl->radius,cyl->radius,cyl->length/2.); //btVector3 halfExtents(cyl->radius,cyl->radius,cyl->length/2.);
//btCylinderShapeZ* cylZShape = new btCylinderShapeZ(halfExtents); //btCylinderShapeZ* cylZShape = new btCylinderShapeZ(halfExtents);
cylZShape->setMargin(0.001); cylZShape->setMargin(0.001);
shape = cylZShape; shape = cylZShape;
break; break;
} }
@@ -225,7 +225,7 @@ void URDFvisual2BulletCollisionShape(my_shared_ptr<const Link> link, GraphicsPhy
btRigidBody* body = new btRigidBody(rbci); btRigidBody* body = new btRigidBody(rbci);
world->addRigidBody(body,bodyCollisionFilterGroup,bodyCollisionFilterMask); world->addRigidBody(body,bodyCollisionFilterGroup,bodyCollisionFilterMask);
// body->setFriction(0); // body->setFriction(0);
@@ -359,13 +359,13 @@ void ImportUrdfDemo::initPhysics(GraphicsPhysicsBridge& gfxBridge)
);//+btIDebugDraw::DBG_DrawConstraintLimits); );//+btIDebugDraw::DBG_DrawConstraintLimits);
btVector3 gravity(0,0,0); btVector3 gravity(0,0,0);
gravity[upAxis]=-9.8; gravity[upAxis]=-9.8;
m_dynamicsWorld->setGravity(gravity); m_dynamicsWorld->setGravity(gravity);
int argc=0; int argc=0;
char* filename="somefile.urdf"; const char* filename="somefile.urdf";
std::string xml_string; std::string xml_string;
@@ -418,7 +418,7 @@ void ImportUrdfDemo::initPhysics(GraphicsPhysicsBridge& gfxBridge)
groundHalfExtents[upAxis]=1.f; groundHalfExtents[upAxis]=1.f;
btBoxShape* box = new btBoxShape(groundHalfExtents); btBoxShape* box = new btBoxShape(groundHalfExtents);
box->initializePolyhedralFeatures(); box->initializePolyhedralFeatures();
gfxBridge.createCollisionShapeGraphicsObject(box); gfxBridge.createCollisionShapeGraphicsObject(box);
btTransform start; start.setIdentity(); btTransform start; start.setIdentity();
btVector3 groundOrigin(0,0,0); btVector3 groundOrigin(0,0,0);
@@ -428,6 +428,6 @@ void ImportUrdfDemo::initPhysics(GraphicsPhysicsBridge& gfxBridge)
btVector3 color(0.5,0.5,0.5); btVector3 color(0.5,0.5,0.5);
gfxBridge.createRigidBodyGraphicsObject(body,color); gfxBridge.createRigidBodyGraphicsObject(body,color);
} }
} }

View File

@@ -14,7 +14,7 @@ extern "C" {
} }
char* sLuaFileName = "init_physics.lua"; const char* sLuaFileName = "init_physics.lua";
static const float scaling=0.35f; static const float scaling=0.35f;
static LuaPhysicsSetup* sLuaDemo = 0; static LuaPhysicsSetup* sLuaDemo = 0;

View File

@@ -145,7 +145,7 @@ struct sth_stash* sth_create(int cachew, int cacheh, RenderCallbacks* renderCall
memset(stash,0,sizeof(struct sth_stash)); memset(stash,0,sizeof(struct sth_stash));
stash->m_renderCallbacks = renderCallbacks; stash->m_renderCallbacks = renderCallbacks;
// Allocate memory for the first texture // Allocate memory for the first texture
texture = (struct sth_texture*)malloc(sizeof(struct sth_texture)); texture = (struct sth_texture*)malloc(sizeof(struct sth_texture));
if (texture == NULL) if (texture == NULL)
@@ -161,11 +161,11 @@ struct sth_stash* sth_create(int cachew, int cacheh, RenderCallbacks* renderCall
stash->itw = 1.0f/cachew; stash->itw = 1.0f/cachew;
stash->ith = 1.0f/cacheh; stash->ith = 1.0f/cacheh;
stash->textures = texture; stash->textures = texture;
stash->m_renderCallbacks->updateTexture(texture, 0, stash->tw, stash->th); stash->m_renderCallbacks->updateTexture(texture, 0, stash->tw, stash->th);
return stash; return stash;
} }
int sth_add_font_from_memory(struct sth_stash* stash, unsigned char* buffer) int sth_add_font_from_memory(struct sth_stash* stash, unsigned char* buffer)
@@ -177,7 +177,7 @@ int sth_add_font_from_memory(struct sth_stash* stash, unsigned char* buffer)
if (fnt == NULL) goto error; if (fnt == NULL) goto error;
memset(fnt,0,sizeof(struct sth_font)); memset(fnt,0,sizeof(struct sth_font));
// Init hash lookup. // Init hash lookup.
for (i = 0; i < HASH_LUT_SIZE; ++i) for (i = 0; i < HASH_LUT_SIZE; ++i)
fnt->lut[i] = -1; fnt->lut[i] = -1;
@@ -187,8 +187,8 @@ int sth_add_font_from_memory(struct sth_stash* stash, unsigned char* buffer)
// Init stb_truetype // Init stb_truetype
if (!stbtt_InitFont(&fnt->font, fnt->data, 0)) if (!stbtt_InitFont(&fnt->font, fnt->data, 0))
goto error; goto error;
// Store normalized line height. The real line height is got // Store normalized line height. The real line height is got
// by multiplying the lineh by font size. // by multiplying the lineh by font size.
stbtt_GetFontVMetrics(&fnt->font, &ascent, &descent, &lineGap); stbtt_GetFontVMetrics(&fnt->font, &ascent, &descent, &lineGap);
@@ -203,7 +203,7 @@ int sth_add_font_from_memory(struct sth_stash* stash, unsigned char* buffer)
fnt->next = stash->fonts; fnt->next = stash->fonts;
stash->fonts = fnt; stash->fonts = fnt;
return idx++; return idx++;
error: error:
@@ -220,7 +220,7 @@ int sth_add_font(struct sth_stash* stash, const char* path)
int datasize; int datasize;
unsigned char* data = NULL; unsigned char* data = NULL;
int idx; int idx;
// Read in the font data. // Read in the font data.
fp = fopen(path, "rb"); fp = fopen(path, "rb");
if (!fp) goto error; if (!fp) goto error;
@@ -229,10 +229,11 @@ int sth_add_font(struct sth_stash* stash, const char* path)
fseek(fp,0,SEEK_SET); fseek(fp,0,SEEK_SET);
data = (unsigned char*)malloc(datasize); data = (unsigned char*)malloc(datasize);
if (data == NULL) goto error; if (data == NULL) goto error;
fread(data, 1, datasize, fp); int bytesRead;
bytesRead = fread(data, 1, datasize, fp);
fclose(fp); fclose(fp);
fp = 0; fp = 0;
idx = sth_add_font_from_memory(stash, data); idx = sth_add_font_from_memory(stash, data);
// Modify type of the loaded font. // Modify type of the loaded font.
if (idx) if (idx)
@@ -241,7 +242,7 @@ int sth_add_font(struct sth_stash* stash, const char* path)
free(data); free(data);
return idx; return idx;
error: error:
if (data) free(data); if (data) free(data);
if (fp) fclose(fp); if (fp) fclose(fp);
@@ -271,7 +272,7 @@ int sth_add_bitmap_font(struct sth_stash* stash, int ascent, int descent, int li
fnt->type = BMFONT; fnt->type = BMFONT;
fnt->next = stash->fonts; fnt->next = stash->fonts;
stash->fonts = fnt; stash->fonts = fnt;
return idx++; return idx++;
error: error:
@@ -295,7 +296,7 @@ error:
if (stash == NULL) return; if (stash == NULL) return;
texture = stash->textures; texture = stash->textures;
while (texture != NULL && texture->id != id) while (texture != NULL && texture->id != id)
texture = texture->next; texture = texture->next;
if (texture == NULL) if (texture == NULL)
@@ -313,7 +314,7 @@ error:
while (fnt != NULL && fnt->idx != idx) fnt = fnt->next; while (fnt != NULL && fnt->idx != idx) fnt = fnt->next;
if (fnt == NULL) return; if (fnt == NULL) return;
if (fnt->type != BMFONT) return; if (fnt->type != BMFONT) return;
for (; *s; ++s) for (; *s; ++s)
{ {
if (!decutf8(&state, &codepoint, *(unsigned char*)s)) break; if (!decutf8(&state, &codepoint, *(unsigned char*)s)) break;
@@ -338,7 +339,7 @@ error:
glyph->xoff = xoffset; glyph->xoff = xoffset;
glyph->yoff = yoffset - base; glyph->yoff = yoffset - base;
glyph->xadv = xadvance; glyph->xadv = xadvance;
// Find code point and size. // Find code point and size.
h = hashint(codepoint) & (HASH_LUT_SIZE-1); h = hashint(codepoint) & (HASH_LUT_SIZE-1);
// Insert char to hash lookup. // Insert char to hash lookup.
@@ -353,7 +354,7 @@ static struct sth_glyph* get_glyph(struct sth_stash* stash, struct sth_font* fnt
float scale; float scale;
struct sth_texture* texture = NULL; struct sth_texture* texture = NULL;
struct sth_glyph* glyph = NULL; struct sth_glyph* glyph = NULL;
unsigned int h; unsigned int h;
float size = isize/10.0f; float size = isize/10.0f;
int rh; int rh;
@@ -369,10 +370,10 @@ static struct sth_glyph* get_glyph(struct sth_stash* stash, struct sth_font* fnt
i = fnt->glyphs[i].next; i = fnt->glyphs[i].next;
} }
// Could not find glyph. // Could not find glyph.
// For bitmap fonts: ignore this glyph. // For bitmap fonts: ignore this glyph.
if (fnt->type == BMFONT) return 0; if (fnt->type == BMFONT) return 0;
// For truetype fonts: create this glyph. // For truetype fonts: create this glyph.
scale = stbtt_ScaleForPixelHeight(&fnt->font, size); scale = stbtt_ScaleForPixelHeight(&fnt->font, size);
g = stbtt_FindGlyphIndex(&fnt->font, codepoint); g = stbtt_FindGlyphIndex(&fnt->font, codepoint);
@@ -380,7 +381,7 @@ static struct sth_glyph* get_glyph(struct sth_stash* stash, struct sth_font* fnt
stbtt_GetGlyphBitmapBox(&fnt->font, g, scale,scale, &x0,&y0,&x1,&y1); stbtt_GetGlyphBitmapBox(&fnt->font, g, scale,scale, &x0,&y0,&x1,&y1);
gw = x1-x0; gw = x1-x0;
gh = y1-y0; gh = y1-y0;
// Check if glyph is larger than maximum texture size // Check if glyph is larger than maximum texture size
if (gw >= stash->tw || gh >= stash->th) if (gw >= stash->tw || gh >= stash->th)
return 0; return 0;
@@ -396,7 +397,7 @@ static struct sth_glyph* get_glyph(struct sth_stash* stash, struct sth_font* fnt
if (texture->rows[i].h >= rh && texture->rows[i].x+gw+1 <= stash->tw) if (texture->rows[i].h >= rh && texture->rows[i].x+gw+1 <= stash->tw)
br = &texture->rows[i]; br = &texture->rows[i];
} }
// If no row is found, there are 3 possibilities: // If no row is found, there are 3 possibilities:
// - add new row // - add new row
// - try next texture // - try next texture
@@ -421,10 +422,10 @@ static struct sth_glyph* get_glyph(struct sth_stash* stash, struct sth_font* fnt
texture = texture->next; texture = texture->next;
if (texture == NULL) goto error; if (texture == NULL) goto error;
memset(texture,0,sizeof(struct sth_texture)); memset(texture,0,sizeof(struct sth_texture));
stash->m_renderCallbacks->updateTexture(texture,0,stash->tw,stash->th); stash->m_renderCallbacks->updateTexture(texture,0,stash->tw,stash->th);
} }
continue; continue;
} }
@@ -434,10 +435,10 @@ static struct sth_glyph* get_glyph(struct sth_stash* stash, struct sth_font* fnt
br->x = BORDER_X_LEFT; br->x = BORDER_X_LEFT;
br->y = py+BORDER_Y_BOTTOM; br->y = py+BORDER_Y_BOTTOM;
br->h = rh+ADDITIONAL_HEIGHT; br->h = rh+ADDITIONAL_HEIGHT;
texture->nrows++; texture->nrows++;
} }
} }
// Alloc space for new glyph. // Alloc space for new glyph.
fnt->nglyphs++; fnt->nglyphs++;
fnt->glyphs = (sth_glyph*)realloc(fnt->glyphs, fnt->nglyphs*sizeof(struct sth_glyph)); fnt->glyphs = (sth_glyph*)realloc(fnt->glyphs, fnt->nglyphs*sizeof(struct sth_glyph));
@@ -473,7 +474,7 @@ static struct sth_glyph* get_glyph(struct sth_stash* stash, struct sth_font* fnt
stash->m_renderCallbacks->updateTexture(texture,glyph, stash->tw, stash->th); stash->m_renderCallbacks->updateTexture(texture,glyph, stash->tw, stash->th);
} }
return glyph; return glyph;
error: error:
@@ -486,26 +487,26 @@ static int get_quad(struct sth_stash* stash, struct sth_font* fnt, struct sth_gl
{ {
float rx,ry; float rx,ry;
float scale = 1.f/s_retinaScale;//1.0f; float scale = 1.f/s_retinaScale;//1.0f;
if (fnt->type == BMFONT) if (fnt->type == BMFONT)
scale = isize/(glyph->size*10.0f); scale = isize/(glyph->size*10.0f);
rx = (*x + scale * float(glyph->xoff)); rx = (*x + scale * float(glyph->xoff));
ry = (*y + scale * float(glyph->yoff)); ry = (*y + scale * float(glyph->yoff));
q->x0 = rx; q->x0 = rx;
q->y0 = ry + 1.5f*0.5f*float(isize)/10.f; q->y0 = ry + 1.5f*0.5f*float(isize)/10.f;
q->x1 = rx + scale * float(glyph->x1 - glyph->x0_); q->x1 = rx + scale * float(glyph->x1 - glyph->x0_);
q->y1 = ry + scale * float(glyph->y1 - glyph->y0)+ 1.5f*0.5f*float(isize)/10.f; q->y1 = ry + scale * float(glyph->y1 - glyph->y0)+ 1.5f*0.5f*float(isize)/10.f;
q->s0 = float(glyph->x0_) * stash->itw; q->s0 = float(glyph->x0_) * stash->itw;
q->t0 = float(glyph->y0) * stash->ith; q->t0 = float(glyph->y0) * stash->ith;
q->s1 = float(glyph->x1) * stash->itw; q->s1 = float(glyph->x1) * stash->itw;
q->t1 = float(glyph->y1) * stash->ith; q->t1 = float(glyph->y1) * stash->ith;
*x += scale * glyph->xadv; *x += scale * glyph->xadv;
return 1; return 1;
} }
@@ -523,7 +524,7 @@ static Vertex* setv(Vertex* v, float x, float y, float s, float t, float width,
} }
v->position.p[2] = 0.f; v->position.p[2] = 0.f;
v->position.p[3] = 1.f; v->position.p[3] = 1.f;
v->uv.p[0] = s; v->uv.p[0] = s;
v->uv.p[1] = t; v->uv.p[1] = t;
@@ -531,7 +532,7 @@ static Vertex* setv(Vertex* v, float x, float y, float s, float t, float width,
v->colour.p[1] = 0.1f; v->colour.p[1] = 0.1f;
v->colour.p[2] = 0.1f; v->colour.p[2] = 0.1f;
v->colour.p[3] = 1.f; v->colour.p[3] = 1.f;
return v+1; return v+1;
} }
@@ -545,7 +546,7 @@ static void flush_draw(struct sth_stash* stash)
{ {
if (texture->nverts > 0) if (texture->nverts > 0)
{ {
stash->m_renderCallbacks->render(texture); stash->m_renderCallbacks->render(texture);
texture->nverts = 0; texture->nverts = 0;
} }
texture = texture->next; texture = texture->next;
@@ -584,7 +585,7 @@ void sth_end_draw(struct sth_stash* stash)
stash->nverts += 6; stash->nverts += 6;
} }
*/ */
flush_draw(stash); flush_draw(stash);
stash->drawing = 0; stash->drawing = 0;
} }
@@ -606,7 +607,7 @@ void sth_draw_texture(struct sth_stash* stash,
short isize = (short)(size*10.0f); short isize = (short)(size*10.0f);
Vertex* v; Vertex* v;
struct sth_font* fnt = NULL; struct sth_font* fnt = NULL;
if (stash == NULL) return; if (stash == NULL) return;
if (!stash->textures) return; if (!stash->textures) return;
@@ -614,23 +615,23 @@ void sth_draw_texture(struct sth_stash* stash,
while(fnt != NULL && fnt->idx != idx) fnt = fnt->next; while(fnt != NULL && fnt->idx != idx) fnt = fnt->next;
if (fnt == NULL) return; if (fnt == NULL) return;
if (fnt->type != BMFONT && !fnt->data) return; if (fnt->type != BMFONT && !fnt->data) return;
int once = true; int once = true;
for (; once; ++s) for (; once; ++s)
{ {
once=false; once=false;
if (decutf8(&state, &codepoint, *(unsigned char*)s)) if (decutf8(&state, &codepoint, *(unsigned char*)s))
continue; continue;
glyph = get_glyph(stash, fnt, codepoint, isize); glyph = get_glyph(stash, fnt, codepoint, isize);
if (!glyph) if (!glyph)
continue; continue;
texture = glyph->texture; texture = glyph->texture;
if (texture->nverts+6 >= VERT_COUNT) if (texture->nverts+6 >= VERT_COUNT)
flush_draw(stash); flush_draw(stash);
if (!get_quad(stash, fnt, glyph, isize, &x, &y, &q)) if (!get_quad(stash, fnt, glyph, isize, &x, &y, &q))
continue; continue;
v = &texture->newverts[texture->nverts]; v = &texture->newverts[texture->nverts];
q.x0 = 0; q.x0 = 0;
q.y0 = 0; q.y0 = 0;
@@ -646,11 +647,11 @@ void sth_draw_texture(struct sth_stash* stash,
v = setv(v, q.x0, q.y1, 0,1,(float)screenwidth,(float)screenheight); v = setv(v, q.x0, q.y1, 0,1,(float)screenwidth,(float)screenheight);
texture->nverts += 6; texture->nverts += 6;
} }
flush_draw(stash); flush_draw(stash);
if (dx) *dx = x; if (dx) *dx = x;
} }
@@ -664,7 +665,7 @@ void sth_draw_text(struct sth_stash* stash,
float x, float y, float x, float y,
const char* s, float* dx, int screenwidth, int screenheight, int measureOnly, float retinaScale) const char* s, float* dx, int screenwidth, int screenheight, int measureOnly, float retinaScale)
{ {
unsigned int codepoint; unsigned int codepoint;
struct sth_glyph* glyph = NULL; struct sth_glyph* glyph = NULL;
struct sth_texture* texture = NULL; struct sth_texture* texture = NULL;
@@ -673,7 +674,7 @@ void sth_draw_text(struct sth_stash* stash,
short isize = (short)(size*10.0f); short isize = (short)(size*10.0f);
Vertex* v; Vertex* v;
struct sth_font* fnt = NULL; struct sth_font* fnt = NULL;
s_retinaScale = retinaScale; s_retinaScale = retinaScale;
if (stash == NULL) return; if (stash == NULL) return;
@@ -682,23 +683,23 @@ void sth_draw_text(struct sth_stash* stash,
while(fnt != NULL && fnt->idx != idx) fnt = fnt->next; while(fnt != NULL && fnt->idx != idx) fnt = fnt->next;
if (fnt == NULL) return; if (fnt == NULL) return;
if (fnt->type != BMFONT && !fnt->data) return; if (fnt->type != BMFONT && !fnt->data) return;
for (; *s; ++s) for (; *s; ++s)
{ {
if (decutf8(&state, &codepoint, *(unsigned char*)s)) if (decutf8(&state, &codepoint, *(unsigned char*)s))
continue; continue;
glyph = get_glyph(stash, fnt, codepoint, isize); glyph = get_glyph(stash, fnt, codepoint, isize);
if (!glyph) continue; if (!glyph) continue;
texture = glyph->texture; texture = glyph->texture;
if (!measureOnly) if (!measureOnly)
{ {
if (texture->nverts+6 >= VERT_COUNT) if (texture->nverts+6 >= VERT_COUNT)
flush_draw(stash); flush_draw(stash);
} }
if (!get_quad(stash, fnt, glyph, isize, &x, &y, &q)) continue; if (!get_quad(stash, fnt, glyph, isize, &x, &y, &q)) continue;
if (!measureOnly) if (!measureOnly)
{ {
v = &texture->newverts[texture->nverts]; v = &texture->newverts[texture->nverts];
@@ -714,7 +715,7 @@ void sth_draw_text(struct sth_stash* stash,
texture->nverts += 6; texture->nverts += 6;
} }
} }
if (dx) *dx = x; if (dx) *dx = x;
} }
@@ -730,16 +731,16 @@ void sth_dim_text(struct sth_stash* stash,
short isize = (short)(size*10.0f); short isize = (short)(size*10.0f);
struct sth_font* fnt = NULL; struct sth_font* fnt = NULL;
float x = 0, y = 0; float x = 0, y = 0;
if (stash == NULL) if (stash == NULL)
return; return;
if (!stash->textures) if (!stash->textures)
return; return;
fnt = stash->fonts; fnt = stash->fonts;
while(fnt != NULL && fnt->idx != idx) fnt = fnt->next; while(fnt != NULL && fnt->idx != idx) fnt = fnt->next;
if (fnt == NULL) return; if (fnt == NULL) return;
if (fnt->type != BMFONT && !fnt->data) return; if (fnt->type != BMFONT && !fnt->data) return;
*minx = *maxx = x; *minx = *maxx = x;
*miny = *maxy = y; *miny = *maxy = y;

View File

@@ -63,6 +63,7 @@ typedef Status (*PFNXGETWINDOWATTRIBUTES) (Display* a,Window b,XWindowAttributes
#define X11_LIBRARY "libX11.so.6" #define X11_LIBRARY "libX11.so.6"
#define MyXSync m_data->m_x11_XSync #define MyXSync m_data->m_x11_XSync
#define MyXGetKeyboardMapping m_data->m_x11_XGetKeyboardMapping
#define MyXSetErrorHandler m_data->m_x11_XSetErrorHandler #define MyXSetErrorHandler m_data->m_x11_XSetErrorHandler
#define MyXOpenDisplay m_data->m_x11_XOpenDisplay #define MyXOpenDisplay m_data->m_x11_XOpenDisplay
#define MyXCreateColormap m_data->m_x11_XCreateColormap #define MyXCreateColormap m_data->m_x11_XCreateColormap
@@ -87,6 +88,7 @@ typedef Status (*PFNXGETWINDOWATTRIBUTES) (Display* a,Window b,XWindowAttributes
#else #else
#define MyXSync XSync #define MyXSync XSync
#define MyXGetKeyboardMapping XGetKeyboardMapping
#define MyXSetErrorHandler XSetErrorHandler #define MyXSetErrorHandler XSetErrorHandler
#define MyXOpenDisplay XOpenDisplay #define MyXOpenDisplay XOpenDisplay
#define MyXCreateColormap XCreateColormap #define MyXCreateColormap XCreateColormap
@@ -612,9 +614,21 @@ void X11OpenGLWindow::closeWindow()
int X11OpenGLWindow::getAsciiCodeFromVirtualKeycode(int keycode) int X11OpenGLWindow::getAsciiCodeFromVirtualKeycode(int keycode)
{ {
int result = 0;
KeySym key, key_lc, key_uc; KeySym key, key_lc, key_uc;
key = MyXKeycodeToKeysym( m_data->m_dpy, keycode, 0 ); int keysyms_per_keycode_return;
KeySym *keysym = MyXGetKeyboardMapping(m_data->m_dpy,
keycode,
1,
&keysyms_per_keycode_return);
key = keysym[0];
//key = MyXKeycodeToKeysym( m_data->m_dpy, keycode, 0 );
switch( key ) switch( key )
{ {
case XK_Escape: return B3G_ESCAPE; case XK_Escape: return B3G_ESCAPE;
@@ -660,9 +674,12 @@ int X11OpenGLWindow::getAsciiCodeFromVirtualKeycode(int keycode)
{ {
return (int) key; return (int) key;
} }
return -1; result = -1;
} }
return 0;
MyXFree(keysym);
return result;
} }
void X11OpenGLWindow::pumpMessage() void X11OpenGLWindow::pumpMessage()

View File

@@ -5,8 +5,14 @@
--flags {} --flags {}
defines { "LUA_COMPAT_ALL"} defines { "LUA_COMPAT_ALL"}
if os.is("Linux") then
defines {"LUA_USE_LINUX"}
end
if os.is("MacOSX") then
defines {"LUA_USE_MACOSX"}
end
targetdir "../../lib" targetdir "../../lib"
includedirs { includedirs {
@@ -18,4 +24,4 @@
} }
include "lua_compiler" include "lua_compiler"
include "lua_standalone" include "lua_standalone"

View File

@@ -115,6 +115,7 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym);
#if defined(LUA_USE_DLOPEN) #if defined(LUA_USE_DLOPEN)
/* /*
** {======================================================================== ** {========================================================================
** This is an implementation of loadlib based on the dlfcn interface. ** This is an implementation of loadlib based on the dlfcn interface.

View File

@@ -42,8 +42,8 @@
#if defined(LUA_USE_LINUX) #if defined(LUA_USE_LINUX)
#define LUA_USE_POSIX #define LUA_USE_POSIX
#define LUA_USE_DLOPEN /* needs an extra library: -ldl */ //#define LUA_USE_DLOPEN /* needs an extra library: -ldl */
#define LUA_USE_READLINE /* needs some extra libraries */ //#define LUA_USE_READLINE /* needs some extra libraries */
#define LUA_USE_STRTODHEX /* assume 'strtod' handles hex formats */ #define LUA_USE_STRTODHEX /* assume 'strtod' handles hex formats */
#define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */ #define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */
#define LUA_USE_LONGLONG /* assume support for long long */ #define LUA_USE_LONGLONG /* assume support for long long */
@@ -51,8 +51,8 @@
#if defined(LUA_USE_MACOSX) #if defined(LUA_USE_MACOSX)
#define LUA_USE_POSIX #define LUA_USE_POSIX
#define LUA_USE_DLOPEN /* does not need -ldl */ //#define LUA_USE_DLOPEN /* does not need -ldl */
#define LUA_USE_READLINE /* needs an extra library: -lreadline */ //#define LUA_USE_READLINE /* needs an extra library: -lreadline */
#define LUA_USE_STRTODHEX /* assume 'strtod' handles hex formats */ #define LUA_USE_STRTODHEX /* assume 'strtod' handles hex formats */
#define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */ #define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */
#define LUA_USE_LONGLONG /* assume support for long long */ #define LUA_USE_LONGLONG /* assume support for long long */

View File

@@ -26,6 +26,8 @@
http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong
Encryption is not supported. Encryption is not supported.
*/ */
#define NOCRYPT
#define NOUNCRYPT
#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) #define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))

View File

@@ -276,8 +276,9 @@ void b3GpuGridBroadphase::calculateOverlappingPairs(int maxPairs)
{ {
b3AlignedObjectArray<b3Int4> pairsCpu; b3AlignedObjectArray<b3Int4> pairsCpu;
m_gpuPairs.copyToHost(pairsCpu); m_gpuPairs.copyToHost(pairsCpu);
printf("m_gpuPairs.size()=%d\n",m_gpuPairs.size()); int sz = m_gpuPairs.size();
printf("m_gpuPairs.size()=%d\n",sz);
for (int i=0;i<m_gpuPairs.size();i++) for (int i=0;i<m_gpuPairs.size();i++)
{ {
printf("pair %d = %d,%d\n",i,pairsCpu[i].x,pairsCpu[i].y); printf("pair %d = %d,%d\n",i,pairsCpu[i].x,pairsCpu[i].y);

View File

@@ -782,7 +782,8 @@ cl_program b3OpenCLUtils_compileCLProgramFromString(cl_context clContext, cl_dev
binarySize = ftell( file ); binarySize = ftell( file );
rewind( file ); rewind( file );
binary = (char*)malloc(sizeof(char)*binarySize); binary = (char*)malloc(sizeof(char)*binarySize);
fread( binary, sizeof(char), binarySize, file ); int bytesRead;
bytesRead = fread( binary, sizeof(char), binarySize, file );
fclose( file ); fclose( file );
m_cpProgram = clCreateProgramWithBinary( clContext, 1,&device, &binarySize, (const unsigned char**)&binary, 0, &status ); m_cpProgram = clCreateProgramWithBinary( clContext, 1,&device, &binarySize, (const unsigned char**)&binary, 0, &status );

View File

@@ -74,13 +74,14 @@ bFile::bFile(const char *filename, const char headerString[7])
fseek(fp, 0L, SEEK_SET); fseek(fp, 0L, SEEK_SET);
mFileBuffer = (char*)malloc(mFileLen+1); mFileBuffer = (char*)malloc(mFileLen+1);
fread(mFileBuffer, mFileLen, 1, fp); int bytesRead;
bytesRead = fread(mFileBuffer, mFileLen, 1, fp);
fclose(fp); fclose(fp);
// //
parseHeader(); parseHeader();
} }
} }
@@ -101,9 +102,9 @@ bFile::bFile( char *memoryBuffer, int len, const char headerString[7])
} }
mFileBuffer = memoryBuffer; mFileBuffer = memoryBuffer;
mFileLen = len; mFileLen = len;
parseHeader(); parseHeader();
} }
@@ -210,12 +211,12 @@ void bFile::parseInternal(int verboseMode, char* memDna,int memDnaLength)
// read the DNA1 block and extract SDNA // read the DNA1 block and extract SDNA
if (getNextBlock(&dna, tempBuffer, mFlags) > 0) if (getNextBlock(&dna, tempBuffer, mFlags) > 0)
{ {
if (strncmp((tempBuffer + ChunkUtils::getOffset(mFlags)), "SDNANAME", 8) ==0) if (strncmp((tempBuffer + ChunkUtils::getOffset(mFlags)), "SDNANAME", 8) ==0)
dna.oldPtr = (tempBuffer + ChunkUtils::getOffset(mFlags)); dna.oldPtr = (tempBuffer + ChunkUtils::getOffset(mFlags));
else dna.oldPtr = 0; else dna.oldPtr = 0;
} }
else dna.oldPtr = 0; else dna.oldPtr = 0;
} }
// Some Bullet files are missing the DNA1 block // Some Bullet files are missing the DNA1 block
// In Blender it's DNA1 + ChunkUtils::getOffset() + SDNA + NAME // In Blender it's DNA1 + ChunkUtils::getOffset() + SDNA + NAME
// In Bullet tests its SDNA + NAME // In Bullet tests its SDNA + NAME
@@ -224,7 +225,7 @@ void bFile::parseInternal(int verboseMode, char* memDna,int memDnaLength)
dna.oldPtr = blenderData + i; dna.oldPtr = blenderData + i;
dna.len = mFileLen-i; dna.len = mFileLen-i;
// Also no REND block, so exit now. // Also no REND block, so exit now.
if (mVersion==276) break; if (mVersion==276) break;
} }
@@ -240,11 +241,11 @@ void bFile::parseInternal(int verboseMode, char* memDna,int memDnaLength)
mFileDNA = new bDNA(); mFileDNA = new bDNA();
///mFileDNA->init will convert part of DNA file endianness to current CPU endianness if necessary ///mFileDNA->init will convert part of DNA file endianness to current CPU endianness if necessary
mFileDNA->init((char*)dna.oldPtr, dna.len, (mFlags & FD_ENDIAN_SWAP)!=0); mFileDNA->init((char*)dna.oldPtr, dna.len, (mFlags & FD_ENDIAN_SWAP)!=0);
if (mVersion==276) if (mVersion==276)
{ {
@@ -270,10 +271,10 @@ void bFile::parseInternal(int verboseMode, char* memDna,int memDnaLength)
mMemoryDNA = new bDNA(); mMemoryDNA = new bDNA();
int littleEndian= 1; int littleEndian= 1;
littleEndian= ((char*)&littleEndian)[0]; littleEndian= ((char*)&littleEndian)[0];
mMemoryDNA->init(memDna,memDnaLength,littleEndian==0); mMemoryDNA->init(memDna,memDnaLength,littleEndian==0);
///@todo we need a better version check, add version/sub version info from FileGlobal into memory DNA/header files ///@todo we need a better version check, add version/sub version info from FileGlobal into memory DNA/header files
@@ -289,16 +290,16 @@ void bFile::parseInternal(int verboseMode, char* memDna,int memDnaLength)
//printf ("Warning, file DNA is newer than built in."); //printf ("Warning, file DNA is newer than built in.");
} }
mFileDNA->initCmpFlags(mMemoryDNA); mFileDNA->initCmpFlags(mMemoryDNA);
parseData(); parseData();
resolvePointers(verboseMode); resolvePointers(verboseMode);
updateOldPointers(); updateOldPointers();
} }
@@ -309,8 +310,8 @@ void bFile::swap(char *head, bChunkInd& dataChunk, bool ignoreEndianFlag)
char *data = head; char *data = head;
short *strc = mFileDNA->getStruct(dataChunk.dna_nr); short *strc = mFileDNA->getStruct(dataChunk.dna_nr);
const char s[] = "SoftBodyMaterialData"; const char s[] = "SoftBodyMaterialData";
int szs = sizeof(s); int szs = sizeof(s);
if (strncmp((char*)&dataChunk.code,"ARAY",4)==0) if (strncmp((char*)&dataChunk.code,"ARAY",4)==0)
@@ -322,7 +323,7 @@ void bFile::swap(char *head, bChunkInd& dataChunk, bool ignoreEndianFlag)
return; return;
} }
} }
int len = mFileDNA->getLength(strc[0]); int len = mFileDNA->getLength(strc[0]);
@@ -410,11 +411,11 @@ void bFile::swapDNA(char* ptr)
// Parse names // Parse names
if (swap) if (swap)
dataLen = ChunkUtils::swapInt(*intPtr); dataLen = ChunkUtils::swapInt(*intPtr);
else else
dataLen = *intPtr; dataLen = *intPtr;
*intPtr = ChunkUtils::swapInt(*intPtr); *intPtr = ChunkUtils::swapInt(*intPtr);
intPtr++; intPtr++;
@@ -426,7 +427,7 @@ void bFile::swapDNA(char* ptr)
cp++; cp++;
} }
{ {
nr= (long)cp; nr= (long)cp;
//long mask=3; //long mask=3;
@@ -448,9 +449,9 @@ void bFile::swapDNA(char* ptr)
intPtr = (int*)cp; intPtr = (int*)cp;
assert(strncmp(cp, "TYPE", 4)==0); intPtr++; assert(strncmp(cp, "TYPE", 4)==0); intPtr++;
if (swap) if (swap)
dataLen = ChunkUtils::swapInt(*intPtr); dataLen = ChunkUtils::swapInt(*intPtr);
else else
dataLen = *intPtr; dataLen = *intPtr;
*intPtr = ChunkUtils::swapInt(*intPtr); *intPtr = ChunkUtils::swapInt(*intPtr);
@@ -485,7 +486,7 @@ void bFile::swapDNA(char* ptr)
intPtr = (int*)cp; intPtr = (int*)cp;
assert(strncmp(cp, "TLEN", 4)==0); intPtr++; assert(strncmp(cp, "TLEN", 4)==0); intPtr++;
shtPtr = (short*)intPtr; shtPtr = (short*)intPtr;
for ( i=0; i<dataLen; i++, shtPtr++) for ( i=0; i<dataLen; i++, shtPtr++)
{ {
@@ -493,7 +494,7 @@ void bFile::swapDNA(char* ptr)
shtPtr[0] = ChunkUtils::swapShort(shtPtr[0]); shtPtr[0] = ChunkUtils::swapShort(shtPtr[0]);
} }
if (dataLen & 1) if (dataLen & 1)
shtPtr++; shtPtr++;
/* /*
@@ -509,12 +510,12 @@ void bFile::swapDNA(char* ptr)
intPtr = (int*)shtPtr; intPtr = (int*)shtPtr;
cp = (char*)intPtr; cp = (char*)intPtr;
assert(strncmp(cp, "STRC", 4)==0); assert(strncmp(cp, "STRC", 4)==0);
intPtr++; intPtr++;
if (swap) if (swap)
dataLen = ChunkUtils::swapInt(*intPtr); dataLen = ChunkUtils::swapInt(*intPtr);
else else
dataLen = *intPtr; dataLen = *intPtr;
*intPtr = ChunkUtils::swapInt(*intPtr); *intPtr = ChunkUtils::swapInt(*intPtr);
@@ -525,7 +526,7 @@ void bFile::swapDNA(char* ptr)
shtPtr = (short*)intPtr; shtPtr = (short*)intPtr;
for ( i=0; i<dataLen; i++) for ( i=0; i<dataLen; i++)
{ {
//if (swap) //if (swap)
{ {
int len = shtPtr[1]; int len = shtPtr[1];
@@ -573,11 +574,11 @@ void bFile::preSwap()
mFileBuffer[8]='V'; mFileBuffer[8]='V';
} }
mDataStart = 12; mDataStart = 12;
char *dataPtr = mFileBuffer+mDataStart; char *dataPtr = mFileBuffer+mDataStart;
@@ -595,7 +596,7 @@ void bFile::preSwap()
while (1) while (1)
{ {
// one behind // one behind
if (dataChunk.code == B3_SDNA || dataChunk.code==B3_DNA1 || dataChunk.code == B3_TYPE || dataChunk.code == B3_TLEN || dataChunk.code==B3_STRC) if (dataChunk.code == B3_SDNA || dataChunk.code==B3_DNA1 || dataChunk.code == B3_TYPE || dataChunk.code == B3_TLEN || dataChunk.code==B3_STRC)
{ {
swapDNA(dataPtr); swapDNA(dataPtr);
@@ -604,7 +605,7 @@ void bFile::preSwap()
{ {
//if (dataChunk.code == DNA1) break; //if (dataChunk.code == DNA1) break;
dataPtrHead = dataPtr+ChunkUtils::getOffset(mFlags); dataPtrHead = dataPtr+ChunkUtils::getOffset(mFlags);
swapLen(dataPtr); swapLen(dataPtr);
if (dataChunk.dna_nr>=0) if (dataChunk.dna_nr>=0)
{ {
@@ -632,7 +633,7 @@ void bFile::preSwap()
} }
} }
@@ -644,7 +645,7 @@ char* bFile::readStruct(char *head, bChunkInd& dataChunk)
if (mFlags & FD_ENDIAN_SWAP) if (mFlags & FD_ENDIAN_SWAP)
swap(head, dataChunk, ignoreEndianFlag); swap(head, dataChunk, ignoreEndianFlag);
if (!mFileDNA->flagEqual(dataChunk.dna_nr)) if (!mFileDNA->flagEqual(dataChunk.dna_nr))
{ {
@@ -656,7 +657,7 @@ char* bFile::readStruct(char *head, bChunkInd& dataChunk)
oldStruct = mFileDNA->getStruct(dataChunk.dna_nr); oldStruct = mFileDNA->getStruct(dataChunk.dna_nr);
oldType = mFileDNA->getType(oldStruct[0]); oldType = mFileDNA->getType(oldStruct[0]);
oldLen = mFileDNA->getLength(oldStruct[0]); oldLen = mFileDNA->getLength(oldStruct[0]);
if ((mFlags&FD_BROKEN_DNA)!=0) if ((mFlags&FD_BROKEN_DNA)!=0)
@@ -951,7 +952,7 @@ void bFile::safeSwapPtr(char *dst, const char *src)
B3_SWITCH_LONGINT(longValue); B3_SWITCH_LONGINT(longValue);
*((int*)dst) = (int)(longValue>>3); *((int*)dst) = (int)(longValue>>3);
} }
} }
else if (ptrMem==8 && ptrFile==4) else if (ptrMem==8 && ptrFile==4)
{ {
@@ -991,7 +992,7 @@ void bFile::getMatchingFileDNA(short* dna_addr, const char* lookupName, const c
const char* type = mFileDNA->getType(dna_addr[0]); const char* type = mFileDNA->getType(dna_addr[0]);
const char* name = mFileDNA->getName(dna_addr[1]); const char* name = mFileDNA->getName(dna_addr[1]);
int eleLen = mFileDNA->getElementSize(dna_addr[0], dna_addr[1]); int eleLen = mFileDNA->getElementSize(dna_addr[0], dna_addr[1]);
@@ -1008,7 +1009,7 @@ void bFile::getMatchingFileDNA(short* dna_addr, const char* lookupName, const c
//int arrayLenold = mFileDNA->getArraySize((char*)name.c_str()); //int arrayLenold = mFileDNA->getArraySize((char*)name.c_str());
int arrayLen = mFileDNA->getArraySizeNew(dna_addr[1]); int arrayLen = mFileDNA->getArraySizeNew(dna_addr[1]);
//assert(arrayLenold == arrayLen); //assert(arrayLenold == arrayLen);
if (name[0] == '*') if (name[0] == '*')
{ {
// cast pointers // cast pointers
@@ -1022,11 +1023,11 @@ void bFile::getMatchingFileDNA(short* dna_addr, const char* lookupName, const c
{ {
//void **sarray = (void**)strcData; //void **sarray = (void**)strcData;
//void **darray = (void**)data; //void **darray = (void**)data;
char *cpc, *cpo; char *cpc, *cpo;
cpc = (char*)strcData; cpc = (char*)strcData;
cpo = (char*)data; cpo = (char*)data;
for (int a=0; a<arrayLen; a++) for (int a=0; a<arrayLen; a++)
{ {
safeSwapPtr(cpc, cpo); safeSwapPtr(cpc, cpo);
@@ -1162,7 +1163,7 @@ void bFile::resolvePointersMismatch()
} }
} }
for (i=0; i<m_pointerPtrFixupArray.size(); i++) for (i=0; i<m_pointerPtrFixupArray.size(); i++)
{ {
char* cur= m_pointerPtrFixupArray.at(i); char* cur= m_pointerPtrFixupArray.at(i);
@@ -1227,7 +1228,7 @@ void bFile::resolvePointersChunk(const bChunkInd& dataChunk, int verboseMode)
int bFile::resolvePointersStructRecursive(char *strcPtr, int dna_nr, int verboseMode,int recursion) int bFile::resolvePointersStructRecursive(char *strcPtr, int dna_nr, int verboseMode,int recursion)
{ {
bParse::bDNA* fileDna = mFileDNA ? mFileDNA : mMemoryDNA; bParse::bDNA* fileDna = mFileDNA ? mFileDNA : mMemoryDNA;
char* memType; char* memType;
@@ -1238,7 +1239,7 @@ int bFile::resolvePointersStructRecursive(char *strcPtr, int dna_nr, int verbose
char* elemPtr= strcPtr; char* elemPtr= strcPtr;
short int* oldStruct = fileDna->getStruct(dna_nr); short int* oldStruct = fileDna->getStruct(dna_nr);
int elementLength = oldStruct[1]; int elementLength = oldStruct[1];
oldStruct+=2; oldStruct+=2;
@@ -1249,8 +1250,8 @@ int bFile::resolvePointersStructRecursive(char *strcPtr, int dna_nr, int verbose
memType = fileDna->getType(oldStruct[0]); memType = fileDna->getType(oldStruct[0]);
memName = fileDna->getName(oldStruct[1]); memName = fileDna->getName(oldStruct[1]);
int arrayLen = fileDna->getArraySizeNew(oldStruct[1]); int arrayLen = fileDna->getArraySizeNew(oldStruct[1]);
if (memName[0] == '*') if (memName[0] == '*')
@@ -1268,7 +1269,7 @@ int bFile::resolvePointersStructRecursive(char *strcPtr, int dna_nr, int verbose
} }
//skip the * //skip the *
printf("<%s type=\"pointer\"> ",&memName[1]); printf("<%s type=\"pointer\"> ",&memName[1]);
printf("%d ", array[a]); printf("%p ", array[a]);
printf("</%s>\n",&memName[1]); printf("</%s>\n",&memName[1]);
} }
@@ -1286,7 +1287,7 @@ int bFile::resolvePointersStructRecursive(char *strcPtr, int dna_nr, int verbose
printf(" "); printf(" ");
} }
printf("<%s type=\"pointer\"> ",&memName[1]); printf("<%s type=\"pointer\"> ",&memName[1]);
printf("%d ", ptr); printf("%p ", ptr);
printf("</%s>\n",&memName[1]); printf("</%s>\n",&memName[1]);
} }
ptr = findLibPointer(ptr); ptr = findLibPointer(ptr);
@@ -1316,7 +1317,7 @@ int bFile::resolvePointersStructRecursive(char *strcPtr, int dna_nr, int verbose
} else } else
{ {
int revType = fileDna->getReverseType(oldStruct[0]); int revType = fileDna->getReverseType(oldStruct[0]);
if (oldStruct[0]>=firstStructType) //revType != -1 && if (oldStruct[0]>=firstStructType) //revType != -1 &&
{ {
char cleanName[MAX_STRLEN]; char cleanName[MAX_STRLEN];
getCleanName(memName,cleanName); getCleanName(memName,cleanName);
@@ -1421,7 +1422,7 @@ int bFile::resolvePointersStructRecursive(char *strcPtr, int dna_nr, int verbose
} }
} }
} }
} }
} }
} }
@@ -1429,7 +1430,7 @@ int bFile::resolvePointersStructRecursive(char *strcPtr, int dna_nr, int verbose
int size = fileDna->getElementSize(oldStruct[0], oldStruct[1]); int size = fileDna->getElementSize(oldStruct[0], oldStruct[1]);
totalSize += size; totalSize += size;
elemPtr+=size; elemPtr+=size;
} }
return totalSize; return totalSize;
@@ -1445,9 +1446,9 @@ void bFile::resolvePointers(int verboseMode)
if (1) //mFlags & (FD_BITS_VARIES | FD_VERSION_VARIES)) if (1) //mFlags & (FD_BITS_VARIES | FD_VERSION_VARIES))
{ {
resolvePointersMismatch(); resolvePointersMismatch();
} }
{ {
if (verboseMode & FD_VERBOSE_EXPORT_XML) if (verboseMode & FD_VERBOSE_EXPORT_XML)
@@ -1465,9 +1466,9 @@ void bFile::resolvePointers(int verboseMode)
//dataChunk.len //dataChunk.len
short int* oldStruct = fileDna->getStruct(dataChunk.dna_nr); short int* oldStruct = fileDna->getStruct(dataChunk.dna_nr);
char* oldType = fileDna->getType(oldStruct[0]); char* oldType = fileDna->getType(oldStruct[0]);
if (verboseMode & FD_VERBOSE_EXPORT_XML) if (verboseMode & FD_VERBOSE_EXPORT_XML)
printf(" <%s pointer=%d>\n",oldType,dataChunk.oldPtr); printf(" <%s pointer=%p>\n",oldType,dataChunk.oldPtr);
resolvePointersChunk(dataChunk, verboseMode); resolvePointersChunk(dataChunk, verboseMode);
@@ -1483,8 +1484,8 @@ void bFile::resolvePointers(int verboseMode)
printf("</bullet_physics>\n"); printf("</bullet_physics>\n");
} }
} }
} }
@@ -1518,13 +1519,13 @@ void bFile::dumpChunks(bParse::bDNA* dna)
bChunkInd& dataChunk = m_chunks[i]; bChunkInd& dataChunk = m_chunks[i];
char* codeptr = (char*)&dataChunk.code; char* codeptr = (char*)&dataChunk.code;
char codestr[5] = {codeptr[0],codeptr[1],codeptr[2],codeptr[3],0}; char codestr[5] = {codeptr[0],codeptr[1],codeptr[2],codeptr[3],0};
short* newStruct = dna->getStruct(dataChunk.dna_nr); short* newStruct = dna->getStruct(dataChunk.dna_nr);
char* typeName = dna->getType(newStruct[0]); char* typeName = dna->getType(newStruct[0]);
printf("%3d: %s ",i,typeName); printf("%3d: %s ",i,typeName);
printf("code=%s ",codestr); printf("code=%s ",codestr);
printf("ptr=%p ",dataChunk.oldPtr); printf("ptr=%p ",dataChunk.oldPtr);
printf("len=%d ",dataChunk.len); printf("len=%d ",dataChunk.len);
printf("nr=%d ",dataChunk.nr); printf("nr=%d ",dataChunk.nr);
@@ -1534,8 +1535,8 @@ void bFile::dumpChunks(bParse::bDNA* dna)
} }
printf("\n"); printf("\n");
} }
@@ -1544,7 +1545,7 @@ void bFile::dumpChunks(bParse::bDNA* dna)
ifd.success = 0; ifd.success = 0;
ifd.IDname = NULL; ifd.IDname = NULL;
ifd.just_print_it = 1; ifd.just_print_it = 1;
for (i=0; i<bf->m_blocks.size(); ++i) for (i=0; i<bf->m_blocks.size(); ++i)
{ {
BlendBlock* bb = bf->m_blocks[i]; BlendBlock* bb = bf->m_blocks[i];
printf("tag='%s'\tptr=%p\ttype=%s\t[%4d]", bb->tag, bb,bf->types[bb->type_index].name,bb->m_array_entries_.size()); printf("tag='%s'\tptr=%p\ttype=%s\t[%4d]", bb->tag, bb,bf->types[bb->type_index].name,bb->m_array_entries_.size());
@@ -1563,7 +1564,7 @@ void bFile::writeChunks(FILE* fp, bool fixupPointers)
for (int i=0;i<m_chunks.size();i++) for (int i=0;i<m_chunks.size();i++)
{ {
bChunkInd& dataChunk = m_chunks.at(i); bChunkInd& dataChunk = m_chunks.at(i);
// Ouch! need to rebuild the struct // Ouch! need to rebuild the struct
short *oldStruct,*curStruct; short *oldStruct,*curStruct;
char *oldType, *newType; char *oldType, *newType;
@@ -1574,7 +1575,7 @@ void bFile::writeChunks(FILE* fp, bool fixupPointers)
oldLen = fileDna->getLength(oldStruct[0]); oldLen = fileDna->getLength(oldStruct[0]);
///don't try to convert Link block data, just memcpy it. Other data can be converted. ///don't try to convert Link block data, just memcpy it. Other data can be converted.
reverseOld = mMemoryDNA->getReverseType(oldType); reverseOld = mMemoryDNA->getReverseType(oldType);
if ((reverseOld!=-1)) if ((reverseOld!=-1))
{ {
@@ -1586,7 +1587,7 @@ void bFile::writeChunks(FILE* fp, bool fixupPointers)
// make sure it's the same // make sure it's the same
assert((strcmp(oldType, newType)==0) && "internal error, struct mismatch!"); assert((strcmp(oldType, newType)==0) && "internal error, struct mismatch!");
curLen = mMemoryDNA->getLength(curStruct[0]); curLen = mMemoryDNA->getLength(curStruct[0]);
dataChunk.dna_nr = reverseOld; dataChunk.dna_nr = reverseOld;
if (strcmp("Link",oldType)!=0) if (strcmp("Link",oldType)!=0)
@@ -1596,10 +1597,10 @@ void bFile::writeChunks(FILE* fp, bool fixupPointers)
{ {
// printf("keep length of link = %d\n",dataChunk.len); // printf("keep length of link = %d\n",dataChunk.len);
} }
//write the structure header //write the structure header
fwrite(&dataChunk,sizeof(bChunkInd),1,fp); fwrite(&dataChunk,sizeof(bChunkInd),1,fp);
short int* curStruct1; short int* curStruct1;
@@ -1615,7 +1616,7 @@ void bFile::writeChunks(FILE* fp, bool fixupPointers)
printf("serious error, struct mismatch: don't write\n"); printf("serious error, struct mismatch: don't write\n");
} }
} }
} }
@@ -1625,9 +1626,9 @@ int bFile::getNextBlock(bChunkInd *dataChunk, const char *dataPtr, const int fl
bool swap = false; bool swap = false;
bool varies = false; bool varies = false;
if (flags &FD_ENDIAN_SWAP) if (flags &FD_ENDIAN_SWAP)
swap = true; swap = true;
if (flags &FD_BITS_VARIES) if (flags &FD_BITS_VARIES)
varies = true; varies = true;
if (VOID_IS_8) if (VOID_IS_8)
@@ -1697,11 +1698,11 @@ int bFile::getNextBlock(bChunkInd *dataChunk, const char *dataPtr, const int fl
{ {
b3Long64 oldPtr =0; b3Long64 oldPtr =0;
memcpy(&oldPtr, &head.m_uniqueInts[0], 8); memcpy(&oldPtr, &head.m_uniqueInts[0], 8);
if (swap) if (swap)
B3_SWITCH_LONGINT(oldPtr); B3_SWITCH_LONGINT(oldPtr);
chunk.m_uniqueInt = (int)(oldPtr >> 3); chunk.m_uniqueInt = (int)(oldPtr >> 3);
} }
chunk.dna_nr = head.dna_nr; chunk.dna_nr = head.dna_nr;
chunk.nr = head.nr; chunk.nr = head.nr;

View File

@@ -1,117 +1,117 @@
/* /*
Bullet Continuous Collision Detection and Physics Library Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2011 Advanced Micro Devices, Inc. http://bulletphysics.org Copyright (c) 2011 Advanced Micro Devices, Inc. http://bulletphysics.org
This software is provided 'as-is', without any express or implied warranty. This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software. In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely, including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions: subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef GRAHAM_SCAN_2D_CONVEX_HULL_H #ifndef GRAHAM_SCAN_2D_CONVEX_HULL_H
#define GRAHAM_SCAN_2D_CONVEX_HULL_H #define GRAHAM_SCAN_2D_CONVEX_HULL_H
#include "btVector3.h" #include "btVector3.h"
#include "btAlignedObjectArray.h" #include "btAlignedObjectArray.h"
struct GrahamVector3 : public btVector3 struct GrahamVector3 : public btVector3
{ {
GrahamVector3(const btVector3& org, int orgIndex) GrahamVector3(const btVector3& org, int orgIndex)
:btVector3(org), :btVector3(org),
m_orgIndex(orgIndex) m_orgIndex(orgIndex)
{ {
} }
btScalar m_angle; btScalar m_angle;
int m_orgIndex; int m_orgIndex;
}; };
struct btAngleCompareFunc { struct btAngleCompareFunc {
btVector3 m_anchor; btVector3 m_anchor;
btAngleCompareFunc(const btVector3& anchor) btAngleCompareFunc(const btVector3& anchor)
: m_anchor(anchor) : m_anchor(anchor)
{ {
} }
bool operator()(const GrahamVector3& a, const GrahamVector3& b) const { bool operator()(const GrahamVector3& a, const GrahamVector3& b) const {
if (a.m_angle != b.m_angle) if (a.m_angle != b.m_angle)
return a.m_angle < b.m_angle; return a.m_angle < b.m_angle;
else else
{ {
btScalar al = (a-m_anchor).length2(); btScalar al = (a-m_anchor).length2();
btScalar bl = (b-m_anchor).length2(); btScalar bl = (b-m_anchor).length2();
if (al != bl) if (al != bl)
return al < bl; return al < bl;
else else
{ {
return a.m_orgIndex < b.m_orgIndex; return a.m_orgIndex < b.m_orgIndex;
} }
} }
} }
}; };
inline void GrahamScanConvexHull2D(btAlignedObjectArray<GrahamVector3>& originalPoints, btAlignedObjectArray<GrahamVector3>& hull, const btVector3& normalAxis) inline void GrahamScanConvexHull2D(btAlignedObjectArray<GrahamVector3>& originalPoints, btAlignedObjectArray<GrahamVector3>& hull, const btVector3& normalAxis)
{ {
btVector3 axis0,axis1; btVector3 axis0,axis1;
btPlaneSpace1(normalAxis,axis0,axis1); btPlaneSpace1(normalAxis,axis0,axis1);
if (originalPoints.size()<=1) if (originalPoints.size()<=1)
{ {
for (int i=0;i<originalPoints.size();i++) for (int i=0;i<originalPoints.size();i++)
hull.push_back(originalPoints[0]); hull.push_back(originalPoints[0]);
return; return;
} }
//step1 : find anchor point with smallest projection on axis0 and move it to first location //step1 : find anchor point with smallest projection on axis0 and move it to first location
for (int i=0;i<originalPoints.size();i++) for (int i=0;i<originalPoints.size();i++)
{ {
// const btVector3& left = originalPoints[i]; // const btVector3& left = originalPoints[i];
// const btVector3& right = originalPoints[0]; // const btVector3& right = originalPoints[0];
btScalar projL = originalPoints[i].dot(axis0); btScalar projL = originalPoints[i].dot(axis0);
btScalar projR = originalPoints[0].dot(axis0); btScalar projR = originalPoints[0].dot(axis0);
if (projL < projR) if (projL < projR)
{ {
originalPoints.swap(0,i); originalPoints.swap(0,i);
} }
} }
//also precompute angles //also precompute angles
originalPoints[0].m_angle = -1e30f; originalPoints[0].m_angle = -1e30f;
for (int i=1;i<originalPoints.size();i++) for (int i=1;i<originalPoints.size();i++)
{ {
btVector3 xvec = axis0; btVector3 xvec = axis0;
btVector3 ar = originalPoints[i]-originalPoints[0]; btVector3 ar = originalPoints[i]-originalPoints[0];
originalPoints[i].m_angle = btCross(xvec, ar).dot(normalAxis) / ar.length(); originalPoints[i].m_angle = btCross(xvec, ar).dot(normalAxis) / ar.length();
} }
//step 2: sort all points, based on 'angle' with this anchor //step 2: sort all points, based on 'angle' with this anchor
btAngleCompareFunc comp(originalPoints[0]); btAngleCompareFunc comp(originalPoints[0]);
originalPoints.quickSortInternal(comp,1,originalPoints.size()-1); originalPoints.quickSortInternal(comp,1,originalPoints.size()-1);
int i; int i;
for (i = 0; i<2; i++) for (i = 0; i<2; i++)
hull.push_back(originalPoints[i]); hull.push_back(originalPoints[i]);
//step 3: keep all 'convex' points and discard concave points (using back tracking) //step 3: keep all 'convex' points and discard concave points (using back tracking)
for (; i != originalPoints.size(); i++) for (; i != originalPoints.size(); i++)
{ {
bool isConvex = false; bool isConvex = false;
while (!isConvex&& hull.size()>1) { while (!isConvex&& hull.size()>1) {
btVector3& a = hull[hull.size()-2]; btVector3& a = hull[hull.size()-2];
btVector3& b = hull[hull.size()-1]; btVector3& b = hull[hull.size()-1];
isConvex = btCross(a-b,a-originalPoints[i]).dot(normalAxis)> 0; isConvex = btCross(a-b,a-originalPoints[i]).dot(normalAxis)> 0;
if (!isConvex) if (!isConvex)
hull.pop_back(); hull.pop_back();
else else
hull.push_back(originalPoints[i]); hull.push_back(originalPoints[i]);
} }
} }
} }
#endif //GRAHAM_SCAN_2D_CONVEX_HULL_H #endif //GRAHAM_SCAN_2D_CONVEX_HULL_H

View File

@@ -46,7 +46,8 @@ class btIDebugDraw
DBG_DrawConstraints = (1 << 11), DBG_DrawConstraints = (1 << 11),
DBG_DrawConstraintLimits = (1 << 12), DBG_DrawConstraintLimits = (1 << 12),
DBG_FastWireframe = (1<<13), DBG_FastWireframe = (1<<13),
DBG_DrawNormals = (1<<14), DBG_DrawNormals = (1<<14),
DBG_DrawFrames = (1<<15),
DBG_MAX_DEBUG_DRAW_MODE DBG_MAX_DEBUG_DRAW_MODE
}; };
@@ -147,7 +148,7 @@ class btIDebugDraw
const btVector3& vx = axis; const btVector3& vx = axis;
btVector3 vy = normal.cross(axis); btVector3 vy = normal.cross(axis);
btScalar step = stepDegrees * SIMD_RADS_PER_DEG; btScalar step = stepDegrees * SIMD_RADS_PER_DEG;
int nSteps = (int)((maxAngle - minAngle) / step); int nSteps = (int)btFabs((maxAngle - minAngle) / step);
if(!nSteps) nSteps = 1; if(!nSteps) nSteps = 1;
btVector3 prev = center + radiusA * vx * btCos(minAngle) + radiusB * vy * btSin(minAngle); btVector3 prev = center + radiusA * vx * btCos(minAngle) + radiusB * vy * btSin(minAngle);
if(drawSect) if(drawSect)
@@ -438,11 +439,10 @@ class btIDebugDraw
drawLine(transform*pt0,transform*pt1,color); drawLine(transform*pt0,transform*pt1,color);
drawLine(transform*pt2,transform*pt3,color); drawLine(transform*pt2,transform*pt3,color);
} }
virtual void flushLines() virtual void flushLines()
{ {
}
}
}; };

File diff suppressed because it is too large Load Diff

0
src/LinearMath/btPoolAllocator.h Executable file → Normal file
View File

View File

@@ -10,7 +10,7 @@
** **
***************************************************************************************************/ ***************************************************************************************************/
// Credits: The Clock class was inspired by the Timer classes in // Credits: The Clock class was inspired by the Timer classes in
// Ogre (www.ogre3d.org). // Ogre (www.ogre3d.org).
#include "btQuickprof.h" #include "btQuickprof.h"
@@ -27,8 +27,8 @@ static btClock gProfileClock;
#include <stdio.h> #include <stdio.h>
#endif #endif
#if defined (SUNOS) || defined (__SUNOS__) #if defined (SUNOS) || defined (__SUNOS__)
#include <stdio.h> #include <stdio.h>
#endif #endif
#if defined(WIN32) || defined(_WIN32) #if defined(WIN32) || defined(_WIN32)
@@ -37,7 +37,7 @@ static btClock gProfileClock;
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#define NOWINRES #define NOWINRES
#define NOMCX #define NOMCX
#define NOIME #define NOIME
#ifdef _XBOX #ifdef _XBOX
#include <Xtl.h> #include <Xtl.h>
@@ -121,34 +121,34 @@ void btClock::reset()
#endif #endif
} }
/// Returns the time in ms since the last call to reset or since /// Returns the time in ms since the last call to reset or since
/// the btClock was created. /// the btClock was created.
unsigned long int btClock::getTimeMilliseconds() unsigned long int btClock::getTimeMilliseconds()
{ {
#ifdef BT_USE_WINDOWS_TIMERS #ifdef BT_USE_WINDOWS_TIMERS
LARGE_INTEGER currentTime; LARGE_INTEGER currentTime;
QueryPerformanceCounter(&currentTime); QueryPerformanceCounter(&currentTime);
LONGLONG elapsedTime = currentTime.QuadPart - LONGLONG elapsedTime = currentTime.QuadPart -
m_data->mStartTime.QuadPart; m_data->mStartTime.QuadPart;
// Compute the number of millisecond ticks elapsed. // Compute the number of millisecond ticks elapsed.
unsigned long msecTicks = (unsigned long)(1000 * elapsedTime / unsigned long msecTicks = (unsigned long)(1000 * elapsedTime /
m_data->mClockFrequency.QuadPart); m_data->mClockFrequency.QuadPart);
// Check for unexpected leaps in the Win32 performance counter. // Check for unexpected leaps in the Win32 performance counter.
// (This is caused by unexpected data across the PCI to ISA // (This is caused by unexpected data across the PCI to ISA
// bridge, aka south bridge. See Microsoft KB274323.) // bridge, aka south bridge. See Microsoft KB274323.)
unsigned long elapsedTicks = GetTickCount() - m_data->mStartTick; unsigned long elapsedTicks = GetTickCount() - m_data->mStartTick;
signed long msecOff = (signed long)(msecTicks - elapsedTicks); signed long msecOff = (signed long)(msecTicks - elapsedTicks);
if (msecOff < -100 || msecOff > 100) if (msecOff < -100 || msecOff > 100)
{ {
// Adjust the starting time forwards. // Adjust the starting time forwards.
LONGLONG msecAdjustment = mymin(msecOff * LONGLONG msecAdjustment = mymin(msecOff *
m_data->mClockFrequency.QuadPart / 1000, elapsedTime - m_data->mClockFrequency.QuadPart / 1000, elapsedTime -
m_data->mPrevElapsedTime); m_data->mPrevElapsedTime);
m_data->mStartTime.QuadPart += msecAdjustment; m_data->mStartTime.QuadPart += msecAdjustment;
elapsedTime -= msecAdjustment; elapsedTime -= msecAdjustment;
// Recompute the number of millisecond ticks elapsed. // Recompute the number of millisecond ticks elapsed.
msecTicks = (unsigned long)(1000 * elapsedTime / msecTicks = (unsigned long)(1000 * elapsedTime /
m_data->mClockFrequency.QuadPart); m_data->mClockFrequency.QuadPart);
} }
@@ -171,36 +171,36 @@ unsigned long int btClock::getTimeMilliseconds()
struct timeval currentTime; struct timeval currentTime;
gettimeofday(&currentTime, 0); gettimeofday(&currentTime, 0);
return (currentTime.tv_sec - m_data->mStartTime.tv_sec) * 1000 + return (currentTime.tv_sec - m_data->mStartTime.tv_sec) * 1000 +
(currentTime.tv_usec - m_data->mStartTime.tv_usec) / 1000; (currentTime.tv_usec - m_data->mStartTime.tv_usec) / 1000;
#endif //__CELLOS_LV2__ #endif //__CELLOS_LV2__
#endif #endif
} }
/// Returns the time in us since the last call to reset or since /// Returns the time in us since the last call to reset or since
/// the Clock was created. /// the Clock was created.
unsigned long int btClock::getTimeMicroseconds() unsigned long int btClock::getTimeMicroseconds()
{ {
#ifdef BT_USE_WINDOWS_TIMERS #ifdef BT_USE_WINDOWS_TIMERS
LARGE_INTEGER currentTime; LARGE_INTEGER currentTime;
QueryPerformanceCounter(&currentTime); QueryPerformanceCounter(&currentTime);
LONGLONG elapsedTime = currentTime.QuadPart - LONGLONG elapsedTime = currentTime.QuadPart -
m_data->mStartTime.QuadPart; m_data->mStartTime.QuadPart;
// Compute the number of millisecond ticks elapsed. // Compute the number of millisecond ticks elapsed.
unsigned long msecTicks = (unsigned long)(1000 * elapsedTime / unsigned long msecTicks = (unsigned long)(1000 * elapsedTime /
m_data->mClockFrequency.QuadPart); m_data->mClockFrequency.QuadPart);
// Check for unexpected leaps in the Win32 performance counter. // Check for unexpected leaps in the Win32 performance counter.
// (This is caused by unexpected data across the PCI to ISA // (This is caused by unexpected data across the PCI to ISA
// bridge, aka south bridge. See Microsoft KB274323.) // bridge, aka south bridge. See Microsoft KB274323.)
unsigned long elapsedTicks = GetTickCount() - m_data->mStartTick; unsigned long elapsedTicks = GetTickCount() - m_data->mStartTick;
signed long msecOff = (signed long)(msecTicks - elapsedTicks); signed long msecOff = (signed long)(msecTicks - elapsedTicks);
if (msecOff < -100 || msecOff > 100) if (msecOff < -100 || msecOff > 100)
{ {
// Adjust the starting time forwards. // Adjust the starting time forwards.
LONGLONG msecAdjustment = mymin(msecOff * LONGLONG msecAdjustment = mymin(msecOff *
m_data->mClockFrequency.QuadPart / 1000, elapsedTime - m_data->mClockFrequency.QuadPart / 1000, elapsedTime -
m_data->mPrevElapsedTime); m_data->mPrevElapsedTime);
m_data->mStartTime.QuadPart += msecAdjustment; m_data->mStartTime.QuadPart += msecAdjustment;
elapsedTime -= msecAdjustment; elapsedTime -= msecAdjustment;
@@ -210,7 +210,7 @@ unsigned long int btClock::getTimeMicroseconds()
m_data->mPrevElapsedTime = elapsedTime; m_data->mPrevElapsedTime = elapsedTime;
// Convert to microseconds. // Convert to microseconds.
unsigned long usecTicks = (unsigned long)(1000000 * elapsedTime / unsigned long usecTicks = (unsigned long)(1000000 * elapsedTime /
m_data->mClockFrequency.QuadPart); m_data->mClockFrequency.QuadPart);
return usecTicks; return usecTicks;
@@ -229,10 +229,10 @@ unsigned long int btClock::getTimeMicroseconds()
struct timeval currentTime; struct timeval currentTime;
gettimeofday(&currentTime, 0); gettimeofday(&currentTime, 0);
return (currentTime.tv_sec - m_data->mStartTime.tv_sec) * 1000000 + return (currentTime.tv_sec - m_data->mStartTime.tv_sec) * 1000000 +
(currentTime.tv_usec - m_data->mStartTime.tv_usec); (currentTime.tv_usec - m_data->mStartTime.tv_usec);
#endif//__CELLOS_LV2__ #endif//__CELLOS_LV2__
#endif #endif
} }
@@ -325,7 +325,7 @@ CProfileNode * CProfileNode::Get_Sub_Node( const char * name )
} }
// We didn't find it, so add it // We didn't find it, so add it
CProfileNode * node = new CProfileNode( name, this ); CProfileNode * node = new CProfileNode( name, this );
node->Sibling = Child; node->Sibling = Child;
Child = node; Child = node;
@@ -337,7 +337,7 @@ void CProfileNode::Reset( void )
{ {
TotalCalls = 0; TotalCalls = 0;
TotalTime = 0.0f; TotalTime = 0.0f;
if ( Child ) { if ( Child ) {
Child->Reset(); Child->Reset();
@@ -359,7 +359,7 @@ void CProfileNode::Call( void )
bool CProfileNode::Return( void ) bool CProfileNode::Return( void )
{ {
if ( --RecursionCounter == 0 && TotalCalls != 0 ) { if ( --RecursionCounter == 0 && TotalCalls != 0 ) {
unsigned long int time; unsigned long int time;
Profile_Get_Ticks(&time); Profile_Get_Ticks(&time);
time-=StartTime; time-=StartTime;
@@ -452,8 +452,8 @@ void CProfileManager::Start_Profile( const char * name )
{ {
if (name != CurrentNode->Get_Name()) { if (name != CurrentNode->Get_Name()) {
CurrentNode = CurrentNode->Get_Sub_Node( name ); CurrentNode = CurrentNode->Get_Sub_Node( name );
} }
CurrentNode->Call(); CurrentNode->Call();
} }
@@ -477,7 +477,7 @@ void CProfileManager::Stop_Profile( void )
* This resets everything except for the tree structure. All of the timing data is reset. * * This resets everything except for the tree structure. All of the timing data is reset. *
*=============================================================================================*/ *=============================================================================================*/
void CProfileManager::Reset( void ) void CProfileManager::Reset( void )
{ {
gProfileClock.reset(); gProfileClock.reset();
Root.Reset(); Root.Reset();
Root.Call(); Root.Call();
@@ -523,9 +523,9 @@ void CProfileManager::dumpRecursive(CProfileIterator* profileIterator, int spaci
printf("Profiling: %s (total running time: %.3f ms) ---\n", profileIterator->Get_Current_Parent_Name(), parent_time ); printf("Profiling: %s (total running time: %.3f ms) ---\n", profileIterator->Get_Current_Parent_Name(), parent_time );
float totalTime = 0.f; float totalTime = 0.f;
int numChildren = 0; int numChildren = 0;
for (i = 0; !profileIterator->Is_Done(); i++,profileIterator->Next()) for (i = 0; !profileIterator->Is_Done(); i++,profileIterator->Next())
{ {
numChildren++; numChildren++;
@@ -546,7 +546,7 @@ void CProfileManager::dumpRecursive(CProfileIterator* profileIterator, int spaci
} }
for (i=0;i<spacing;i++) printf("."); for (i=0;i<spacing;i++) printf(".");
printf("%s (%.3f %%) :: %.3f ms\n", "Unaccounted:",parent_time > SIMD_EPSILON ? ((parent_time - accumulated_time) / parent_time) * 100 : 0.f, parent_time - accumulated_time); printf("%s (%.3f %%) :: %.3f ms\n", "Unaccounted:",parent_time > SIMD_EPSILON ? ((parent_time - accumulated_time) / parent_time) * 100 : 0.f, parent_time - accumulated_time);
for (i=0;i<numChildren;i++) for (i=0;i<numChildren;i++)
{ {
profileIterator->Enter_Child(i); profileIterator->Enter_Child(i);

View File

@@ -97,7 +97,7 @@ inline int btGetVersion()
#ifdef BT_DEBUG #ifdef BT_DEBUG
#ifdef _MSC_VER #ifdef _MSC_VER
#include <stdio.h> #include <stdio.h>
#define btAssert(x) { if(!(x)){printf("Assert " __FILE__ ":%u ("#x")\n", __LINE__);__debugbreak(); }} #define btAssert(x) { if(!(x)){printf("Assert "__FILE__ ":%u ("#x")\n", __LINE__);__debugbreak(); }}
#else//_MSC_VER #else//_MSC_VER
#include <assert.h> #include <assert.h>
#define btAssert assert #define btAssert assert
@@ -125,7 +125,7 @@ inline int btGetVersion()
#ifdef __SPU__ #ifdef __SPU__
#include <spu_printf.h> #include <spu_printf.h>
#define printf spu_printf #define printf spu_printf
#define btAssert(x) {if(!(x)){printf("Assert " __FILE__ ":%u ("#x")\n", __LINE__);spu_hcmpeq(0,0);}} #define btAssert(x) {if(!(x)){printf("Assert "__FILE__ ":%u ("#x")\n", __LINE__);spu_hcmpeq(0,0);}}
#else #else
#define btAssert assert #define btAssert assert
#endif #endif

View File

@@ -21,7 +21,7 @@ extern char** gArgv;
namespace namespace
{ {
struct ExecuteBullet3NarrowphaseKernels : public ::testing::Test struct ExecuteBullet3NarrowphaseKernels : public ::testing::Test
{ {
cl_context m_clContext; cl_context m_clContext;
cl_device_id m_clDevice; cl_device_id m_clDevice;
@@ -41,7 +41,7 @@ namespace
initCL(); initCL();
} }
virtual ~ExecuteBullet3NarrowphaseKernels() virtual ~ExecuteBullet3NarrowphaseKernels()
{ {
// You can do clean-up work that doesn't throw exceptions here. // You can do clean-up work that doesn't throw exceptions here.
exitCL(); exitCL();
@@ -51,8 +51,8 @@ namespace
// and cleaning up each test, you can define the following methods: // and cleaning up each test, you can define the following methods:
#include "initCL.h" #include "initCL.h"
virtual void SetUp() virtual void SetUp()
{ {
@@ -60,7 +60,7 @@ namespace
// before each test). // before each test).
} }
virtual void TearDown() virtual void TearDown()
{ {
// Code here will be called immediately after each test (right // Code here will be called immediately after each test (right
// before the destructor). // before the destructor).
@@ -71,13 +71,13 @@ namespace
TEST_F(ExecuteBullet3NarrowphaseKernels,satKernelsCL) TEST_F(ExecuteBullet3NarrowphaseKernels,satKernelsCL)
{ {
cl_int errNum=0; cl_int errNum=0;
char flags[1024]={0}; char flags[1024]={0};
cl_program satProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,satKernelsCL,&errNum,flags,0,true); cl_program satProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,satKernelsCL,&errNum,flags,0,true);
ASSERT_EQ(CL_SUCCESS,errNum); ASSERT_EQ(CL_SUCCESS,errNum);
{ {
cl_kernel m_findSeparatingAxisKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satKernelsCL, "findSeparatingAxisKernel",&errNum,satProg ); cl_kernel m_findSeparatingAxisKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satKernelsCL, "findSeparatingAxisKernel",&errNum,satProg );
ASSERT_EQ(CL_SUCCESS,errNum); ASSERT_EQ(CL_SUCCESS,errNum);
@@ -101,9 +101,9 @@ namespace
ASSERT_EQ(CL_SUCCESS,errNum); ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(m_findConcaveSeparatingAxisKernel ); clReleaseKernel(m_findConcaveSeparatingAxisKernel );
} }
{ {
cl_kernel m_findCompoundPairsKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satKernelsCL, "findCompoundPairsKernel",&errNum,satProg ); cl_kernel m_findCompoundPairsKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satKernelsCL, "findCompoundPairsKernel",&errNum,satProg );
ASSERT_EQ(CL_SUCCESS,errNum); ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(m_findCompoundPairsKernel); clReleaseKernel(m_findCompoundPairsKernel);
@@ -122,7 +122,7 @@ namespace
TEST_F(ExecuteBullet3NarrowphaseKernels,satConcaveKernelsCL) TEST_F(ExecuteBullet3NarrowphaseKernels,satConcaveKernelsCL)
{ {
cl_int errNum=0; cl_int errNum=0;
char flags[1024]={0}; char flags[1024]={0};
cl_program satConcaveProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,satConcaveKernelsCL,&errNum,flags,0,true); cl_program satConcaveProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,satConcaveKernelsCL,&errNum,flags,0,true);
@@ -133,20 +133,20 @@ namespace
ASSERT_EQ(CL_SUCCESS,errNum); ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(m_findConcaveSeparatingAxisVertexFaceKernel); clReleaseKernel(m_findConcaveSeparatingAxisVertexFaceKernel);
} }
{ {
cl_kernel m_findConcaveSeparatingAxisEdgeEdgeKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satConcaveKernelsCL, "findConcaveSeparatingAxisEdgeEdgeKernel",&errNum,satConcaveProg ); cl_kernel m_findConcaveSeparatingAxisEdgeEdgeKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satConcaveKernelsCL, "findConcaveSeparatingAxisEdgeEdgeKernel",&errNum,satConcaveProg );
ASSERT_EQ(CL_SUCCESS,errNum); ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(m_findConcaveSeparatingAxisEdgeEdgeKernel); clReleaseKernel(m_findConcaveSeparatingAxisEdgeEdgeKernel);
} }
clReleaseProgram(satConcaveProg); clReleaseProgram(satConcaveProg);
} }
TEST_F(ExecuteBullet3NarrowphaseKernels,satClipKernelsCL) TEST_F(ExecuteBullet3NarrowphaseKernels,satClipKernelsCL)
{ {
char flags[1024]={0}; char flags[1024]={0};
cl_int errNum=0; cl_int errNum=0;
//#ifdef CL_PLATFORM_INTEL //#ifdef CL_PLATFORM_INTEL
@@ -167,7 +167,7 @@ namespace
ASSERT_EQ(CL_SUCCESS,errNum); ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(m_clipCompoundsHullHullKernel); clReleaseKernel(m_clipCompoundsHullHullKernel);
} }
{ {
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satClipKernelsCL, "findClippingFacesKernel",&errNum,satClipContactsProg); cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satClipKernelsCL, "findClippingFacesKernel",&errNum,satClipContactsProg);
ASSERT_EQ(CL_SUCCESS,errNum); ASSERT_EQ(CL_SUCCESS,errNum);
@@ -177,13 +177,13 @@ namespace
{ {
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satClipKernelsCL, "clipFacesAndFindContactsKernel",&errNum,satClipContactsProg); cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satClipKernelsCL, "clipFacesAndFindContactsKernel",&errNum,satClipContactsProg);
ASSERT_EQ(CL_SUCCESS,errNum); ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(k); clReleaseKernel(k);
} }
{ {
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satClipKernelsCL, "clipHullHullConcaveConvexKernel",&errNum,satClipContactsProg); cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satClipKernelsCL, "clipHullHullConcaveConvexKernel",&errNum,satClipContactsProg);
ASSERT_EQ(CL_SUCCESS,errNum); ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(k); clReleaseKernel(k);
} }
@@ -191,9 +191,9 @@ namespace
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satClipKernelsCL, cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satClipKernelsCL,
"newContactReductionKernel",&errNum,satClipContactsProg); "newContactReductionKernel",&errNum,satClipContactsProg);
ASSERT_EQ(CL_SUCCESS,errNum); ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(k); clReleaseKernel(k);
} }
clReleaseProgram(satClipContactsProg); clReleaseProgram(satClipContactsProg);
} }
@@ -201,7 +201,7 @@ namespace
TEST_F(ExecuteBullet3NarrowphaseKernels,bvhTraversalKernels) TEST_F(ExecuteBullet3NarrowphaseKernels,bvhTraversalKernels)
{ {
cl_int errNum=0; cl_int errNum=0;
cl_program bvhTraversalProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,bvhTraversalKernelCL,&errNum,"",0,true); cl_program bvhTraversalProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,bvhTraversalKernelCL,&errNum,"",0,true);
ASSERT_EQ(CL_SUCCESS,errNum); ASSERT_EQ(CL_SUCCESS,errNum);
@@ -209,7 +209,7 @@ namespace
{ {
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,bvhTraversalKernelCL, "bvhTraversalKernel",&errNum,bvhTraversalProg,""); cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,bvhTraversalKernelCL, "bvhTraversalKernel",&errNum,bvhTraversalProg,"");
ASSERT_EQ(CL_SUCCESS,errNum); ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(k); clReleaseKernel(k);
} }
clReleaseProgram(bvhTraversalProg); clReleaseProgram(bvhTraversalProg);
} }
@@ -224,21 +224,21 @@ namespace
{ {
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,primitiveContactsKernelsCL, "primitiveContactsKernel",&errNum,primitiveContactsProg,""); cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,primitiveContactsKernelsCL, "primitiveContactsKernel",&errNum,primitiveContactsProg,"");
ASSERT_EQ(CL_SUCCESS,errNum); ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(k); clReleaseKernel(k);
} }
{ {
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,primitiveContactsKernelsCL, "findConcaveSphereContactsKernel",&errNum,primitiveContactsProg ); cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,primitiveContactsKernelsCL, "findConcaveSphereContactsKernel",&errNum,primitiveContactsProg );
ASSERT_EQ(CL_SUCCESS,errNum); ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(k); clReleaseKernel(k);
} }
{ {
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,primitiveContactsKernelsCL, "processCompoundPairsPrimitivesKernel",&errNum,primitiveContactsProg,""); cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,primitiveContactsKernelsCL, "processCompoundPairsPrimitivesKernel",&errNum,primitiveContactsProg,"");
ASSERT_EQ(CL_SUCCESS,errNum); ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(k); clReleaseKernel(k);
} }
clReleaseProgram(primitiveContactsProg); clReleaseProgram(primitiveContactsProg);
} }
@@ -272,8 +272,8 @@ namespace
unzFile zipfile = unzOpen( relativeFileName); unzFile zipfile = unzOpen( relativeFileName);
if ( zipfile == NULL ) if ( zipfile == NULL )
{ {
printf( "%s: not found\n" ); printf( "%s: not found\n" ,relativeFileName);
} }
// Get info about the zip file // Get info about the zip file
@@ -286,17 +286,17 @@ namespace
} else } else
{ {
result = unzLocateFile(zipfile, fileName, 0); result = unzLocateFile(zipfile, fileName, 0);
if (result == UNZ_OK) if (result == UNZ_OK)
{ {
unz_file_info info; unz_file_info info;
result = unzGetCurrentFileInfo( zipfile, &info, NULL, 0, NULL, 0, NULL, 0 ); result = unzGetCurrentFileInfo( zipfile, &info, NULL, 0, NULL, 0, NULL, 0 );
if ( result != UNZ_OK ) if ( result != UNZ_OK )
{ {
b3Printf("unzGetCurrentFileInfo() != UNZ_OK (%d)\n", result); b3Printf("unzGetCurrentFileInfo() != UNZ_OK (%d)\n", result);
} else } else
{ {
result = unzOpenCurrentFile(zipfile); result = unzOpenCurrentFile(zipfile);
if (result == UNZ_OK) if (result == UNZ_OK)
{ {
buffer = (unsigned char*)malloc(info.uncompressed_size); buffer = (unsigned char*)malloc(info.uncompressed_size);
result = unzReadCurrentFile(zipfile,buffer,info.uncompressed_size); result = unzReadCurrentFile(zipfile,buffer,info.uncompressed_size);
@@ -334,7 +334,7 @@ namespace
f = fopen(relativeFileName,"rb"); f = fopen(relativeFileName,"rb");
} }
//first try from data.zip, otherwise directly load the file from disk //first try from data.zip, otherwise directly load the file from disk
if (f) if (f)
{ {
int sizeInBytes=0; int sizeInBytes=0;
@@ -355,7 +355,7 @@ namespace
} }
fclose(f); fclose(f);
} }
} }
return buffer; return buffer;
@@ -374,7 +374,7 @@ namespace
int num = *(int*)&buf[serializedBytes]; int num = *(int*)&buf[serializedBytes];
launcher.launch1D( num); launcher.launch1D( num);
free(buf); free(buf);
//this clFinish is for testing on errors //this clFinish is for testing on errors
} }
@@ -382,13 +382,13 @@ namespace
TEST_F(ExecuteBullet3NarrowphaseKernels,mprKernelsCL) TEST_F(ExecuteBullet3NarrowphaseKernels,mprKernelsCL)
{ {
cl_int errNum=0; cl_int errNum=0;
const char* srcConcave = satConcaveKernelsCL; const char* srcConcave = satConcaveKernelsCL;
char flags[1024]={0}; char flags[1024]={0};
cl_program mprProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,mprKernelsCL,&errNum,flags,0,true); cl_program mprProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,mprKernelsCL,&errNum,flags,0,true);
ASSERT_EQ(CL_SUCCESS,errNum); ASSERT_EQ(CL_SUCCESS,errNum);
{ {
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,mprKernelsCL, "mprPenetrationKernel",&errNum,mprProg ); cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,mprKernelsCL, "mprPenetrationKernel",&errNum,mprProg );
ASSERT_EQ(CL_SUCCESS,errNum); ASSERT_EQ(CL_SUCCESS,errNum);
@@ -397,7 +397,7 @@ namespace
{ {
const char* fileNames[]={"mprPenetrationKernel60.bin","mprPenetrationKernel61.bin","mprPenetrationKernel70.bin","mprPenetrationKernel128.bin"}; const char* fileNames[]={"mprPenetrationKernel60.bin","mprPenetrationKernel61.bin","mprPenetrationKernel70.bin","mprPenetrationKernel128.bin"};
int results[] = {0,1,46,98}; int results[] = {0,1,46,98};
int numTests = sizeof(fileNames)/sizeof(const char*); int numTests = sizeof(fileNames)/sizeof(const char*);
for (int i=0;i<numTests;i++) for (int i=0;i<numTests;i++)
{ {
@@ -414,7 +414,7 @@ namespace
ASSERT_EQ(results[i],numContacts); ASSERT_EQ(results[i],numContacts);
} }
//printf("numContacts = %d\n",numContacts); //printf("numContacts = %d\n",numContacts);
//nContacts = m_totalContactsOut.at(0); //nContacts = m_totalContactsOut.at(0);
} }
@@ -422,15 +422,15 @@ namespace
clReleaseKernel(k); clReleaseKernel(k);
} }
{ {
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,mprKernelsCL, "findSeparatingAxisUnitSphereKernel",&errNum,mprProg ); cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,mprKernelsCL, "findSeparatingAxisUnitSphereKernel",&errNum,mprProg );
ASSERT_EQ(CL_SUCCESS,errNum); ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(k); clReleaseKernel(k);
} }
clReleaseProgram(mprProg); clReleaseProgram(mprProg);
} }

View File

@@ -111,7 +111,7 @@ __kernel void testKernel( __global int* testData, __global b3Contact4Data_t* c
void myprintf(const char* msg) void myprintf(const char* msg)
{ {
//OutputDebugStringA(msg); //OutputDebugStringA(msg);
printf(msg); printf("%s",msg);
} }
int main(int argc, char* argv[]) int main(int argc, char* argv[])
@@ -160,7 +160,7 @@ int main(int argc, char* argv[])
cl_command_queue queue = clCreateCommandQueue(context, dev, 0, &errNum); cl_command_queue queue = clCreateCommandQueue(context, dev, 0, &errNum);
cl_program pairBenchProg=0; cl_program pairBenchProg=0;
cl_kernel testKernel = b3OpenCLUtils::compileCLKernelFromString(context,dev,s_testKernelString,"testKernel",&errNum,pairBenchProg); cl_kernel testKernel = b3OpenCLUtils::compileCLKernelFromString(context,dev,s_testKernelString,"testKernel",&errNum,pairBenchProg);
@@ -173,7 +173,7 @@ int main(int argc, char* argv[])
b3OpenCLArray<int> atomicCounter(context,queue); b3OpenCLArray<int> atomicCounter(context,queue);
b3OpenCLArray<b3Contact4Data> deviceContacts(context,queue); b3OpenCLArray<b3Contact4Data> deviceContacts(context,queue);
b3AlignedObjectArray<b3Contact4Data> hostContacts; b3AlignedObjectArray<b3Contact4Data> hostContacts;
b3Contact4Data tmp; b3Contact4Data tmp;
int sz = sizeof(b3Contact4Data); int sz = sizeof(b3Contact4Data);
memset(&tmp,1,sz); memset(&tmp,1,sz);
@@ -182,7 +182,7 @@ int main(int argc, char* argv[])
memset(&tmp,2,sz); memset(&tmp,2,sz);
deviceContacts.push_back(tmp); deviceContacts.push_back(tmp);
b3Contact4Data tmp3 = tmp; b3Contact4Data tmp3 = tmp;
atomicCounter.push_back(0); atomicCounter.push_back(0);
deviceElements.resize(numWorkItems); deviceElements.resize(numWorkItems);
@@ -190,7 +190,7 @@ int main(int argc, char* argv[])
run.setBuffer(deviceElements.getBufferCL()); run.setBuffer(deviceElements.getBufferCL());
run.setBuffer(deviceContacts.getBufferCL()); run.setBuffer(deviceContacts.getBufferCL());
run.setBuffer(atomicCounter.getBufferCL()); run.setBuffer(atomicCounter.getBufferCL());
run.launch1D(numWorkItems); run.launch1D(numWorkItems);
b3AlignedObjectArray<int> hostElements; b3AlignedObjectArray<int> hostElements;
@@ -198,7 +198,7 @@ int main(int argc, char* argv[])
deviceContacts.copyToHost(hostContacts); deviceContacts.copyToHost(hostContacts);
tmp2 = hostContacts[0]; tmp2 = hostContacts[0];
tmp3 = hostContacts[1]; tmp3 = hostContacts[1];
printf("...\n"); printf("...\n");
@@ -207,7 +207,7 @@ int main(int argc, char* argv[])
printf("kernel failed to compile\n"); printf("kernel failed to compile\n");
} }
} }
} }