OSDN Git Service

Some features of Dialog class are modified; Dialog#item now returns DialogItem object...
[molby/Molby.git] / MolLib / Trackball.h
1 /*
2  *  Trackball.h
3  *
4  *  Created by Toshi Nagata on 2005/09/17.
5  *  Copyright 2005-2008 Toshi Nagata. All rights reserved.
6  *
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.
10  
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.
15  */
16
17 #ifndef __Trackball_H__
18 #define __Trackball_H__
19
20 #include <math.h>
21
22 #ifndef kRad2Deg
23 #define kRad2Deg  (180./3.14159265358979)
24 #endif
25 #ifndef kDeg2Rad
26 #define kDeg2Rad  (3.14159265358979 / 180.)
27 #endif
28 #ifndef kLog10
29 #define kLog10 2.3025851
30 #endif
31 #ifndef kCot15Deg
32 #define kCot15Deg 3.73205075
33 #endif
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38         
39 typedef enum TrackballMode {
40         kTrackballRotateMode = 1,
41         kTrackballTranslateMode,
42         kTrackballScaleMode,
43         /*  The following "modes" are not related to the trackball operation,
44             but maybe useful for use in molecular modeling applications  */
45         kTrackballSelectionMode,
46         kTrackballCreateMode,
47         kTrackballEraseMode
48 } TrackballMode;
49
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 {
54         int refCount;
55     float start[2];     /*  Drag started here  */
56     float startQuat[4]; /*  Rotation from the start point to the center (of the trackball) */
57     TrackballMode   mode;
58
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 */
65 } Trackball;
66
67 Trackball *TrackballNew(void);
68 void TrackballRetain(Trackball *track);
69 void TrackballRelease(Trackball *track);
70
71 void TrackballGetRotate(const Trackball *track, float *a);
72 void TrackballGetTranslate(const Trackball *track, float *a);
73 void TrackballGetPerspective(const Trackball *track, float *a);
74
75 void TrackballReset(Trackball *track);
76 void TrackballSetScale(Trackball *track, float scale);
77 void TrackballSetTranslate(Trackball *track, const float *a);
78
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);
83
84 #ifdef __cplusplus
85 }
86 #endif
87                 
88 #endif /* __Trackball_H__  */