1 /***********************************************************************/
2 /* Open Visualization Data Explorer                                    */
3 /* (C) Copyright IBM Corp. 1989,1999                                   */
4 /* ALL RIGHTS RESERVED                                                 */
5 /* This code licensed under the                                        */
6 /*    "IBM PUBLIC LICENSE - Open Visualization Data Explorer"          */
7 /***********************************************************************/
8 
9 #if defined(__cplusplus) || defined(c_plusplus)
10 extern "C" {
11 #endif
12 
13 #ifndef _DXI_USERINTERACTORS_H_
14 #define _DXI_USERINTERACTORS_H_
15 
16 /*
17  *  ROTXY creates a matrix which rotates about a unit vector [x y 0].
18  *  This matrix can be composed from a rotation about Z to align the
19  *  vector with the X axis, followed by a rotation about the X axis, then
20  *  finished with the inverse of the Z rotation:
21  *
22  *  x -y  0  0       1      0       0   0        x  y  0  0
23  *  y  x  0  0   X   0  cos(a)  sin(a)  0   X   -y  x  0  0
24  *  0  0  1  0       0 -sin(a)  cos(a)  0        0  0  1  0
25  *  0  0  0  1       0      0       0   1        0  0  0  1
26  *
27  *  This composes into:
28  *
29  *  x*x + y*y*cos(a)  x*y - x*y*cos(a)  -y*sin(a)  0
30  *  x*y - x*y*cos(a)  y*y + x*x*cos(a)   x*sin(a)  0
31  *          y*sin(a)         -x*sin(a)     cos(a)  0
32  *                0                 0          0   1
33  *
34  *  By using the identity x*x + y*y = 1 and defining t = 1 - cos(a), the
35  *  matrix can be simplified as follows:
36  */
37 
38 #define ROTXY(m, x, y, s, c, t) {\
39 m[0][0]= t*x*x + c;   m[0][1]=  t*x*y;       m[0][2]= -s*y;         m[0][3] =0;\
40 m[1][0]= t*x*y;       m[1][1]=  t*y*y + c;   m[1][2]=  s*x;         m[1][3] =0;\
41 m[2][0]= s*y;         m[2][1]= -s*x;         m[2][2]=  c;           m[2][3] =0;\
42 m[3][0]= 0;           m[3][1]=  0;           m[3][2]=  0;           m[3][3] =1;}
43 
44 /*
45  *  ROTXYZ is derived in a fashion analogous to ROTXY, extended for the Z
46  *  component of a unit rotation axis [x y z].
47  */
48 
49 #define ROTXYZ(m, x, y, z, s, c, t) {\
50 m[0][0]= t*x*x + c;   m[0][1]= t*x*y + s*z; m[0][2]= t*x*z - s*y; m[0][3]= 0;\
51 m[1][0]= t*x*y - s*z; m[1][1]= t*y*y + c;   m[1][2]= t*y*z + s*x; m[1][3]= 0;\
52 m[2][0]= t*x*z + s*y; m[2][1]= t*y*z - s*x; m[2][2]= t*z*z + c;   m[2][3]= 0;\
53 m[3][0]= 0;           m[3][1]= 0;           m[3][2]= 0;           m[3][3]= 1;}
54 
55 
56 typedef struct
57 {
58     int   event;
59     int   pad[7];
60 } DXAnyEvent;
61 
62 typedef struct
63 {
64     int   event;
65     int   x;
66     int   y;
67     int   state;
68     int   kstate;
69 } DXMouseEvent;
70 
71 typedef struct
72 {
73     int   event;
74     int   x;
75     int   y;
76     int   key;
77     int   kstate;
78 } DXKeyPressEvent;
79 
80 typedef union
81 {
82 	DXAnyEvent	any;
83 	DXMouseEvent 	mouse;
84 	DXKeyPressEvent keypress;
85 } DXEvent,  *DXEvents;
86 
87 /*
88  * The following are convenience typedefs that MUST agree with the
89  * subsequent structure definition elements
90  */
91 typedef void *(*InitMode)(Object args, int width, int height, int *mask);
92 typedef void  (*EndMode)(void *handle);
93 typedef void  (*SetCamera)(void *handle, float *to, float *from, float *up,
94                               int projection, float fov, float width);
95 typedef int   (*GetCamera)(void *handle, float *to, float *from, float *up,
96                               int *projection, float *fov, float *width);
97 typedef void  (*SetRenderable)(void *handle, Object obj);
98 typedef int   (*GetRenderable)(void *handle, Object *obj);
99 
100 typedef void  (*EventHandler)(void *handler, DXEvent *event);
101 
102 struct _userInteractor
103 {
104     void *(*InitMode)(Object, int, int, int *);
105     void  (*EndMode)(void *);
106     void  (*SetCamera)(void *, float *, float *, float *,
107 		int, float, float);
108     int   (*GetCamera)(void *, float *, float *, float *,
109 		int *, float *, float *);
110     void  (*SetRenderable)(void *, Object);
111     int   (*GetRenderable)(void *, Object *);
112 
113     void  (*EventHandler)(void *, DXEvent *);
114 };
115 
116 typedef struct _userInteractor UserInteractor;
117 
118 /*
119  * Events
120  */
121 #define DXEVENT_LEFT		0x01
122 #define DXEVENT_MIDDLE		0x02
123 #define DXEVENT_RIGHT		0x04
124 #define DXEVENT_KEYPRESS	0x08
125 
126 /*
127  * Button states
128  */
129 #define BUTTON_UP     1
130 #define BUTTON_DOWN   2
131 #define BUTTON_MOTION 3
132 
133 #define LEFTBUTTON	0
134 #define MIDDLEBUTTON	1
135 #define RIGHTBUTTON	2
136 #define NO_BUTTON	-1
137 
138 #define WHICH_BUTTON(e)	\
139 	((((DXAnyEvent *)e)->event) == DXEVENT_LEFT ? LEFTBUTTON :				\
140 	    (((DXAnyEvent *)e)->event) == DXEVENT_MIDDLE ? MIDDLEBUTTON :			\
141 		(((DXAnyEvent *)e)->event) == DXEVENT_RIGHT ? RIGHTBUTTON : NO_BUTTON)
142 
143 #endif /* _DXI_USERINTERACTORS_H_ */
144 
145 #if defined(__cplusplus) || defined(c_plusplus)
146 }
147 #endif
148 
149