As noted by Andrew Devis, “cameras are notoriously difficult to get to grips with in After Effects” (see video at bottom). Once example is trying to fly a camera around a CC Sphere layer, which isn't really 3D.
Here are the expressions for X, Y & Z-rotation use above as explained by Chris Meyer and Andrew Kramer:
Paste this code into the X rotation:
value + lookAt(thisComp.activeCamera.toWorld([0,0,0]),position)[0] Paste this code into the Y rotation:
value + lookAt(thisComp.activeCamera.toWorld([0,0,0]),position)[1] Paste this code into the Z rotation:
value + lookAt(thisComp.activeCamera.toWorld([0,0,0]),position)[2] It's untested here, but Rick Gerard says that the Z value isn't needed: “Draw an equator on your planet and you'll quickly see the problem. You can fix the problem by removing the expression from CCSphere Rotation z.” He also provides an Animation Preset to insert a different set of expressions; see the discussion at the Adobe forums in Interacting 3D elements – CC Sphere and 3D Rotate Around Circle Animation Preset.
A longer expression was posted on motion graphics eXchange by Filip Vandueren in Ultimate CC Sphere/Light/Comp Camera linker. Here are the expressions for X, Y & Z-rotation:
“CC Sphere Rotation X:
// change camera & effect names as needed…
campos=thisComp.activeCamera.toWorld([0,0,0]);
planetpos=thisLayer.toWorld(effect(“CC Sphere”)(“Offset”));
x=length([planetpos[0],planetpos[1]], [campos[0],campos[2]]);
y=campos[1]-planetpos[1];
alpha=Math.atan2(y,x)
value+radiansToDegrees(alpha) ;
CC Sphere Rotation Y:
// change camera & effect names as needed…
campos=thisComp.activeCamera.toWorld([0,0,0]);
planetpos=thisLayer.toWorld(effect(“CC Sphere”)(“Offset”));
x=campos[0]-planetpos[0];
y=planetpos[1]-campos[2];
beta=Math.atan2(y,x)
value+radiansToDegrees(beta) – 90;
CC Sphere Rotation Z:
No expression
And here are the expressions for the light.
Step1: create your lightsource, and make it an adjustment layer, make sure all the planets are above the light-adj., because we want them to be only lit by the CC Sphere plugin, not receive light. If there are other 3d-layers that do need the shading, put them below the adj.-light. You can just pickwhip the light color and light-intensity from the lightsource to the light-settings of CC Sphere.
CC Sphere Light Height
// change camera & light names as needed…
campos=thisComp.activeCamera.toWorld([0,0,0]);
planetpos=thisLayer.toWorld(effect(“CC Sphere”)(“Offset”));
sunpos=thisComp.layer(“Light 1”).toWorld([0,0,0]);
camvector=normalize(campos-planetpos);
sunvector=normalize(sunpos-planetpos);
angle=Math.acos(dot(camvector, sunvector));
100 – (angle/Math.PI)*200
CC Sphere Light Direction
// change light name as needed…
thesun=thisComp.layer(“Light 1”);
xy=thisLayer.fromWorld(thesun.position) – effect(“CC Sphere”)(“Offset”);
angle=Math.atan2(xy[1],xy[0]);
radiansToDegrees(angle) + 90;
// by Filip Vandueren“
Yet another variation was pondered on the Adobe forum, with Rick Gerard providing a solution in Problem CC Sphere in 3D comp with Camera Mouvement.
Power Sphere might make things easier. It's a new 3D sphere plug-in from CROSSPHERE Koizum with power controls for elliptic distortion, unfolding, rich shading, self shadowing, reflections, DOF and comp lights and camera. Another script, Create3DShapes by Charles Bordenave, is another matter but provides interesting options. Here's the demo for Power Sphere:
If you want to start at the beginning for learning AE's 3D camera, there's general guidance from Chris and Trish Meyer, and from Andrew Devis, among many others. For more, see the AE Help page Adjust a 3D view or move a camera, light, or point of interest.
- CMG Hidden Gems: Chapter 13 – 3D Space covers the basics of working with 3D layers in After Effects and includes moving, rotating and animating layers in 3D space, offsetting their anchor point in Z, as well as auto-orientating layers along a 3D path. Also covered is using the Composition’s 3D Views, View Layouts, and Axis Modes, along with the rendering order when mixing 2D and 3D layers.
- CMG Hidden Gems: Chapter 14 – Camera covers creating and animating a camera, including creating camera rigs and taking advantage of auto orientation, as well as showing how to cut between multiple cameras. They conclude by discussing the camera’s parameters in more detail, including how to fake focus and depth of field effects.
- In Animating a Camera 1: Camera Difficulties, Andrew Devis explains some of the behaviors and problems that are common to camera animation and then shows how … to create a simple camera rig, and why it is important to get the order of the layers correct to achieve predictable results”: