-
Find center of composition in layer coordinates
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¿?