GL Studio Safety Critical Embedded C++ Runtime Library
gls_display_object.h
Go to the documentation of this file.
1#ifndef _GLS_DISPLAY_OBJECT_H
2#define _GLS_DISPLAY_OBJECT_H
3
4/*! \file gls_display_object.h
5\brief This header defines the base class for all graphical objects in
6 the GL Studio DO-178B Runtime Library.
7
8\par Copyright Information
9Copyright (C) 1999-2012 The DiSTI Corporation<br>
10Orlando, FL USA<br>
11All rights reserved.<br>
12
13 This file is copyrighted software and contains proprietary trade secrets of
14DiSTI, and embodies substantial creative efforts as well as confidential
15information, ideas, and expressions.
16
17 Permission to use, and copy this software and its documentation for any
18purpose is hereby granted per the Distribution Agreement and/or the Licensing
19Agreement signed with DiSTI. This permission is granted provided that:
20 1. The above copyright notice appears in all copies.
21 2. That both the copyright notice and this permission notice appear in
22 the supporting documentation.
23 3. That the names DiSTI and GL Studio not be used in advertising or
24 publicity pertaining to distribution of the software without specific,
25 written prior permission of DiSTI.
26
27 Permission to modify the software is granted, but not the right to
28distribute the source code whether modified, or non-modified. Modifying the
29software might invalidate the DO-178B certification package.
30
31 Permission to distribute binaries produced by compiling source code, or
32modified source code is granted, provided you:
33 1. Provide your name and address as the primary contact for the support
34 of your modified version.
35 2. Retain our contact information in regard to use of the base software.
36
37 DiSTI does not provide warranty for this software or guarantee that it
38satisfies any specification or requirement unless otherwise stated in a
39specific contractual arrangement between the customer and DiSTI.
40
41*/
42
43#include "gls_include.h"
44#include "gls_types.h"
45#include "gls_gl.h"
46#include "gls_assert.h"
47#include "gls_vertex.h"
49#include "gls_event.h"
50
51// forward ref
52class GlsStateManager;
53class GlsInputManager;
54
55/** Base Class for all graphical objects. It is an abstract class.
56 * All drawn objects are derived from this class.
57 * \invariant _dcsMatrix.Invariant(), _location.IsValid(), GlsDisplayObjectTypeIsValid( _objectType ),
58 * GlsDisplayObjectPickModeIsValid( _pickMode ), _pickRegion.IsValid(),
59 * _rotationPoint.IsValid(), _blinkRate > 0.0f, _drawMatrix.Invariant(), _dynamicRotation.IsValid(),
60 * _dynamicScale.IsValid(),
61 * ( _dynamicScale.x >= 0.0f ) && ( _dynamicScale.y >= 0.0f ) && ( _dynamicScale.z >= 0.0f ),
62 * _dynamicTranslation.IsValid()
63 */
65{
66public:
68
69 /** Enumeration for possible base object types */
71 {
72 OBJECT_TYPE_COMPOSITE, /**< Object is derived from GlsCompositeObject */
73 OBJECT_TYPE_RENDERABLE, /**< Object is dervied from GlsRenderObject */
74
75 #if defined( GLS_DEBUG )
76 OBJECT_TYPE_INVALID /**< Invalid object type ( GLS_DEBUG only ) */
77 #endif // GLS_DEBUG
78 };
79
80 /** Enumeration for possible pick modes */
82 {
83 PICK_MODE_NEVER, /**< Picking will be disabled for this object */
84 PICK_MODE_FIRST, /**< Picking is based on draw order only. The first geometry hit wins. */
85 PICK_MODE_ALWAYS, /**< Picking will ignore geometry of this object, and always return a pick as if hit.
86 * This is still only found through normal draw order traversal.*/
87
88 #if defined( GLS_DEBUG )
89 PICK_MODE_INVALID /**< Invalid pick mode ( GLS_DEBUG only ) */
90 #endif // GLS_DEBUG
91 };
92
93 /** describes a 3D rectangular picking region */
95 {
96 GlsVector3D lowerNearLeft; /**< lower left near point of region */
97 GlsVector3D upperFarRight; /**< upper right far point of region */
98
99 #if defined( GLS_DEBUG )
100 /** Determine if region is valid ( GLS_DEBUG only )
101 * \return GLS_TRUE if valid else GLS_FALSE
102 * \pre none
103 * \post none
104 */
105 GlsBool IsValid( void ) const;
106 #endif // GLS_DEBUG
107 };
108
109 /** initialization parameters for a GlsDisplayObject */
111 {
112 const GlsBool blinking; /**< GLS_TRUE if object is initially blinking
113 * else GLS_FALSE */
114 const GlsFloat32 blinkRate; /**< blinking rate (Hz.) (>0.0) */
115 const GlsMatrixAffineD::CStyleMatrix dcsMatrix; /**< dcs matrix of object */
116 const GlsMatrixAffineD::CStyleMatrix dcsMatrixInverse; /**< inverse of dcs matrix */
117 const GlsVector3D location; /**< location of object */
118 const GlsBool needCalculate; /**< GLS_TRUE if object needs Calculate() method called
119 * else GLS_FALSE */
120 const PickMode pickMode; /**< initial pick mode for object */
121 const PickRegion pickRegion; /**< pick region for object */
122 const GlsVector3D rotationPoint; /**< location, in the object coordinate system,
123 * of the rotation point */
124 const GlsBool visible; /**< GLS_TRUE if object is initially visible
125 * else GLS_FALSE */
126
127 #if defined( GLS_DEBUG )
128 /** Validate initialization parameters ( GLS_DEBUG only )
129 * \return GLS_TRUE if valid else GLS_FALSE
130 * \pre none
131 * \post none
132 */
133 GlsBool IsValid( void ) const;
134 #endif
135 };
136
137 /** Draws this object. Pure virtual method
138 * \param gl GL State manager for OpenGL into which object is drawn
139 * \param time the elaspsed time in seconds since program start
140 * \pre time >= 0.0
141 * \post object is drawn to OpenGL if visible and not blinked off
142 */
143 virtual void Draw( GlsStateManager &gl, const GlsFloat64 time ) = 0;
144
145 /** Provides a mechanism for performing regular calculations, separate
146 * from drawing. In a standalone applicaton Calculate is recursively
147 * called by the main loop before the objects are drawn.
148 * \param time The elaspsed time in seconds since program start
149 * \pre time >= 0.0
150 * \post calculations (if any) completed
151 */
152 virtual void Calculate( const GlsFloat64 time );
153
154 /** Perform a pick test of the given point in window coordinates against this object
155 * \param windowCoord point in question
156 * \param inputManager input manager managing input for this object
157 * \param parentDrawMatrix draw matrix used when rendering parent object
158 * \return object that is picked by given window coordinate else GLS_NULL
159 * \pre windowCoord.IsValid(), GLMatrixAffineFIsValid( parentDrawMatrix )
160 * \post none
161 */
162 virtual GlsDisplayObject* PickTest( const GlsVector2D &windowCoord, GlsInputManager &inputManager,
163 const GlsMatrixAffineD::GLMatrixAffineF &parentDrawMatrix );
164
165 /** Handle an event
166 * \param event event in question
167 * \return object that handled event else GLS_NULL
168 * \pre event.IsValid()
169 * \post event is handled if return value is not GLS_NULL
170 */
172
173 /** Get the type of this object
174 * \return type of this object
175 * \pre none
176 * \post none
177 */
179
180 /** Set the blinking state for this object
181 * \param blinking Whether or not to blink this object ( GLS_TRUE, GLS_FALSE )
182 * \pre none
183 * \post object has new blinking state
184 */
185 void SetBlinking( const GlsBool blinking );
186
187 /** Set the blinking rate for this object
188 * \param blinkRate Number of times per second to blink this object
189 * \pre blinkRate > 0.0, GlsFloatIsValid( blinkRate )
190 * \post object has new blink rate
191 */
192 void SetBlinkRate( const GlsFloat32 blinkRate );
193
194 /** Sets the dynamic rotations to the specified value for all axes (in degrees)
195 * \param dynamicRotation Vector containing the new dynamic rotation angles for each axis
196 * \pre dynamicRotation.IsValid()
197 * \post object has new dynamic rotation
198 */
199 void SetDynamicRotation( const GlsVector3D &dynamicRotation );
200
201 /** Sets the dynamic scale values for each axis
202 * \param dynamicScale The new dynamic scale for the object
203 * \pre dynamicScale.IsValid(), dynamicScale.x >= 0.0, dynamicScale.y >= 0.0, dynamicScale.z >= 0.0
204 * \post object has new dynamic scale
205 */
206 void SetDynamicScale( const GlsVector3D &dynamicScale );
207
208 /** Sets the dynamic translation to the specified value for all axes (in logical units)
209 * \param dynamicTranslation The new dynamic translation for the X, Y, and Z axes
210 * \pre dynamicTranslation.IsValid()
211 * \post object has new dynamic translation
212 */
213 void SetDynamicTranslation( const GlsVector3D &dynamicTranslation );
214
215 /** Set the visiblity state for this object
216 * \param visible GLS_TRUE to enable this object for drawing else GLS_FALSE
217 * \pre none
218 * \post object has new visibility state
219 */
220 void SetVisibility( const GlsBool visible );
221
222 /** Set the parent object for this object
223 * \param parent parent object for this object
224 * \pre parent != GLS_NULL
225 * \post object has new parent
226 */
227 void SetParent( GlsDisplayObject* const parent );
228
229 /** Set the pick mode for this object
230 * \param pickMode new pick mode
231 * \pre GlsDisplayObjectPickModeIsValid( pickMode )
232 * \post object has new pick mode
233 */
234 void SetPickMode( const PickMode pickMode );
235
236 /** Determine if Calculate() needs to be called on this object
237 * \return GLS_TRUE if Calculate() needs to be called else GLS_FALSE
238 * \pre none
239 * \post none
240 */
241 GlsBool NeedCalculate( void ) const;
242
243 /** Invalidate cached picking screen coordinates
244 * \pre none
245 * \post cached screen picking coordinates are marked invalid
246 */
248
249 #if defined( GLS_UNIT_TEST )
250 /** Get the memory offset of the _objectType member of GlsDisplayObject ( GLS_UNIT_TEST only )
251 * This static inline method is only used when unit testing and is not present otherwise.
252 * \pre none
253 * \post none
254 * \return the memory offset of the _objectType member of GlsDisplayObject
255 */
256 static const void* OffsetOfObjectType( void );
257 #endif // defined( GLS_UNIT_TEST )
258
259protected:
260 const GlsMatrixAffineD _dcsMatrix; /**< The dynamic coordinate system. The Dynamic changes
261 * to rotation, scale, and translate will
262 * be modified by this and applied to the _drawMatrix. */
263 const GlsMatrixAffineD _dcsMatrixInverse; /**< inverse of _dcsMatrix */
264 const GlsBool _dcsMatrixIsIdentity; /**< GLS_TRUE if _dscMatrix is identity else GLS_FALSE */
265 const GlsVector3D _location; /**< The location of the origin point for this object,
266 * in the world coordinate system. */
267 const GlsBool _needCalculate; /**< GLS_TRUE if Calculate() needs be called on this object
268 * else GLS_FALSE. */
269 const ObjectType _objectType; /**< OBJECT_TYPE_RENDERABLE or OBJECT_TYPE_COMPOSITE */
270 const PickRegion _pickRegion; /**< pick region for object */
271 GlsEventDispatcher* const _eventDispatcher; /**< dispatcher for received events else GLS_NULL */
272 const GlsVector3D _rotationPoint; /**< The location, in the object coordinate system,
273 * of the point to rotate this object around when the object is
274 * dynamically rotated. So when we want to rotate this object
275 * (not just rotate the view), this is the point to rotate about.
276 * This point is relative to the _location,
277 * which makes in in the objects coordinate system. */
278
279 GlsBool _blinking; /**< GLS_TRUE if blinking is turned on else GLS_FALSE ) */
280 GlsFloat32 _blinkRate; /**< Number of times per second the object will blink (>0.0) */
281 GlsMatrixAffineD::GLMatrixAffineF _drawMatrix; /**< The objects contribution to the OpenGL draw matrix.
282 * This will be multiplied by the current matrix at draw time.
283 * If identity, this object has no contribution
284 * (it is not dynamic) */
285 GlsVector3D _dynamicRotation; /**< The current (dynamic) rotation of the object, in degrees and relative to
286 * the object's rotation point. Order of rotation is x, then y, then z */
287 GlsVector3D _dynamicScale; /**< The current (dynamic) scale of the object */
288 GlsBool _dynamicScaleIsUnity; /**< GLS_TRUE if _dynamic scale is unity on all three axes */
289 GlsVector3D _dynamicTranslation; /**< The current (dynamic) translation of the object, in logical units
290 * and relative to the object's DCS. */
291 GlsBool _needCalcDrawMatrix; /**< GLS_TRUE if CalcDrawMatrix() needs to be called on this object
292 * else GLS_FALSE. */
293 GlsBool _visible; /**< GLS_TRUE if object drawing is enabled else GLS_FALSE */
294 PickMode _pickMode; /**< pick mode for object */
295 GlsBool _windowPickRegionValid; /**< GLS_TRUE if cached window pick region values are valid */
296 GlsVector2D _windowPickLowerLeft; /**< lower left coord of pick region in window coords if
297 * _windowPickRegionValid == GLS_TRUE */
298 GlsVector2D _windowPickUpperRight; /**< upper right coord of pick region in window coords if
299 * _windowPickRegionValid == GLS_TRUE */
300 GlsVector2D _windowPickUpperLeft; /**< upper left coord of pick region in window coords if
301 * _windowPickRegionValid == GLS_TRUE */
302 GlsVector2D _windowPickLowerRight; /**< lower right coord of pick region in window coords if
303 * _windowPickRegionValid == GLS_TRUE */
304 GlsMatrixAffineD::GLMatrixAffineF _pickMatrix; /**< matrix used to transform window pick region if
305 * _windowPickRegionValid == GLS_TRUE */
306 GlsDisplayObject *_parent; /**< parent of this object else GLS_NULL */
307
308 /** Constructor for display objects. Invoked by constructors of derived classes.
309 * \param initParameters initialization parameters
310 * \param objectType object type for this object
311 * \param eventDispatcher event dispatcher for this object else GLS_NULL
312 * \pre initParameters.IsValid(), GlsDisplayObjectTypeIsValid( objectType )
313 * \post object is constructed and initialized
314 */
315 GlsDisplayObject( const InitParameters &initParameters, const ObjectType objectType,
316 GlsEventDispatcher* const eventDispatcher );
317
318 /** Destructor - shall never be called
319 * \pre none
320 * \post none
321 */
323
324 /** Recalculates the _drawMatrix if needed
325 * If _dynamicRotation, _dynamicScale, or _dynamicTranslate change you must call CalcDrawMatrix()
326 * \param additionalTransform additional transform to apply to calculated draw matrix else
327 * GLS_NULL for no addition transform
328 * \param includeLocation GLS_TRUE to include contribution from _location else GLS_FALSE
329 * \return GLS_TRUE if draw matrix was recalculated else GLS_FALSE
330 * \pre none
331 * \post _drawMatrix is recalculated if needed
332 */
333 GlsBool CalcDrawMatrix( const GlsMatrixAffineD* const additionalTransform, const GlsBool includeLocation );
334
335 /** Recalculates the window picking region if needed
336 * \param inputManager input manager managing input for this object
337 * \param parentDrawMatrix draw matrix used when rendering parent object
338 * \pre _needCalcDrawMatrix == GLS_FALSE (_drawMatrix is up to date)
339 * \post _windowPickLowerLeft, _windowPickUpperRight, _windowPickUpperLeft,
340 * _windowPickLowerRight and _pickMatrix are recalculated
341 * if _windowPickRegionValid == GLS_FALSE,
342 */
343 virtual void CalcWindowPickRegion( GlsInputManager &inputManager,
344 const GlsMatrixAffineD::GLMatrixAffineF &parentDrawMatrix );
345
346 /** Determine if the object is in an "off" blink cycle (invisible)
347 * \param time elapsed time in seconds since program start
348 * \return GLS_TRUE if blinked off else GLS_FALSE
349 * \pre _blinking == TRUE, _blinkRate > 0.0f, time >= 0.0, _blinkRate > 0.0
350 * \post none
351 */
352 GlsBool IsBlinkedOff( const GlsFloat64 time ) const;
353
354private:
355 // Disable implicit generated Members
356 GlsDisplayObject& operator=( const GlsDisplayObject &rhs );
358};
359
360#if defined( GLS_DEBUG )
361#pragma BullseyeCoverage save off
362/** Determine if the given object type is valid
363 * \param objectType object type in question
364 * \return GLS_TRUE if valid else GLS_FALSE
365 * \pre none
366 * \post none
367 */
368inline GlsBool GlsDisplayObjectTypeIsValid( const GlsDisplayObject::ObjectType objectType )
369{
370 return( ( GlsDisplayObject::OBJECT_TYPE_COMPOSITE == objectType ) ||
372
373}
374#pragma BullseyeCoverage restore
375#endif // GLS_DEBUG
376
377#if defined( GLS_DEBUG )
378#pragma BullseyeCoverage save off
379/** Determine if the given pick mode is valid
380 * \param pickMode pick mode in question
381 * \return GLS_TRUE if valid else GLS_FALSE
382 * \pre none
383 * \post none
384 */
385inline GlsBool GlsDisplayObjectPickModeIsValid( const GlsDisplayObject::PickMode pickMode )
386{
387 return( ( GlsDisplayObject::PICK_MODE_NEVER == pickMode ) ||
388 ( GlsDisplayObject::PICK_MODE_FIRST == pickMode ) ||
389 ( GlsDisplayObject::PICK_MODE_ALWAYS == pickMode ) );
390}
391#pragma BullseyeCoverage restore
392#endif // GLS_DEBUG
393
394#if defined( GLS_UNIT_TEST )
395#pragma BullseyeCoverage save off
396/* Get the memory offset of the _objectType member of GlsDisplayObject ( GLS_UNIT_TEST only )
397 * This static inline method is only used when unit testing and is not present otherwise.
398 * \pre none
399 * \post none
400 * \return the memory offset of the _objectType member of GlsDisplayObject
401 */
402inline const void* GlsDisplayObject::OffsetOfObjectType( void )
403{
404 return( &( ( (GlsDisplayObject*) 0 )->_objectType ) );
405}
406#pragma BullseyeCoverage restore
407#endif // defined( GLS_UNIT_TEST )
408
409#endif // _GLS_DISPLAY_OBJECT_H
Definition: gls_display_object.h:65
GlsBool _dynamicScaleIsUnity
Definition: gls_display_object.h:288
const GlsMatrixAffineD _dcsMatrixInverse
Definition: gls_display_object.h:263
ObjectType
Definition: gls_display_object.h:71
@ OBJECT_TYPE_COMPOSITE
Definition: gls_display_object.h:72
@ OBJECT_TYPE_RENDERABLE
Definition: gls_display_object.h:73
GlsDisplayObject * HandleEvent(GlsEvent &event)
GlsVector3D _dynamicRotation
Definition: gls_display_object.h:285
void SetParent(GlsDisplayObject *const parent)
virtual GlsDisplayObject * PickTest(const GlsVector2D &windowCoord, GlsInputManager &inputManager, const GlsMatrixAffineD::GLMatrixAffineF &parentDrawMatrix)
void InvalidatePickCache(void)
const GlsVector3D _rotationPoint
Definition: gls_display_object.h:272
GlsFloat32 _blinkRate
Definition: gls_display_object.h:280
GlsMatrixAffineD::GLMatrixAffineF _drawMatrix
Definition: gls_display_object.h:281
PickMode _pickMode
Definition: gls_display_object.h:294
void SetDynamicRotation(const GlsVector3D &dynamicRotation)
GlsBool _visible
Definition: gls_display_object.h:293
void SetVisibility(const GlsBool visible)
const GlsMatrixAffineD _dcsMatrix
Definition: gls_display_object.h:260
void SetDynamicTranslation(const GlsVector3D &dynamicTranslation)
void SetDynamicScale(const GlsVector3D &dynamicScale)
void SetBlinking(const GlsBool blinking)
const GlsBool _dcsMatrixIsIdentity
Definition: gls_display_object.h:264
void SetBlinkRate(const GlsFloat32 blinkRate)
PickMode
Definition: gls_display_object.h:82
@ PICK_MODE_NEVER
Definition: gls_display_object.h:83
@ PICK_MODE_ALWAYS
Definition: gls_display_object.h:85
@ PICK_MODE_FIRST
Definition: gls_display_object.h:84
GlsBool NeedCalculate(void) const
const PickRegion _pickRegion
Definition: gls_display_object.h:270
GlsMatrixAffineD::GLMatrixAffineF _pickMatrix
Definition: gls_display_object.h:304
const GlsVector3D _location
Definition: gls_display_object.h:265
void SetPickMode(const PickMode pickMode)
GlsBool CalcDrawMatrix(const GlsMatrixAffineD *const additionalTransform, const GlsBool includeLocation)
virtual void Draw(GlsStateManager &gl, const GlsFloat64 time)=0
GlsVector2D _windowPickLowerLeft
Definition: gls_display_object.h:296
GlsBool IsBlinkedOff(const GlsFloat64 time) const
GlsBool _windowPickRegionValid
Definition: gls_display_object.h:295
GlsBool _needCalcDrawMatrix
Definition: gls_display_object.h:291
GlsDisplayObject * _parent
Definition: gls_display_object.h:306
virtual void Calculate(const GlsFloat64 time)
const ObjectType _objectType
Definition: gls_display_object.h:269
const GlsBool _needCalculate
Definition: gls_display_object.h:267
GlsDisplayObject(const InitParameters &initParameters, const ObjectType objectType, GlsEventDispatcher *const eventDispatcher)
GlsVector3D _dynamicScale
Definition: gls_display_object.h:287
GlsEventDispatcher *const _eventDispatcher
Definition: gls_display_object.h:271
virtual ~GlsDisplayObject()
GlsVector2D _windowPickLowerRight
Definition: gls_display_object.h:302
ObjectType GetObjectType(void) const
GlsBool _blinking
Definition: gls_display_object.h:279
virtual void CalcWindowPickRegion(GlsInputManager &inputManager, const GlsMatrixAffineD::GLMatrixAffineF &parentDrawMatrix)
GlsVector2D _windowPickUpperRight
Definition: gls_display_object.h:298
GlsVector3D _dynamicTranslation
Definition: gls_display_object.h:289
GlsVector2D _windowPickUpperLeft
Definition: gls_display_object.h:300
Definition: gls_event.h:305
Definition: gls_input_manager.h:54
Definition: gls_matrix_affine_double.h:55
GlsFloat64 CStyleMatrix[DIMENSION][DIMENSION]
Definition: gls_matrix_affine_double.h:60
GLfloat GLMatrixAffineF[DIMENSION *DIMENSION]
Definition: gls_matrix_affine_double.h:63
Definition: gls_state_manager.h:64
This header defines the runtime assert checking macros for the GL Studio DO-178B Runtime Library.
#define GLS_CLASS_INVARIANT_DECLARATION(ClassName)
Definition: gls_class_invariant.h:80
This header the GlsEvent structure and related classes in the GL Studio DO-178B Runtime Library.
This header includes the API for the OpenGL provider used in the GL Studio DO-178B Runtime Library.
This header defines any preprocessor defines needed to configure the GL Studio DO-178B Runtime Librar...
This header defines The GlsMatrixAffineD class for use in the GL Studio DO-178B Runtime Library.
This header defines the basic types used by the GL Studio DO-178B Runtime Library.
bool GlsBool
Definition: gls_types.h:96
double GlsFloat64
Definition: gls_types.h:87
float GlsFloat32
Definition: gls_types.h:78
This header defines classes for working with 2D and 3D vectors, vertices and textured vertices in the...
Definition: gls_display_object.h:111
const GlsMatrixAffineD::CStyleMatrix dcsMatrixInverse
Definition: gls_display_object.h:116
const GlsBool needCalculate
Definition: gls_display_object.h:118
const GlsVector3D location
Definition: gls_display_object.h:117
const GlsMatrixAffineD::CStyleMatrix dcsMatrix
Definition: gls_display_object.h:115
const GlsVector3D rotationPoint
Definition: gls_display_object.h:122
const PickMode pickMode
Definition: gls_display_object.h:120
const GlsBool visible
Definition: gls_display_object.h:124
const GlsFloat32 blinkRate
Definition: gls_display_object.h:114
const PickRegion pickRegion
Definition: gls_display_object.h:121
const GlsBool blinking
Definition: gls_display_object.h:112
Definition: gls_display_object.h:95
GlsVector3D lowerNearLeft
Definition: gls_display_object.h:96
GlsVector3D upperFarRight
Definition: gls_display_object.h:97
Definition: gls_event.h:53
Definition: gls_vertex.h:50
Definition: gls_vertex.h:66