| 1 | // SPDX-FileCopyrightText: 2000 David Megginson |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | |
| 4 | #include <math.h> |
| 5 | #include <simgear/props/props.hxx> |
| 6 | |
| 7 | #include "GL_utils.hxx" |
| 8 | #include "FGInstrumentLayer.hxx" |
| 9 | |
| 10 | FGInstrumentLayer::FGInstrumentLayer (const int w, const int h) : |
| 11 | m_w (w), m_h (h) { |
| 12 | } |
| 13 | |
| 14 | FGInstrumentLayer::~FGInstrumentLayer () { |
| 15 | for (transformation_list::iterator it = m_transformations.begin (); |
| 16 | it != m_transformations.end (); |
| 17 | ++it) { |
| 18 | delete *it; |
| 19 | *it = 0; |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | void |
| 24 | FGInstrumentLayer::transform () const { |
| 25 | for (transformation_list::const_iterator it = m_transformations.begin (); |
| 26 | it != m_transformations.end (); |
| 27 | ++it) { |
| 28 | FGPanelTransformation *t = *it; |
| 29 | if (t->test ()) { |
| 30 | float val (t->node == 0 ? 0.0 : t->node->getFloatValue ()); |
| 31 | if (t->has_mod) { |
| 32 | val = fmod (val, t->mod); |
| 33 | } |
| 34 | if (val < t->min) { |
| 35 | val = t->min; |
| 36 | } else if (val > t->max) { |
| 37 | val = t->max; |
| 38 | } |
| 39 | |
| 40 | if (t->table == 0) { |
| 41 | val = val * t->factor + t->offset; |
| 42 | } else { |
| 43 | val = t->table->interpolate (val) * t->factor + t->offset; |
| 44 | } |
| 45 | |
| 46 | switch (t->type) { |
| 47 | case FGPanelTransformation::XSHIFT: |
| 48 | GL_utils::instance ().glTranslatef (val, 0.0, 0.0); |
| 49 | break; |
| 50 | case FGPanelTransformation::YSHIFT: |
| 51 | GL_utils::instance ().glTranslatef (0.0, val, 0.0); |
| 52 | break; |
| 53 | case FGPanelTransformation::ROTATION: |
| 54 | GL_utils::instance ().glRotatef (-val, 0.0, 0.0, 1.0); |
| 55 | break; |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | int |
| 62 | FGInstrumentLayer::getWidth () const { |
| 63 | return m_w; |
| 64 | } |
| 65 | |
| 66 | int |
| 67 | FGInstrumentLayer::getHeight () const { |
| 68 | return m_h; |
| 69 | } |
| 70 | |
| 71 | void |
| 72 | FGInstrumentLayer::setWidth (const int w) { |
| 73 | m_w = w; |
| 74 | } |
| 75 | |
| 76 | void |
| 77 | FGInstrumentLayer::setHeight (const int h) { |
| 78 | m_h = h; |
| 79 | } |
| 80 | |
| 81 | void |
| 82 | FGInstrumentLayer::addTransformation (FGPanelTransformation * const transformation) { |
| 83 | m_transformations.push_back (transformation); |
| 84 | } |