~ubuntu-branches/ubuntu/trusty/libspnav/trusty

« back to all changes in this revision

Viewing changes to spnav_magellan.c

  • Committer: Bazaar Package Importer
  • Author(s): M G Berberich
  • Date: 2010-05-25 21:20:21 UTC
  • mto: (1.1.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20100525212021-g2sk0ukjkyr4ebkt
ImportĀ upstreamĀ versionĀ 0.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
This file is part of libspnav, part of the spacenav project (spacenav.sf.net)
 
3
Copyright (C) 2007-2010 John Tsiombikas <nuclear@member.fsf.org>
 
4
 
 
5
Redistribution and use in source and binary forms, with or without
 
6
modification, are permitted provided that the following conditions are met:
 
7
 
 
8
1. Redistributions of source code must retain the above copyright notice, this
 
9
   list of conditions and the following disclaimer.
 
10
2. Redistributions in binary form must reproduce the above copyright notice,
 
11
   this list of conditions and the following disclaimer in the documentation
 
12
   and/or other materials provided with the distribution.
 
13
3. The name of the author may not be used to endorse or promote products
 
14
   derived from this software without specific prior written permission.
 
15
 
 
16
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 
17
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 
18
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
 
19
EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
20
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 
21
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
22
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 
23
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 
24
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 
25
OF SUCH DAMAGE.
 
26
*/
 
27
 
 
28
/* spnav_magellan.h and spnav_magellan.c provide source-level compatibility
 
29
 * with the original proprietary Magellan SDK provided by 3Dconnexion.
 
30
 * It is actually implemented as a wrapper on top of the new spnav interface
 
31
 * (see spnav.h).
 
32
 */
 
33
#include "spnav_magellan.h"
 
34
#include "spnav.h"
 
35
 
 
36
int MagellanInit(Display *dpy, Window win)
 
37
{
 
38
        return spnav_x11_open(dpy, win) == -1 ? 0 : 1;
 
39
}
 
40
 
 
41
int MagellanClose(Display *dpy)
 
42
{
 
43
        return spnav_close() == -1 ? 0 : 1;
 
44
}
 
45
 
 
46
int MagellanSetWindow(Display *dpy, Window win)
 
47
{
 
48
        return spnav_x11_window(win) == -1 ? 0 : 1;
 
49
}
 
50
 
 
51
int MagellanApplicationSensitivity(Display *dpy, double sens)
 
52
{
 
53
        return spnav_sensitivity(sens) == -1 ? 0 : 1;
 
54
}
 
55
 
 
56
 
 
57
int MagellanInputEvent(Display *dpy, XEvent *xev, MagellanIntEvent *mev)
 
58
{
 
59
        int i;
 
60
        spnav_event event;
 
61
 
 
62
        if(!spnav_x11_event(xev, &event)) {
 
63
                return 0;
 
64
        }
 
65
 
 
66
        if(event.type == SPNAV_EVENT_MOTION) {
 
67
                mev->type = MagellanInputMotionEvent;
 
68
 
 
69
                for(i=0; i<6; i++) {
 
70
                        mev->u.data[i] = event.motion.data[i];
 
71
                }
 
72
                mev->u.data[6] = event.motion.period * 1000 / 60;
 
73
        } else {
 
74
                mev->type = event.button.press ? MagellanInputButtonPressEvent : MagellanInputButtonReleaseEvent;
 
75
                mev->u.button = event.button.bnum;
 
76
        }
 
77
 
 
78
        return mev->type;
 
79
}
 
80
 
 
81
 
 
82
int MagellanTranslateEvent(Display *dpy, XEvent *xev, MagellanFloatEvent *mev, double tscale, double rscale)
 
83
{
 
84
        int i;
 
85
        spnav_event event;
 
86
 
 
87
        if(!spnav_x11_event(xev, &event)) {
 
88
                return 0;
 
89
        }
 
90
 
 
91
        if(event.type == SPNAV_EVENT_MOTION) {
 
92
                mev->MagellanType = MagellanInputMotionEvent;
 
93
 
 
94
                for(i=0; i<6; i++) {
 
95
                        mev->MagellanData[i] = (double)event.motion.data[i] * (i < 3 ? tscale : rscale);
 
96
                }
 
97
                mev->MagellanPeriod = event.motion.period;
 
98
        } else {
 
99
                mev->MagellanType = event.button.press ? MagellanInputButtonPressEvent : MagellanInputButtonReleaseEvent;
 
100
                mev->MagellanButton = event.button.bnum;
 
101
        }
 
102
 
 
103
        return mev->MagellanType;
 
104
}
 
105
 
 
106
int MagellanRemoveMotionEvents(Display *dpy)
 
107
{
 
108
        return spnav_remove_events(SPNAV_EVENT_MOTION);
 
109
}
 
110
 
 
111
 
 
112
int MagellanRotationMatrix(double mat[4][4], double x, double y, double z)
 
113
{
 
114
        return 0;       /* TODO */
 
115
}
 
116
 
 
117
int MagellanMultiplicationMatrix(double mat_a[4][4], double mat_b[4][4], double mat_c[4][4])
 
118
{
 
119
        return 0;       /* TODO */
 
120
}