2 * Copyright (C) 2016 Alexander Schmidt
4 * This file is part of Seamulator.
6 * Seamulator is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Seamulator is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Seamulator. If not, see <http://www.gnu.org/licenses/>.
26 SeaView::SeaView(double distance, double azimuth, double altitude) :
33 void SeaView::onMouseEvent(int button, int state, int x, int y)
35 if (button == 3 && state == 0) {
36 m_distance += m_distance*DISTANCE_MULTIPLIER;
39 else if (button == 4 && state == 0) {
40 m_distance -= m_distance*DISTANCE_MULTIPLIER;
43 else if (button == 0 && state == 0) {
44 m_mouseDownPos[0] = x;
45 m_mouseDownPos[1] = y;
46 m_mouseDownAzimuth = m_azimuth;
47 m_mouseDownAltitude = m_altitude;
51 void SeaView::onMouseMove(int x, int y)
54 fmod(m_mouseDownAltitude +
55 (double)((y - m_mouseDownPos[1]) *
56 2*M_PI / glutGet(GLUT_WINDOW_HEIGHT)),
60 fmod(m_mouseDownAzimuth +
61 (double)((x - m_mouseDownPos[0]) *
62 2*M_PI / glutGet(GLUT_WINDOW_WIDTH)),
68 void SeaView::setupView() const
70 glMatrixMode(GL_MODELVIEW);
73 const double eyePos[3] =
74 {m_distance * cos(m_altitude) * sin(m_azimuth),
75 m_distance * cos(m_altitude) * cos(m_azimuth),
76 m_distance * sin(m_altitude)};
78 gluLookAt(eyePos[0], eyePos[1], eyePos[2],