| 1094 | } |
| 1095 | |
| 1096 | void CreateGridCellShape(HCollisionObject2D collision_object, uint32_t shape_index, uint32_t child) |
| 1097 | { |
| 1098 | Body* body = (Body*) collision_object; |
| 1099 | GridShapeData* shape_data = GetGridShapeData(body, shape_index); |
| 1100 | |
| 1101 | if (b2Shape_IsValid(shape_data->m_CellPolygonShapes[child])) |
| 1102 | { |
| 1103 | return; |
| 1104 | } |
| 1105 | |
| 1106 | const GridShapeData::Cell& cell = shape_data->m_Cells[child]; |
| 1107 | if (cell.m_Index == B2GRIDSHAPE_EMPTY_CELL) |
| 1108 | return; |
| 1109 | |
| 1110 | HullSet::Hull& hull = shape_data->m_HullSet->m_Hulls[cell.m_Index]; |
| 1111 | assert(hull.m_Count <= B2_MAX_POLYGON_VERTICES); |
| 1112 | |
| 1113 | b2Vec2 vertices[B2_MAX_POLYGON_VERTICES]; |
| 1114 | uint32_t count = GetGridCellVertices(shape_data, child, vertices); |
| 1115 | |
| 1116 | if (count > 0) |
| 1117 | { |
| 1118 | for (uint32_t j = 0; j < count; ++j) |
| 1119 | { |
| 1120 | vertices[j].x *= shape_data->m_ShapeDataBase.m_CreationScale; |
| 1121 | vertices[j].y *= shape_data->m_ShapeDataBase.m_CreationScale; |
| 1122 | } |
| 1123 | |
| 1124 | // Filters can potentially have changed between creating/initializing the grid shape and when we need to create the actual b2 shapes |
| 1125 | b2ShapeDef shape_def = shape_data->m_ShapeDef; |
| 1126 | shape_def.filter.categoryBits = shape_data->m_CellFilters[child].m_Group; |
| 1127 | shape_def.filter.maskBits = shape_data->m_CellFilters[child].m_Mask; |
| 1128 | |
| 1129 | b2Hull polygon_hull = b2ComputeHull(vertices, count); |
| 1130 | b2Polygon polygon = b2MakePolygon(&polygon_hull, shape_data->m_Radius); |
| 1131 | shape_data->m_CellPolygonShapes[child] = b2CreatePolygonShape(body->m_BodyId, &shape_def, &polygon); |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | bool SetGridShapeHull(HCollisionObject2D collision_object, uint32_t shape_index, uint32_t row, uint32_t column, uint32_t hull, HullFlags flags) |
| 1136 | { |