Suggestion for rotateShapeByOrigin()
-
Shapes, especially how those are handled in FUZE4 seem to me an excellent way to get into programming graphics: a few lines with a quick viewable result. I really hope you can add some more advanced functions (like those for sprites) to simplify the coding.
What about adding this function? Its really fun to use it along with joinShape() and create custom shapes and rotate them:
The following code will rotate any shape around the given origin:
function rotateShapeByOrigin(shape, origin, angle) p_rot = {} p = getShapeLocation(shape) - origin p_rot.x = p.x * cos(angle) - p.y * sin(angle) p_rot.y = p.y * cos(angle) + p.x * sin(angle) p_rot += origin rotateShape(shape, angle) setShapeLocation(shape, p_rot) return shape
Example:
box = createBox(800, 500) rotation_center = {400,400} angle_diff = 2 loop clear(lightgrey) drawShape(box) rotateShapeByOrigin(box, rotation_center, angle_diff) update() repeat
(for the implementation in FUZE: maybe modify it to become a setShapeOrigin() function, so it looks like the analog setSpriteOrigin() function, and adapt the rotateShape() afterwards to support it, see our discussion).
-
Shared the code on SW-4464-9632-0709.
-
@spikey Thanks for the suggestion, I've made a note to bring it up for internal discussion. I agree, it would make sense for shapes to have an origin like sprites!
(And sorry it took so long to get back to you!)