POV-Ray : Newsgroups : povray.advanced-users : Camera Navigation and Orientation Server Time
25 Nov 2024 23:25:48 EST (-0500)
  Camera Navigation and Orientation (Message 1 to 3 of 3)  
From: Christopher Johnson
Subject: Camera Navigation and Orientation
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

From: Daniel Matthews
Subject: Re: Camera Navigation and Orientation
Date: 17 Nov 2001 03:39:52
Message: <1402535.cojqenx9y0@3-e.net>
That looks nifty, I will have a play with it in a couple of days and if my 
NSEW system works with it I will post the resulting code.

:o)
Dan

Christopher Johnson wrote:

> 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

From: Christopher Johnson
Subject: Re: Camera Navigation and Orientation
Date: 17 Nov 2001 15:30:29
Message: <3bf6c8e5@news.povray.org>
"Daniel Matthews" <dan### [at] 3-enet> wrote in message
news:140### [at] 3-enet...
> That looks nifty, I will have a play with it in a couple of days and if my
> NSEW system works with it I will post the resulting code.

How does you NSEW work?  For basic camera and target placement, I was just
using Rotsph to create a point that was X degree's above or below the +z and
Y degree's to the left or right and then Z units along the resulting vector.

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

        result
#end

It works out well for when you have an object at the origin and you just
want to view it from different angles. I'd just define the camera as

Camera
    location Rotsph (Angle1,Angle2,Distance)
    look_at <0,0,0>

It was simple and worked well for placing other objects around the focal
point, such as lights.

I'm going to try to neaten up the Camera include file though.  Mostly to
make it easier to define the order in which the transformations take place.
In the other hand, it works now, and if I mess with it too much I'll end up
screwing something up.  It's been entirely too long since I've had to use
trig.

CJ


Post a reply to this message

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