|
|
ingo <ing### [at] tagpovrayorg> wrote:
> How do I get the proper functions for defining a perspective camera as a
> user_defined one? There's all kind of stuff I can calculate, but can't
> get it into functions. Been at it for a few days, must say that young
> blokes playing games a meter away doesn't help either.
>
> I'd like to define location look at and angle, possibly roll.
> ...
Hi Ingo
The code below shows how you can transform the direction-functions for a user
defined camera.
--
Tor Olav
http://subcube.com
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
#version 3.8;
global_settings { assumed_gamma 1.0 }
#include "colors.inc"
#include "transforms.inc"
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
#declare pLocation = <0.0, 0.5, -6.0>;
#declare pLookAt = <0.0, 0.0, 1.0>;
#declare vDirection = pLookAt - pLocation;
#declare vRight = image_width/image_height*x;
#declare vUp = y;
#declare Angle = 90;
#declare vNewDirection = vDirection + 2.5*y;
#declare RotationAngle = 60;
#declare DirectionTransform =
transform {
Reorient_Trans(vDirection, vNewDirection)
Axis_Rotate_Trans(vNewDirection, RotationAngle)
}
#declare vT_X = vtransform(x, DirectionTransform);
#declare X_X = vT_X.x;
#declare X_Y = vT_X.y;
#declare X_Z = vT_X.z;
#declare vT_Y = vtransform(y, DirectionTransform);
#declare Y_X = vT_Y.x;
#declare Y_Y = vT_Y.y;
#declare Y_Z = vT_Y.z;
#declare vT_Z = vtransform(z, DirectionTransform);
#declare Z_X = vT_Z.x;
#declare Z_Y = vT_Z.y;
#declare Z_Z = vT_Z.z;
// To show where these components belong in a transformation matrix
//
// #declare vT_O = vtransform(<0, 0, 0>, DirectionTransform);
// #declare O_X = vT_O.x;
// #declare O_Y = vT_O.y;
// #declare O_Z = vT_O.z;
//
// #declare Transform =
// transform {
// matrix <
// X_X, X_Y, X_Z,
// Y_X, Y_Y, Y_Z,
// Z_X, Z_Y, Z_Z,
// O_X, O_Y, O_Z
// >
// }
#declare DX_Fn = function(u, v) { image_width*u };
#declare DY_Fn = function(u, v) { image_height*v };
#declare DZ_Fn = function(u, v) { image_width/2/tan(radians(Angle/2)) };
#declare NewDX_Fn =
function(u, v) {
0
+ X_X*DX_Fn(u, v)
+ Y_X*DY_Fn(u, v)
+ Z_X*DZ_Fn(u, v)
}
#declare NewDY_Fn =
function(u, v) {
0
+ X_Y*DX_Fn(u, v)
+ Y_Y*DY_Fn(u, v)
+ Z_Y*DZ_Fn(u, v)
}
#declare NewDZ_Fn =
function(u, v) {
0
+ X_Z*DX_Fn(u, v)
+ Y_Z*DY_Fn(u, v)
+ Z_Z*DZ_Fn(u, v)
}
#declare LocationX = pLocation.x;
#declare LocationY = pLocation.y;
#declare LocationZ = pLocation.z;
camera {
user_defined
location {
function { LocationX }
function { LocationY }
function { LocationZ }
}
direction {
function { NewDX_Fn(u, v) }
function { NewDY_Fn(u, v) }
function { NewDZ_Fn(u, v) }
}
}
/*
camera {
perspective
location pLocation
direction vtransform(vDirection, DirectionTransform)
right vtransform(vRight, DirectionTransform)
up vtransform(vUp, DirectionTransform)
angle Angle
}
*/
/*
camera {
user_defined
location {
function { LocationX }
function { LocationY }
function { LocationZ }
}
direction {
function { DX_Fn(u, v) }
function { DY_Fn(u, v) }
function { DZ_Fn(u, v) }
}
}
*/
/*
camera {
perspective
location pLocation
direction vDirection
right vRight
up vUp
angle Angle
}
*/
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
#declare Radius = 0.1;
sphere { < 0, 0, 2>, Radius pigment { checker White Black } }
sphere { < 0, 0, -2>, Radius pigment { checker White Red } }
sphere { < 2, 0, 0>, Radius pigment { checker White Green } }
sphere { <-2, 0, 0>, Radius pigment { checker White Blue } }
union {
sphere { < 0, 0, 2>, Radius pigment { White } }
sphere { < 0, 0, -2>, Radius pigment { Red } }
sphere { < 2, 0, 0>, Radius pigment { Green } }
sphere { <-2, 0, 0>, Radius pigment { Blue } }
translate 0.5*y
}
background { color Gray20 }
light_source { <1, 1, -1>*100 White }
light_source { <0, 0, 0> Gray10 }
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
Post a reply to this message
|
|