-
Notifications
You must be signed in to change notification settings - Fork 9
/
util.h
175 lines (157 loc) · 5.79 KB
/
util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#pragma once
#include <eq/eq.h>
#include <osg/Matrix>
#include <vmmlib/matrix.hpp>
#if EQ_VERSION_GE( 1, 8, 0 )
#include <eq/fabric/eventEnums.h>
#elif EQ_VERSION_GT( 1, 1, 0 )
#include <eq/client/event.h>
#else
#include <eq/event.h>
#endif
#include <osgGA/GUIEventAdapter>
#include <osgViewer/Viewer>
#include "renderer.h"
// ----------------------------------------------------------------------------
/**
* Converts a matrix from the VMML library to a matrix of the OSG library.
* @param matrix a vmml matrix.
* @return the converted osg matrix.
*/
inline osg::Matrix vmmlToOsg( const eq::Matrix4f& matrix )
{
return osg::Matrix( matrix( 0, 0 ), matrix( 1, 0 ),
matrix( 2, 0 ), matrix( 3, 0 ),
matrix( 0, 1 ), matrix( 1, 1 ),
matrix( 2, 1 ), matrix( 3, 1 ),
matrix( 0, 2 ), matrix( 1, 2 ),
matrix( 2, 2 ), matrix( 3, 2 ),
matrix( 0, 3 ), matrix( 1, 3 ),
matrix( 2, 3 ), matrix( 3, 3 ));
}
inline eq::Matrix4f osgToVmml( const osg::Matrix& matrix )
{
#if 1
eq::Matrix4f M;
M( 0,0 ) = matrix( 0,0 );
M( 0,1 ) = matrix( 1,0 );
M( 0,2 ) = matrix( 2,0 );
M( 0,3 ) = matrix( 3,0 );
M( 1,0 ) = matrix( 0,1 );
M( 1,1 ) = matrix( 1,1 );
M( 1,2 ) = matrix( 2,1 );
M( 1,3 ) = matrix( 3,1 );
M( 2,0 ) = matrix( 0,2 );
M( 2,1 ) = matrix( 1,2 );
M( 2,2 ) = matrix( 2,2 );
M( 2,3 ) = matrix( 3,2 );
M( 3,0 ) = matrix( 0,3 );
M( 3,1 ) = matrix( 1,3 );
M( 3,2 ) = matrix( 2,3 );
M( 3,3 ) = matrix( 3,3 );
return M;
#else
eq::Matrix4f m;
m.set( matrix.ptr( ), matrix.ptr( ) + 4 * 4, false );
return m;
#endif
}
inline osg::Vec3d vmmlToOsg( const eq::Vector3f& vector )
{
return osg::Vec3d( vector.x( ), vector.y( ), vector.z( ));
}
inline eq::Vector3f osgToVmml( const osg::Vec3d& vector )
{
return eq::Vector3f( vector.x( ), vector.y( ), vector.z( ));
}
inline unsigned int eqButtonToOsg( uint32_t button )
{
switch( button )
{
case eq::PTR_BUTTON1: return 1;
case eq::PTR_BUTTON2: return 2;
case eq::PTR_BUTTON3: return 3;
case eq::PTR_BUTTON4: return 4;
case eq::PTR_BUTTON5: return 5;
case eq::PTR_BUTTON6: return 6;
case eq::PTR_BUTTON7: return 7;
}
return 0;
}
// undo <linux/input.h> #defines
#ifdef EV_VERSION
#undef KEY_F1
#undef KEY_F2
#undef KEY_F3
#undef KEY_F4
#undef KEY_F5
#undef KEY_F6
#undef KEY_F7
#undef KEY_F8
#undef KEY_F9
#undef KEY_F10
#undef KEY_F11
#undef KEY_F12
#undef KEY_F13
#undef KEY_F14
#undef KEY_F15
#undef KEY_F16
#undef KEY_F17
#undef KEY_F18
#undef KEY_F19
#undef KEY_F20
#undef KEY_F21
#undef KEY_F22
#undef KEY_F23
#undef KEY_F24
#endif
inline int eqKeyToOsg( uint32_t key )
{
int k;
switch (key) {
case eq::KC_ESCAPE: k = osgGA::GUIEventAdapter::KEY_Escape; break;
case eq::KC_BACKSPACE: k = osgGA::GUIEventAdapter::KEY_BackSpace; break;
case eq::KC_RETURN: k = osgGA::GUIEventAdapter::KEY_Return; break;
case eq::KC_TAB: k = osgGA::GUIEventAdapter::KEY_Tab; break;
case eq::KC_HOME: k = osgGA::GUIEventAdapter::KEY_Home; break;
case eq::KC_LEFT: k = osgGA::GUIEventAdapter::KEY_Left; break;
case eq::KC_UP: k = osgGA::GUIEventAdapter::KEY_Up; break;
case eq::KC_RIGHT: k = osgGA::GUIEventAdapter::KEY_Right; break;
case eq::KC_DOWN: k = osgGA::GUIEventAdapter::KEY_Down; break;
case eq::KC_PAGE_UP: k = osgGA::GUIEventAdapter::KEY_Page_Up; break;
case eq::KC_PAGE_DOWN: k = osgGA::GUIEventAdapter::KEY_Page_Down; break;
case eq::KC_END: k = osgGA::GUIEventAdapter::KEY_End; break;
case eq::KC_F1: k = osgGA::GUIEventAdapter::KEY_F1; break;
case eq::KC_F2: k = osgGA::GUIEventAdapter::KEY_F2; break;
case eq::KC_F3: k = osgGA::GUIEventAdapter::KEY_F3; break;
case eq::KC_F4: k = osgGA::GUIEventAdapter::KEY_F4; break;
case eq::KC_F5: k = osgGA::GUIEventAdapter::KEY_F5; break;
case eq::KC_F6: k = osgGA::GUIEventAdapter::KEY_F6; break;
case eq::KC_F7: k = osgGA::GUIEventAdapter::KEY_F7; break;
case eq::KC_F8: k = osgGA::GUIEventAdapter::KEY_F8; break;
case eq::KC_F9: k = osgGA::GUIEventAdapter::KEY_F9; break;
case eq::KC_F10: k = osgGA::GUIEventAdapter::KEY_F10; break;
case eq::KC_F11: k = osgGA::GUIEventAdapter::KEY_F11; break;
case eq::KC_F12: k = osgGA::GUIEventAdapter::KEY_F12; break;
case eq::KC_F13: k = osgGA::GUIEventAdapter::KEY_F13; break;
case eq::KC_F14: k = osgGA::GUIEventAdapter::KEY_F14; break;
case eq::KC_F15: k = osgGA::GUIEventAdapter::KEY_F15; break;
case eq::KC_F16: k = osgGA::GUIEventAdapter::KEY_F16; break;
case eq::KC_F17: k = osgGA::GUIEventAdapter::KEY_F17; break;
case eq::KC_F18: k = osgGA::GUIEventAdapter::KEY_F18; break;
case eq::KC_F19: k = osgGA::GUIEventAdapter::KEY_F19; break;
case eq::KC_F20: k = osgGA::GUIEventAdapter::KEY_F20; break;
case eq::KC_F21: k = osgGA::GUIEventAdapter::KEY_F21; break;
case eq::KC_F22: k = osgGA::GUIEventAdapter::KEY_F22; break;
case eq::KC_F23: k = osgGA::GUIEventAdapter::KEY_F23; break;
case eq::KC_F24: k = osgGA::GUIEventAdapter::KEY_F24; break;
case eq::KC_SHIFT_L: k = osgGA::GUIEventAdapter::KEY_Shift_L; break;
case eq::KC_SHIFT_R: k = osgGA::GUIEventAdapter::KEY_Shift_R; break;
case eq::KC_CONTROL_L: k = osgGA::GUIEventAdapter::KEY_Control_L; break;
case eq::KC_CONTROL_R: k = osgGA::GUIEventAdapter::KEY_Control_R; break;
case eq::KC_ALT_L: k = osgGA::GUIEventAdapter::KEY_Alt_L; break;
case eq::KC_ALT_R: k = osgGA::GUIEventAdapter::KEY_Alt_R; break;
default: k = key; break;
}
return k;
}