// Persistence of Vision Ray Tracer version 3.5 Include File // File: Camera Functions.inc // By: Christopher D. Johnson // Last updated: 2001.11.21 // Description: // These macros are designed to allow camera navigation and // orientation based on film industry camera techniques. I attempted // to make camera placement more intuitive. Please read the // documentation files for usage instructions // // Things to work on : // Crane setups etc., other camera types, "lens + film" pre-sets #ifndef(Camera_Func_Temp) // if include file has already been included, do nothing #declare Camera_Func_Temp = version; #include "math.inc" #ifdef(View_POV_Include_Stack) #debug "including camera_functions\n" #end // 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 (); #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 = ; result #end // Main Camera Function Macros #macro Create_Camera() // Default Camera Parameters #ifndef (Cam_position) #declare Cam_position = <0,0,0>; #end #ifndef (Cam_target) #declare Cam_target = <0,0,0>; #end #ifndef (Cam_right) #declare Cam_right = <4/3,0,0>; #end #ifndef (Cam_up) #declare Cam_up = <0,1,0>; #end #ifndef (Cam_fov) #declare Cam_fov = 67.5; #end #ifndef (Cam_truck) #declare Cam_truck = <0,0>; #end #ifndef (Cam_roll) #declare Cam_roll = 0; #end #ifndef (Cam_tilt) #declare Cam_tilt = 0; #end #ifndef (Cam_pan) #declare Cam_pan = 0; #end #ifndef (Cam_dolly) #declare Cam_dolly = 0; #end #ifndef (Tar_dolly) #declare Tar_dolly = 0; #end #ifndef (All_dolly) #declare All_dolly = 0; #end #ifndef (Cam_perspective) #declare Cam_perspective = 0; #end #ifndef (fov_rate) #declare fov_rate = 1; #end #ifndef (dolly_rate) #declare dolly_rate = 1; #end #if ((abs (All_dolly)) > 0 ) #declare Cam_dolly = All_dolly; #declare Tar_dolly = All_dolly; #end #declare CAMERA_TO_TARGET = Target_ROT((Cam_target - Cam_position)); #declare TARGET_TO_CAMERA = Target_ROT ((Cam_position - Cam_target)); #declare SKY_VECTOR = vrotate (y,<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 * fov_rate)); #if (ANGLE <= 0) #declare ANGLE = (1/pow(10,9)); #end #if (ANGLE >= 180) #declare ANGLE = (180-(1/pow(10,9))); #end #declare DOLLY_UNIT = (Rotsph(TILT,PAN,1) * dolly_rate); #declare CAMERA_DOLLY = (Cam_dolly + (Cam_perspective * dolly_rate)); #declare TARGET_DOLLY = (Tar_dolly + TARGET_TO_CAMERA.z); #declare TRUCK = vrotate (,); #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 } #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 (" Initial Distance to Target = < ",str(CAMERA_TO_TARGET.z,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 (" Final Distance to Target = < ",str((vlength (TARGET_VECTOR - POSITION_VECTOR)),0,2)," >\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") #end #macro Set_Position(Vector) #declare Cam_position = Vector; #end #macro Set_Target(Vector) #declare Cam_target = Vector; #end #macro Set_Right(Vector) #declare Cam_right = Vector; #end #macro Set_Up(Vector) #declare Cam_up = Vector; #end #macro Set_Fov(Angle) #declare Cam_fov = Angle; #end #macro Set_Truck(Vector) #declare Cam_truck = Vector; #end #macro Set_Roll(Angle) #declare Cam_roll = Angle; #end #macro Set_Tilt(Angle) #declare Cam_tilt = Angle; #end #macro Set_Pan(Value) #declare Cam_pan = Value; #end #macro Set_Cam_Dolly(Value) #declare Cam_dolly = Value; #end #macro Set_Tar_Dolly(Value) #declare Tar_dolly = Value; #end #macro Set_All_Dolly(Value) #declare All_dolly = Value; #end #macro Set_Perspective(Value) #declare Cam_perspective = Value; #end #macro Set_Fov_Rate(Value) #declare fov_rate = Value; #end #macro Set_Dolly_Rate(Value) #declare dolly_rate = Value; #end #macro Basic_Camera (Location, LookAt) Set_Position (Location) Set_Target (LookAt) #end #macro Camera_TPR (TL,PN,RL) Set_Tilt (TL) Set_Pan (PN) Set_Roll (RL) #end #version Camera_Func_Temp; #end