GL Studio API
glsutil.h
Go to the documentation of this file.
1 /*! \file
2  \brief GL Studio helper functions.
3 
4  \par Copyright Information
5 
6  Copyright (c) 2015 by The DiSTI Corporation.<br>
7  11301 Corporate Blvd; Suite 100<br>
8  Orlando, Florida 32817<br>
9  USA<br>
10  <br>
11  All rights reserved.<br>
12 
13  This Software contains proprietary trade secrets of DiSTI and may not be
14 reproduced, in whole or part, in any form, or by any means of electronic,
15 mechanical, or otherwise, without the written permission of DiSTI. Said
16 permission may be derived through the purchase of applicable DiSTI product
17 licenses which detail the distribution rights of this content and any
18 Derivative Works based on this or other copyrighted DiSTI Software.
19 
20  NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26 
27  LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34 EXCEED FIVE DOLLARS (US$5.00).
35 
36  The aforementioned terms and restrictions are governed by the laws of the
37 State of Florida and the United States of America.
38 
39 */
40 #ifndef __GLSUTIL_H
41 #define __GLSUTIL_H
42 
43 #include "display.h"
44 
45 namespace disti
46 {
47 
48 /** Returns the minimum angular distance
49  * between angle1 and angle2.
50  */
51 GLS_EXPORT float AngularDistance(float angle1, float angle2);
52 
53 /** Returns the absolute value of the minimum angular distance
54  * between angle1 and angle2.
55  */
56 GLS_EXPORT float AngularDistanceAbs(float angle1, float angle2);
57 
58 /** Decomposes an integer into individual digits.
59  * Returns the individual digits making up the supplied integer
60  * \param source The number to break up
61  * \param _1 The pointer to the integer to contain the Least Significant Digit (rightmost digit).
62  * \param _2 (optional) The pointer to the integer to containing the second digit from the right.
63  * \param _3 (optional) The pointer to the integer to containing the third digit from the right.
64  * \param _4 (optional) The pointer to the integer to containing the fourth digit from the right.
65  * \param _5 (optional) The pointer to the integer to containing the fifth digit from the right.
66  * \param _6 (optional) The pointer to the integer to containing the sixth digit from the right.
67  * \param _7 (optional) The pointer to the integer to containing the seventh digit from the right.
68  * \param _8 (optional) The pointer to the integer to containing the eigth digit from the right.
69  */
70 GLS_EXPORT void GetDigits(int source,
71  int *_1, //least significant digit
72  int *_2 = NULL,
73  int *_3 = NULL,
74  int *_4 = NULL,
75  int *_5 = NULL,
76  int *_6 = NULL,
77  int *_7 = NULL,
78  int *_8 = NULL);
79 
80 
81 /** \brief Rotates a needle on a non-linear scale
82  * Rotates a needle object to the degree amount determined by
83  * the given value relative to the minimum and maximum values.
84  * Use multiple segments to map a gauge with a non-linear readout.
85  *
86  * \param obj The display object that will move (usually the needle)
87  * \param value The actual value that the needle should point to.
88  * \param gauge_values A 2 dimensional array that contains the values
89  * and the angles that correspond to the gauge. The
90  * first of the pair is the gauge value. The second
91  * of the pair is the angle the needle should be
92  * rotated in order to point to it.
93  * The first pair should be the minimal angle the
94  * needle will be rotated while the last pair should
95  * be the maximum angle the needle will be rotated.
96  * \param segments The number of pairs in the gauge_values array.
97  * \sa Uses Interpolate() internally.
98  */
99 GLS_EXPORT void ChangeNeedle(DisplayObject *obj, const float value, float gauge_values[][2], const int segments);
100 
101 // Clamp a value to the given range
102 #define CLAMP_VALUE(val,min,max) ((val) < (min) ? (min) : ((val) > (max) ? (max) : (val)))
103 
104 /** The ramp functions can be used to generate
105  * varying data for testing purposes.
106  * \param time The system time (Available from the Calculate method)
107  * \param min The smallest value to return
108  * \param max The largest value to return
109  * \returns A value varying from min to max.
110  */
111 GLS_EXPORT int RampInt(double time,int min,int max);
112 
113 /** RampBool can be used to generate
114  * varying data for testing purposes.
115  * \param time The system time (Available from the Calculate method)
116  * \returns A value varying from false to true
117  */
118 GLS_EXPORT bool RampBool(double time);
119 
120 /** RampFloat is used to generate
121  * varying data for testing purposes.
122  * \param time The system time (Available from the Calculate method)
123  * \param min The smallest value to return
124  * \param max The largest value to return
125  * \returns A value varying from min to max.
126  */
127 GLS_EXPORT float RampFloat(double time,float min,float max);
128 
129 /** RampDouble is used to generate
130  * varying data for testing purposes.
131  * \param time The system time (Available from the Calculate method)
132  * \param min The smallest value to return
133  * \param max The largest value to return
134  * \returns A value varying from min to max.
135  */
136 GLS_EXPORT double RampDouble(double time,double min,double max);
137 
138 /** \brief Interpolates based on the specified array.
139  *
140  * Returns an iterpolated value determined by
141  * the given value relative to the set of specified
142  * values.
143  * Use multiple segments to map a gauge with a non-linear readout.
144  * \param value The value to be converted.
145  * \param gauge_values A 2 dimensional array that contains the values
146  * and the angles that correspond to the gauge. The
147  * first of the pair is the gauge value. The second
148  * of the pair is the angle the needle should be
149  * rotated in order to point to it.
150  * The first pair should be the minimal value while the last pair should
151  * be the maximum value.
152  * \param segments The number of pairs in the gauge_values array.
153  * \return the interpolated value.
154  * \sa Used by ChangeNeedle()
155  */
156 GLS_EXPORT float Interpolate(const float value, float gauge_values[][2], const int segments);
157 
158 /** \brief Moves an object horizontally based on the given values.
159  * Moves a digit strip horizontally to the location determined by
160  * the given value relative to the minimum and maximum values.
161  *
162  * \param obj - The display object to move (usually a horizontal strip of digits.
163  * \param value - The value to be displayed on the digit strip.
164  * \param min - The smallest value that will be displayed
165  * \param max - The largest value that will be displayed.
166  * \param refPt - The location (x) of the object this object is attached to
167  * \param locAtMin - The location (x-coord) of the digit strip when placed so that the min value is displayed.
168  * \param locAtMax - The location (x-coord) of the digit strip when placed so that the max value is displayed.
169  */
170 GLS_EXPORT void ChangeHStrip(DisplayObject *obj, float value, const float min, const float max,
171  float refPt,const float locAtMin, const float locAtMax);
172 
173 /** \brief Moves an object vertically based on the given values.
174  * Moves a digit strip vertically to the location determined by
175  * the given value relative to the minimum and maximum values.
176  *
177  * \param obj - The display object to move (usually a horizontal strip of digits.
178  * \param value - The value to be displayed on the digit strip.
179  * \param min - The smallest value that will be displayed
180  * \param max - The largest value that will be displayed.
181  * \param refPt - The location (y) of the object this object is attached to
182  * \param locAtMin - The location (y-coord) of the digit strip when placed so that the min value is displayed.
183  * \param locAtMax - The location (y-coord) of the digit strip when placed so that the max value is displayed.
184  */
185 GLS_EXPORT void ChangeVStrip(DisplayObject *obj, float value, const float min, const float max,
186  const float refPt,const float locAtMin, const float locAtMax);
187 
188 
189 /** Move a texture within an object to make the object appear to be moving in a Horizontal direction.
190  * Useful for instruments with moving digits.
191  * Assumptions:
192  * The Texture cannot be rotated,
193  * The object cannot be flipped, or reversed
194  * Min value is on the left side of the texture
195  * Max value is on the right side of the texture
196  * The Texture height and width must be powers of 2!
197  *
198  * \param obj - The object with the texture to move.
199  * \param unit_movement - How far to move the texture per unit on the scale, e.g., .007227
200  * This is specific to the texture.
201  * unit_movement = ((pixel count of largest unit) - (pixel count of smallest unit)) divided by
202  * (the pixel width of the image) divided by
203  * (number of units between the smallest and largest, e.g., 100 MPH)
204  * this then yeilds (pixel ratio) per unit
205  * \param min_units - The smallest unit displayed, e.g., 0 MPH
206  * \param max_units - The largest unit displayed, e.g., 100 MPH
207  * \param units - How many units to move the Scale, e.g. 33 MPH
208  * \param starting_x - The starting x position of the texture
209  * The following code can be used to save the starting position:
210  * Vertex *texture = obj->GetTextureCoordinates()[0].x;
211  * starting_x = texture[0].x;
212  */
213 GLS_EXPORT void ChangeHTexture
214 (
215  DisplayObject *obj, // The object with the texture to move
216  const float unit_movement, // How far to move the texture per unit on the scale, e.g., .007227
217  const float min_units, // The smallest unit displayed, e.g., 0 MPH
218  const float max_units, // The largest unit displayed, e.g., 100 MPH
219  float units, // How many units to move the Scale, e.g. 33 MPH
220  const float starting_x // The starting x position of the texture
221 );
222 
223 /** \brief Move a texture within an object to make the object appear to be moving in a Vertical direction.
224  * Useful for instruments with moving digits.
225  * Assumptions:
226  * The Texture cannot be rotated,
227  * The object cannot be flipped, or reversed
228  * Min value is on the bottom side of the texture
229  * Max value is on the top side of the texture
230  * The Texture height and width must be powers of 2!
231  *
232  * \param obj - The object with the texture to move.
233  * \param unit_movement - How far to move the texture per unit on the scale, e.g., .007227
234  * This is specific to the texture.
235  * unit_movement = ((pixel count of largest unit) - (pixel count of smallest unit)) divided by
236  * (the pixel width of the image) divided by
237  * (number of units between the smallest and largest, e.g., 100 MPH)
238  * this then yeilds (pixel ratio) per unit
239  * \param min_units - The smallest unit displayed, e.g., 0 MPH
240  * \param max_units - The largest unit displayed, e.g., 100 MPH
241  * \param units - How many units to move the Scale, e.g. 33 MPH
242  * \param starting_y - The starting x position of the texture
243  * The following code can be used to save the starting position:
244  * Vertex *texture = obj->GetTextureCoordinates()[0].y;
245  * starting_y = texture[0].y;
246  */
247 GLS_EXPORT void ChangeVTexture
248 (
249  DisplayObject *obj, // The object with the texture to move
250  const float unit_movement, // How far to move the texture per unit on the scale, e.g., .007227
251  const float min_units, // The smallest unit displayed, e.g., 0 MPH
252  const float max_units, // The largest unit displayed, e.g., 100 MPH
253  float units, // How many units to move the Scale, e.g. 33 MPH
254  const float starting_y // The starting Y ratio of the texture
255 );
256 
257 GLS_EXPORT void ChangeVTexture
258 (
259  DisplayObject *obj, // The object with the texture to move
260  const float unit_movement, // How far to move the texture per unit on the scale, e.g., .007227
261  const float min_units, // The smallest unit displayed, e.g., 0 MPH
262  const float max_units, // The largest unit displayed, e.g., 100 MPH
263  float units, // How many units to move the Scale, e.g. 33 MPH
264  const float *starting_y // array of starting Ys ratio of the texture (4 elements)
265 );
266 
267 //! Enumeration for Input Operators
268 typedef enum
269 {
270  INPUT_VERTICAL = 1,
271  INPUT_HORIZONTAL = 2
273 
274 //! Enumeration for Input Operators
275 typedef enum
276 {
277  INPUT_FLAG_NORMAL = 0,
278  INPUT_FLAG_SNAPBACK = 1,
279  INPUT_FLAG_WRAPAROUND = 2
281 
282 /** Uses event data to calculate a new switch position based on the DCS of the object.
283  * This is not intended to be called directly.
284  */
285 GLS_EXPORT int CalcSwitchPosDCS(DisplayObject *self, DisplayEvent *ev,
286  InputOrientationEnum inputType, int numPositions,
287  float scale = 1.0f);
288 
289 } // namespace disti
290 
291 #endif
292 
InputPositionEnum
Enumeration for Input Operators.
Definition: glsutil.h:275
void ChangeHTexture(DisplayObject *obj, const float unit_movement, const float min_units, const float max_units, float units, const float starting_x)
double RampDouble(double time, double min, double max)
InputOrientationEnum
Enumeration for Input Operators.
Definition: glsutil.h:268
void ChangeNeedle(DisplayObject *obj, const float value, float gauge_values[][2], const int segments)
Rotates a needle on a non-linear scale Rotates a needle object to the degree amount determined by the...
The disti::DisplayObject class and global enumerations.
float Interpolate(const float value, float gauge_values[][2], const int segments)
Interpolates based on the specified array.
void ChangeVTexture(DisplayObject *obj, const float unit_movement, const float min_units, const float max_units, float units, const float starting_y)
Move a texture within an object to make the object appear to be moving in a Vertical direction...
bool RampBool(double time)
float AngularDistanceAbs(float angle1, float angle2)
int CalcSwitchPosDCS(DisplayObject *self, DisplayEvent *ev, InputOrientationEnum inputType, int numPositions, float scale=1.0f)
void GetDigits(int source, int *_1, int *_2=NULL, int *_3=NULL, int *_4=NULL, int *_5=NULL, int *_6=NULL, int *_7=NULL, int *_8=NULL)
void ChangeHStrip(DisplayObject *obj, float value, const float min, const float max, float refPt, const float locAtMin, const float locAtMax)
Moves an object horizontally based on the given values. Moves a digit strip horizontally to the locat...
float RampFloat(double time, float min, float max)
int RampInt(double time, int min, int max)
void ChangeVStrip(DisplayObject *obj, float value, const float min, const float max, const float refPt, const float locAtMin, const float locAtMax)
Moves an object vertically based on the given values. Moves a digit strip vertically to the location ...
float AngularDistance(float angle1, float angle2)
Definition: bmpimage.h:46