void Geometry::offset(const Point &offset) { S32 count = getVertCount(); for(S32 i = 0; i < count; i++) setVert(getVert(i) + offset, i); }
// Make object bigger or smaller void Geometry::scale(const Point ¢er, F32 scale) { S32 count = getVertCount(); for(S32 j = 0; j < count; j++) setVert((getVert(j) - center) * scale + center, j); }
void SpritePolygonPerformanceTestStatic::initIncrementStats() { auto t = experimental::SpritePolygon::create(s_pathGrossini); _incVert = (int)t->getVertCount(); _incTri = (int)t->getTrianglesCount(); _incPix = (int)t->getArea(); }
// Could probably be more clever about this, but only used when merging polygons in the editor, so speed not critical void Geometry::reverseWinding() { S32 count = getVertCount(); Vector<Point> temp(count); for(S32 i = 0; i < count; i++) temp.push_back(getVert(i)); for(S32 i = 0; i < count; i++) setVert(temp[i], count - i - 1); }
void Geometry::rotateAboutPoint(const Point ¢er, F32 angle) { F32 sinTheta = sin(angle * Float2Pi / 360.0f); F32 cosTheta = cos(angle * Float2Pi / 360.0f); for(S32 j = 0; j < getVertCount(); j++) { Point v = getVert(j) - center; Point n(v.x * cosTheta + v.y * sinTheta, v.y * cosTheta - v.x * sinTheta); setVert(n + center, j); } }
void Geometry::flip(F32 center, bool isHoriz) { S32 count = getVertCount(); for(S32 i = 0; i < count; i++) { Point p = getVert(i); if(isHoriz) p.x = center * 2 - p.x; else p.y = center * 2 - p.y; setVert(p, i); } }