2626__BEGIN_YAFRAY
2727
2828angularCam_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
3943void 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 ¶ms, 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 ¶ms, 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