void KHalfEdgeMeshPrivate::connectBoundaries() { for (HalfEdge &edge : m_halfEdges) { if (edge.face == 0 && edge.next == 0) { connectEdges(&edge); } } }
b2Shape* b2Body::CreateShape(b2ShapeDef* def) { b2Assert(m_world->m_lock == false); if (m_world->m_lock == true) { return NULL; } // TODO: Decide on a better place to initialize edgeShapes. (b2Shape::Create() can't // return more than one shape to add to parent body... maybe it should add // shapes directly to the body instead of returning them?) if (def->type == e_edgeShape) { b2EdgeChainDef* edgeDef = (b2EdgeChainDef*)def; b2Vec2 v1; b2Vec2 v2; int i; if (edgeDef->isALoop) { v1 = edgeDef->vertices[edgeDef->vertexCount-1]; i = 0; } else { v1 = edgeDef->vertices[0]; i = 1; } b2EdgeShape* s0 = NULL; b2EdgeShape* s1 = NULL; b2EdgeShape* s2 = NULL; float32 angle = 0.0f; for (; i < edgeDef->vertexCount; i++) { v2 = edgeDef->vertices[i]; void* mem = m_world->m_blockAllocator.Allocate(sizeof(b2EdgeShape)); s2 = new (mem) b2EdgeShape(v1, v2, def, settings); if(m_lastShape) m_lastShape->m_next = s2; if(!m_shapeList) m_shapeList = s2; m_lastShape = s2; ++m_shapeCount; s2->m_body = this; s2->CreateProxy(m_world->m_broadPhase, m_xf); s2->UpdateSweepRadius(m_sweep.localCenter); if (s1 == NULL) { s0 = s2; angle = b2Atan2(s2->GetDirectionVector().y, s2->GetDirectionVector().x); } else { angle = connectEdges(s1, s2, angle); } s1 = s2; v1 = v2; } if (edgeDef->isALoop) connectEdges(s1, s0, angle); return s0; } b2Shape* s = b2Shape::Create(def, &m_world->m_blockAllocator, settings); if(m_lastShape) m_lastShape->m_next = s; if(!m_shapeList) m_shapeList = s; m_lastShape = s; ++m_shapeCount; s->m_body = this; // Add the shape to the world's broad-phase. s->CreateProxy(m_world->m_broadPhase, m_xf); // Compute the sweep radius for CCD. s->UpdateSweepRadius(m_sweep.localCenter); return s; }