FreeWRL/FreeX3D  3.0.0
Viewer.h
1 /*
2 
3 
4 Viewer ???
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"
32 void fwl_set_viewer_type(const int type);
33 int 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 #define INITIATE_SLERP \
96  if (viewer->transitionType != VIEWER_TRANSITION_TELEPORT) { \
97  viewer->SLERPing = TRUE; \
98  viewer->startSLERPtime = TickTime(); \
99  memcpy (&viewer->startSLERPPos, &viewer->Pos, sizeof (struct point_XYZ)); \
100  memcpy (&viewer->startSLERPAntiPos, &viewer->AntiPos, sizeof (struct point_XYZ)); \
101  memcpy (&viewer->startSLERPQuat, &viewer->Quat, sizeof (Quaternion)); \
102  memcpy (&viewer->startSLERPAntiQuat, &viewer->AntiQuat, sizeof (Quaternion)); \
103  memcpy (&viewer->startSLERPbindTimeQuat, &viewer->bindTimeQuat, sizeof (Quaternion)); \
104  memcpy (&viewer->startSLERPprepVPQuat, &viewer->prepVPQuat, sizeof (Quaternion)); \
105  } else { viewer->SLERPing = FALSE; }
106 
107 
108 #define INITIATE_POSITION \
109  xd = vp->position.c[0]-vp->centerOfRotation.c[0]; \
110  yd = vp->position.c[1]-vp->centerOfRotation.c[1]; \
111  zd = vp->position.c[2]-vp->centerOfRotation.c[2]; \
112  viewer->Dist = sqrt (xd*xd+yd*yd+zd*zd);
113 
114 #define INITIATE_ROTATION_ORIGIN \
115  viewer->examine.Origin.x = vp->centerOfRotation.c[0]; \
116  viewer->examine.Origin.y = vp->centerOfRotation.c[1]; \
117  viewer->examine.Origin.z = vp->centerOfRotation.c[2];
118 
119 #define INITIATE_POSITION_ANTIPOSITION \
120  viewer->Pos.x = vp->position.c[0]; \
121  viewer->Pos.y = vp->position.c[1]; \
122  viewer->Pos.z = vp->position.c[2]; \
123  viewer->AntiPos.x = vp->position.c[0]; \
124  viewer->AntiPos.y = vp->position.c[1]; \
125  viewer->AntiPos.z = vp->position.c[2]; \
126  viewer->currentPosInModel.x = vp->position.c[0]; \
127  viewer->currentPosInModel.y = vp->position.c[1]; \
128  viewer->currentPosInModel.z = vp->position.c[2]; \
129  vrmlrot_to_quaternion (&viewer->Quat,vp->orientation.c[0], \
130  vp->orientation.c[1],vp->orientation.c[2],-vp->orientation.c[3]); /* dug9 sign change on orientation Jan 18,2010 to accomodate level_to_bound() */ \
131  vrmlrot_to_quaternion (&viewer->bindTimeQuat,vp->orientation.c[0], \
132  vp->orientation.c[1],vp->orientation.c[2],-vp->orientation.c[3]); /* '' */ \
133  vrmlrot_to_quaternion (&q_i,vp->orientation.c[0], \
134  vp->orientation.c[1],vp->orientation.c[2],-vp->orientation.c[3]); /* '' */ \
135  quaternion_inverse(&(viewer->AntiQuat),&q_i); \
136  vrmlrot_to_quaternion(&viewer->prepVPQuat,vp->orientation.c[0],vp->orientation.c[1],vp->orientation.c[2],-vp->orientation.c[3]);
137 
138 
139 /* extern struct point_XYZ ViewerPosition; */
140 /* extern struct orient ViewerOrientation; */
141 
142 
143 typedef struct viewer_walk {
144  double SX;
145  double SY;
146  double XD;
147  double YD;
148  double ZD;
149  double RD;
151 
152 
153 typedef struct viewer_examine {
154  struct point_XYZ Origin;
155  Quaternion OQuat;
156  Quaternion SQuat;
157  double ODist;
158  double SY;
160 
161 typedef struct viewer_ypz {
162  double ypz0[3];
163  double ypz[3];
164  float x,y;
166 
167 typedef struct viewer_inplane {
168  double x,y;
169  double xx,yy;
170  int on;
171  int ibut;
173 
174 typedef struct key {
175  char key;
176  unsigned int hit;
177 } Key;
178 typedef struct keyHit {
179  int direction;
180  double epoch; //original keydown time
181  double era; //keydown time not yet used by handle_tick
182  int once; //flag for handle_tick to tell if its used this keyHit already
183 } KeyHit;
184 
185 
186 /* Modeled after Descent(tm) ;) */
187 typedef struct viewer_fly {
188  double Velocity[2][3];
189  KeyHit down[2][3]; //
190  int ndown[2][3]; //number of clicks queued per axis motion
191  KeyHit wasDown[2][3][10]; //up to 10 chars per axis motion are queued for fly_tick
192  double lasttime;
194 
195 
196 typedef struct viewer {
197  struct point_XYZ Pos;
198  struct point_XYZ AntiPos;
199  struct point_XYZ currentPosInModel;
200  Quaternion Quat;
201  Quaternion AntiQuat;
202  Quaternion bindTimeQuat;
203  int headlight;
204  int collision; //added July 7, 2012
205  double speed;
206  double Dist; //examine dist
207  //double exploreDist; //explore dist
208  /*stereovision...*/
209  int isStereo; /*=1 stereovision of any type (all types require viewpoint to shift left and right in scene) */
210  int isStereoB;
211  int iside; /* rendering buffer index Left=0 Right=1 */
212  int isideB;
213  int sidebyside; /*=1 if 2 viewport method*/
214  int updown; /*=1 if 2 viewport method*/
215  int updownB; //for contenttype_stereo_updown
216  int shutterGlasses;
217  int haveQuadbuffer;
218  int anaglyph; /* = 1 if analglyph is turned on */
219  int anaglyphB; //for contenttype_stereo_anaglyph
220  int dominantEye; /* 2D screen cursor picks in which viewport? 0=Left 1=Right */
221  int eitherDominantEye; //1 = switch based on which viewport mouse is over (sidebyside and updown) 0= always use dominantEye;
222  double stereoParameter;
223  double eyehalf;
224  double eyehalfangle;
225  double screendist;
226  double eyedist;
227 
228  int iprog[2]; /*anaglyph R=0,GBACM per side */
229  unsigned int buffer;
230  int oktypes[18]; /* boolean for types being acceptable. */
231  X3D_Viewer_Walk walk;
232  X3D_Viewer_Examine examine;
233  X3D_Viewer_Fly fly;
235  X3D_Viewer_InPlane inplane;
236 
237  struct point_XYZ VPvelocity;
238 
239  int SLERPing2;
240  int SLERPing2justStarted;
241 
242  int SLERPing;
243  double startSLERPtime;
244 
245  int SLERPing3;
246 
247  int type; /* eg, VIEWER_EXAMINE, etc */
248  int lastType; /* LOOKAT saves previous type, and recovers it when done */
249  int LookatMode; //0 = not, 1= mainloop should do a node pick operation then set this back to 0 */
250  int transitionType; /* going from one viewpoint to another */
251  double transitionTime;
252  double lasttime;
253 
254  struct point_XYZ startSLERPPos;
255  struct point_XYZ startSLERPAntiPos;
256  Quaternion startSLERPQuat;
257  Quaternion startSLERPAntiQuat;
258  Quaternion startSLERPbindTimeQuat;
259  Quaternion prepVPQuat;
260  Quaternion startSLERPprepVPQuat;
261 
262  double startSLERPDist, endSLERPDist;
263  struct point_XYZ endSLERPPos;
264  Quaternion endSLERPQuat;
265 
266 
267  struct X3D_GeoViewpoint *GeoSpatialNode; /* NULL, unless we are a GeoViewpoint */
268 
269  int doExamineModeDistanceCalculations;
270 
271  /* are we perspective or ortho? */
272  int ortho;
273  double orthoField[4];
274 
275  /* are we normal, or rotated? (makes sense only for mobile devices) */
276  int screenOrientation;
277 
278  double nearPlane;
279  double farPlane;
280  double xcenter;
281  double backgroundPlane ;
282  GLDOUBLE fieldofview;
283  GLDOUBLE fovZoom ;
284  int wasBound; /* 0 for default viewpoint, 1 thereafter (for no-slerp startup) */
285 
286 } X3D_Viewer;
287 X3D_Viewer *ViewerByLayerId(int layerid);
288 //extern X3D_Viewer Viewer; /* in VRMLC.pm */
289 X3D_Viewer *Viewer();
290 void fwl_set_viewer_type0(X3D_Viewer *viewer, const int type);
291 void viewer_default(void);
292 
293 void Viewer_anaglyph_setSide(int iside);
294 void Viewer_anaglyph_clearSides();
295 void fwl_init_StereoDefaults(void);
296 
297 void viewer_postGLinit_init(void);
298 
299 void viewer_init(X3D_Viewer *viewer, int type);
300 
301 void print_viewer();
302 int fwl_get_headlight();
303 void fwl_toggle_headlight();
304 //int use_keys(void);
305 
306 void set_eyehalf( const double eyehalf, const double eyehalfangle);
307 void resolve_pos(void);
308 void getViewpointExamineDistance(void);
309 
310 void xy2qua(Quaternion *ret,
311  const double x,
312  const double y);
313 
314 void viewer_togl( double fieldofview);
315 
316 void handle(const int mev, const unsigned int button, const float x, const float y);
317 void handle_key(const char key, double keytime);
318 void handle_keyrelease (const char key, double keytime);
319 void handle_tick();
320 void set_stereo_offset0(); /*int iside, double eyehalf, double eyehalfangle);*/
321 /*
322 void
323 set_stereo_offset(unsigned int buffer,
324  const double eyehalf,
325  const double eyehalfangle,
326  double fieldofview);
327 */
328 void increment_pos( struct point_XYZ *vec);
329 
330 void bind_Viewpoint(struct X3D_Viewpoint *node);
331 void bind_OrthoViewpoint(struct X3D_OrthoViewpoint *node);
332 void bind_GeoViewpoint(struct X3D_GeoViewpoint *node);
333 void bind_Fog(struct X3D_Fog *node);
334 
335 extern float eyedist;
336 extern float screendist;
337 
338 void getCurrentSpeed(void);
339 void getCurrentPosInModel (int addInAntiPos);
340 
341 void toggle_collision(void);
342 void viewer_lastP_clear(void);
343 void avatar2BoundViewpointVerticalAvatar(GLDOUBLE *matA2BVVA, GLDOUBLE *matBVVA2A);
344 
345 void toggleOrSetStereo(int type);
346 void setAnaglyphSideColor(char val, int iside);
347 void updateEyehalf(void);
348 void viewer_level_to_bound(void);
349 
350 int getAnaglyphPrimarySide(int primary, int iside);
351 void setAnaglyphPrimarySide(int primary, int iside);
352 int viewer_getKeyChord();
353 void viewer_setKeyChord(int chord);
354 
355 #endif /* __FREEWRL_VIEWER_H__ */
Definition: Viewer.h:178
Definition: Viewer.h:196
Definition: Viewer.h:174