//========================== // NW N N NE // \ | | / // a-----------b // / | | \ // SW S S SE //========================== int Stick::extrudeLines(const PathType& path, float width) { if (path.size() < 2) { return EXTRUDE_FAIL; } int pointSize = path.size(); int lineSize = pointSize - 1; _indexList.resize( lineSize*IDEX_FACTOR ); for (int idx=0; idx < lineSize; idx++) { const VecType& a = path[idx]; const VecType& b = path[idx+1]; VecType e = (b-a); e.normalize(); e *= width; VecType N = VecType(-e.y(), e.x(), 0); VecType S = -N; VecType NE = N + e; VecType NW = N - e; VecType SW = -NE; VecType SE = -NW; _vertexList.push_back( Vertex(a + SW) ); _vertexList.push_back( Vertex(a + NW) ); _vertexList.push_back( Vertex(a + S) ); _vertexList.push_back( Vertex(a + N) ); _vertexList.push_back( Vertex(b + S) ); _vertexList.push_back( Vertex(b + N) ); _vertexList.push_back( Vertex(b + SE) ); _vertexList.push_back( Vertex(b + NE) ); } _generateTriangleTexCoord(); _generateTriangesIndices(); return EXTRUDE_SUCCESS; }
int RoadComposer::extrude_lines(const Point* point_list, int point_num, int width, float (&tex_coord)[4], V2F2F* vertex_page, int vertex_size, IType* index_page, int index_size, int index_off) { if (point_num < 2) { return EXTRUDE_FAIL; } int line_size = point_num - 1; int v_cursor = 0; for (int idx=0; idx < line_size; idx++) { const Point& p0 = point_list[idx]; const Point& p1 = point_list[idx+1]; VecType a(p0.x, p0.y); VecType b(p1.x, p1.y); VecType e = (b-a); e.normalize(); e *= width; VecType N = VecType(-e.y(), e.x()); VecType S = -N; VecType NE = N + e; VecType NW = N - e; VecType SW = -NE; VecType SE = -NW; if (v_cursor + LINE_MAX_VERT_SIZE > vertex_size) { return EXTRUDE_FAIL; } ASSIGN_2F_ARRAY( vertex_page[v_cursor].xy, VecType(a + SW).getValue() ); v_cursor++; ASSIGN_2F_ARRAY( vertex_page[v_cursor].xy, VecType(a + NW).getValue() ); v_cursor++; ASSIGN_2F_ARRAY( vertex_page[v_cursor].xy, VecType(a + S).getValue() ); v_cursor++; ASSIGN_2F_ARRAY( vertex_page[v_cursor].xy, VecType(a + N).getValue() ); v_cursor++; ASSIGN_2F_ARRAY( vertex_page[v_cursor].xy, VecType(b + S).getValue() ); v_cursor++; ASSIGN_2F_ARRAY( vertex_page[v_cursor].xy, VecType(b + N).getValue() ); v_cursor++; if (idx==line_size-1) { // 最后一段增加尾部 ASSIGN_2F_ARRAY( vertex_page[v_cursor].xy, VecType(b + S).getValue() ); v_cursor++; ASSIGN_2F_ARRAY( vertex_page[v_cursor].xy, VecType(b + N).getValue() ); v_cursor++; ASSIGN_2F_ARRAY( vertex_page[v_cursor].xy, VecType(b + SE).getValue() ); v_cursor++; ASSIGN_2F_ARRAY( vertex_page[v_cursor].xy, VecType(b + NE).getValue() ); v_cursor++; } } _generate_triangle_texCoord(line_size, vertex_size, vertex_page, tex_coord); return _generate_trianges_indices(line_size, index_size, index_page, index_off);; }