Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions need orientation of an object to camera

  • need orientation of an object to camera

    Posted by Mike Gottschalk on July 29, 2009 at 4:58 pm

    I had a solid in After Effects and I was trying to get the values of its orientation relative to the world. These values were displayed as Source Text in a text layer above it through the following expression (based on the expression Mr. Ebberts):

    C = thisComp.layer(“solid”);
    u = C.toWorldVec([1,0,0]);
    v = C.toWorldVec([0,1,0]);
    w = C.toWorldVec([0,0,1]);

    sinb = clamp(w[0],-1,1);
    b = Math.asin(sinb);
    cosb = Math.cos(b);
    if (Math.abs(cosb) > .0005){
    c = -Math.atan2(v[0],u[0]);
    a = -Math.atan2(w[1],w[2]);
    }else{
    a = Math.atan2(u[1],v[1]);
    c = 0;
    }

    xValue=Math.round(radiansToDegrees(a));
    yValue=Math.round(radiansToDegrees(b));
    zValue=Math.round(radiansToDegrees(c));

    [(xValue),(yValue),(zValue)]

    Does anyone know of a way to get the values of that solid’s orientation relative to an animating camera?

    Thanks for any help!

    -Mike

    Mike Gottschalk replied 16 years, 9 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    July 29, 2009 at 7:56 pm

    Try this:

    L = thisComp.layer(“solid”);
    C = thisComp.activeCamera;
    u = C.fromWorldVec(L.toWorldVec([1,0,0]));
    v = C.fromWorldVec(L.toWorldVec([0,1,0]));
    w = C.fromWorldVec(L.toWorldVec([0,0,1]));

    sinb = clamp(w[0],-1,1);
    b = Math.asin(sinb);
    cosb = Math.cos(b);
    if (Math.abs(cosb) > .0005){
    c = -Math.atan2(v[0],u[0]);
    a = -Math.atan2(w[1],w[2]);
    }else{
    a = Math.atan2(u[1],v[1]);
    c = 0;
    }

    xValue=Math.round(radiansToDegrees(a));
    yValue=Math.round(radiansToDegrees(b));
    zValue=Math.round(radiansToDegrees(c));

    [(xValue),(yValue),(zValue)]

    Dan

  • Mike Gottschalk

    July 30, 2009 at 12:48 am

    Dan,

    That’s great! Thanks!

    -Mike

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