• Keep in touch:
  • Linked In
  • Twitter
  • RSS

How do I make something rotate?

Changing the orientation of an object, as with changing size makes use of coordinate transforms.

transform = CoordTransform.translate(x, y);
orientation = CoordTransform.rotate(angle);
transform = new CoordTransform(CoordTransform.product(position
    .getMatrix(), orientation.getMatrix()));

movie.add(new Place(rectangle.getIdentifier(), 2, transform));
movie.add(ShowFrame.getInstance());

Transform allows you to specify the angle in degrees. It then converted to radians before before used to create the transform.

int angle = 0;
int delta = 15;
int steps = 360/delta;
CoordTransform transform = CoordTransform.translate(x, y);

for (int i=0; i<steps; i++) {
    angle += delta;

    orientation = CoordTransform.rotate(angle);
    transform = new CoordTransform(CoordTransform.product(
        position.getMatrix(), orientation.getMatrix()));

    movie.add(new Place2().setType(PlaceType.MODIFY)
        .setLayer(1).setTransform(transform);
    movie.add(ShowFrame.getInstance());
}

Creating an animation to rotate an object uses the same process as changing its size - the angle of rotation is updated and used to generate a coordinate transform which changes the original definition of the object - not the previous transform applied.