Bullet physics wireframe drawn in a wrong place

Started by
0 comments, last by Sponji 9 years, 8 months ago

Hello,

I'm trying to get my Bullet physics debug working properly. And I am experiencing a problem while drawing wireframe - it gets drawn in a wrong place. It looks like the problem is purely of mathematical origin but I just don't know how to get around it. I've recorded a video showing the problem.

My guess is that it is related to the fact that I draw all the objects using VAO, but the wireframe drawLine function is umplemented using glBegin(GL_LINES)-glEnd.

Here is my draw function:



void World::Draw()
{
    glClearColor(0.1f,0.4f,0.9f,1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glm::mat4 VP =m_camera->GetViewProjection();
    for(std::list<Object*>::iterator it = m_list.begin(), end =m_list.end(); it !=end; ++it) {
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, *(*it)->TextureIDPtr());
        m_shader.Update((*it)->TransformMatrixPtr(),&VP);
        for(int k=0;k<(*it)->ModelPtr()->numMeshes;k++) {
            glBindVertexArray((*it)->ModelPtr()->Meshes[k].m_VAOID);
            glDrawElements(GL_TRIANGLES, (*it)->ModelPtr()->Meshes[k].m_drawCount, GL_UNSIGNED_INT, 0);
        }
        glBindVertexArray(0);
    }
    m_dynamicsWorld->debugDrawWorld();
}

m_dynamicsWorld->debugDrawWorld() in it's turn calls the following function


void bulletDebugDrawer::drawLine(const btVector3& from,const btVector3& to,const btVector3& color)
{
    glBegin(GL_LINES);
            glColor3f(color.getX(), color.getY(), color.getZ());
            glVertex3d(from.getX(), from.getY(), from.getZ());
            glColor3f(color.getX(), color.getY(), color.getZ());
            glVertex3d(to.getX(), to.getY(), to.getZ());
    glEnd();
}

So I would greatly appreciate any help or hint on how to fix this thinghappy.png

Advertisement

Do you set the projection and view matrices somewhere?

Maybe something like this:


void World::Draw() {
	// ... 

	glMatrixMode(GL_PROJECTION);
	glLoadMatrixf(glm::value_ptr(projection_matrix));

	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf(glm::value_ptr(view_matrix));

	m_dynamicsWorld->debugDrawWorld();
}

Derp

This topic is closed to new replies.

Advertisement