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