// Called when we create a brand new object and insert it in the editor, like when we drag a new item from the dock void PolygonObject::newObjectFromDock(F32 gridSize) { #ifndef ZAP_DEDICATED F32 w = INITIAL_HEIGHT * gridSize / 2; F32 h = INITIAL_WIDTH * gridSize / 2; setVert(Point(-w, -h), 0); setVert(Point(-w, h), 1); setVert(Point( w, h), 2); setVert(Point( w, -h), 3); Parent::newObjectFromDock(gridSize); #endif }
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); }
// 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); } }
void polygon :: listMess(int argc, t_atom*argv) { if(0==m_numInputs) { if(argc%3) { error("list must contain 3 elements for each vertex!"); return; } createVertices(argc/3); } if(m_numVertices*3==argc) { int i=0; for(i=0; i<m_numVertices; i++) { setVert(i, atom_getfloat(argv+0), atom_getfloat(argv+1), atom_getfloat(argv+2) ); argv+=3; } } else { error("vertex-list must have exactly %d numbers", m_numVertices*3); } }