Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Find center of composition in layer coordinates

  • Find center of composition in layer coordinates

    Posted by Juan Irache on May 14, 2017 at 4:34 pm

    Hello,

    I’ve got a video layer that uses the effect “Optics Compensation”. I want the “View Center” property of the effect to be always in he center of the composition, regardless of any translations or rotations the layer has experienced. I think toWorld() or toComp() should help with this, but I must be doing something wrong. By default, the effect sets its “View Center” in the center of the Layer. Here’s where I got so far:

    Thanks a lot!

    L = thisLayer;
    C = L.toComp(L.position); //find where the center of the layer is, in composition coordinates
    D = [thisComp.width/2,thisComp.height/2] - C; //find the distance to the actual composition center
    //if the layer has been rotated we have to de-rotate the vector C to compensate for that
    A = L.transform.rotation; //rotation of the layer
    while (L.hasParent){ //add rotation of parents
    A += L.parent.rotation;
    L = L.parent;
    }
    while (A>360) A -= 360; //simplify to +360 (for some reason otherwise I get different results on each rotation, which should not happen¿?)
    while (A<0) A += 360;
    newX = D[0]*Math.cos(-A) - D[1]*Math.sin(-A);//substract the rotation by derotating the vector
    newY = D[0]*Math.sin(-A) + D[1]*Math.cos(-A);
    effect("Optics Compensation")("View Center")+[newX,newY] //this should be the position of the composition center in layer coordinates¿?

    Juan Irache replied 8 years, 11 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    May 14, 2017 at 10:02 pm

    Try this:

    fromComp([thisComp.width,thisComp.height]/2)

    Dan

  • Juan Irache

    May 15, 2017 at 3:40 am

    Awesome, much appreciated, Dan!

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy