source: trunk/src/testing/dim/hwcapture/mouse_to_joy.PIE @ 4

Revision 4, 10.3 KB checked in by ajaworski, 13 years ago (diff)

Added modified SAGE sources

Line 
1//////////////////////////////////////////////////////////////////////////////////
2//
3// DIM - A Direct Interaction Manager for SAGE
4// Copyright (C) 2007 Electronic Visualization Laboratory,
5// University of Illinois at Chicago
6//
7// All rights reserved.
8//
9// Redistribution and use in source and binary forms, with or without
10// modification, are permitted provided that the following conditions are met:
11//
12//  * Redistributions of source code must retain the above copyright
13//    notice, this list of conditions and the following disclaimer.
14//  * Redistributions in binary form must reproduce the above
15//    copyright notice, this list of conditions and the following disclaimer
16//    in the documentation and/or other materials provided with the distribution.
17//  * Neither the name of the University of Illinois at Chicago nor
18//    the names of its contributors may be used to endorse or promote
19//    products derived from this software without specific prior written permission.
20//
21// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32//
33// Direct questions, comments etc about SAGE UI to www.evl.uic.edu/cavern/forum
34//
35// Author: Ratko Jagodic
36//       
37////////////////////////////////////////////////////////////////////////
38
39
40
41
42
43// A script for converting 5 mouse-like devices on the system to 5 virtual joysticks
44// For use with the device manager for SAGE
45//
46// Author: Ratko Jagodic
47// Date:   April, 2007
48//
49/////////////////////////////////////////////////////////////////////////////////////
50
51
52// minimze upon startup
53//if var.minimized == 0
54//   MinimizePIE()
55//   var.minimized = 1
56//end if
57
58
59// when converting to joystick -1 <-> 1 axis values, we will
60// blank out the region -drift <-> +drift and start mapping
61// the values at +-var.drift up to +-1
62var.drift= 0.001 //001
63var.range= 400
64
65// mouse1 <-> ppjoy1
66   var.dx_1 = RemoveUnits(mouse1.DirectInputX) - var.oldX_1
67   var.dy_1 = RemoveUnits(mouse1.DirectInputY) - var.oldY_1
68
69   var.oldX_1 = RemoveUnits(mouse1.DirectInputX)
70   var.oldY_1 = RemoveUnits(mouse1.DirectInputY)
71   PPJoy1.analog0 = MapRange(var.dx_1, -var.range,var.range, -1,1)
72   PPJoy1.analog1 = MapRange(var.dy_1, -var.range,var.range, -1,1)
73   /*if Sign(var.dx_1) == -1 then
74      PPJoy1.analog0 = EnsureMapRange(var.dx_1, -var.range,1, -1,-var.drift)
75   elseif Sign(var.dx_1)== 1 then
76      PPJoy1.analog0 = EnsureMapRange(var.dx_1, 1,var.range, var.drift,1)
77   else
78      PPJoy1.analog0 = 0
79   endif
80
81   if Sign(var.dy_1) == -1 then
82      PPJoy1.analog1 = EnsureMapRange(var.dy_1, -var.range,1, -1,-var.drift)
83   elseif Sign(var.dy_1)== 1 then
84      PPJoy1.analog1 = EnsureMapRange(var.dy_1, 1,var.range, var.drift,1)
85   else
86      PPJoy1.analog1 = 0
87   endif
88       */
89   PPJoy1.digital1 = mouse1.LeftButton
90   PPJoy1.digital2 = mouse1.RightButton
91   PPJoy1.digital3 = mouse1.MiddleButton
92   mouse1.DirectInputX = 0
93   mouse1.DirectInputY = 0
94
95
96// mouse2 <-> ppjoy2
97   var.dx_2 = RemoveUnits(mouse2.DirectInputX) - var.oldX_2
98   var.dy_2 = RemoveUnits(mouse2.DirectInputY) - var.oldY_2
99
100   var.oldX_2 = RemoveUnits(mouse2.DirectInputX)
101   var.oldY_2 = RemoveUnits(mouse2.DirectInputY)
102
103   if Sign(var.dx_2) == -1 then
104      PPJoy2.analog0 = EnsureMapRange(var.dx_2, -var.range,1, -1,-var.drift)
105   elseif Sign(var.dx_2)== 1 then
106      PPJoy2.analog0 = EnsureMapRange(var.dx_2, 1,var.range, var.drift,1)
107   else
108      PPJoy2.analog0 = 0
109   endif
110
111   if Sign(var.dy_2) == -1 then
112      PPJoy2.analog1 = EnsureMapRange(var.dy_2, -var.range,1, -1,-var.drift)
113   elseif Sign(var.dy_2)== 1 then
114      PPJoy2.analog1 = EnsureMapRange(var.dy_2, 1,var.range, var.drift,1)
115   else
116      PPJoy2.analog1 = 0
117   endif
118
119   PPJoy2.digital1 = mouse2.LeftButton
120   PPJoy2.digital2 = mouse2.RightButton
121   PPJoy2.digital3 = mouse2.MiddleButton
122   mouse2.DirectInputX = 0
123   mouse2.DirectInputY = 0
124
125
126// mouse3 <-> ppjoy3
127   var.dx_3 = RemoveUnits(mouse3.DirectInputX) - var.oldX_3
128   var.dy_3 = RemoveUnits(mouse3.DirectInputY) - var.oldY_3
129
130   var.oldX_3 = RemoveUnits(mouse3.DirectInputX)
131   var.oldY_3 = RemoveUnits(mouse3.DirectInputY)
132
133   if Sign(var.dx_3) == -1 then
134      PPJoy3.analog0 = EnsureMapRange(var.dx_3, -var.range,1, -1,-var.drift)
135   elseif Sign(var.dx_3)== 1 then
136      PPJoy3.analog0 = EnsureMapRange(var.dx_3, 1,var.range, var.drift,1)
137   else
138      PPJoy3.analog0 = 0
139   endif
140
141   if Sign(var.dy_3) == -1 then
142      PPJoy3.analog1 = EnsureMapRange(var.dy_3, -var.range,1, -1,-var.drift)
143   elseif Sign(var.dy_3)== 1 then
144      PPJoy3.analog1 = EnsureMapRange(var.dy_3, 1,var.range, var.drift,1)
145   else
146      PPJoy3.analog1 = 0
147   endif
148
149   PPJoy3.digital1 = mouse3.LeftButton
150   PPJoy3.digital2 = mouse3.RightButton
151   PPJoy3.digital3 = mouse3.MiddleButton
152   mouse3.DirectInputX = 0
153   mouse3.DirectInputY = 0
154
155
156// mouse4 <-> ppjoy4
157   var.dx_4 = RemoveUnits(mouse4.DirectInputX) - var.oldX_4
158   var.dy_4 = RemoveUnits(mouse4.DirectInputY) - var.oldY_4
159
160   var.oldX_4 = RemoveUnits(mouse4.DirectInputX)
161   var.oldY_4 = RemoveUnits(mouse4.DirectInputY)
162
163   if Sign(var.dx_4) == -1 then
164      PPJoy4.analog0 = EnsureMapRange(var.dx_4, -var.range,1, -1,-var.drift)
165   elseif Sign(var.dx_4)== 1 then
166      PPJoy4.analog0 = EnsureMapRange(var.dx_4, 1,var.range, var.drift,1)
167   else
168      PPJoy4.analog0 = 0
169   endif
170
171   if Sign(var.dy_4) == -1 then
172      PPJoy4.analog1 = EnsureMapRange(var.dy_4, -var.range,1, -1,-var.drift)
173   elseif Sign(var.dy_4)== 1 then
174      PPJoy4.analog1 = EnsureMapRange(var.dy_4, 1,var.range, var.drift,1)
175   else
176      PPJoy4.analog1 = 0
177   endif
178
179   PPJoy4.digital1 = mouse4.LeftButton
180   PPJoy4.digital2 = mouse4.RightButton
181   PPJoy4.digital3 = mouse4.MiddleButton
182   mouse4.DirectInputX = 0
183   mouse4.DirectInputY = 0
184
185
186// mouse5 <-> ppjoy5
187   var.dx_5 = RemoveUnits(mouse5.DirectInputX) - var.oldX_5
188   var.dy_5 = RemoveUnits(mouse5.DirectInputY) - var.oldY_5
189
190   var.oldX_5 = RemoveUnits(mouse5.DirectInputX)
191   var.oldY_5 = RemoveUnits(mouse5.DirectInputY)
192
193   if Sign(var.dx_5) == -1 then
194      PPJoy5.analog0 = EnsureMapRange(var.dx_5, -var.range,1, -1,-var.drift)
195   elseif Sign(var.dx_5)== 1 then
196      PPJoy5.analog0 = EnsureMapRange(var.dx_5, 1,var.range, var.drift,1)
197   else
198      PPJoy5.analog0 = 0
199   endif
200
201   if Sign(var.dy_5) == -1 then
202      PPJoy5.analog1 = EnsureMapRange(var.dy_5, -var.range,1, -1,-var.drift)
203   elseif Sign(var.dy_5)== 1 then
204      PPJoy5.analog1 = EnsureMapRange(var.dy_5, 1,var.range, var.drift,1)
205   else
206      PPJoy5.analog1 = 0
207   endif
208
209   PPJoy5.digital1 = mouse5.LeftButton
210   PPJoy5.digital2 = mouse5.RightButton
211   PPJoy5.digital3 = mouse5.MiddleButton
212   mouse5.DirectInputX = 0
213   mouse5.DirectInputY = 0
214
215
216// mouse6 <-> ppjoy6
217   var.dx_6 = RemoveUnits(mouse6.DirectInputX) - var.oldX_6
218   var.dy_6 = RemoveUnits(mouse6.DirectInputY) - var.oldY_6
219
220   var.oldX_6 = RemoveUnits(mouse6.DirectInputX)
221   var.oldY_6 = RemoveUnits(mouse6.DirectInputY)
222
223   if Sign(var.dx_6) == -1 then
224      PPJoy6.analog0 = EnsureMapRange(var.dx_6, -var.range,1, -1,-var.drift)
225   elseif Sign(var.dx_6)== 1 then
226      PPJoy6.analog0 = EnsureMapRange(var.dx_6, 1,var.range, var.drift,1)
227   else
228      PPJoy6.analog0 = 0
229   endif
230
231   if Sign(var.dy_6) == -1 then
232      PPJoy6.analog1 = EnsureMapRange(var.dy_6, -var.range,1, -1,-var.drift)
233   elseif Sign(var.dy_6)== 1 then
234      PPJoy6.analog1 = EnsureMapRange(var.dy_6, 1,var.range, var.drift,1)
235   else
236      PPJoy6.analog1 = 0
237   endif
238
239   PPJoy6.digital1 = mouse6.LeftButton
240   PPJoy6.digital2 = mouse6.RightButton
241   PPJoy6.digital3 = mouse6.MiddleButton
242   mouse6.DirectInputX = 0
243   mouse6.DirectInputY = 0
244
245
246
247// mouse7 <-> ppjoy7
248   var.dx_7 = RemoveUnits(mouse7.DirectInputX) - var.oldX_7
249   var.dy_7 = RemoveUnits(mouse7.DirectInputY) - var.oldY_7
250
251   var.oldX_7 = RemoveUnits(mouse7.DirectInputX)
252   var.oldY_7 = RemoveUnits(mouse7.DirectInputY)
253
254   if Sign(var.dx_7) == -1 then
255      PPJoy7.analog0 = EnsureMapRange(var.dx_7, -var.range,1, -1,-var.drift)
256   elseif Sign(var.dx_7)== 1 then
257      PPJoy7.analog0 = EnsureMapRange(var.dx_7, 1,var.range, var.drift,1)
258   else
259      PPJoy7.analog0 = 0
260   endif
261
262   if Sign(var.dy_7) == -1 then
263      PPJoy7.analog1 = EnsureMapRange(var.dy_7, -var.range,1, -1,-var.drift)
264   elseif Sign(var.dy_7)== 1 then
265      PPJoy7.analog1 = EnsureMapRange(var.dy_7, 1,var.range, var.drift,1)
266   else
267      PPJoy7.analog1 = 0
268   endif
269
270   PPJoy7.digital1 = mouse7.LeftButton
271   PPJoy7.digital2 = mouse7.RightButton
272   PPJoy7.digital3 = mouse7.MiddleButton
273   mouse7.DirectInputX = 0
274   mouse7.DirectInputY = 0
275
276
277
278// mouse8 <-> ppjoy8
279   var.dx_8 = RemoveUnits(mouse8.DirectInputX) - var.oldX_8
280   var.dy_8 = RemoveUnits(mouse8.DirectInputY) - var.oldY_8
281
282   var.oldX_8 = RemoveUnits(mouse8.DirectInputX)
283   var.oldY_8 = RemoveUnits(mouse8.DirectInputY)
284
285   if Sign(var.dx_8) == -1 then
286      PPJoy8.analog0 = EnsureMapRange(var.dx_8, -var.range,1, -1,-var.drift)
287   elseif Sign(var.dx_8)== 1 then
288      PPJoy8.analog0 = EnsureMapRange(var.dx_8, 1,var.range, var.drift,1)
289   else
290      PPJoy8.analog0 = 0
291   endif
292
293   if Sign(var.dy_8) == -1 then
294      PPJoy8.analog1 = EnsureMapRange(var.dy_8, -var.range,1, -1,-var.drift)
295   elseif Sign(var.dy_8)== 1 then
296      PPJoy8.analog1 = EnsureMapRange(var.dy_8, 1,var.range, var.drift,1)
297   else
298      PPJoy8.analog1 = 0
299   endif
300
301   PPJoy8.digital1 = mouse8.LeftButton
302   PPJoy8.digital2 = mouse8.RightButton
303   PPJoy8.digital3 = mouse8.MiddleButton
304   mouse8.DirectInputX = 0
305   mouse8.DirectInputY = 0
306
307mouse.Swallow = true
308
309
310
Note: See TracBrowser for help on using the repository browser.