Skip to content

Commit

Permalink
Fixed a bug with manipulating pen rotation. Supporting tweening of pe…
Browse files Browse the repository at this point in the history
…n length/angle.
  • Loading branch information
jbum committed May 31, 2015
1 parent 8061e7d commit 0e31392
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
18 changes: 16 additions & 2 deletions Animation.pde
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
// ffmpeg2 -r 30 -y -pattern_type glob -i 'frame_*.png' -vcodec libx264 -pix_fmt yuv420p -pass 1 -s 800x800 -threads 0 -f mp4 untitled.mp4
import java.text.DecimalFormat;

float[] tweenDest = {0,0,0,0,0,0,0,0,0,0};
float[] tweenSrce = {0,0,0,0,0,0,0,0,0,0};
float[] tweenDest = {0,0,0,0,0,0,0,0,0,0,0,0};
float[] tweenSrce = {0,0,0,0,0,0,0,0,0,0,0,0};
float tweenSteps;
float tweenIdx;
boolean isTweening = false;
Expand All @@ -19,6 +19,8 @@ DecimalFormat df = new DecimalFormat("#0000");
void saveTweenSnapshot()
{
System.arraycopy( setupMounts[setupMode], 0, tweenDest, 0, setupMounts[setupMode].length );
tweenDest[10] = penRig.len;
tweenDest[11] = penRig.angle;
lastTweenSnapshot = setupMode;
println("\n" + getSetupString());
println("Snapshot saved, now position pen/arms to the starting point and hit S");
Expand All @@ -31,12 +33,16 @@ void beginTweening()
return;
}
System.arraycopy( setupMounts[setupMode], 0, tweenSrce, 0, setupMounts[setupMode].length );
tweenSrce[10] = penRig.len;
tweenSrce[11] = penRig.angle;

float maxTravelLength = 0;
for (MountPoint mp : activeMountPoints) {
if (mp.setupIdx != -1) {
maxTravelLength = max(maxTravelLength, mp.getDistance(tweenDest[mp.setupIdx],tweenSrce[mp.setupIdx]));
}
}
maxTravelLength = max(maxTravelLength, abs(tweenSrce[10]-tweenDest[10]) * abs(kPenLabelIncr));
println("Max travel length: " + maxTravelLength/inchesToPoints);
tweenSteps = int(maxTravelLength); // One frame for each point of travel.
println("Movie will be " + tweenSteps + " frames and will take " + tweenSteps/30.0 + " at 30 fps");
Expand Down Expand Up @@ -71,6 +77,14 @@ void nextTween()
mp.itsMountLength = src + (dst-src)*tweenIdx/(float)tweenSteps;
}
}
float src = tweenSrce[10];
float dst = tweenDest[10];
penRig.len = src + (dst-src)*tweenIdx/(float)tweenSteps;

src = tweenSrce[11];
dst = tweenDest[11];
penRig.angle = src + (dst-src)*tweenIdx/(float)tweenSteps;

clearPaper();
completeDrawing();
}
4 changes: 3 additions & 1 deletion Mechanics.pde
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ class PenRig implements Selectable {
MountPoint itsMP;
int lastDirection = -1; // these are used to avoid rotational wierdness with manipulations
long lastRotation = -1;
int lastKey = -1;


PenRig(float len, float angle, MountPoint itsMP) {
Expand Down Expand Up @@ -362,7 +363,7 @@ class PenRig implements Selectable {
int chooseBestDirection(int direction, int keycode, float lenIncr, float angIncr)
{
if (abs(angIncr) > abs(lenIncr) && lastRotation != -1 && (millis()-lastRotation) < 10000) {
return lastDirection;
return lastDirection * (lastKey == keycode? 1 : -1);
}

PVector pNeg = getPosition(len -lenIncr, angle-angIncr);
Expand Down Expand Up @@ -395,6 +396,7 @@ class PenRig implements Selectable {
lastRotation = millis();
}
lastDirection = direction;
lastKey = kc;

this.angle += angIncr*direction;
if (this.angle > 180) {
Expand Down
3 changes: 2 additions & 1 deletion Utils.pde
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ void completeDrawing()
myFrameCount = 0;
penRaised = true;
int totalRotations = computeCyclicRotations();
println("Total turntable cycles needed = " + totalRotations);
if (!isTweening)
println("Total turntable cycles needed = " + totalRotations);
int framesPerRotation = int(TWO_PI / crankSpeed);
myLastFrame = framesPerRotation * totalRotations + 1;
passesPerFrame = isRecording? 10 : 360*2;
Expand Down

0 comments on commit 0e31392

Please sign in to comment.