FreeWRL / FreeX3D 4.3.0
Viewer.h
1/*
2
3
4Viewer ???
5
6*/
7
8/****************************************************************************
9 This file is part of the FreeWRL/FreeX3D Distribution.
10
11 Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
12
13 FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
14 it under the terms of the GNU Lesser Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 FreeWRL/FreeX3D is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
25****************************************************************************/
26
27
28#ifndef __FREEWRL_VIEWER_H__
29#define __FREEWRL_VIEWER_H__
30
31#include "quaternion.h"
32void fwl_set_viewer_type(const int type);
33int fwl_setNavMode(char *mode);
34
35#define PRESS "PRESS"
36#define PRESS_LEN 5
37
38#define DRAG "DRAG"
39#define DRAG_LEN 4
40
41#define RELEASE "RELEASE"
42#define RELEASE_LEN 7
43
44#define KEYS_HANDLED 12
45
46
47#define VIEWER_STEREO_OFF 0
48#define VIEWER_STEREO_SHUTTERGLASSES 1
49#define VIEWER_STEREO_SIDEBYSIDE 2
50#define VIEWER_STEREO_ANAGLYPH 3
51#define VIEWER_STEREO_UPDOWN 4
52
53
54#define X_AXIS 0
55#define Y_AXIS 1
56#define Z_AXIS 2
57
58#define STRING_SIZE 256
59
60#ifdef _MSC_VER
61#define IN_FILE "C:/tmp/inpdev.txt"
62#else
63#define IN_FILE "/tmp/inpdev"
64#endif
65#define IN_FILE_BYTES 100
66#define INPUT_LEN 9
67#define INPUT_LEN_Z 8
68#define X_OFFSET 8
69#define Y_OFFSET 17
70#define Z_OFFSET 0
71#define QUAT_W_OFFSET 26
72#define QUAT_X_OFFSET 35
73#define QUAT_Y_OFFSET 44
74#define QUAT_Z_OFFSET 53
75
76
77#define VIEWER_TRANSITION_TELEPORT 0
78#define VIEWER_TRANSITION_LINEAR 1
79#define VIEWER_TRANSITION_ANIMATE 2
80
81
82#define CALCULATE_EXAMINE_DISTANCE \
83 { \
84 float xd, yd,zd; \
85 double test; \
86 /* calculate distance between the node position and defined centerOfRotation */ \
87 xd = (float) viewer->currentPosInModel.x; \
88 yd = (float) viewer->currentPosInModel.y; \
89 zd = (float) viewer->currentPosInModel.z; \
90 test = sqrt (xd*xd+yd*yd+zd*zd); \
91 /* printf ("htw; cur Dist %4.2f, calculated %4.2f at %lf\n", Viewer.Dist, test,TickTime()); */\
92 viewer->Dist = test; \
93 }
94
95
96#define INITIATE_POSITION \
97 xd = vp->position.c[0]-vp->centerOfRotation.c[0]; \
98 yd = vp->position.c[1]-vp->centerOfRotation.c[1]; \
99 zd = vp->position.c[2]-vp->centerOfRotation.c[2]; \
100 viewer->Dist = sqrt (xd*xd+yd*yd+zd*zd);
101
102#define INITIATE_ROTATION_ORIGIN \
103 viewer->examine.Origin.x = vp->centerOfRotation.c[0]; \
104 viewer->examine.Origin.y = vp->centerOfRotation.c[1]; \
105 viewer->examine.Origin.z = vp->centerOfRotation.c[2];
106
107
108typedef struct viewer_walk {
109 double SX;
110 double SY;
111 double XD;
112 double YD;
113 double ZD;
114 double RD;
116
117
118typedef struct viewer_examine {
119 struct point_XYZ Origin;
120 Quaternion OQuat;
121 Quaternion SQuat;
122 double ODist;
123 double SY;
125
126typedef struct viewer_ypz {
127 double ypz0[3];
128 double ypz[3];
129 float x,y;
131
132typedef struct viewer_inplane {
133 double x,y;
134 double xx,yy;
135 int on;
136 int ibut;
138
139typedef struct key {
140 char key;
141 unsigned int hit;
142} Key;
143typedef struct keyHit {
144 int direction;
145 double epoch; //original keydown time
146 double era; //keydown time not yet used by handle_tick
147 int once; //flag for handle_tick to tell if its used this keyHit already
148} KeyHit;
149
150
151/* Modeled after Descent(tm) ;) */
152typedef struct viewer_fly {
153 double Velocity[2][3];
154 KeyHit down[2][3]; //
155 int ndown[2][3]; //number of clicks queued per axis motion
156 KeyHit wasDown[2][3][10]; //up to 10 chars per axis motion are queued for fly_tick
157 double lasttime;
159
160
161
162typedef struct viewer {
163 struct point_XYZ currentPosInModel;
164 struct point_XYZ Pos;
165 Quaternion Quat;
166 struct point_XYZ Pos0;
167 Quaternion Quat0;
168 struct point_XYZ Up; // 0 1 0 except geoVP
169 int headlight;
170 int collision; //added July 7, 2012
171 double speed;
172 double Dist; //examine dist
173 /*stereovision...*/
174 int isStereo; /*=1 stereovision of any type (all types require viewpoint to shift left and right in scene) */
175 int isStereoB;
176 int iside; /* rendering buffer index Left=0 Right=1 */
177 int isideB;
178 int sidebyside; /*=1 if 2 viewport method*/
179 int updown; /*=1 if 2 viewport method*/
180 int updownB; //for contenttype_stereo_updown
181 int shutterGlasses;
182 int haveQuadbuffer;
183 int anaglyph; /* = 1 if analglyph is turned on */
184 int anaglyphB; //for contenttype_stereo_anaglyph
185 int dominantEye; /* 2D screen cursor picks in which viewport? 0=Left 1=Right */
186 int eitherDominantEye; //1 = switch based on which viewport mouse is over (sidebyside and updown) 0= always use dominantEye;
187 double stereoParameter;
188 double eyehalf;
189 double eyehalfangle;
190 double screendist;
191 double eyedist;
192
193 int iprog[2]; /*anaglyph R=0,GBACM per side */
194 unsigned int buffer;
195 int oktypes[18]; /* boolean for types being acceptable. */
196 X3D_Viewer_Walk walk;
197 X3D_Viewer_Examine examine;
198 X3D_Viewer_Fly fly;
200 X3D_Viewer_InPlane inplane;
201
202 struct point_XYZ VPvelocity;
203
204 int SLERPing2;
205 int SLERPing2justStarted;
206
207 int SLERPing;
208 double startSLERPtime;
209
210 int SLERPing3;
211
212 int type; /* eg, VIEWER_EXAMINE, etc */
213 int lastType; /* LOOKAT saves previous type, and recovers it when done */
214 int LookatMode; //0 = not, 1= mainloop should do a node pick operation then set this back to 0 */
215 int transitionType; /* going from one viewpoint to another */
216 double transitionTime;
217 double lasttime;
218
219 struct point_XYZ startSLERPPos;
220 Quaternion startSLERPQuat;
221
222 double startSLERPDist, endSLERPDist;
223 struct point_XYZ endSLERPPos;
224 Quaternion endSLERPQuat;
225
226 double slerp_viewmatrix[16];
227 double slerp_posorimatrix[16];
228 int vp2rnSaved;
229
230 int doExamineModeDistanceCalculations;
231
232 /* are we perspective or ortho? */
233 int ortho;
234 double orthoField[4];
235
236 /* are we normal, or rotated? (makes sense only for mobile devices) */
237 int screenOrientation;
238
239 double nearPlane;
240 double farPlane;
241 double xcenter;
242 double backgroundPlane ;
243 GLDOUBLE fieldofview;
244 GLDOUBLE fovZoom ;
245 int wasBound; /* 0 for default viewpoint, 1 thereafter (for no-slerp startup) */
246
247} X3D_Viewer;
248X3D_Viewer *ViewerByLayerId(int layerid);
249//extern X3D_Viewer Viewer; /* in VRMLC.pm */
250X3D_Viewer *Viewer();
251struct X3D_Node *getActiveLayerBoundViewpoint();
252void fwl_set_viewer_type0(X3D_Viewer *viewer, const int type);
253void viewer_default(void);
254void viewer_update_user_offsets0(X3D_Viewer *viewer);
255void viewer_fetch_user_offsets0(X3D_Viewer *viewer);
256void viewer_update_LCS(X3D_Viewer *viewer);
257void viewer_fetch_LCS(X3D_Viewer *viewer);
258
259void Viewer_anaglyph_setSide(int iside);
260void Viewer_anaglyph_clearSides();
261void fwl_init_StereoDefaults(void);
262
263void viewer_postGLinit_init(void);
264
265void viewer_init(X3D_Viewer *viewer, int type);
266
267void print_viewer();
268int fwl_get_headlight();
269void fwl_toggle_headlight();
270//int use_keys(void);
271
272void set_eyehalf( const double eyehalf, const double eyehalfangle);
273void resolve_pos(void);
274void getViewpointExamineDistance(void);
275
276void xy2qua(Quaternion *ret,
277 const double x,
278 const double y);
279
280void viewer_togl( double fieldofview);
281
282void handle(const int mev, const unsigned int button, const float x, const float y);
283void handle_key(const char key, double keytime);
284void handle_keyrelease (const char key, double keytime);
285void handle_tick();
286void set_stereo_offset0(); /*int iside, double eyehalf, double eyehalfangle);*/
287
288void increment_pos( struct point_XYZ *vec);
289
290void bind_Viewpoint(struct X3D_Viewpoint *node);
291void bind_OrthoViewpoint(struct X3D_OrthoViewpoint *node);
292void bind_GeoViewpoint(struct X3D_GeoViewpoint *node);
293void bind_Fog(struct X3D_Fog *node);
294
295extern float eyedist;
296extern float screendist;
297
298void getCurrentSpeed(void);
299void getCurrentPosInModelB ();
300
301void toggle_collision(void);
302void viewer_lastP_clear(void);
303void avatar2BoundViewpointVerticalAvatar(GLDOUBLE *matA2BVVA, GLDOUBLE *matBVVA2A);
304
305void toggleOrSetStereo(int type);
306void setAnaglyphSideColor(char val, int iside);
307void updateEyehalf(void);
308void viewer_level_to_bound(void);
309void viewer_viewall();
310int getAnaglyphPrimarySide(int primary, int iside);
311void setAnaglyphPrimarySide(int primary, int iside);
312int viewer_getKeyChord();
313void viewer_setKeyChord(int chord);
314
315void handle0(const int mev, const unsigned int button, const float x, const float yup);
316
317#endif /* __FREEWRL_VIEWER_H__ */
Definition Viewer.h:139