Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions camera to object angle

  • camera to object angle

    Posted by Basilisk on September 25, 2005 at 8:26 am

    I am planning to film a number of elements on a turntable against a green screen. I then wish to place them in an AE 3D enviroment and animate a camera moving round them. What I want to do is calculate the angle between the camera and the layer, and then change the layer’s frame so that it appears that the object is at the correct angle to the camera. I am hoping to do this with an expression but my scripting is still a bit basic. Has anyone done this before, or would they be able to give any pointers?

    many thanks
    James
    basilisk.co.uk

    Basilisk replied 20 years, 7 months ago 4 Members · 11 Replies
  • 11 Replies
  • Mylenium

    September 25, 2005 at 9:15 am

    Unlees I completely misunderstand you, you won’t need any expression at all. Just work with the auto-orient to camera option for your layers.

    Mylenium

    [Pour Myl

  • Basilisk

    September 25, 2005 at 10:46 am

    Thanks Mylenium
    Yes – the layer is auto-oriented towards the camera. The problem is that the layer is a video of an object rotating on a turntable. Let me try and explain more clearly:
    1. I film a complete rotation of the object in 360 frames
    2. the AE camera rotates around my 3d set.
    3. the object layer is auto oriented to the camera.
    4. If the angle between the object layer and the AE camera is 78 degrees I need to go to frame 78 of the object layer movie, which is the frame at which the object is at 78 degrees to the real camera.

    My expression needs to do two things – it needs to measure the angle between the object and camera – and it needs to tell a layer to play a particular frame.

    Thanks
    James

  • Dan Ebberts

    September 25, 2005 at 3:48 pm

    Why not just position the camera and object layer, make the object layer the parent of the camera, then rotate the object layer to match the rotation of the object within the footage? Would that work?

    Dan

  • Basilisk

    September 25, 2005 at 4:16 pm

    Thanks Dan – that would work if I was just rotating the AE camera round the object. What I want to do is some fairly complex camera moves where the angle between the object and camera is detected automatically. I have worked out that I need to put the script in the time remap channel of the rotated object layer. Something like this

    v=(position)-(thisComp.layer(“Camera 1”).position) //gives vector between camera and layer
    a = radiansToDegrees(Math.atan2(v[2], v[0])) // deduces angle between camera and layer in x/z plane
    a // need to do some maths to convert this to the correct value for the time remap amount

    I have a new problem – if I parent the camera to some nulls to help with animating the camera the “.position” value is not the actual position of the camera in 3D space. I have tried to use the “toWorld” expression but it doesn’t seem to give the results I expect. Am I using the correct expression here?

    thanks
    James

  • Dan Ebberts

    September 25, 2005 at 6:00 pm

    OK – I see where you’re going. I think your time remap expression is going to end up looking something like this:

    revTime = 4; //time for 1 revolution of object (seconds)
    v = position – thisComp.layer(“Camera 1”).toWorld([0,0,0]);
    a = radiansToDegrees(Math.atan2(v[2], v[0]));
    linear(a,0,360,0,revTime)

    I haven’t tried it, so it may not be exactly right and you may have to change a sign or add an offset to get it all lined up.

    Dan

  • Basilisk

    September 25, 2005 at 7:09 pm

    Many thanks for this Dan – I think it is looking good – I think I need to get my head round the trigonometry to sort out the bugs, but it is great to have pointers on correct usage on “toWorld” and “linear”. This is my first multiline expression, and although I am familiar with ActionScript in Flash, I am finding the Adobe documentation (by comparison) a bit poor and lacking in examples of usage. Maybe I am looking in the wrong place!
    Is there anyway of tracing variables easily? I can see the final effect of an expression, but if there is something wrong in the middle it is quite difficult to find it.

    thanks
    James

  • Dan Ebberts

    September 25, 2005 at 7:47 pm

    One thing I do is apply the expression to a slider or text layer and comment out everything after the variable I want to track. Not great, but it works.

    Dan

  • Basilisk

    September 25, 2005 at 8:00 pm

    Dan

    I was working my way towards the applying expression to text layer approach… I guess AE 7 will have a full console etc.

    Thanks again for you help – I have got it working now. “atan2” flips to the negative at 180 so it needs a corrector in there – otherwise spot on. Saved me several hours!

    revTime = 7.2; //time for 1 revolution of object (seconds)
    v = position – thisComp.layer(“Camera 1”).toWorld([0,0,0]);
    a = radiansToDegrees(Math.atan2(v[0], v[2]));
    if(a < 0){ a = a+360 } linear(a,0,360,0,revTime) I might post a sample when I have got it working with real footage cheers James

  • Dan Ebberts

    September 25, 2005 at 8:30 pm

    >I might post a sample when I have got it working with real footage

    Please do.

    Glad it worked out for you!

    Dan

  • Isaac

    September 25, 2005 at 11:43 pm

    please post i would like to see outcome

Page 1 of 2

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