| 174 | } |
| 175 | |
| 176 | GL_ShapeDrawer::ShapeCache* GL_ShapeDrawer::cache(btConvexShape* shape) |
| 177 | { |
| 178 | ShapeCache* sc = (ShapeCache*)shape->getUserPointer(); |
| 179 | if (!sc) |
| 180 | { |
| 181 | sc = new (btAlignedAlloc(sizeof(ShapeCache), 16)) ShapeCache(shape); |
| 182 | sc->m_shapehull.buildHull(shape->getMargin()); |
| 183 | m_shapecaches.push_back(sc); |
| 184 | shape->setUserPointer(sc); |
| 185 | /* Build edges */ |
| 186 | const int ni = sc->m_shapehull.numIndices(); |
| 187 | const int nv = sc->m_shapehull.numVertices(); |
| 188 | const unsigned int* pi = sc->m_shapehull.getIndexPointer(); |
| 189 | const btVector3* pv = sc->m_shapehull.getVertexPointer(); |
| 190 | btAlignedObjectArray<ShapeCache::Edge*> edges; |
| 191 | sc->m_edges.reserve(ni); |
| 192 | edges.resize(nv * nv, 0); |
| 193 | for (int i = 0; i < ni; i += 3) |
| 194 | { |
| 195 | const unsigned int* ti = pi + i; |
| 196 | const btVector3 nrm = btCross(pv[ti[1]] - pv[ti[0]], pv[ti[2]] - pv[ti[0]]).normalized(); |
| 197 | for (int j = 2, k = 0; k < 3; j = k++) |
| 198 | { |
| 199 | const unsigned int a = ti[j]; |
| 200 | const unsigned int b = ti[k]; |
| 201 | ShapeCache::Edge*& e = edges[btMin(a, b) * nv + btMax(a, b)]; |
| 202 | if (!e) |
| 203 | { |
| 204 | sc->m_edges.push_back(ShapeCache::Edge()); |
| 205 | e = &sc->m_edges[sc->m_edges.size() - 1]; |
| 206 | e->n[0] = nrm; |
| 207 | e->n[1] = -nrm; |
| 208 | e->v[0] = a; |
| 209 | e->v[1] = b; |
| 210 | } |
| 211 | else |
| 212 | { |
| 213 | e->n[1] = nrm; |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | return (sc); |
| 219 | } |
| 220 | |
| 221 | void renderSquareA(float x, float y, float z) |
| 222 | { |
nothing calls this directly
no test coverage detected