FORUMS: list search recent posts

Scaling the position travelled

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
ole sturm
Scaling the position travelled
on Apr 23, 2014 at 4:09:16 am

Hi. I've been noodling around with this for some time and sort of have a solution... but not quite. Here's the scenario - I often track filmed footage in order to obtain a realistic camera wobble - I then apply these keyframes to a parent null. However, sometimes the wobble is simply too much and I want to scale it down (or up when the wobble is not enough). I've tried to come up with an expression which is applied to the target layer's position, which references the layer with the tracking keyframes. The expression also references an expression control called "scale", which controls the amount by which the distances are scaled. This expression works fine as long as the tracked item is moving around the centre of the frame - if it's off to one side it falls over.

I'd hugely appreciate it if someone on this forum were able to point me in the right direction.

Many thanks.

x = thisComp.layer("tracked item").transform.position[0]; // the value of the tracked layer
y = thisComp.layer("tracked item").transform.position[1];
cntrX=thisComp.width/2; // calculates the centres of the comp
cntrY=thisComp.height/2;
diffX=x-cntrX; // calculates the distance of the tracked layer moved from the centre
diffY=y-cntrY;
if (effect("scale")("Slider")>1) { // checks whether the scaler is negative or positive
[x+(diffX*effect("scale")("Slider")), y+(diffY*effect("scale")("Slider"))]
} else {
[x-(diffX*effect("scale")("Slider")), y-(diffY*effect("scale")("Slider"))]
}


Return to posts index

Dan Ebberts
Re: Scaling the position travelled
on Apr 23, 2014 at 5:06:28 am

Just thinking off the top of my head here, it seems like you need a center reference. I guess you could eyeball an average and hard code it, or calculate it based on where the track points at time zero. (Or you could even create an expression to calculate the average over all frames and then convert that to keyframes). In any case, your expression would do its calculation based on the current distance of the center from the reference center.

Dan



Return to posts index

ole sturm
Re: Scaling the position travelled
on Apr 23, 2014 at 10:34:23 am

Ahhh Dan, ever the wanna-be expressioneers knight in shining armour. When you put it the way you've put it, it seems so much clearer. The "average" approach is tempting but I have no idea where I would need to start with that. Are you able to point me in the right direction?

As ever, thanks so much for your help over the years.


Return to posts index


Dan Ebberts
Re: Scaling the position travelled
on Apr 23, 2014 at 4:27:23 pm

The details would depend on how you have things set up, but in general, getting the average of a point over the duration of the comp would go something like this:


point = thisComp.layer("Null 1").transform.position;

accum = [0,0];
fTotal = timeToFrames(thisComp.duration);
for (f = 0; f < fTotal; f++){
accum += point.valueAtTime(framesToTime(f));
}
accum/fTotal


You could extend the idea to include multiple points if what you have to work with are the corners of a rectangle (just add all fours points to the accumulator in the loop, then divide by (fTotal*4) at the end). Then you'd probably want to convert the expression to keyframes so you don't have to do that calculation on every frame. Something like that.


Dan



Return to posts index

ole sturm
Re: Scaling the position travelled
on Apr 23, 2014 at 9:41:18 pm

Fantastic Dan, thanks very much - that'll keep me going.

Best regards.

p.s. loving your Motion Monkey plugin.


Return to posts index

Dan Ebberts
Re: Scaling the position travelled
on Apr 23, 2014 at 9:49:40 pm

>p.s. loving your Motion Monkey plugin

Thanks--that was a fun project.


Dan



Return to posts index


ole sturm
Re: Scaling the position travelled
on Apr 23, 2014 at 11:19:21 pm

Hi Dan,

Ok. just having a play around with that but am not having any joy (I'm probably misunderstanding your approach). To test the expression I added keyframes to "Null 1" and then applied the expression to a layer's position. If you understand it correctly skewing Null 1's keyframes off centre should affect the position of the layer, is that right?

As for the plugin, keep them coming - I for one am certainly up for them.


Return to posts index

Dan Ebberts
Re: Scaling the position travelled
on Apr 23, 2014 at 11:38:29 pm

The expression should average the position of the null over the duration of the comp. So if you move all the keyframes towards one corner of the comp, the layer should move in that direction. Note that the layer's position won't animate, it just sits at the average of all past, present, and future frames.

Dan



Return to posts index

ole sturm
Re: Scaling the position travelled
on Apr 29, 2014 at 12:47:39 am

Hi Dan,

Sorry for the delay in getting back to you. Got it working - thanks a stack... much appreciated.

cheerio

Ole


Return to posts index


ole sturm
Re: Scaling the position travelled
on Apr 29, 2014 at 1:18:20 am

FYI, here's what I've ended up with:

point = thisComp.layer("tracked").transform.position; //"tracked" is the layer which contains the tracking data
accum = [0,0];
fTotal = timeToFrames(thisComp.duration);
for (f = 0; f &lt; fTotal; f++){
accum += point.valueAtTime(framesToTime(f));
}
centre=accum/fTotal;
distance=thisComp.layer("tracked").transform.position;
difference=distance-centre;
if (effect("scale")("Slider")>1) { //the "scale" effects is a slider expression control which scales the tracked data up or down
distance+(difference*effect("scale")("Slider"));
} else {
distance-(difference*effect("scale")("Slider"));
}


Return to posts index

ole sturm
Re: Scaling the position travelled
on Apr 29, 2014 at 1:45:32 am

Next question now is how to apply your expression to averaging the rotation values of a tracked camera wobble?


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]