Creating complex motion using alternate rotation and translation

edited September 2017 in How To...

I enjoy figuring things out for myself but in this case I don't want spend ages reinventing the wheel only to discover I'm using an inefficient approach...

The effect I'm trying to get is of a shape (e.g. triangle) moving across the screen in potentially very complex or random ways by alternate rotation and then transformation. E.g. rotate so many degrees followed by translating so many pixels in the x and y, then repeat the cycle with different values.

Obviously, each time void draw() restarts, the objects location and rotation from the previous iteration are lost which means you can't just pick up where you left off with the transformations; we need to get the shape back to it's last location and rotation before applying the subsequent transforms.

  • Storing cumulative translation and rotation in 3 separate variables (2 for x,y and 1 for rotation) doesn't work (unless I'm doing something really stupid). My instinct tells me that storing rotations cumulatively in a variable will work but that this won't work for the translations.

  • One could store the entire rotation and translation history in 3 arrays but that would make the program run slower and use more memory with each new frame.

  • I thought of using trig to somehow calculate the last position of the shape relative to coordinate system at the start of void draw() and then storing that position in two variables.

Tagged:

Answers

Sign In or Register to comment.