POV-Ray : Newsgroups : povray.advanced-users : Camera Navigation and Orientation : Camera Navigation and Orientation Server Time
29 Jul 2024 16:29:21 EDT (-0400)
  Camera Navigation and Orientation  
From: Christopher Johnson
Date: 17 Nov 2001 00:58:24
Message: <3bf5fc80@news.povray.org>
I managed to organize all my camera function together into an include file.
It works but I have a feeling that I ended up re-inventing the wheel.  I was
trying to get it so you could define a starting position for the camera and
a starting target (look_at) and use the various ather values to modify the
shot.  Anyone have any suggestions or comments?

I'd like to add a crane setup and some other other camera types and defined
"lens and film" setups but I'd like to try and tidy up and optimize this if
it's possible.

CJ

//    Persistence of Vision Ray Tracer version 3.5 Include File
//    File: Camera Functions.inc
//    By: Christopher D. Johnson <Age### [at] hotmailcom>
//    Last updated: 2001.11.17
//    Description: This file helps to standardize camera declarations
//                 I've only used it for perspective camera's so far

// INCLUDES

#include "math.inc"

// UTILITY MACROS

#macro Rotsph(Tilt, Pan, Distance)
        #local result = vrotate(<0,Distance,0>,<(90-Tilt),Pan,0>);

        result
#end

#macro Target_ROT (tar)
        #local ntar = vnormalize (<tar.x,0,tar.z>);
        #local tpan = VRotationD (z,ntar,y);
        #local itar = vrotate (tar,<0,-tpan,0>);
        #local ttilt = -VRotationD (z,itar,x);
        #local tlen = vlength (tar);
        #local result = <ttilt,tpan,tlen>;
        result
#end

/* Adjustable Variables

    These are the values you set to define the camera
    I've tried to label this as best I can
    It assumes a local camera space looking down +z with up = +y and right =
+x

    Rotations are zero at +z axis and +/- 180 at -z axis
    Rotsph simply takes a TILT,PAN,and Distance and converts it into <x,y,x>
coordinates

    I'm generally satisfied with everything with the exception of Cam_roll
    I haven't decided if that works the way it should as far as rotation
directions.

*/
#declare Cam_position = <0,0,0>; // Defines Where the camera will be
initially
#declare Cam_target = <0,0,0>; // Defines where the camera is supposed to be
looking initially
#declare Cam_right = <4/3,0,0>; // camera right vector
#declare Cam_up = <0,1,0>; // camera up vector
#declare Cam_fov = 67.00; // base camera angle (Field of view) in degrees
#declare Cam_truck = <0,0>;  // moves the camera and target perpendicular to
line of sight (xy plane)
#declare Cam_roll = 0; // Adjusts camera roll local z-axis (+ clockwise, -
counter clockwise)
#declare Cam_tilt = 0; // Adjusts camera tilt away from target (+ up, -
down)
#declare Cam_pan = 0; // Adjusts camera pan away from target (+ right, -
left)
#declare Cam_dolly = 0; // Adjusts along local z-axis (+ forwards, -
backwards)
#declare Tar_dolly = 0; // Dollies target
#declare All_dolly = 0; // Sets both Camera and Target Dolly values
#declare Cam_perspective = 0; // ( - dolly back & FOV dec, + dolly in & FOV
inc)
#declare Cam_p_fov_rate  = 1; // how much fov changes in relation to dolly
in perspective

// Don't Change these .... well, try not to anyway unless you can find more
elegant ways of doing it

#if ((abs (All_dolly)) > 0 )
    #declare Cam_dolly = All_dolly;
    #declare Tar_dolly = All_dolly;
#end

#declare TranslationVectCT  = (Cam_target - Cam_position);
#declare CAMERA_TO_TARGET   = Target_ROT(TranslationVectCT);
#declare TranslationVectTC  = (Cam_position - Cam_target);
#declare TARGET_TO_CAMERA   = Target_ROT (TranslationVectTC);

#declare SKY_VECTOR = vrotate (<0,1,0>,<0,0,(0 - Cam_roll)>);
#declare TILT = CAMERA_TO_TARGET.x + Cam_tilt;
#declare PAN = CAMERA_TO_TARGET.y + Cam_pan;
#declare ANGLE = (Cam_fov + (Cam_perspective * Cam_p_fov_rate));

#declare DOLLY_UNIT  = Rotsph(TILT,PAN,1);
#declare CAMERA_DOLLY = (Cam_dolly + Cam_perspective);
#declare TARGET_DOLLY = (Tar_dolly + TARGET_TO_CAMERA.z);

#declare TRUCK = vrotate (<Cam_truck.x,Cam_truck.y,0>,<TILT,PAN,0>);

#declare POSITION_VECTOR = (Cam_position + (CAMERA_DOLLY * DOLLY_UNIT) +
TRUCK );
#declare TARGET_VECTOR = (Cam_position + (TARGET_DOLLY * DOLLY_UNIT) + TRUCK
 );

// This actually creates the camera
camera {

  perspective
  location  POSITION_VECTOR
  right     Cam_right
  up        Cam_up
  sky       SKY_VECTOR
  angle     ANGLE
  look_at   TARGET_VECTOR
}

// This is just to view the numeric results
#debug concat ("\n      Initial Camera Position = < ",vstr(3, Cam_position,
", ", 0,2)," >\n")
#debug concat ("      Initial Target Position = < ",vstr(3, Cam_target, ",
", 0,2)," >\n")
#debug concat ("        Final Camera Position = < ",vstr(3, POSITION_VECTOR,
", ", 0,2)," >\n")
#debug concat ("        Final Target Position = < ",vstr(3, TARGET_VECTOR,
", ", 0,2)," >\n\n")
#debug concat ("    Position to Target Angles = < ",vstr(3,
CAMERA_TO_TARGET, ", ", 0,2)," >\n")
#debug concat ("    Target to Position Angles = < ",vstr(3,
TARGET_TO_CAMERA, ", ", 0,2)," >\n\n")
#debug concat ("                   Sky Vector = < ",vstr(3, SKY_VECTOR, ",
", 0,2)," >\n")
#debug concat ("      Total X Rotation (tilt) = < ",str(TILT,0,2)," >\n")
#debug concat ("       Total Y Rotation (pan) = < ",str(PAN,0,2)," >\n\n")
#debug concat ("                 Camera Dolly = < ",str(CAMERA_DOLLY,0,2),"
>\n\n")
#debug concat ("                 Target Dolly = < ",str(CAMERA_DOLLY,0,2),"
>\n\n")
#debug concat ("         Initial Camera Angle = < ",str(Cam_fov,0,2)," >\n")
#debug concat ("           Final Camera Angle = < ",str(ANGLE,0,2)," >\n\n")


Post a reply to this message

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