4 * Created by Toshi Nagata on 2005/09/17.
5 * Copyright 2005-2008 Toshi Nagata. All rights reserved.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation version 2 of the License.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
17 #ifndef __Trackball_H__
18 #define __Trackball_H__
23 #define kRad2Deg (180./3.14159265358979)
26 #define kDeg2Rad (3.14159265358979 / 180.)
29 #define kLog10 2.3025851
32 #define kCot15Deg 3.73205075
39 typedef enum TrackballMode {
40 kTrackballRotateMode = 1,
41 kTrackballTranslateMode,
43 /* The following "modes" are not related to the trackball operation,
44 but maybe useful for use in molecular modeling applications */
45 kTrackballSelectionMode,
50 /* Simulate the trackball operation. The screen coordinates should be converted
51 * so that the unit circle represents the trackball (i.e. the center of the
52 * view is (0, 0), and the half of the screen height (or width) is 1.0) */
53 typedef struct Trackball {
55 float start[2]; /* Drag started here */
56 float startQuat[4]; /* Rotation from the start point to the center (of the trackball) */
59 float quat[4]; /* Rotation (in quaternion) */
60 float tempQuat[4]; /* Temporary rotation during dragging of trackball */
61 float trans[3]; /* Translation */
62 float tempTrans[3]; /* Temporary translation */
63 float scale; /* Scale */
64 float tempScale; /* Temporary scale */
67 Trackball *TrackballNew(void);
68 void TrackballRetain(Trackball *track);
69 void TrackballRelease(Trackball *track);
71 void TrackballGetRotate(const Trackball *track, float *a);
72 void TrackballGetTranslate(const Trackball *track, float *a);
73 void TrackballGetPerspective(const Trackball *track, float *a);
75 void TrackballReset(Trackball *track);
76 void TrackballSetScale(Trackball *track, float scale);
77 void TrackballSetTranslate(Trackball *track, const float *a);
79 void TrackballStartDragging(Trackball *track, const float *mousePos, TrackballMode mode);
80 void TrackballSetTemporaryRotation(Trackball *track, const float *q);
81 void TrackballDrag(Trackball *track, const float *mousePos);
82 void TrackballEndDragging(Trackball *track, const float *mousePos);
88 #endif /* __Trackball_H__ */