# ofPolyline vs ofPath / Scaling, Rotating, Translating

Hey,

I’m playing around with Box2d (more or less unrelated to this post) and creating a custom polygon body for use with the physics engine. I’m loading my shape data from a file that contains all the points, and creating a ofPolyline from those points. I can use this ofPolyline to create the Box2d polygon with polyline.getVertexes(). This is great, but the shape is always created at the same position and size (not surprising, that’s the vertex data I’m using).

I’m looking for a way to scale, rotate and translate the ofPolyline shape before creating the Box2d polygon with it. I noticed the ofPath has some methods for scaling and rotating, but ofPolyline does not. I can do the scaling and rotating with an ofPath version of the same shape data, but I don’t know how to get all the vertexes of the ofPath to create the Box2d body from (I think because ofPath has subPaths and not just one single vector of points like ofPolyline?)

Generally, I’m hoping someone can explain the differences between ofPath and ofPolyline, why you would choose one over the other, and if there is anyway to scale, rotate and translate an ofPolyline shape. Maybe I just need to write the methods to loop through all the ofPolyline points and do those myself? (translate seems easy enough, but i’m not sure about scale or rotate)

M.

Hey,

There’s some good definitions of each in the docs section (eg. http://openframeworks.cc/documentation/graphics/ofPath.html). In general though, I think of ofPolyline as a single vector of points and use this as a replacement for such. ofPath (which can also be used in ofPolyline mode), is usually made up from multiple vectors of points, as well as having some convenient drawing functions (eg. draw with fill and outline), and mesh/tessellation helpers.

To get the vertices from an ofPath to pass to Box2D you call myPath.getOutline()[0].getVertices() which would give you the first ofPolyline’s vector of points. Also, the code for scaling, rotating, and translating an ofPolyline’s individual points is actually in the ofPath.cpp methods if your interested.

If you want to scale your Box2D shapes after they have been added to your physics world, it’s quite different as your vertices have already been turned into b2PolygonShape’s and b2Vec2’s. It’s possible though.