3
* Copyright (C) 2003 Fabien Chereau
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
#include "cylinder_projector.h"
23
CylinderProjector::CylinderProjector(const Vec4i& viewport,
25
:CustomProjector(viewport, _fov) {
32
bool CylinderProjector::project_custom(const Vec3d& v, Vec3d& win, const Mat4d& mat) const
39
z = (win.length() - zNear) / (zFar-zNear);
43
delta = atan2(win[2],win[0]);
45
win[0] = center[0] + delta/fov * 180./M_PI * MY_MIN(vec_viewport[2],vec_viewport[3]);
46
win[1] = center[1] + alpha/fov * 180./M_PI * MY_MIN(vec_viewport[2],vec_viewport[3]);
48
return true;//(a<0.9*M_PI) ? true : false;
52
bool CylinderProjector::project_custom(const Vec3d &v,
54
const Mat4d &mat) const {
57
const double win_length = win.length();
58
const double alpha = asin(win[1]/win_length);
59
const double delta = atan2(win[2],win[0]);
60
win[0] = center[0] + flip_horz * delta*view_scaling_factor;
61
win[1] = center[1] + flip_vert * alpha*view_scaling_factor;
62
win[2] = (win_length - zNear) / (zFar-zNear);
66
void CylinderProjector::unproject(double x, double y,
67
const Mat4d& m, Vec3d& v) const {
68
const double d = flip_horz * (x - center[0]) / view_scaling_factor;
69
const double a = flip_vert * (y - center[1]) / view_scaling_factor;
70
v[0] = cos(a) * cos(d);
72
v[2] = - cos(a) * sin(d); // why minus ?