~ubuntu-branches/debian/jessie/stellarium/jessie

« back to all changes in this revision

Viewing changes to src/cylinder_projector.cpp

Tags: upstream-0.9.0
Import upstream version 0.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Stellarium
3
 
 * Copyright (C) 2003 Fabien Chereau
4
 
 *
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.
9
 
 *
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.
14
 
 *
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.
18
 
 */
19
 
 
20
 
#include "cylinder_projector.h"
21
 
 
22
 
 
23
 
CylinderProjector::CylinderProjector(const Vec4i& viewport,
24
 
                                     double _fov)
25
 
                  :CustomProjector(viewport, _fov) {
26
 
  min_fov = 0.001;
27
 
  max_fov = 500.00001;
28
 
  set_fov(_fov);
29
 
}
30
 
 
31
 
/*
32
 
bool CylinderProjector::project_custom(const Vec3d& v, Vec3d& win, const Mat4d& mat) const
33
 
{
34
 
        double z;
35
 
        double alpha, delta;
36
 
 
37
 
        win = v;
38
 
        win.transfo4d(mat);
39
 
        z = (win.length() - zNear) / (zFar-zNear);
40
 
        win.normalize();
41
 
 
42
 
        alpha = asin(win[1]);
43
 
        delta = atan2(win[2],win[0]);
44
 
 
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]);
47
 
        win[2] = z;
48
 
        return true;//(a<0.9*M_PI) ? true : false;
49
 
}
50
 
*/
51
 
 
52
 
bool CylinderProjector::project_custom(const Vec3d &v,
53
 
                                       Vec3d &win,
54
 
                                       const Mat4d &mat) const {
55
 
  win = v;
56
 
  win.transfo4d(mat);
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);
63
 
  return true;
64
 
}
65
 
 
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);
71
 
  v[1] = sin(a);
72
 
  v[2] = - cos(a) * sin(d); // why minus ?
73
 
  v.transfo4d(m);
74
 
}
75
 
 
76