Skip to content
This repository was archived by the owner on Jul 18, 2020. It is now read-only.

Commit aca2ca4

Browse files
committed
Angular camera: modified to add several types of angular projections and to fix new ortographic calculations
1 parent 69f3d40 commit aca2ca4

3 files changed

Lines changed: 47 additions & 18 deletions

File tree

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ This is an abbreviated list of changes. The full/detailed list of changes can be
66
* YafaRay Core code: https://github.com/YafaRay/Core/commits/master
77

88

9+
YafaRay v3.4.4 (2020-05-09)
10+
---------------------------
11+
* Angular camera: modified to add several types of angular projections and to fix new ortographic calculations.
12+
13+
914
YafaRay v3.4.3 (2020-05-09)
1015
---------------------------
1116
* Angular camera: added "Ortographic" projection.

include/cameras/angularCamera.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,32 @@ __BEGIN_YAFRAY
1111
class paraMap_t;
1212
class renderEnvironment_t;
1313

14+
enum class AngularProjection : int //Fish Eye Projections as defined in https://en.wikipedia.org/wiki/Fisheye_lens
15+
{
16+
Equidistant = 0, //Default and used traditionally in YafaRay
17+
Orthographic = 1, //Orthographic projection where the centre of the image is enlarged/more defined at the cost of much more distorted edges
18+
Stereographic = 2,
19+
EquisolidAngle = 3,
20+
Rectilinear = 4,
21+
};
1422

1523
class angularCam_t: public camera_t
1624
{
1725
public:
1826
angularCam_t(const point3d_t &pos, const point3d_t &look, const point3d_t &up,
19-
int _resx, int _resy, float aspect, float angle, bool circ, bool orthographic,
27+
int _resx, int _resy, float aspect, float angle, float max_angle, bool circ, const AngularProjection &projection,
2028
float const near_clip_distance = 0.0f, float const far_clip_distance = 1e6f);
2129
virtual void setAxis(const vector3d_t &vx, const vector3d_t &vy, const vector3d_t &vz);
2230
virtual ray_t shootRay(float px, float py, float lu, float lv, float &wt) const;
2331
virtual point3d_t screenproject(const point3d_t &p) const;
2432

2533
static camera_t* factory(paraMap_t &params, renderEnvironment_t &render);
2634
protected:
27-
float aspect,hor_phi, max_r;
35+
float aspect;
36+
float focal_length;
37+
float max_radius;
2838
bool circular;
29-
bool orthographic; //Orthographic projection where the centre of the image is enlarged/more defined at the cost of much more distorted edges
39+
AngularProjection projection;
3040
};
3141

3242

src/cameras/angularCamera.cc

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,18 @@
2626
__BEGIN_YAFRAY
2727

2828
angularCam_t::angularCam_t(const point3d_t &pos, const point3d_t &look, const point3d_t &up,
29-
int _resx, int _resy, float asp, float angle, bool circ, bool orthographic,
29+
int _resx, int _resy, float asp, float angle, float max_angle, bool circ, const AngularProjection &projection,
3030
float const near_clip_distance, float const far_clip_distance) :
31-
camera_t(pos, look, up, _resx, _resy, asp, near_clip_distance, far_clip_distance), hor_phi(angle*M_PI/180.f), circular(circ), orthographic(orthographic)
31+
camera_t(pos, look, up, _resx, _resy, asp, near_clip_distance, far_clip_distance), max_radius(max_angle / angle), circular(circ), projection(projection)
3232
{
3333
// Initialize camera specific plane coordinates
3434
setAxis(camX,camY,camZ);
3535

36-
max_r = 1;
36+
if(projection == AngularProjection::Orthographic) focal_length = 1.f / fSin(angle);
37+
else if(projection == AngularProjection::Stereographic) focal_length = 1.f / 2.f / tan(angle / 2.f);
38+
else if(projection == AngularProjection::EquisolidAngle) focal_length = 1.f / 2.f / fSin(angle / 2.f);
39+
else if(projection == AngularProjection::Rectilinear) focal_length = 1.f / tan(angle);
40+
else focal_length = 1.f / angle; //By default, AngularProjection::Equidistant
3741
}
3842

3943
void angularCam_t::setAxis(const vector3d_t &vx, const vector3d_t &vy, const vector3d_t &vz)
@@ -56,12 +60,15 @@ ray_t angularCam_t::shootRay(float px, float py, float lu, float lv, float &wt)
5660
float v = 2.f * (py/(float)resy) - 1.f;
5761
v *= aspect_ratio;
5862
float radius = fSqrt(u*u + v*v);
59-
if (circular && radius>max_r) { wt=0; return ray; }
63+
if (circular && radius>max_radius) { wt=0; return ray; }
6064
float theta=0;
6165
if (!((u==0) && (v==0))) theta = atan2(v,u);
6266
float phi = 0.f;
63-
if(orthographic) phi = asin(radius) * hor_phi / M_PI_2;
64-
else phi = radius * hor_phi;
67+
if(projection == AngularProjection::Orthographic) phi = asin(radius/focal_length);
68+
else if(projection == AngularProjection::Stereographic) phi = 2.f * atan(radius/(2.f*focal_length));
69+
else if(projection == AngularProjection::EquisolidAngle) phi = 2.f * asin(radius/(2.f*focal_length));
70+
else if(projection == AngularProjection::Rectilinear) phi = atan(radius/focal_length);
71+
else phi = radius/focal_length; //By default, AngularProjection::Equidistant
6572
//float sp = sin(phi);
6673
ray.dir = fSin(phi)*(fCos(theta)*vright + fSin(theta)*vup ) + fCos(phi)*vto;
6774

@@ -75,8 +82,10 @@ camera_t* angularCam_t::factory(paraMap_t &params, renderEnvironment_t &render)
7582
{
7683
point3d_t from(0,1,0), to(0,0,0), up(0,1,1);
7784
int resx=320, resy=200;
78-
double aspect=1.0, angle=90, max_angle=90;
79-
bool circular = true, mirrored = false, orthographic = false;
85+
double aspect=1.0, angle_degrees=90, max_angle_degrees=90;
86+
AngularProjection projection = AngularProjection::Equidistant;
87+
std::string projectionString;
88+
bool circular = true, mirrored = false;
8089
float nearClip = 0.0f, farClip = -1.0e38f;
8190
std::string viewName = "";
8291

@@ -86,19 +95,24 @@ camera_t* angularCam_t::factory(paraMap_t &params, renderEnvironment_t &render)
8695
params.getParam("resx", resx);
8796
params.getParam("resy", resy);
8897
params.getParam("aspect_ratio", aspect);
89-
params.getParam("angle", angle);
90-
max_angle = angle;
91-
params.getParam("max_angle", max_angle);
98+
params.getParam("angle", angle_degrees);
99+
max_angle_degrees = angle_degrees;
100+
params.getParam("max_angle", max_angle_degrees);
92101
params.getParam("circular", circular);
93102
params.getParam("mirrored", mirrored);
94-
params.getParam("orthographic", orthographic);
103+
params.getParam("projection", projectionString);
95104
params.getParam("nearClip", nearClip);
96105
params.getParam("farClip", farClip);
97106
params.getParam("view_name", viewName);
98-
99-
angularCam_t *cam = new angularCam_t(from, to, up, resx, resy, aspect, angle, circular, orthographic, nearClip, farClip);
107+
108+
if(projectionString == "orthographic") projection = AngularProjection::Orthographic;
109+
else if(projectionString == "stereographic") projection = AngularProjection::Stereographic;
110+
else if(projectionString == "equisolid_angle") projection = AngularProjection::EquisolidAngle;
111+
else if(projectionString == "rectilinear") projection = AngularProjection::Rectilinear;
112+
else projection = AngularProjection::Equidistant;
113+
114+
angularCam_t *cam = new angularCam_t(from, to, up, resx, resy, aspect, angle_degrees*M_PI/180.f, max_angle_degrees*M_PI/180.f, circular, projection, nearClip, farClip);
100115
if(mirrored) cam->vright *= -1.0;
101-
cam->max_r = max_angle/angle;
102116

103117
cam->view_name = viewName;
104118

0 commit comments

Comments
 (0)