allow obsolete OpenGL2 drawer to render with z-up axis.

This commit is contained in:
erwincoumans
2016-11-12 11:59:40 -08:00
parent 7577c6d893
commit 9bad64fed9
7 changed files with 33 additions and 25 deletions

View File

@@ -1,7 +0,0 @@
--start_demo_name=R2D2 Grasp
--mouse_move_multiplier=0.400000
--mouse_wheel_multiplier=0.010000
--background_color_red= 0.900000
--background_color_green= 0.900000
--background_color_blue= 1.000000
--fixed_timestep= 0.000000

View File

@@ -782,7 +782,7 @@ GL_ShapeDrawer::~GL_ShapeDrawer()
}
}
void GL_ShapeDrawer::drawSceneInternal(const btDiscreteDynamicsWorld* dynamicsWorld, int pass)
void GL_ShapeDrawer::drawSceneInternal(const btDiscreteDynamicsWorld* dynamicsWorld, int pass, int cameraUpAxis)
{
btAssert(dynamicsWorld);
@@ -849,7 +849,12 @@ void GL_ShapeDrawer::drawSceneInternal(const btDiscreteDynamicsWorld* dynamicsWo
//if (!(getDebugMode()& btIDebugDraw::DBG_DrawWireframe))
int debugMode = 0;//getDebugMode()
//btVector3 m_sundirection(-1,-1,-1);
btVector3 m_sundirection(btVector3(1,-2,1)*1000);
if (cameraUpAxis==2)
{
m_sundirection = btVector3(1,1,-2)*1000;
}
switch(pass)
{
@@ -861,9 +866,12 @@ void GL_ShapeDrawer::drawSceneInternal(const btDiscreteDynamicsWorld* dynamicsWo
}
void GL_ShapeDrawer::drawScene(const btDiscreteDynamicsWorld* dynamicsWorld, bool useShadows)
//this GL_ShapeDrawer will be removed, in the meanwhile directly access this global 'useShadoMaps'
extern bool useShadowMap;
void GL_ShapeDrawer::drawScene(const btDiscreteDynamicsWorld* dynamicsWorld, bool useShadows1, int cameraUpAxis)
{
bool useShadows = useShadowMap;
GLfloat light_ambient[] = { btScalar(0.2), btScalar(0.2), btScalar(0.2), btScalar(1.0) };
GLfloat light_diffuse[] = { btScalar(1.0), btScalar(1.0), btScalar(1.0), btScalar(1.0) };
GLfloat light_specular[] = { btScalar(1.0), btScalar(1.0), btScalar(1.0), btScalar(1.0 )};
@@ -897,7 +905,7 @@ void GL_ShapeDrawer::drawScene(const btDiscreteDynamicsWorld* dynamicsWorld, boo
{
glClear(GL_STENCIL_BUFFER_BIT);
glEnable(GL_CULL_FACE);
drawSceneInternal(dynamicsWorld,0);
drawSceneInternal(dynamicsWorld,0, cameraUpAxis);
glDisable(GL_LIGHTING);
glDepthMask(GL_FALSE);
@@ -907,10 +915,10 @@ void GL_ShapeDrawer::drawScene(const btDiscreteDynamicsWorld* dynamicsWorld, boo
glStencilFunc(GL_ALWAYS,1,0xFFFFFFFFL);
glFrontFace(GL_CCW);
glStencilOp(GL_KEEP,GL_KEEP,GL_INCR);
drawSceneInternal(dynamicsWorld,1);
drawSceneInternal(dynamicsWorld,1,cameraUpAxis);
glFrontFace(GL_CW);
glStencilOp(GL_KEEP,GL_KEEP,GL_DECR);
drawSceneInternal(dynamicsWorld,1);
drawSceneInternal(dynamicsWorld,1,cameraUpAxis);
glFrontFace(GL_CCW);
glPolygonMode(GL_FRONT,GL_FILL);
@@ -929,7 +937,7 @@ void GL_ShapeDrawer::drawScene(const btDiscreteDynamicsWorld* dynamicsWorld, boo
glStencilFunc( GL_NOTEQUAL, 0, 0xFFFFFFFFL );
glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
glDisable(GL_LIGHTING);
drawSceneInternal(dynamicsWorld,2);
drawSceneInternal(dynamicsWorld,2,cameraUpAxis);
glEnable(GL_LIGHTING);
glDepthFunc(GL_LESS);
glDisable(GL_STENCIL_TEST);
@@ -938,6 +946,6 @@ void GL_ShapeDrawer::drawScene(const btDiscreteDynamicsWorld* dynamicsWorld, boo
else
{
glDisable(GL_CULL_FACE);
drawSceneInternal(dynamicsWorld,0);
drawSceneInternal(dynamicsWorld,0,cameraUpAxis);
}
}

View File

@@ -44,7 +44,7 @@ protected:
ShapeCache* cache(btConvexShape*);
virtual void drawSceneInternal(const btDiscreteDynamicsWorld* world, int pass);
virtual void drawSceneInternal(const btDiscreteDynamicsWorld* world, int pass, int cameraUpAxis);
public:
GL_ShapeDrawer();
@@ -53,7 +53,7 @@ public:
virtual void drawScene(const btDiscreteDynamicsWorld* world, bool useShadows);
virtual void drawScene(const btDiscreteDynamicsWorld* world, bool useShadows, int cameraUpAxis);
///drawOpenGL might allocate temporary memoty, stores pointer in shape userpointer
virtual void drawOpenGL(btScalar* m, const btCollisionShape* shape, const btVector3& color,int debugMode,const btVector3& worldBoundsMin,const btVector3& worldBoundsMax);

View File

@@ -338,7 +338,7 @@ void OpenGLGuiHelper::render(const btDiscreteDynamicsWorld* rbWorld)
if (m_data->m_gl2ShapeDrawer && rbWorld)
{
m_data->m_gl2ShapeDrawer->enableTexture(true);
m_data->m_gl2ShapeDrawer->drawScene(rbWorld,true);
m_data->m_gl2ShapeDrawer->drawScene(rbWorld,true, m_data->m_glApp->getUpAxis());
}
}
void OpenGLGuiHelper::createPhysicsDebugDrawer(btDiscreteDynamicsWorld* rbWorld)

View File

@@ -44,7 +44,7 @@ public:
};
btAlignedObjectArray<std::string> gFileNameArray;
static btAlignedObjectArray<std::string> gMCFJFileNameArray;
#define MAX_NUM_MOTORS 1024
@@ -94,7 +94,7 @@ ImportMJCFSetup::ImportMJCFSetup(struct GUIHelperInterface* helper, int option,
setFileName(fileName);
} else
{
gFileNameArray.clear();
gMCFJFileNameArray.clear();
@@ -112,26 +112,26 @@ ImportMJCFSetup::ImportMJCFSetup(struct GUIHelperInterface* helper, int option,
b3Printf("mjcf_files.txt entry %s",fileName);
if (result==1)
{
gFileNameArray.push_back(fileName);
gMCFJFileNameArray.push_back(fileName);
}
} while (result==1);
fclose(f);
}
if (gFileNameArray.size()==0)
if (gMCFJFileNameArray.size()==0)
{
gFileNameArray.push_back("quadruped/quadruped.mjcf");
gMCFJFileNameArray.push_back("quadruped/quadruped.mjcf");
}
int numFileNames = gFileNameArray.size();
int numFileNames = gMCFJFileNameArray.size();
if (count>=numFileNames)
{
count=0;
}
sprintf(m_fileName,"%s",gFileNameArray[count++].c_str());
sprintf(m_fileName,"%s",gMCFJFileNameArray[count++].c_str());
}
}

View File

@@ -70,6 +70,11 @@ struct SimpleOpenGL2AppInternalData
{
GLuint m_fontTextureId;
GLuint m_largeFontTextureId;
int m_upAxis;
SimpleOpenGL2AppInternalData()
:m_upAxis(1)
{
}
};
static GLuint BindFont2(const CTexFont *_Font)
@@ -268,10 +273,11 @@ void SimpleOpenGL2App::drawGrid(DrawGridData data)
}
void SimpleOpenGL2App::setUpAxis(int axis)
{
this->m_data->m_upAxis = axis;
}
int SimpleOpenGL2App::getUpAxis() const
{
return 1;
return this->m_data->m_upAxis;
}
void SimpleOpenGL2App::swapBuffer()

View File

@@ -33,6 +33,7 @@ void SimpleOpenGL2Renderer::updateCamera(int upAxis)
float projection[16];
float view[16];
m_camera.setAspectRatio((float)m_width/(float)m_height);
m_camera.setCameraUpAxis(upAxis);
m_camera.update();
m_camera.getCameraProjectionMatrix(projection);
m_camera.getCameraViewMatrix(view);