POV-Ray : Newsgroups : povray.animations : How to align objects to camera. : Re: How to align objects to camera. Server Time
4 May 2024 10:40:06 EDT (-0400)
  Re: How to align objects to camera.  
From: John VanSickle
Date: 26 Jan 2009 07:38:44
Message: <497daed4$1@news.povray.org>
Allen wrote:
> I have an animation which the camera is moving through the scene.  However,
> certain objects are to remain aligned to the camera as if the camera was at <0,
> 0, 0> with right in the +x direction and up in the +y direction and looking
> along +z.  How can I take an object(s) and transform them based on the camera's
> current position, angle, etc to achieve this?

That depends on how you place the camera.

In my animations, I make heavy use of titling and objects placed in 
front of the camera to produce fade effects.  For this I use the 
following variables:

pCamL= the location of the camera
pCamE = the look_at position of the camera
vCamS = the up direction for the scene (y for lefty worlds, z for righty 
worlds)
sCamZ = the zoom value

My main .POV file assigns default values to these, and then calls a 
scene file.  The scene file changes the values to whatever fits for the 
camera in the scene.  The main file then does the following:

#declare vCamD=vnormalize(pCamE-pCamL);
#declare vCamR=vnormalize(vcross(vCamS,vCamD));
#declare vCamU=vnormalize(vcross(vCamD,vCamR));

camera {
     right vCamR*image_width/image_height
     up vCamU
     direction vCamD*sCamZ
     locate pCamL
}

Then the main .POV file calls another .INC that builds the titling.  All 
titling is built so that it lies in or just beyond a rectangle that is 
centered at the origin and extends by half of the aspect ratio to the 
left, a similar amount to the right, and by .5 up and .5 down.

I then apply the following transforms to each titling object:

   translate z*sCamZ // (or y*sCamZ if you are modeling in a right-hand
                     // world)
   scale .1 // only needed if your titling intersects with the stuff
            // in your scene
   Matrix_Transform(vCamR,vCamU,vCamD,pCamL) // left-hand world
// or
   Matrix_Transform(vCamR,vCamD,vCamU,pCamL) // right-hand world

It is best to have titling that is very thin in the camera's direction, 
because if the zoom value changes, it will be apparent in the rendering 
of the titling objects.  However, don't make it too thin, or POV-Ray 
will not render some things (text, I have found) properly.

Your titling objects should be textured with ambient=1, diffuse=0, and 
do not cast shadows or are visible in reflections (unless you want this 
effect).

If you've understood all of this, your camera can be doing all sorts of 
wild gyrations, but the titling will remain solidly in place.

Hope this helps,
John


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.