RotateFit node

This macro is a Rotate node with a Viewport node after it to fit the rotated image into the frame. It makes nice use of both conditional statements and some math expressions to determine what quadrant the image has been rotated to (floor(RotImg.angle/90)%2==0), and then uses trigonometry to calculate the new resolution. I didn't include all of the Rotate parameters for the sake of simplicity, but you could of course easily add them on your own if you want to control motion blur parameters.

It also gives an example of defining a value inside of a macro with the line

 curve ImgHyp = sqrt(pow(width,2)+pow(height,2));

By prefacing the line with curve, we tell Shake to evaluate this line during processing. This is because Shake otherwise compiles a script before executing it. Because it hasn't executed it, Shake has no idea what the input resolution is, and therefore cannot evaluate the variables width and height in that line. When we place curve before the line, we, in effect, tell Shake to hold off processing this line until script execution.

 

 

image RotateFit(
  image in,
  float angle
)
{
  RotImg = Rotate(in, angle, 1, 0, 0, 0, 0.5, 0);
  curve ImgHyp = sqrt(pow(width,2)+pow(height,2));
  return Viewport(RotImg, 
   floor(RotImg.angle/90)%2==0?
    cosd(RotImg.angle+90)*height:
    cosd(atan2d(height,width)+RotImg.angle)*ImgHyp, 
   floor(RotImg.angle/90)%2==0?
    0:
    sind(RotImg.angle+90)*height, 
   floor(RotImg.angle/90)%2==0?
    cosd(RotImg.angle)*width:
    0, 
   floor(RotImg.angle/90)%2==0?
    sind(atan2d(height,width)+RotImg.angle)*ImgHyp:
    sind(RotImg.angle)*width);
}