[167] | 1 | #include "GLDebugDrawer.h" |
---|
| 2 | #include "GLDebugFont.h" |
---|
| 3 | #include "GlutStuff.h" |
---|
| 4 | |
---|
| 5 | #include <stdio.h> //printf debugging |
---|
| 6 | |
---|
| 7 | GLDebugDrawer::GLDebugDrawer() |
---|
| 8 | :m_debugMode(0) |
---|
| 9 | { |
---|
| 10 | |
---|
| 11 | } |
---|
| 12 | |
---|
| 13 | void GLDebugDrawer::drawLine(const btVector3& from,const btVector3& to,const btVector3& fromColor, const btVector3& toColor) |
---|
| 14 | { |
---|
| 15 | glBegin(GL_LINES); |
---|
| 16 | glColor3f(fromColor.getX(), fromColor.getY(), fromColor.getZ()); |
---|
| 17 | glVertex3d(from.getX(), from.getY(), from.getZ()); |
---|
| 18 | glColor3f(toColor.getX(), toColor.getY(), toColor.getZ()); |
---|
| 19 | glVertex3d(to.getX(), to.getY(), to.getZ()); |
---|
| 20 | glEnd(); |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | void GLDebugDrawer::drawLine(const btVector3& from,const btVector3& to,const btVector3& color) |
---|
| 24 | { |
---|
| 25 | // if (m_debugMode > 0) |
---|
| 26 | { |
---|
| 27 | glBegin(GL_LINES); |
---|
| 28 | glColor4f(color.getX(), color.getY(), color.getZ(),1.f); |
---|
| 29 | glVertex3d(from.getX(), from.getY(), from.getZ()); |
---|
| 30 | glVertex3d(to.getX(), to.getY(), to.getZ()); |
---|
| 31 | glEnd(); |
---|
| 32 | } |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | void GLDebugDrawer::drawSphere (const btVector3& p, btScalar radius, const btVector3& color) |
---|
| 36 | { |
---|
| 37 | glColor4f (color.getX(), color.getY(), color.getZ(), btScalar(1.0f)); |
---|
| 38 | glPushMatrix (); |
---|
| 39 | glTranslatef (p.getX(), p.getY(), p.getZ()); |
---|
| 40 | |
---|
| 41 | int lats = 5; |
---|
| 42 | int longs = 5; |
---|
| 43 | |
---|
| 44 | int i, j; |
---|
| 45 | for(i = 0; i <= lats; i++) { |
---|
| 46 | btScalar lat0 = SIMD_PI * (-btScalar(0.5) + (btScalar) (i - 1) / lats); |
---|
| 47 | btScalar z0 = radius*sin(lat0); |
---|
| 48 | btScalar zr0 = radius*cos(lat0); |
---|
| 49 | |
---|
| 50 | btScalar lat1 = SIMD_PI * (-btScalar(0.5) + (btScalar) i / lats); |
---|
| 51 | btScalar z1 = radius*sin(lat1); |
---|
| 52 | btScalar zr1 = radius*cos(lat1); |
---|
| 53 | |
---|
| 54 | glBegin(GL_QUAD_STRIP); |
---|
| 55 | for(j = 0; j <= longs; j++) { |
---|
| 56 | btScalar lng = 2 * SIMD_PI * (btScalar) (j - 1) / longs; |
---|
| 57 | btScalar x = cos(lng); |
---|
| 58 | btScalar y = sin(lng); |
---|
| 59 | |
---|
| 60 | glNormal3f(x * zr0, y * zr0, z0); |
---|
| 61 | glVertex3f(x * zr0, y * zr0, z0); |
---|
| 62 | glNormal3f(x * zr1, y * zr1, z1); |
---|
| 63 | glVertex3f(x * zr1, y * zr1, z1); |
---|
| 64 | } |
---|
| 65 | glEnd(); |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | glPopMatrix(); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | void GLDebugDrawer::drawBox (const btVector3& boxMin, const btVector3& boxMax, const btVector3& color, btScalar alpha) |
---|
| 72 | { |
---|
| 73 | btVector3 halfExtent = (boxMax - boxMin) * btScalar(0.5f); |
---|
| 74 | btVector3 center = (boxMax + boxMin) * btScalar(0.5f); |
---|
| 75 | //glEnable(GL_BLEND); // Turn blending On |
---|
| 76 | //glBlendFunc(GL_SRC_ALPHA, GL_ONE); |
---|
| 77 | glColor4f (color.getX(), color.getY(), color.getZ(), alpha); |
---|
| 78 | glPushMatrix (); |
---|
| 79 | glTranslatef (center.getX(), center.getY(), center.getZ()); |
---|
| 80 | glScaled(2*halfExtent[0], 2*halfExtent[1], 2*halfExtent[2]); |
---|
| 81 | // glutSolidCube(1.0); |
---|
| 82 | glPopMatrix (); |
---|
| 83 | //glDisable(GL_BLEND); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | void GLDebugDrawer::drawTriangle(const btVector3& a,const btVector3& b,const btVector3& c,const btVector3& color,btScalar alpha) |
---|
| 87 | { |
---|
| 88 | // if (m_debugMode > 0) |
---|
| 89 | { |
---|
| 90 | const btVector3 n=btCross(b-a,c-a).normalized(); |
---|
| 91 | glBegin(GL_TRIANGLES); |
---|
| 92 | glColor4f(color.getX(), color.getY(), color.getZ(),alpha); |
---|
| 93 | glNormal3d(n.getX(),n.getY(),n.getZ()); |
---|
| 94 | glVertex3d(a.getX(),a.getY(),a.getZ()); |
---|
| 95 | glVertex3d(b.getX(),b.getY(),b.getZ()); |
---|
| 96 | glVertex3d(c.getX(),c.getY(),c.getZ()); |
---|
| 97 | glEnd(); |
---|
| 98 | } |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | void GLDebugDrawer::setDebugMode(int debugMode) |
---|
| 102 | { |
---|
| 103 | m_debugMode = debugMode; |
---|
| 104 | |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | void GLDebugDrawer::draw3dText(const btVector3& location,const char* textString) |
---|
| 108 | { |
---|
| 109 | glRasterPos3f(location.x(), location.y(), location.z()); |
---|
| 110 | //BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),textString); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | void GLDebugDrawer::reportErrorWarning(const char* warningString) |
---|
| 114 | { |
---|
| 115 | printf("%s", warningString); |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | void GLDebugDrawer::drawContactPoint(const btVector3& pointOnB,const btVector3& normalOnB,btScalar distance,int lifeTime,const btVector3& color) |
---|
| 119 | { |
---|
| 120 | |
---|
| 121 | { |
---|
| 122 | btVector3 to=pointOnB+normalOnB*distance; |
---|
| 123 | const btVector3&from = pointOnB; |
---|
| 124 | glColor4f(color.getX(), color.getY(), color.getZ(),1.f); |
---|
| 125 | //glColor4f(0,0,0,1.f); |
---|
| 126 | |
---|
| 127 | glBegin(GL_LINES); |
---|
| 128 | glVertex3d(from.getX(), from.getY(), from.getZ()); |
---|
| 129 | glVertex3d(to.getX(), to.getY(), to.getZ()); |
---|
| 130 | glEnd(); |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | glRasterPos3f(from.x(), from.y(), from.z()); |
---|
| 134 | char buf[12]; |
---|
| 135 | sprintf(buf," %d",lifeTime); |
---|
| 136 | //BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf); |
---|
| 137 | |
---|
| 138 | |
---|
| 139 | } |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | |
---|