1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
#ifndef _H_NXOPENGLCAMERA_SM
#define _H_NXOPENGLCAMERA_SM
#define SMC_USES_IOSTREAMS
#include "statemap.h"
// Forward declarations.
class Trackball;
class Trackball_Initial;
class Trackball_Rotating;
class Trackball_Panning;
class Trackball_Default;
class NXOpenGLCameraState;
class NXOpenGLCameraContext;
class NXOpenGLCamera;
class NXOpenGLCameraState :
public statemap::State
{
public:
NXOpenGLCameraState(const char *name, int stateId)
: statemap::State(name, stateId)
{};
virtual void Entry(NXOpenGLCameraContext&) {};
virtual void Exit(NXOpenGLCameraContext&) {};
virtual void panEvent(NXOpenGLCameraContext& context, int x, int y);
virtual void panStartEvent(NXOpenGLCameraContext& context, int x, int y);
virtual void panStopEvent(NXOpenGLCameraContext& context, int x, int y);
virtual void rotateStartEvent(NXOpenGLCameraContext& context, int x, int y);
virtual void rotateStopEvent(NXOpenGLCameraContext& context, int x, int y);
virtual void rotatingEvent(NXOpenGLCameraContext& context, int x, int y);
protected:
virtual void Default(NXOpenGLCameraContext& context);
};
class Trackball
{
public:
static Trackball_Initial Initial;
static Trackball_Rotating Rotating;
static Trackball_Panning Panning;
};
class Trackball_Default :
public NXOpenGLCameraState
{
public:
Trackball_Default(const char *name, int stateId)
: NXOpenGLCameraState(name, stateId)
{};
};
class Trackball_Initial :
public Trackball_Default
{
public:
Trackball_Initial(const char *name, int stateId)
: Trackball_Default(name, stateId)
{};
void Default(NXOpenGLCameraContext& context);
void panStartEvent(NXOpenGLCameraContext& context, int x, int y);
void rotateStartEvent(NXOpenGLCameraContext& context, int x, int y);
};
class Trackball_Rotating :
public Trackball_Default
{
public:
Trackball_Rotating(const char *name, int stateId)
: Trackball_Default(name, stateId)
{};
void Default(NXOpenGLCameraContext& context);
void rotateStopEvent(NXOpenGLCameraContext& context, int x, int y);
void rotatingEvent(NXOpenGLCameraContext& context, int x, int y);
};
class Trackball_Panning :
public Trackball_Default
{
public:
Trackball_Panning(const char *name, int stateId)
: Trackball_Default(name, stateId)
{};
void Default(NXOpenGLCameraContext& context);
void panEvent(NXOpenGLCameraContext& context, int x, int y);
void panStopEvent(NXOpenGLCameraContext& context, int x, int y);
};
class NXOpenGLCameraContext :
public statemap::FSMContext
{
public:
NXOpenGLCameraContext(NXOpenGLCamera& owner)
: _owner(owner)
{
setState(Trackball::Initial);
Trackball::Initial.Entry(*this);
};
NXOpenGLCamera& getOwner() const
{
return (_owner);
};
NXOpenGLCameraState& getState() const
{
if (_state == NULL)
{
throw statemap::StateUndefinedException();
}
return (dynamic_cast<NXOpenGLCameraState&>(*_state));
};
void panEvent(int x, int y)
{
(getState()).panEvent(*this, x, y);
};
void panStartEvent(int x, int y)
{
(getState()).panStartEvent(*this, x, y);
};
void panStopEvent(int x, int y)
{
(getState()).panStopEvent(*this, x, y);
};
void rotateStartEvent(int x, int y)
{
(getState()).rotateStartEvent(*this, x, y);
};
void rotateStopEvent(int x, int y)
{
(getState()).rotateStopEvent(*this, x, y);
};
void rotatingEvent(int x, int y)
{
(getState()).rotatingEvent(*this, x, y);
};
private:
NXOpenGLCamera& _owner;
};
#endif // _H_NXOPENGLCAMERA_SM
|