Skip to main content
Inspiring
April 24, 2021
Question

Converting layer coordinates to composition coordinates

  • April 24, 2021
  • 1 reply
  • 269 views

Does anyone have effect plugin code for converting a coordinate in a layer to a coordinate in the composition? I'm basically trying to determine the bounds of a layer at a given time, and express that in coordinates of the composition.

 

For example, suppose the user creates an adjustment layer. Then they resize and move the adjustment layer, and apply my effect to it. I'm trying to determine where the 4 corners of the adjustment layer are within the composition.

 

I have a feeling the solution will involve calling AEGP_GetLayerToWorldXform(), figuring out the untransformed bounds of the layer, and then transforming them into composition coordinates. However, I'd rather not reinvent the wheel. Has anyone done this before?

 

Thanks for your help.

This topic has been closed for replies.

1 reply

Community Expert
April 25, 2021

if it's done during a UI event, then there are the layer_to_comp and get_layer2comp_xform (and their opposites).

however, if it's for rendering purposes, then these callback are not available at that time. in which case, you'll indeed need to get the full rendering matrix of the layer, which is a bit tricky.

AEGP_GetLayerToWorldXform() will give you the transofmation matrix of the layer which you need to multiply by the camera matrix wich can be gotten using AEGP_GetEffectCameraMatrix().

alas, that matrix is onlt the transformation matrix of the camera, which you'll need to invert and multiply by the perspective matrix derived from the camera's FOV. you can get the FOV by calling AEGP_GetEffectCamera(), which return the layer handle of the active camera, from which you can get value of the FOV stream.

if there's no active camera, you'll need to create a default matrix with an FOV of a 35mm camera (if i recall correctly).

as i said, it's tricky.