add basic debug drawing interface for btMultiBodyPoint2Point constraint
add basic debug drawing drawText3D in SimpleOpenGL3App remove a few warnings add drawTexturedRect3D to GLPrimitiveRenderer to support debug drawing
This commit is contained in:
@@ -60,6 +60,9 @@ public:
|
||||
virtual void renderScene()
|
||||
{
|
||||
m_app->m_renderer->renderScene();
|
||||
m_app->drawText3D("X",1,0,0,1);
|
||||
m_app->drawText3D("Y",0,1,0,1);
|
||||
m_app->drawText3D("Z",0,0,1,1);
|
||||
}
|
||||
|
||||
virtual void drawArc(const btVector3& center, const btVector3& normal, const btVector3& axis, btScalar radiusA, btScalar radiusB, btScalar minAngle, btScalar maxAngle,
|
||||
|
||||
@@ -21,6 +21,7 @@ void CoordinateFrameDemoPhysicsSetup::debugDraw()
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/btgui
|
||||
..
|
||||
)
|
||||
|
||||
FILE(GLOB OpenGLWindow_HDRS "*.h" )
|
||||
@@ -19,9 +18,9 @@ LIST(REMOVE_ITEM OpenGLWindowCommon_CPP X11OpenGLWindow.cpp )
|
||||
#MESSAGE (${OpenGLWindowCommon_CPP})
|
||||
|
||||
IF (WIN32)
|
||||
SET(OpenGLWindow_SRCS ${BULLET_PHYSICS_SOURCE_DIR}/btgui/OpenGLWindow/GlewWindows/glew.c ${OpenGLWindowWin32_CPP} ${OpenGLWindowCommon_CPP})
|
||||
SET(OpenGLWindow_SRCS GlewWindows/glew.c ${OpenGLWindowWin32_CPP} ${OpenGLWindowCommon_CPP})
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/btgui/OpenGLWindow/GlewWindows
|
||||
GlewWindows
|
||||
)
|
||||
ADD_DEFINITIONS(-DGLEW_STATIC)
|
||||
ENDIF(WIN32)
|
||||
@@ -33,13 +32,13 @@ ENDIF(APPLE)
|
||||
#no Linux detection?
|
||||
IF(NOT WIN32 AND NOT APPLE)
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/btgui/OpenGLWindow/GlewWindows
|
||||
GlewWindows
|
||||
)
|
||||
ADD_DEFINITIONS(-DGLEW_STATIC)
|
||||
ADD_DEFINITIONS("-DGLEW_INIT_OPENGL11_FUNCTIONS=1")
|
||||
ADD_DEFINITIONS("-DGLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS=1")
|
||||
|
||||
SET(OpenGLWindow_SRCS ${OpenGLWindowLinux_CPP} ${BULLET_PHYSICS_SOURCE_DIR}/btgui/OpenGLWindow/GlewWindows/glew.c ${OpenGLWindowCommon_CPP} )
|
||||
SET(OpenGLWindow_SRCS ${OpenGLWindowLinux_CPP} GlewWindows/glew.c ${OpenGLWindowCommon_CPP} )
|
||||
ENDIF()
|
||||
|
||||
|
||||
|
||||
@@ -42,9 +42,10 @@ struct CommonGraphicsApp
|
||||
|
||||
virtual void swapBuffer() = 0;
|
||||
virtual void drawText( const char* txt, int posX, int posY) = 0;
|
||||
|
||||
virtual void drawText3D( const char* txt, float posX, float posZY, float posZ, float size)=0;
|
||||
virtual int registerCubeShape(float halfExtentsX,float halfExtentsY, float halfExtentsZ)=0;
|
||||
virtual int registerGraphicsSphereShape(float radius, bool usePointSprites=true, int largeSphereThreshold=100, int mediumSphereThreshold=10)=0;
|
||||
virtual void registerGrid(int xres, int yres, float color0[4], float color1[4])=0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -32,6 +32,9 @@ struct CommonRenderInterface
|
||||
virtual void getCameraTargetPosition(float cameraPos[4]) const=0;
|
||||
virtual void getCameraTargetPosition(double cameraPos[4]) const=0;
|
||||
|
||||
virtual void getCameraViewMatrix(float viewMat[16]) const=0;
|
||||
virtual void getCameraProjectionMatrix(float projMat[16]) const=0;
|
||||
|
||||
virtual void renderScene()=0;
|
||||
|
||||
virtual int getScreenWidth() = 0;
|
||||
@@ -49,8 +52,59 @@ struct CommonRenderInterface
|
||||
|
||||
virtual void writeSingleInstanceTransformToCPU(const float* position, const float* orientation, int srcIndex)=0;
|
||||
virtual void writeSingleInstanceTransformToCPU(const double* position, const double* orientation, int srcIndex)=0;
|
||||
virtual void writeSingleInstanceColorToCPU(float* color, int srcIndex)=0;
|
||||
virtual void writeSingleInstanceColorToCPU(double* color, int srcIndex)=0;
|
||||
virtual void writeTransforms()=0;
|
||||
virtual void enableBlend(bool blend)=0;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline int projectWorldCoordToScreen(T objx, T objy, T objz,
|
||||
const T modelMatrix[16],
|
||||
const T projMatrix[16],
|
||||
const int viewport[4],
|
||||
T *winx, T *winy, T *winz)
|
||||
{
|
||||
int i;
|
||||
T in2[4];
|
||||
T tmp[4];
|
||||
|
||||
in2[0]=objx;
|
||||
in2[1]=objy;
|
||||
in2[2]=objz;
|
||||
in2[3]=T(1.0);
|
||||
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
tmp[i] = in2[0] * modelMatrix[0*4+i] + in2[1] * modelMatrix[1*4+i] +
|
||||
in2[2] * modelMatrix[2*4+i] + in2[3] * modelMatrix[3*4+i];
|
||||
}
|
||||
|
||||
T out[4];
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
out[i] = tmp[0] * projMatrix[0*4+i] + tmp[1] * projMatrix[1*4+i] + tmp[2] * projMatrix[2*4+i] + tmp[3] * projMatrix[3*4+i];
|
||||
}
|
||||
|
||||
if (out[3] == T(0.0))
|
||||
return 0;
|
||||
out[0] /= out[3];
|
||||
out[1] /= out[3];
|
||||
out[2] /= out[3];
|
||||
/* Map x, y and z to range 0-1 */
|
||||
out[0] = out[0] * T(0.5) + T(0.5);
|
||||
out[1] = out[1] * T(0.5) + T(0.5);
|
||||
out[2] = out[2] * T(0.5) + T(0.5);
|
||||
|
||||
/* Map x,y to viewport */
|
||||
out[0] = out[0] * viewport[2] + viewport[0];
|
||||
out[1] = out[1] * viewport[3] + viewport[1];
|
||||
|
||||
*winx=out[0];
|
||||
*winy=out[1];
|
||||
*winz=out[2];
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif//COMMON_RENDER_INTERFACE_H
|
||||
|
||||
|
||||
@@ -112,8 +112,7 @@ struct b3GraphicsInstance
|
||||
|
||||
bool m_ortho = false;
|
||||
|
||||
static GLfloat projectionMatrix[16];
|
||||
static GLfloat modelviewMatrix[16];
|
||||
|
||||
|
||||
//static GLfloat depthLightModelviewMatrix[16];
|
||||
|
||||
@@ -157,7 +156,8 @@ struct InternalDataRenderer : public GLInstanceRendererInternalData
|
||||
int m_middleMouseButton;
|
||||
int m_rightMouseButton;
|
||||
|
||||
|
||||
GLfloat m_projectionMatrix[16];
|
||||
GLfloat m_viewMatrix[16];
|
||||
|
||||
|
||||
GLuint m_defaultTexturehandle;
|
||||
@@ -185,7 +185,12 @@ struct InternalDataRenderer : public GLInstanceRendererInternalData
|
||||
m_altPressed(0),
|
||||
m_controlPressed(0)
|
||||
{
|
||||
|
||||
//clear to zero to make it obvious if the matrix is used uninitialized
|
||||
for (int i=0;i<16;i++)
|
||||
{
|
||||
m_projectionMatrix[i]=0;
|
||||
m_viewMatrix[i]=0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -224,6 +229,7 @@ struct InternalDataRenderer : public GLInstanceRendererInternalData
|
||||
|
||||
void mouseMoveCallback(float x, float y)
|
||||
{
|
||||
// printf("moved to %f,%f\n",x,y);
|
||||
if (m_altPressed || m_controlPressed)
|
||||
{
|
||||
float xDelta = x-m_mouseXpos;
|
||||
@@ -460,6 +466,13 @@ void GLInstancingRenderer::writeSingleInstanceTransformToCPU(const float* positi
|
||||
*/
|
||||
}
|
||||
|
||||
void GLInstancingRenderer::writeSingleInstanceColorToCPU(double* color, int srcIndex)
|
||||
{
|
||||
m_data->m_instance_colors_ptr[srcIndex*4+0]=float(color[0]);
|
||||
m_data->m_instance_colors_ptr[srcIndex*4+1]=float(color[1]);
|
||||
m_data->m_instance_colors_ptr[srcIndex*4+2]=float(color[2]);
|
||||
m_data->m_instance_colors_ptr[srcIndex*4+3]=float(color[3]);
|
||||
}
|
||||
|
||||
void GLInstancingRenderer::writeSingleInstanceColorToCPU(float* color, int srcIndex)
|
||||
{
|
||||
@@ -643,6 +656,7 @@ int GLInstancingRenderer::registerGraphicsInstance(int shapeIndex, const float*
|
||||
m_data->m_instance_scale_ptr[index*3+2] = scaling[2];
|
||||
|
||||
gfxObj->m_numGraphicsInstances++;
|
||||
m_data->m_totalNumInstances++;
|
||||
} else
|
||||
{
|
||||
b3Error("registerGraphicsInstance out of range, %d\n", maxElements);
|
||||
@@ -690,8 +704,6 @@ void GLInstancingRenderer::updateShape(int shapeIndex, const float* vertices)
|
||||
glUnmapBuffer( GL_ARRAY_BUFFER);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int GLInstancingRenderer::registerShape(const float* vertices, int numvertices, const int* indices, int numIndices,int primitiveType, int textureId)
|
||||
{
|
||||
b3GraphicsInstance* gfxObj = new b3GraphicsInstance;
|
||||
@@ -897,9 +909,9 @@ void GLInstancingRenderer::init()
|
||||
{
|
||||
if (x<2||y<2||x>253||y>253)
|
||||
{
|
||||
pi[0]=0;
|
||||
pi[1]=0;
|
||||
pi[2]=0;
|
||||
pi[0]=255;//0;
|
||||
pi[1]=255;//0;
|
||||
pi[2]=255;//0;
|
||||
} else
|
||||
{
|
||||
pi[0]=255;
|
||||
@@ -1091,7 +1103,7 @@ void GLInstancingRenderer::updateCamera(int upAxis)
|
||||
};
|
||||
|
||||
|
||||
float m_frustumZNear=0.1;
|
||||
float m_frustumZNear=0.01;
|
||||
float m_frustumZFar=1000.f;
|
||||
|
||||
|
||||
@@ -1132,13 +1144,13 @@ void GLInstancingRenderer::updateCamera(int upAxis)
|
||||
|
||||
if (m_screenWidth > m_screenHeight)
|
||||
{
|
||||
b3CreateFrustum(-aspect * m_frustumZNear, aspect * m_frustumZNear, -m_frustumZNear, m_frustumZNear, m_frustumZNear, m_frustumZFar,projectionMatrix);
|
||||
b3CreateFrustum(-aspect * m_frustumZNear, aspect * m_frustumZNear, -m_frustumZNear, m_frustumZNear, m_frustumZNear, m_frustumZFar,m_data->m_projectionMatrix);
|
||||
} else
|
||||
{
|
||||
b3CreateFrustum(-aspect * m_frustumZNear, aspect * m_frustumZNear, -m_frustumZNear, m_frustumZNear, m_frustumZNear, m_frustumZFar,projectionMatrix);
|
||||
b3CreateFrustum(-aspect * m_frustumZNear, aspect * m_frustumZNear, -m_frustumZNear, m_frustumZNear, m_frustumZNear, m_frustumZFar,m_data->m_projectionMatrix);
|
||||
}
|
||||
|
||||
b3CreateLookAt(m_data->m_cameraPosition,m_data->m_cameraTargetPosition,m_data->m_cameraUp,modelviewMatrix);
|
||||
b3CreateLookAt(m_data->m_cameraPosition,m_data->m_cameraTargetPosition,m_data->m_cameraUp,m_data->m_viewMatrix);
|
||||
|
||||
|
||||
}
|
||||
@@ -1276,7 +1288,7 @@ void writeTextureToPng(int textureWidth, int textureHeight, const char* fileName
|
||||
pixels[(j*textureWidth+i)*numComponents]=char(orgPixels[(j*textureWidth+i)]*255.f);
|
||||
pixels[(j*textureWidth+i)*numComponents+1]=0;//255.f;
|
||||
pixels[(j*textureWidth+i)*numComponents+2]=0;//255.f;
|
||||
pixels[(j*textureWidth+i)*numComponents+3]=255;
|
||||
pixels[(j*textureWidth+i)*numComponents+3]=127;
|
||||
|
||||
|
||||
//pixels[(j*textureWidth+i)*+1]=val;
|
||||
@@ -1342,8 +1354,8 @@ void GLInstancingRenderer::renderScene()
|
||||
|
||||
void GLInstancingRenderer::drawPoint(const double* position, const double color[4], double pointDrawSize)
|
||||
{
|
||||
float pos[4]={position[0],position[1],position[2],0};
|
||||
float clr[4] = {color[0],color[1],color[2],color[3]};
|
||||
float pos[4]={(float)position[0],(float)position[1],(float)position[2],0};
|
||||
float clr[4] = {(float)color[0],(float)color[1],(float)color[2],(float)color[3]};
|
||||
drawPoints(pos,clr,1,3*sizeof(float),float(pointDrawSize));
|
||||
}
|
||||
|
||||
@@ -1351,16 +1363,16 @@ void GLInstancingRenderer::drawPoint(const float* positions, const float color[4
|
||||
{
|
||||
drawPoints(positions,color,1,3*sizeof(float),pointDrawSize);
|
||||
}
|
||||
|
||||
void GLInstancingRenderer::drawPoints(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, float pointDrawSize)
|
||||
{
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D,0);
|
||||
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);glUseProgram(linesShader);
|
||||
glUniformMatrix4fv(lines_ProjectionMatrix, 1, false, &projectionMatrix[0]);
|
||||
glUniformMatrix4fv(lines_ModelViewMatrix, 1, false, &modelviewMatrix[0]);
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
glUseProgram(linesShader);
|
||||
glUniformMatrix4fv(lines_ProjectionMatrix, 1, false, &m_data->m_projectionMatrix[0]);
|
||||
glUniformMatrix4fv(lines_ModelViewMatrix, 1, false, &m_data->m_viewMatrix[0]);
|
||||
glUniform4f(lines_colour,color[0],color[1],color[2],color[3]);
|
||||
|
||||
glPointSize(pointDrawSize);
|
||||
@@ -1393,22 +1405,26 @@ void GLInstancingRenderer::drawPoints(const float* positions, const float color[
|
||||
|
||||
glBindVertexArray(0);
|
||||
glPointSize(1);
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
void GLInstancingRenderer::drawLines(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, const unsigned int* indices, int numIndices, float pointDrawSize)
|
||||
void GLInstancingRenderer::drawLines(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, const unsigned int* indices, int numIndices, float lineWidthIn)
|
||||
{
|
||||
float lineWidth = lineWidthIn;
|
||||
b3Clamp(lineWidth,(float)lineWidthRange[0],(float)lineWidthRange[1]);
|
||||
glLineWidth(lineWidth);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo);
|
||||
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D,0);
|
||||
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);glUseProgram(linesShader);
|
||||
glUniformMatrix4fv(lines_ProjectionMatrix, 1, false, &projectionMatrix[0]);
|
||||
glUniformMatrix4fv(lines_ModelViewMatrix, 1, false, &modelviewMatrix[0]);
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
glUseProgram(linesShader);
|
||||
glUniformMatrix4fv(lines_ProjectionMatrix, 1, false, &m_data->m_projectionMatrix[0]);
|
||||
glUniformMatrix4fv(lines_ModelViewMatrix, 1, false, &m_data->m_viewMatrix[0]);
|
||||
glUniform4f(lines_colour,color[0],color[1],color[2],color[3]);
|
||||
|
||||
// glPointSize(pointDrawSize);
|
||||
@@ -1450,7 +1466,7 @@ void GLInstancingRenderer::drawLines(const float* positions, const float color[4
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
glPointSize(1);
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
void GLInstancingRenderer::drawLine(const double fromIn[4], const double toIn[4], const double colorIn[4], double lineWidthIn)
|
||||
@@ -1463,6 +1479,7 @@ void GLInstancingRenderer::drawLine(const double fromIn[4], const double toIn[4]
|
||||
}
|
||||
void GLInstancingRenderer::drawLine(const float from[4], const float to[4], const float color[4], float lineWidth)
|
||||
{
|
||||
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
@@ -1475,8 +1492,8 @@ void GLInstancingRenderer::drawLine(const float from[4], const float to[4], cons
|
||||
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
|
||||
glUniformMatrix4fv(lines_ProjectionMatrix, 1, false, &projectionMatrix[0]);
|
||||
glUniformMatrix4fv(lines_ModelViewMatrix, 1, false, &modelviewMatrix[0]);
|
||||
glUniformMatrix4fv(lines_ProjectionMatrix, 1, false, &m_data->m_projectionMatrix[0]);
|
||||
glUniformMatrix4fv(lines_ModelViewMatrix, 1, false, &m_data->m_viewMatrix[0]);
|
||||
glUniform4f(lines_colour,color[0],color[1],color[2],color[3]);
|
||||
|
||||
|
||||
@@ -1526,7 +1543,7 @@ void GLInstancingRenderer::drawLine(const float from[4], const float to[4], cons
|
||||
glLineWidth(1);
|
||||
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
struct PointerCaster
|
||||
@@ -1769,8 +1786,8 @@ b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
if (gfxObj->m_primitiveType==B3_GL_POINTS)
|
||||
{
|
||||
glUseProgram(instancingShaderPointSprite);
|
||||
glUniformMatrix4fv(ProjectionMatrixPointSprite, 1, false, &projectionMatrix[0]);
|
||||
glUniformMatrix4fv(ModelViewMatrixPointSprite, 1, false, &modelviewMatrix[0]);
|
||||
glUniformMatrix4fv(ProjectionMatrixPointSprite, 1, false, &m_data->m_projectionMatrix[0]);
|
||||
glUniformMatrix4fv(ModelViewMatrixPointSprite, 1, false, &m_data->m_viewMatrix[0]);
|
||||
glUniform1f(screenWidthPointSprite,float(m_screenWidth));
|
||||
|
||||
//glUniform1i(uniform_texture_diffusePointSprite, 0);
|
||||
@@ -1792,8 +1809,8 @@ b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
case B3_DEFAULT_RENDERMODE:
|
||||
{
|
||||
glUseProgram(instancingShader);
|
||||
glUniformMatrix4fv(ProjectionMatrix, 1, false, &projectionMatrix[0]);
|
||||
glUniformMatrix4fv(ModelViewMatrix, 1, false, &modelviewMatrix[0]);
|
||||
glUniformMatrix4fv(ProjectionMatrix, 1, false, &m_data->m_projectionMatrix[0]);
|
||||
glUniformMatrix4fv(ModelViewMatrix, 1, false, &m_data->m_viewMatrix[0]);
|
||||
glUniform1i(uniform_texture_diffuse, 0);
|
||||
glDrawElementsInstanced(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, indexOffset, gfxObj->m_numGraphicsInstances);
|
||||
break;
|
||||
@@ -1821,10 +1838,10 @@ b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
}
|
||||
|
||||
glUseProgram(useShadowMapInstancingShader);
|
||||
glUniformMatrix4fv(useShadow_ProjectionMatrix, 1, false, &projectionMatrix[0]);
|
||||
glUniformMatrix4fv(useShadow_ModelViewMatrix, 1, false, &modelviewMatrix[0]);
|
||||
glUniformMatrix4fv(useShadow_ProjectionMatrix, 1, false, &m_data->m_projectionMatrix[0]);
|
||||
glUniformMatrix4fv(useShadow_ModelViewMatrix, 1, false, &m_data->m_viewMatrix[0]);
|
||||
float MVP[16];
|
||||
b3Matrix4x4Mul16(projectionMatrix,modelviewMatrix,MVP);
|
||||
b3Matrix4x4Mul16(m_data->m_projectionMatrix,m_data->m_viewMatrix,MVP);
|
||||
glUniformMatrix4fv(useShadow_MVP, 1, false, &MVP[0]);
|
||||
b3Vector3 gLightDir = gLightPos;
|
||||
gLightDir.normalize();
|
||||
@@ -1877,7 +1894,7 @@ b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
|
||||
|
||||
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
}
|
||||
|
||||
@@ -1894,3 +1911,19 @@ void GLInstancingRenderer::enableShadowMap()
|
||||
//glBindTexture(GL_TEXTURE_2D, m_data->m_defaultTexturehandle);
|
||||
|
||||
}
|
||||
|
||||
void GLInstancingRenderer::getCameraViewMatrix(float viewMat[16]) const
|
||||
{
|
||||
for (int i=0;i<16;i++)
|
||||
{
|
||||
viewMat[i] = m_data->m_viewMatrix[i];
|
||||
}
|
||||
|
||||
}
|
||||
void GLInstancingRenderer::getCameraProjectionMatrix(float projMat[16]) const
|
||||
{
|
||||
for (int i=0;i<16;i++)
|
||||
{
|
||||
projMat[i] = m_data->m_projectionMatrix[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,8 +64,7 @@ public:
|
||||
|
||||
///vertices must be in the format x,y,z, nx,ny,nz, u,v
|
||||
virtual int registerShape(const float* vertices, int numvertices, const int* indices, int numIndices, int primitiveType=B3_GL_TRIANGLES, int textureIndex=-1);
|
||||
|
||||
|
||||
|
||||
virtual int registerTexture(const unsigned char* texels, int width, int height);
|
||||
|
||||
///position x,y,z, quaternion x,y,z,w, color r,g,b,a, scaling x,y,z
|
||||
@@ -94,6 +93,7 @@ public:
|
||||
virtual void writeSingleInstanceTransformToGPU(float* position, float* orientation, int srcIndex);
|
||||
|
||||
virtual void writeSingleInstanceColorToCPU(float* color, int srcIndex);
|
||||
virtual void writeSingleInstanceColorToCPU(double* color, int srcIndex);
|
||||
|
||||
virtual void getMouseDirection(float* dir, int mouseX, int mouseY);
|
||||
|
||||
@@ -141,6 +141,10 @@ public:
|
||||
virtual float getCameraYaw() const;
|
||||
virtual float getCameraPitch() const;
|
||||
|
||||
virtual void getCameraViewMatrix(float viewMat[16]) const;
|
||||
virtual void getCameraProjectionMatrix(float projMat[16]) const;
|
||||
|
||||
|
||||
virtual void resize(int width, int height);
|
||||
virtual int getScreenWidth()
|
||||
{
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
struct PrimInternalData
|
||||
{
|
||||
GLuint m_shaderProg;
|
||||
GLint m_viewmatUniform;
|
||||
GLint m_projMatUniform;
|
||||
GLint m_positionUniform;
|
||||
GLint m_colourAttribute;
|
||||
GLint m_positionAttribute;
|
||||
|
||||
@@ -5,11 +5,10 @@
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
static const char* vertexShader= \
|
||||
static const char* vertexShader3D= \
|
||||
"#version 150 \n"
|
||||
"\n"
|
||||
"\n"
|
||||
"uniform mat4 viewMatrix, projMatrix;\n"
|
||||
"in vec4 position;\n"
|
||||
"in vec4 colour;\n"
|
||||
"out vec4 colourV;\n"
|
||||
@@ -21,11 +20,11 @@ static const char* vertexShader= \
|
||||
"void main (void)\n"
|
||||
"{\n"
|
||||
" colourV = colour;\n"
|
||||
" gl_Position = vec4(position.x, position.y,0.f,1.f);\n"
|
||||
" gl_Position = projMatrix * viewMatrix * position ;\n"
|
||||
" texuvV=texuv;\n"
|
||||
"}\n";
|
||||
|
||||
static const char* fragmentShader= \
|
||||
static const char* fragmentShader3D= \
|
||||
"#version 150\n"
|
||||
"\n"
|
||||
"uniform vec2 p;\n"
|
||||
@@ -42,42 +41,12 @@ static const char* fragmentShader= \
|
||||
" {\n"
|
||||
" texcolor = vec4(1,1,1,texcolor.x);\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" fragColour = colourV*texcolor;\n"
|
||||
" fragColour = colourV*texcolor;\n"
|
||||
"}\n";
|
||||
|
||||
|
||||
|
||||
static unsigned int s_indexData[6] = {0,1,2,0,2,3};
|
||||
struct vec2
|
||||
{
|
||||
vec2(float x, float y)
|
||||
{
|
||||
p[0] = x;
|
||||
p[1] = y;
|
||||
}
|
||||
float p[2];
|
||||
};
|
||||
|
||||
struct vec4
|
||||
{
|
||||
vec4(float x,float y, float z, float w)
|
||||
{
|
||||
p[0] = x;
|
||||
p[1] = y;
|
||||
p[2] = z;
|
||||
p[3] = w;
|
||||
|
||||
}
|
||||
|
||||
float p[4];
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
vec4 position;
|
||||
vec4 colour;
|
||||
vec2 uv;
|
||||
} Vertex;
|
||||
|
||||
|
||||
|
||||
@@ -90,9 +59,16 @@ m_screenHeight(screenHeight)
|
||||
|
||||
m_data = new PrimInternalData;
|
||||
|
||||
m_data->m_shaderProg = gltLoadShaderPair(vertexShader,fragmentShader);
|
||||
m_data->m_shaderProg = gltLoadShaderPair(vertexShader3D,fragmentShader3D);
|
||||
|
||||
|
||||
m_data->m_viewmatUniform = glGetUniformLocation(m_data->m_shaderProg,"viewMatrix");
|
||||
if (m_data->m_viewmatUniform < 0) {
|
||||
assert(0);
|
||||
}
|
||||
m_data->m_projMatUniform = glGetUniformLocation(m_data->m_shaderProg,"projMatrix");
|
||||
if (m_data->m_projMatUniform < 0) {
|
||||
assert(0);
|
||||
}
|
||||
m_data->m_positionUniform = glGetUniformLocation(m_data->m_shaderProg, "p");
|
||||
if (m_data->m_positionUniform < 0) {
|
||||
assert(0);
|
||||
@@ -117,11 +93,11 @@ m_screenHeight(screenHeight)
|
||||
void GLPrimitiveRenderer::loadBufferData()
|
||||
{
|
||||
|
||||
Vertex vertexData[4] = {
|
||||
{ vec4(-1, -1, 0.0, 1.0 ), vec4( 1.0, 0.0, 0.0, 1.0 ) ,vec2(0,0)},
|
||||
{ vec4(-1, 1, 0.0, 1.0 ), vec4( 0.0, 1.0, 0.0, 1.0 ) ,vec2(0,1)},
|
||||
{ vec4( 1, 1, 0.0, 1.0 ), vec4( 0.0, 0.0, 1.0, 1.0 ) ,vec2(1,1)},
|
||||
{ vec4( 1, -1, 0.0, 1.0 ), vec4( 1.0, 1.0, 1.0, 1.0 ) ,vec2(1,0)}
|
||||
PrimVertex vertexData[4] = {
|
||||
{ PrimVec4(-1, -1, 0.0, 1.0 ), PrimVec4( 1.0, 0.0, 0.0, 1.0 ) ,PrimVec2(0,0)},
|
||||
{ PrimVec4(-1, 1, 0.0, 1.0 ), PrimVec4( 0.0, 1.0, 0.0, 1.0 ) ,PrimVec2(0,1)},
|
||||
{ PrimVec4( 1, 1, 0.0, 1.0 ), PrimVec4( 0.0, 0.0, 1.0, 1.0 ) ,PrimVec2(1,1)},
|
||||
{ PrimVec4( 1, -1, 0.0, 1.0 ), PrimVec4( 1.0, 1.0, 1.0, 1.0 ) ,PrimVec2(1,0)}
|
||||
};
|
||||
|
||||
|
||||
@@ -130,7 +106,7 @@ void GLPrimitiveRenderer::loadBufferData()
|
||||
|
||||
glGenBuffers(1, &m_data->m_vertexBuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vertexBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(Vertex), vertexData, GL_DYNAMIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(PrimVertex), vertexData, GL_DYNAMIC_DRAW);
|
||||
|
||||
assert(glGetError()==GL_NO_ERROR);
|
||||
|
||||
@@ -146,9 +122,9 @@ void GLPrimitiveRenderer::loadBufferData()
|
||||
|
||||
glEnableVertexAttribArray(m_data->m_textureAttribute);
|
||||
|
||||
glVertexAttribPointer(m_data->m_positionAttribute, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *)0);
|
||||
glVertexAttribPointer(m_data->m_colourAttribute , 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *)sizeof(vec4));
|
||||
glVertexAttribPointer(m_data->m_textureAttribute , 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *)(sizeof(vec4)+sizeof(vec4)));
|
||||
glVertexAttribPointer(m_data->m_positionAttribute, 4, GL_FLOAT, GL_FALSE, sizeof(PrimVertex), (const GLvoid *)0);
|
||||
glVertexAttribPointer(m_data->m_colourAttribute , 4, GL_FLOAT, GL_FALSE, sizeof(PrimVertex), (const GLvoid *)sizeof(PrimVec4));
|
||||
glVertexAttribPointer(m_data->m_textureAttribute , 2, GL_FLOAT, GL_FALSE, sizeof(PrimVertex), (const GLvoid *)(sizeof(PrimVec4)+sizeof(PrimVec4)));
|
||||
assert(glGetError()==GL_NO_ERROR);
|
||||
|
||||
|
||||
@@ -225,13 +201,18 @@ void GLPrimitiveRenderer::drawRect(float x0, float y0, float x1, float y1, float
|
||||
|
||||
}
|
||||
|
||||
void GLPrimitiveRenderer::drawTexturedRect(float x0, float y0, float x1, float y1, float color[4], float u0,float v0, float u1, float v1, int useRGBA)
|
||||
|
||||
void GLPrimitiveRenderer::drawTexturedRect3D(const PrimVertex& v0,const PrimVertex& v1,const PrimVertex& v2,const PrimVertex& v3,float viewMat[16],float projMat[16], bool useRGBA)
|
||||
{
|
||||
|
||||
assert(glGetError()==GL_NO_ERROR);
|
||||
|
||||
|
||||
glUseProgram(m_data->m_shaderProg);
|
||||
|
||||
|
||||
glUniformMatrix4fv(m_data->m_viewmatUniform, 1, false, viewMat);
|
||||
glUniformMatrix4fv(m_data->m_projMatUniform, 1, false, projMat);
|
||||
|
||||
assert(glGetError()==GL_NO_ERROR);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vertexBuffer);
|
||||
@@ -248,14 +229,11 @@ void GLPrimitiveRenderer::drawTexturedRect(float x0, float y0, float x1, float y
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
}
|
||||
|
||||
Vertex vertexData[4] = {
|
||||
{ vec4(-1.f+2.f*x0/float(m_screenWidth), 1.f-2.f*y0/float(m_screenHeight), 0.f, 0.f ), vec4( color[0], color[1], color[2], color[3] ) ,vec2(u0,v0)},
|
||||
{ vec4(-1.f+2.f*x0/float(m_screenWidth), 1.f-2.f*y1/float(m_screenHeight), 0.f, 1.f ), vec4( color[0], color[1], color[2], color[3] ) ,vec2(u0,v1)},
|
||||
{ vec4( -1.f+2.f*x1/float(m_screenWidth), 1.f-2.f*y1/float(m_screenHeight), 1.f, 1.f ), vec4(color[0], color[1], color[2], color[3]) ,vec2(u1,v1)},
|
||||
{ vec4( -1.f+2.f*x1/float(m_screenWidth), 1.f-2.f*y0/float(m_screenHeight), 1.f, 0.f ), vec4( color[0], color[1], color[2], color[3] ) ,vec2(u1,v0)}
|
||||
};
|
||||
PrimVertex vertexData[4] = {
|
||||
v0,v1,v2,v3
|
||||
};
|
||||
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0,4 * sizeof(Vertex), vertexData);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0,4 * sizeof(PrimVertex), vertexData);
|
||||
|
||||
|
||||
|
||||
@@ -264,7 +242,7 @@ void GLPrimitiveRenderer::drawTexturedRect(float x0, float y0, float x1, float y
|
||||
|
||||
assert(glGetError()==GL_NO_ERROR);
|
||||
|
||||
vec2 p( 0.f,0.f);//?b?0.5f * sinf(timeValue), 0.5f * cosf(timeValue) );
|
||||
PrimVec2 p( 0.f,0.f);//?b?0.5f * sinf(timeValue), 0.5f * cosf(timeValue) );
|
||||
if (useRGBA)
|
||||
{
|
||||
p.p[0] = 1.f;
|
||||
@@ -285,9 +263,9 @@ void GLPrimitiveRenderer::drawTexturedRect(float x0, float y0, float x1, float y
|
||||
|
||||
glEnableVertexAttribArray(m_data->m_textureAttribute);
|
||||
|
||||
glVertexAttribPointer(m_data->m_positionAttribute, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *)0);
|
||||
glVertexAttribPointer(m_data->m_colourAttribute , 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *)sizeof(vec4));
|
||||
glVertexAttribPointer(m_data->m_textureAttribute , 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *)(sizeof(vec4)+sizeof(vec4)));
|
||||
glVertexAttribPointer(m_data->m_positionAttribute, 4, GL_FLOAT, GL_FALSE, sizeof(PrimVertex), (const GLvoid *)0);
|
||||
glVertexAttribPointer(m_data->m_colourAttribute , 4, GL_FLOAT, GL_FALSE, sizeof(PrimVertex), (const GLvoid *)sizeof(PrimVec4));
|
||||
glVertexAttribPointer(m_data->m_textureAttribute , 2, GL_FLOAT, GL_FALSE, sizeof(PrimVertex), (const GLvoid *)(sizeof(PrimVec4)+sizeof(PrimVec4)));
|
||||
assert(glGetError()==GL_NO_ERROR);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_data->m_indexBuffer);
|
||||
@@ -319,6 +297,23 @@ void GLPrimitiveRenderer::drawTexturedRect(float x0, float y0, float x1, float y
|
||||
|
||||
}
|
||||
|
||||
|
||||
void GLPrimitiveRenderer::drawTexturedRect(float x0, float y0, float x1, float y1, float color[4], float u0,float v0, float u1, float v1, int useRGBA)
|
||||
{
|
||||
float identity[16]={1,0,0,0,
|
||||
0,1,0,0,
|
||||
0,0,1,0,
|
||||
0,0,0,1};
|
||||
PrimVertex vertexData[4] = {
|
||||
{ PrimVec4(-1.f+2.f*x0/float(m_screenWidth), 1.f-2.f*y0/float(m_screenHeight), 0.f, 1.f ), PrimVec4( color[0], color[1], color[2], color[3] ) ,PrimVec2(u0,v0)},
|
||||
{ PrimVec4(-1.f+2.f*x0/float(m_screenWidth), 1.f-2.f*y1/float(m_screenHeight), 0.f, 1.f ), PrimVec4( color[0], color[1], color[2], color[3] ) ,PrimVec2(u0,v1)},
|
||||
{ PrimVec4( -1.f+2.f*x1/float(m_screenWidth), 1.f-2.f*y1/float(m_screenHeight), 0.f, 1.f ), PrimVec4(color[0], color[1], color[2], color[3]) ,PrimVec2(u1,v1)},
|
||||
{ PrimVec4( -1.f+2.f*x1/float(m_screenWidth), 1.f-2.f*y0/float(m_screenHeight), 0.f, 1.f ), PrimVec4( color[0], color[1], color[2], color[3] ) ,PrimVec2(u1,v0)}
|
||||
};
|
||||
|
||||
drawTexturedRect3D(vertexData[0],vertexData[1],vertexData[2],vertexData[3],identity,identity,useRGBA);
|
||||
}
|
||||
|
||||
void GLPrimitiveRenderer::setScreenSize(int width, int height)
|
||||
{
|
||||
m_screenWidth = width;
|
||||
|
||||
@@ -3,6 +3,39 @@
|
||||
|
||||
//#include "OpenGLInclude.h"
|
||||
|
||||
struct PrimVec2
|
||||
{
|
||||
PrimVec2(float x, float y)
|
||||
{
|
||||
p[0] = x;
|
||||
p[1] = y;
|
||||
}
|
||||
float p[2];
|
||||
};
|
||||
|
||||
struct PrimVec4
|
||||
{
|
||||
PrimVec4() {}
|
||||
PrimVec4(float x,float y, float z, float w)
|
||||
{
|
||||
p[0] = x;
|
||||
p[1] = y;
|
||||
p[2] = z;
|
||||
p[3] = w;
|
||||
|
||||
}
|
||||
|
||||
float p[4];
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PrimVec4 position;
|
||||
PrimVec4 colour;
|
||||
PrimVec2 uv;
|
||||
} PrimVertex;
|
||||
|
||||
|
||||
class GLPrimitiveRenderer
|
||||
{
|
||||
int m_screenWidth;
|
||||
@@ -19,6 +52,7 @@ public:
|
||||
|
||||
void drawRect(float x0, float y0, float x1, float y1, float color[4]);
|
||||
void drawTexturedRect(float x0, float y0, float x1, float y1, float color[4], float u0,float v0, float u1, float v1, int useRGBA=0);
|
||||
void drawTexturedRect3D(const PrimVertex& v0,const PrimVertex& v1,const PrimVertex& v2,const PrimVertex& v3,float viewMat[16],float projMat[16], bool useRGBA = true);
|
||||
void drawLine();//float from[4], float to[4], float color[4]);
|
||||
void setScreenSize(int width, int height);
|
||||
|
||||
|
||||
@@ -398,11 +398,12 @@ void MacOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci)
|
||||
// }];
|
||||
|
||||
//see http://stackoverflow.com/questions/8238473/cant-get-nsmousemoved-events-from-nexteventmatchingmask-with-an-nsopenglview
|
||||
ProcessSerialNumber psn;
|
||||
GetCurrentProcess(&psn);
|
||||
/* ProcessSerialNumber psn;
|
||||
GetCurrentProcess(&psn);
|
||||
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
||||
SetFrontProcess(&psn);
|
||||
|
||||
*/
|
||||
|
||||
m_retinaScaleFactor = [m_internalData->m_myview convertSizeToBacking:sz].width;
|
||||
|
||||
[m_internalData->m_myApp finishLaunching];
|
||||
@@ -808,45 +809,8 @@ void MacOpenGLWindow::startRendering()
|
||||
}
|
||||
}
|
||||
|
||||
if ([event type]== NSLeftMouseUp)
|
||||
{
|
||||
// printf("right mouse!");
|
||||
|
||||
NSPoint eventLocation = [event locationInWindow];
|
||||
NSPoint center = [m_internalData->m_myview convertPoint:eventLocation fromView:nil];
|
||||
m_mouseX = center.x;
|
||||
m_mouseY = [m_internalData->m_myview GetWindowHeight] - center.y;
|
||||
|
||||
|
||||
// printf("mouse coord = %f, %f\n",mouseX,mouseY);
|
||||
if (m_mouseButtonCallback)
|
||||
{
|
||||
(*m_mouseButtonCallback)(0,0,m_mouseX,m_mouseY);
|
||||
//handledEvent = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if ([event type]== NSLeftMouseDown)
|
||||
{
|
||||
// printf("right mouse!");
|
||||
|
||||
NSPoint eventLocation = [event locationInWindow];
|
||||
NSPoint center = [m_internalData->m_myview convertPoint:eventLocation fromView:nil];
|
||||
m_mouseX = center.x;
|
||||
m_mouseY = [m_internalData->m_myview GetWindowHeight] - center.y;
|
||||
|
||||
// printf("mouse coord = %f, %f\n",mouseX,mouseY);
|
||||
if (m_mouseButtonCallback)
|
||||
{
|
||||
//handledEvent = true;
|
||||
(*m_mouseButtonCallback)(0,1,m_mouseX,m_mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ([event type]== NSRightMouseDown)
|
||||
if (([event type]== NSRightMouseDown) || ([ event type]==NSLeftMouseDown)||([event type]==NSOtherMouseDown))
|
||||
{
|
||||
// printf("right mouse!");
|
||||
// float mouseX,mouseY;
|
||||
@@ -855,17 +819,39 @@ void MacOpenGLWindow::startRendering()
|
||||
NSPoint center = [m_internalData->m_myview convertPoint:eventLocation fromView:nil];
|
||||
m_mouseX = center.x;
|
||||
m_mouseY = [m_internalData->m_myview GetWindowHeight] - center.y;
|
||||
|
||||
int button=0;
|
||||
switch ([event type])
|
||||
{
|
||||
case NSLeftMouseDown:
|
||||
{
|
||||
button=0;
|
||||
break;
|
||||
}
|
||||
case NSOtherMouseDown:
|
||||
{
|
||||
button=1;
|
||||
break;
|
||||
}
|
||||
case NSRightMouseDown:
|
||||
{
|
||||
button=2;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
// printf("mouse coord = %f, %f\n",mouseX,mouseY);
|
||||
if (m_mouseButtonCallback)
|
||||
{
|
||||
//handledEvent = true;
|
||||
(*m_mouseButtonCallback)(2,1,m_mouseX,m_mouseY);
|
||||
(*m_mouseButtonCallback)(button,1,m_mouseX,m_mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ([event type]== NSRightMouseUp)
|
||||
if (([event type]== NSRightMouseUp) || ([ event type]==NSLeftMouseUp)||([event type]==NSOtherMouseUp))
|
||||
{
|
||||
// printf("right mouse!");
|
||||
// float mouseX,mouseY;
|
||||
@@ -875,9 +861,33 @@ void MacOpenGLWindow::startRendering()
|
||||
m_mouseX = center.x;
|
||||
m_mouseY = [m_internalData->m_myview GetWindowHeight] - center.y;
|
||||
|
||||
int button=0;
|
||||
switch ([event type])
|
||||
{
|
||||
case NSLeftMouseUp:
|
||||
{
|
||||
button=0;
|
||||
break;
|
||||
}
|
||||
case NSOtherMouseUp:
|
||||
{
|
||||
button=1;
|
||||
break;
|
||||
}
|
||||
case NSRightMouseUp:
|
||||
{
|
||||
button=2;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
// printf("mouse coord = %f, %f\n",mouseX,mouseY);
|
||||
if (m_mouseButtonCallback)
|
||||
(*m_mouseButtonCallback)(2,0,m_mouseX,m_mouseY);
|
||||
(*m_mouseButtonCallback)(button,0,m_mouseX,m_mouseY);
|
||||
|
||||
}
|
||||
|
||||
@@ -899,7 +909,7 @@ void MacOpenGLWindow::startRendering()
|
||||
}
|
||||
}
|
||||
|
||||
if ([event type] == NSLeftMouseDragged)
|
||||
if (([event type] == NSLeftMouseDragged) || ([event type] == NSRightMouseDragged) || ([event type] == NSOtherMouseDragged))
|
||||
{
|
||||
int dx1, dy1;
|
||||
CGGetLastMouseDelta (&dx1, &dy1);
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "OpenGLWindow/opengl_fontstashcallbacks.h"
|
||||
#include <assert.h>
|
||||
#include "OpenGLWindow/GLRenderToTexture.h"
|
||||
#include "Bullet3Common/b3Quaternion.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define popen _popen
|
||||
@@ -35,6 +36,7 @@
|
||||
struct SimpleInternalData
|
||||
{
|
||||
GLuint m_fontTextureId;
|
||||
GLuint m_largeFontTextureId;
|
||||
struct sth_stash* m_fontStash;
|
||||
OpenGL2RenderCallbacks* m_renderCallbacks;
|
||||
int m_droidRegular;
|
||||
@@ -48,8 +50,10 @@ struct SimpleInternalData
|
||||
|
||||
static SimpleOpenGL3App* gApp=0;
|
||||
|
||||
static void SimpleResizeCallback( float width, float height)
|
||||
static void SimpleResizeCallback( float widthf, float heightf)
|
||||
{
|
||||
int width = (int)widthf;
|
||||
int height = (int)heightf;
|
||||
gApp->m_instancingRenderer->resize(width,height);
|
||||
gApp->m_primRenderer->setScreenSize(width,height);
|
||||
|
||||
@@ -111,7 +115,7 @@ SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height)
|
||||
|
||||
m_window->setWindowTitle(title);
|
||||
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
|
||||
glClearColor(0.9,0.9,1,1);
|
||||
m_window->startRendering();
|
||||
@@ -156,6 +160,8 @@ SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height)
|
||||
|
||||
TwGenerateDefaultFonts();
|
||||
m_data->m_fontTextureId = BindFont(g_DefaultNormalFont);
|
||||
m_data->m_largeFontTextureId = BindFont(g_DefaultLargeFont);
|
||||
|
||||
|
||||
|
||||
{
|
||||
@@ -189,12 +195,193 @@ struct sth_stash* SimpleOpenGL3App::getFontStash()
|
||||
return m_data->m_fontStash;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SimpleOpenGL3App::drawText( const char* txt, int posX, int posY)
|
||||
void SimpleOpenGL3App::drawText3D( const char* txt, float worldPosX, float worldPosY, float worldPosZ, float size1)
|
||||
{
|
||||
|
||||
float viewMat[16];
|
||||
float projMat[16];
|
||||
m_instancingRenderer->getCameraViewMatrix(viewMat);
|
||||
m_instancingRenderer->getCameraProjectionMatrix(projMat);
|
||||
|
||||
|
||||
float camPos[4];
|
||||
this->m_instancingRenderer->getCameraPosition(camPos);
|
||||
b3Vector3 cp= b3MakeVector3(camPos[0],camPos[2],camPos[1]);
|
||||
b3Vector3 p = b3MakeVector3(worldPosX,worldPosY,worldPosZ);
|
||||
float dist = (cp-p).length();
|
||||
float dv = 0;//dist/1000.f;
|
||||
//
|
||||
//printf("str = %s\n",unicodeText);
|
||||
|
||||
float dx=0;
|
||||
|
||||
//int measureOnly=0;
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
int viewport[4]={0,0,m_instancingRenderer->getScreenWidth(),m_instancingRenderer->getScreenHeight()};
|
||||
|
||||
float posX = 450.f;
|
||||
float posY = 100.f;
|
||||
float winx,winy, winz;
|
||||
|
||||
if (!projectWorldCoordToScreen(worldPosX, worldPosY, worldPosZ,viewMat,projMat,viewport,&winx, &winy, &winz))
|
||||
{
|
||||
return;
|
||||
}
|
||||
posX = winx;
|
||||
posY = m_instancingRenderer->getScreenHeight()/2+(m_instancingRenderer->getScreenHeight()/2)-winy;
|
||||
|
||||
|
||||
if (0)//m_useTrueTypeFont)
|
||||
{
|
||||
bool measureOnly = false;
|
||||
|
||||
float fontSize= 32;//64;//512;//128;
|
||||
sth_draw_text(m_data->m_fontStash,
|
||||
m_data->m_droidRegular,fontSize,posX,posY,
|
||||
txt,&dx, this->m_instancingRenderer->getScreenWidth(),this->m_instancingRenderer->getScreenHeight(),measureOnly,m_window->getRetinaScale());
|
||||
sth_end_draw(m_data->m_fontStash);
|
||||
sth_flush_draw(m_data->m_fontStash);
|
||||
} else
|
||||
{
|
||||
//float width = 0.f;
|
||||
int pos=0;
|
||||
//float color[]={0.2f,0.2,0.2f,1.f};
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D,m_data->m_largeFontTextureId);
|
||||
|
||||
//float width = r.x;
|
||||
//float extraSpacing = 0.;
|
||||
|
||||
float startX = posX;
|
||||
float startY = posY-g_DefaultLargeFont->m_CharHeight;
|
||||
|
||||
|
||||
while (txt[pos])
|
||||
{
|
||||
int c = txt[pos];
|
||||
//r.h = g_DefaultNormalFont->m_CharHeight;
|
||||
//r.w = g_DefaultNormalFont->m_CharWidth[c]+extraSpacing;
|
||||
float endX = startX+g_DefaultLargeFont->m_CharWidth[c];
|
||||
float endY = posY;
|
||||
|
||||
|
||||
float currentColor[]={1.f,0.2,0.2f,1.f};
|
||||
|
||||
// m_primRenderer->drawTexturedRect(startX, startY, endX, endY, currentColor,g_DefaultLargeFont->m_CharU0[c],g_DefaultLargeFont->m_CharV0[c],g_DefaultLargeFont->m_CharU1[c],g_DefaultLargeFont->m_CharV1[c]);
|
||||
float u0 = g_DefaultLargeFont->m_CharU0[c];
|
||||
float u1 = g_DefaultLargeFont->m_CharU1[c];
|
||||
float v0 = g_DefaultLargeFont->m_CharV0[c];
|
||||
float v1 = g_DefaultLargeFont->m_CharV1[c];
|
||||
float color[4] = {currentColor[0],currentColor[1],currentColor[2],currentColor[3]};
|
||||
float x0 = startX;
|
||||
float x1 = endX;
|
||||
float y0 = startY;
|
||||
float y1 = endY;
|
||||
int screenWidth = m_instancingRenderer->getScreenWidth();
|
||||
int screenHeight = m_instancingRenderer->getScreenHeight();
|
||||
|
||||
float z = 2.f*winz-1.f;//*(far
|
||||
float identity[16]={1,0,0,0,
|
||||
0,1,0,0,
|
||||
0,0,1,0,
|
||||
0,0,0,1};
|
||||
PrimVertex vertexData[4] = {
|
||||
{ PrimVec4(-1.f+2.f*x0/float(screenWidth), 1.f-2.f*y0/float(screenHeight), z, 1.f ), PrimVec4( color[0], color[1], color[2], color[3] ) ,PrimVec2(u0,v0)},
|
||||
{ PrimVec4(-1.f+2.f*x0/float(screenWidth), 1.f-2.f*y1/float(screenHeight), z, 1.f ), PrimVec4( color[0], color[1], color[2], color[3] ) ,PrimVec2(u0,v1)},
|
||||
{ PrimVec4( -1.f+2.f*x1/float(screenWidth), 1.f-2.f*y1/float(screenHeight), z, 1.f ), PrimVec4(color[0], color[1], color[2], color[3]) ,PrimVec2(u1,v1)},
|
||||
{ PrimVec4( -1.f+2.f*x1/float(screenWidth), 1.f-2.f*y0/float(screenHeight), z, 1.f ), PrimVec4( color[0], color[1], color[2], color[3] ) ,PrimVec2(u1,v0)}
|
||||
};
|
||||
|
||||
m_primRenderer->drawTexturedRect3D(vertexData[0],vertexData[1],vertexData[2],vertexData[3],identity,identity,false);
|
||||
|
||||
//DrawTexturedRect(0,r,g_DefaultNormalFont->m_CharU0[c],g_DefaultNormalFont->m_CharV0[c],g_DefaultNormalFont->m_CharU1[c],g_DefaultNormalFont->m_CharV1[c]);
|
||||
// DrawFilledRect(r);
|
||||
|
||||
startX = endX;
|
||||
//startY = endY;
|
||||
|
||||
pos++;
|
||||
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D,0);
|
||||
}
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
|
||||
#if 0
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
|
||||
int pos=0;
|
||||
//float color[]={0.2f,0.2,0.2f,1.f};
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D,m_data->m_largeFontTextureId);
|
||||
|
||||
//float width = r.x;
|
||||
//float extraSpacing = 0.;
|
||||
|
||||
float startX = posX;
|
||||
float startY = posY;
|
||||
|
||||
|
||||
while (txt[pos])
|
||||
{
|
||||
float scaling = 0.02;
|
||||
|
||||
int c = txt[pos];
|
||||
//r.h = g_DefaultNormalFont->m_CharHeight;
|
||||
//r.w = g_DefaultNormalFont->m_CharWidth[c]+extraSpacing;
|
||||
float endX = startX-float(g_DefaultLargeFont->m_CharWidth[c])*scaling;
|
||||
float endY = startY-float(g_DefaultLargeFont->m_CharHeight)*scaling;
|
||||
|
||||
|
||||
float currentColor[]={0.2f,0.2,0.2f,1.f};
|
||||
|
||||
float u0 = g_DefaultLargeFont->m_CharU0[c];
|
||||
float v0 = g_DefaultLargeFont->m_CharV0[c];
|
||||
float u1 = g_DefaultLargeFont->m_CharU1[c];
|
||||
float v1 = g_DefaultLargeFont->m_CharV1[c];
|
||||
float color[4] = {0,0,0,1};
|
||||
|
||||
PrimVertex vertexData[4] = {
|
||||
{ PrimVec4(startX, startY, 0, 1.f ), PrimVec4( color[0], color[1], color[2], color[3] ) ,PrimVec2(u0,v0)},
|
||||
{ PrimVec4(startX, endY, 0 , 1.f), PrimVec4( color[0], color[1], color[2], color[3] ) ,PrimVec2(u0,v1)},
|
||||
{ PrimVec4(endX, endY,0.f, 1.f ), PrimVec4(color[0], color[1], color[2], color[3]) ,PrimVec2(u1,v1)},
|
||||
{ PrimVec4(endX,startY, 0.f, 1.f ), PrimVec4( color[0], color[1], color[2], color[3] ) ,PrimVec2(u1,v0)}
|
||||
};
|
||||
float viewMat[16];
|
||||
float projMat[16];
|
||||
m_instancingRenderer->getCameraViewMatrix(viewMat);
|
||||
m_instancingRenderer->getCameraProjectionMatrix(projMat);
|
||||
|
||||
m_primRenderer->drawTexturedRect3D(vertexData[0],vertexData[1],vertexData[2],vertexData[3],viewMat,projMat,false);
|
||||
|
||||
//DrawTexturedRect(0,r,g_DefaultNormalFont->m_CharU0[c],g_DefaultNormalFont->m_CharV0[c],g_DefaultNormalFont->m_CharU1[c],g_DefaultNormalFont->m_CharV1[c]);
|
||||
// DrawFilledRect(r);
|
||||
|
||||
startX = endX;
|
||||
//startY = endY;
|
||||
|
||||
pos++;
|
||||
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D,0);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SimpleOpenGL3App::drawText( const char* txt, int posXi, int posYi)
|
||||
{
|
||||
|
||||
float posX = (float)posXi;
|
||||
float posY = (float) posYi;
|
||||
|
||||
|
||||
//
|
||||
@@ -213,9 +400,15 @@ void SimpleOpenGL3App::drawText( const char* txt, int posX, int posY)
|
||||
bool measureOnly = false;
|
||||
|
||||
float fontSize= 64;//512;//128;
|
||||
int bla=0;
|
||||
float bla2=1;
|
||||
sth_draw_text(m_data->m_fontStash,
|
||||
m_data->m_droidRegular,fontSize,posX,posY,
|
||||
txt,&dx, this->m_instancingRenderer->getScreenWidth(),this->m_instancingRenderer->getScreenHeight(),measureOnly,m_window->getRetinaScale());
|
||||
txt,&dx, this->m_instancingRenderer->getScreenWidth(),
|
||||
this->m_instancingRenderer->getScreenHeight(),
|
||||
measureOnly,
|
||||
m_window->getRetinaScale());
|
||||
|
||||
sth_end_draw(m_data->m_fontStash);
|
||||
sth_flush_draw(m_data->m_fontStash);
|
||||
} else
|
||||
@@ -224,13 +417,13 @@ void SimpleOpenGL3App::drawText( const char* txt, int posX, int posY)
|
||||
int pos=0;
|
||||
//float color[]={0.2f,0.2,0.2f,1.f};
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D,m_data->m_fontTextureId);
|
||||
glBindTexture(GL_TEXTURE_2D,m_data->m_largeFontTextureId);
|
||||
|
||||
//float width = r.x;
|
||||
//float extraSpacing = 0.;
|
||||
|
||||
int startX = posX;
|
||||
int startY = posY;
|
||||
float startX = posX;
|
||||
float startY = posY;
|
||||
|
||||
|
||||
while (txt[pos])
|
||||
@@ -238,13 +431,13 @@ void SimpleOpenGL3App::drawText( const char* txt, int posX, int posY)
|
||||
int c = txt[pos];
|
||||
//r.h = g_DefaultNormalFont->m_CharHeight;
|
||||
//r.w = g_DefaultNormalFont->m_CharWidth[c]+extraSpacing;
|
||||
int endX = startX+g_DefaultNormalFont->m_CharWidth[c];
|
||||
int endY = startY+g_DefaultNormalFont->m_CharHeight;
|
||||
float endX = startX+g_DefaultLargeFont->m_CharWidth[c];
|
||||
float endY = startY+g_DefaultLargeFont->m_CharHeight;
|
||||
|
||||
|
||||
float currentColor[]={0.2f,0.2,0.2f,1.f};
|
||||
|
||||
m_primRenderer->drawTexturedRect(startX, startY, endX, endY, currentColor,g_DefaultNormalFont->m_CharU0[c],g_DefaultNormalFont->m_CharV0[c],g_DefaultNormalFont->m_CharU1[c],g_DefaultNormalFont->m_CharV1[c]);
|
||||
m_primRenderer->drawTexturedRect(startX, startY, endX, endY, currentColor,g_DefaultLargeFont->m_CharU0[c],g_DefaultLargeFont->m_CharV0[c],g_DefaultLargeFont->m_CharU1[c],g_DefaultLargeFont->m_CharV1[c]);
|
||||
|
||||
//DrawTexturedRect(0,r,g_DefaultNormalFont->m_CharU0[c],g_DefaultNormalFont->m_CharV0[c],g_DefaultNormalFont->m_CharU1[c],g_DefaultNormalFont->m_CharV1[c]);
|
||||
// DrawFilledRect(r);
|
||||
@@ -290,11 +483,45 @@ int SimpleOpenGL3App::registerCubeShape(float halfExtentsX,float halfExtentsY, f
|
||||
verts[i].u = cube_vertices[i*9+7];
|
||||
verts[i].v = cube_vertices[i*9+8];
|
||||
}
|
||||
|
||||
|
||||
int shapeId = m_instancingRenderer->registerShape(&verts[0].x,numVertices,cube_indices,numIndices);
|
||||
return shapeId;
|
||||
}
|
||||
|
||||
void SimpleOpenGL3App::registerGrid(int cells_x, int cells_z, float color0[4], float color1[4])
|
||||
{
|
||||
b3Vector3 cubeExtents=b3MakeVector3(0.5,0.5,0.5);
|
||||
cubeExtents[m_data->m_upAxis] = 0;
|
||||
int cubeId = registerCubeShape(cubeExtents[0],cubeExtents[1],cubeExtents[2]);
|
||||
|
||||
b3Quaternion orn(0,0,0,1);
|
||||
b3Vector3 center=b3MakeVector3(0,0,0,1);
|
||||
b3Vector3 scaling=b3MakeVector3(1,1,1,1);
|
||||
|
||||
for ( int i = 0; i < cells_x; i++)
|
||||
{
|
||||
for (int j = 0; j < cells_z; j++)
|
||||
{
|
||||
float* color =0;
|
||||
if ((i + j) % 2 == 0)
|
||||
{
|
||||
color = (float*)color0;
|
||||
} else {
|
||||
color = (float*)color1;
|
||||
}
|
||||
if (this->m_data->m_upAxis==1)
|
||||
{
|
||||
center =b3MakeVector3((i + 0.5f) - cells_x * 0.5f, 0.f, (j + 0.5f) - cells_z * 0.5f);
|
||||
} else
|
||||
{
|
||||
center =b3MakeVector3((i + 0.5f) - cells_x * 0.5f, (j + 0.5f) - cells_z * 0.5f,0.f );
|
||||
}
|
||||
m_instancingRenderer->registerGraphicsInstance(cubeId,center,orn,color,scaling);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
int SimpleOpenGL3App::registerGraphicsSphereShape(float radius, bool usePointSprites, int largeSphereThreshold, int mediumSphereThreshold)
|
||||
{
|
||||
@@ -459,10 +686,10 @@ static void writeTextureToFile(int textureWidth, int textureHeight, const char*
|
||||
{
|
||||
for (int i=0;i<textureWidth;i++)
|
||||
{
|
||||
pixels[(j*textureWidth+i)*numComponents] = orgPixels[(j*textureWidth+i)*numComponents]*255.f;
|
||||
pixels[(j*textureWidth+i)*numComponents+1]=orgPixels[(j*textureWidth+i)*numComponents+1]*255.f;
|
||||
pixels[(j*textureWidth+i)*numComponents+2]=orgPixels[(j*textureWidth+i)*numComponents+2]*255.f;
|
||||
pixels[(j*textureWidth+i)*numComponents+3]=orgPixels[(j*textureWidth+i)*numComponents+3]*255.f;
|
||||
pixels[(j*textureWidth+i)*numComponents] = char(orgPixels[(j*textureWidth+i)*numComponents]*255.f);
|
||||
pixels[(j*textureWidth+i)*numComponents+1]=char(orgPixels[(j*textureWidth+i)*numComponents+1]*255.f);
|
||||
pixels[(j*textureWidth+i)*numComponents+2]=char(orgPixels[(j*textureWidth+i)*numComponents+2]*255.f);
|
||||
pixels[(j*textureWidth+i)*numComponents+3]=char(orgPixels[(j*textureWidth+i)*numComponents+3]*255.f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -508,8 +735,8 @@ void SimpleOpenGL3App::swapBuffer()
|
||||
m_window->endRendering();
|
||||
if (m_data->m_frameDumpPngFileName)
|
||||
{
|
||||
writeTextureToFile(m_window->getRetinaScale()*m_instancingRenderer->getScreenWidth(),
|
||||
m_window->getRetinaScale()*this->m_instancingRenderer->getScreenHeight(),m_data->m_frameDumpPngFileName,
|
||||
writeTextureToFile((int)m_window->getRetinaScale()*m_instancingRenderer->getScreenWidth(),
|
||||
(int) m_window->getRetinaScale()*this->m_instancingRenderer->getScreenHeight(),m_data->m_frameDumpPngFileName,
|
||||
m_data->m_ffmpegFile);
|
||||
//m_data->m_renderTexture->disable();
|
||||
//if (m_data->m_ffmpegFile==0)
|
||||
@@ -522,8 +749,8 @@ void SimpleOpenGL3App::swapBuffer()
|
||||
// see also http://blog.mmacklin.com/2013/06/11/real-time-video-capture-with-ffmpeg/
|
||||
void SimpleOpenGL3App::dumpFramesToVideo(const char* mp4FileName)
|
||||
{
|
||||
int width = m_window->getRetinaScale()*m_instancingRenderer->getScreenWidth();
|
||||
int height = m_window->getRetinaScale()*m_instancingRenderer->getScreenHeight();
|
||||
int width = (int)m_window->getRetinaScale()*m_instancingRenderer->getScreenWidth();
|
||||
int height = (int)m_window->getRetinaScale()*m_instancingRenderer->getScreenHeight();
|
||||
char cmd[8192];
|
||||
|
||||
sprintf(cmd,"ffmpeg -r 60 -f rawvideo -pix_fmt rgba -s %dx%d -i - "
|
||||
|
||||
@@ -19,9 +19,9 @@ struct SimpleOpenGL3App : public CommonGraphicsApp
|
||||
SimpleOpenGL3App(const char* title, int width,int height);
|
||||
virtual ~SimpleOpenGL3App();
|
||||
|
||||
int registerCubeShape(float halfExtentsX=1.f,float halfExtentsY=1.f, float halfExtentsZ = 1.f);
|
||||
int registerGraphicsSphereShape(float radius, bool usePointSprites=true, int largeSphereThreshold=100, int mediumSphereThreshold=10);
|
||||
|
||||
virtual int registerCubeShape(float halfExtentsX=1.f,float halfExtentsY=1.f, float halfExtentsZ = 1.f);
|
||||
virtual int registerGraphicsSphereShape(float radius, bool usePointSprites=true, int largeSphereThreshold=100, int mediumSphereThreshold=10);
|
||||
virtual void registerGrid(int xres, int yres, float color0[4], float color1[4]);
|
||||
void dumpNextFrameToPng(const char* pngFilename);
|
||||
void dumpFramesToVideo(const char* mp4Filename);
|
||||
|
||||
@@ -31,6 +31,7 @@ struct SimpleOpenGL3App : public CommonGraphicsApp
|
||||
|
||||
virtual void swapBuffer();
|
||||
virtual void drawText( const char* txt, int posX, int posY);
|
||||
virtual void drawText3D( const char* txt, float posX, float posZY, float posZ, float size);
|
||||
struct sth_stash* getFontStash();
|
||||
|
||||
|
||||
|
||||
@@ -153,6 +153,7 @@ public:
|
||||
m_maxAppliedImpulse = maxImp;
|
||||
}
|
||||
|
||||
virtual void debugDraw(class btIDebugDraw* drawer)=0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -756,6 +756,11 @@ void btMultiBodyDynamicsWorld::removeMultiBodyConstraint( btMultiBodyConstraint*
|
||||
m_multiBodyConstraints.remove(constraint);
|
||||
}
|
||||
|
||||
void btMultiBodyDynamicsWorld::debugDrawMultiBodyConstraint(btMultiBodyConstraint* constraint)
|
||||
{
|
||||
constraint->debugDraw(getDebugDrawer());
|
||||
}
|
||||
|
||||
|
||||
void btMultiBodyDynamicsWorld::debugDrawWorld()
|
||||
{
|
||||
@@ -772,11 +777,17 @@ void btMultiBodyDynamicsWorld::debugDrawWorld()
|
||||
|
||||
if (drawConstraints)
|
||||
{
|
||||
BT_PROFILE("btMultiBody stepPositions");
|
||||
//integrate and update the Featherstone hierarchies
|
||||
BT_PROFILE("btMultiBody debugDrawWorld");
|
||||
|
||||
btAlignedObjectArray<btQuaternion> world_to_local;
|
||||
btAlignedObjectArray<btVector3> local_origin;
|
||||
|
||||
for (int c=0;c<m_multiBodyConstraints.size();c++)
|
||||
{
|
||||
btMultiBodyConstraint* constraint = m_multiBodyConstraints[c];
|
||||
debugDrawMultiBodyConstraint(constraint);
|
||||
}
|
||||
|
||||
for (int b = 0; b<m_multiBodies.size(); b++)
|
||||
{
|
||||
btMultiBody* bod = m_multiBodies[b];
|
||||
|
||||
@@ -56,5 +56,7 @@ public:
|
||||
virtual void integrateTransforms(btScalar timeStep);
|
||||
|
||||
virtual void debugDrawWorld();
|
||||
|
||||
virtual void debugDrawMultiBodyConstraint(btMultiBodyConstraint* constraint);
|
||||
};
|
||||
#endif //BT_MULTIBODY_DYNAMICS_WORLD_H
|
||||
|
||||
@@ -36,7 +36,11 @@ public:
|
||||
virtual void createConstraintRows(btMultiBodyConstraintArray& constraintRows,
|
||||
btMultiBodyJacobianData& data,
|
||||
const btContactSolverInfo& infoGlobal);
|
||||
|
||||
|
||||
virtual void debugDraw(class btIDebugDraw* drawer)
|
||||
{
|
||||
//todo(erwincoumans)
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -45,7 +45,11 @@ public:
|
||||
{
|
||||
m_desiredVelocity = velTarget;
|
||||
}
|
||||
|
||||
|
||||
virtual void debugDraw(class btIDebugDraw* drawer)
|
||||
{
|
||||
//todo(erwincoumans)
|
||||
}
|
||||
};
|
||||
|
||||
#endif //BT_MULTIBODY_JOINT_MOTOR_H
|
||||
|
||||
@@ -18,6 +18,7 @@ subject to the following restrictions:
|
||||
#include "btMultiBodyPoint2Point.h"
|
||||
#include "btMultiBodyLinkCollider.h"
|
||||
#include "BulletDynamics/Dynamics/btRigidBody.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
|
||||
#ifndef BTMBP2PCONSTRAINT_BLOCK_ANGULAR_MOTION_TEST
|
||||
#define BTMBP2PCONSTRAINT_DIM 3
|
||||
@@ -95,18 +96,18 @@ void btMultiBodyPoint2Point::createConstraintRows(btMultiBodyConstraintArray& co
|
||||
const btContactSolverInfo& infoGlobal)
|
||||
{
|
||||
|
||||
// int i=1;
|
||||
// int i=1;
|
||||
int numDim = BTMBP2PCONSTRAINT_DIM;
|
||||
for (int i=0;i<numDim;i++)
|
||||
{
|
||||
|
||||
btMultiBodySolverConstraint& constraintRow = constraintRows.expandNonInitializing();
|
||||
//memset(&constraintRow,0xffffffff,sizeof(btMultiBodySolverConstraint));
|
||||
constraintRow.m_relpos1CrossNormal.setValue(0,0,0);
|
||||
constraintRow.m_contactNormal1.setValue(0,0,0);
|
||||
constraintRow.m_relpos2CrossNormal.setValue(0,0,0);
|
||||
constraintRow.m_contactNormal2.setValue(0,0,0);
|
||||
constraintRow.m_angularComponentA.setValue(0,0,0);
|
||||
//memset(&constraintRow,0xffffffff,sizeof(btMultiBodySolverConstraint));
|
||||
constraintRow.m_relpos1CrossNormal.setValue(0,0,0);
|
||||
constraintRow.m_contactNormal1.setValue(0,0,0);
|
||||
constraintRow.m_relpos2CrossNormal.setValue(0,0,0);
|
||||
constraintRow.m_contactNormal2.setValue(0,0,0);
|
||||
constraintRow.m_angularComponentA.setValue(0,0,0);
|
||||
constraintRow.m_angularComponentB.setValue(0,0,0);
|
||||
|
||||
constraintRow.m_solverBodyIdA = data.m_fixedBodyId;
|
||||
@@ -154,8 +155,8 @@ int numDim = BTMBP2PCONSTRAINT_DIM;
|
||||
posError,
|
||||
infoGlobal,
|
||||
-m_maxAppliedImpulse, m_maxAppliedImpulse
|
||||
);
|
||||
//@todo: support the case of btMultiBody versus btRigidBody,
|
||||
);
|
||||
//@todo: support the case of btMultiBody versus btRigidBody,
|
||||
//see btPoint2PointConstraint::getInfo2NonVirtual
|
||||
#else
|
||||
const btVector3 dummy(0, 0, 0);
|
||||
@@ -176,4 +177,36 @@ int numDim = BTMBP2PCONSTRAINT_DIM;
|
||||
);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void btMultiBodyPoint2Point::debugDraw(class btIDebugDraw* drawer)
|
||||
{
|
||||
btTransform tr;
|
||||
tr.setIdentity();
|
||||
|
||||
if (m_rigidBodyA)
|
||||
{
|
||||
btVector3 pivot = m_rigidBodyA->getCenterOfMassTransform() * m_pivotInA;
|
||||
tr.setOrigin(pivot);
|
||||
drawer->drawTransform(tr, 0.1);
|
||||
}
|
||||
if (m_bodyA)
|
||||
{
|
||||
btVector3 pivotAworld = m_bodyA->localPosToWorld(m_linkA, m_pivotInA);
|
||||
tr.setOrigin(pivotAworld);
|
||||
drawer->drawTransform(tr, 0.1);
|
||||
}
|
||||
if (m_rigidBodyB)
|
||||
{
|
||||
// that ideally should draw the same frame
|
||||
btVector3 pivot = m_rigidBodyB->getCenterOfMassTransform() * m_pivotInB;
|
||||
tr.setOrigin(pivot);
|
||||
drawer->drawTransform(tr, 0.1);
|
||||
}
|
||||
if (m_bodyB)
|
||||
{
|
||||
btVector3 pivotBworld = m_bodyB->localPosToWorld(m_linkB, m_pivotInB);
|
||||
tr.setOrigin(pivotBworld);
|
||||
drawer->drawTransform(tr, 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ public:
|
||||
m_pivotInB = pivotInB;
|
||||
}
|
||||
|
||||
virtual void debugDraw(class btIDebugDraw* drawer);
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user