8
#include <GLUT/glut.h> // why does Apple have to put glut.h here...
10
#include <GL/glut.h> // ...when everyone else puts it here?
15
// the camera capability for Gluvi
18
virtual ~Camera(void) {}
19
virtual void click(int button, int state, int x, int y) = 0;
20
virtual void drag(int x, int y) = 0;
21
virtual void return_to_default(void) = 0;
22
//@@@ add these to be called by a user glutKeyboardFunc() thing so that
23
//@@@ cameras can easily add keyboard shortcuts for e.g. return_to_default, transformation, etc.
24
//virtual void navigation_keyboard_handler(unsigned char key, int x, int y) = 0;
25
//virtual void navigation_special_key_handler(int key, int x, int y) = 0;
26
virtual void gl_transform(void) = 0;
27
virtual void export_rib(std::ostream &output) = 0;
28
virtual void display_screen(void) {} // in case the camera needs to show anything on screen
31
struct Target3D : public Camera
33
float target[3], dist;
35
float default_target[3], default_dist;
36
float default_heading, default_pitch;
38
float near_clip_factor, far_clip_factor;
39
enum {INACTIVE, ROTATE, TRUCK, DOLLY} action_mode;
40
int oldmousex, oldmousey;
42
Target3D(float target_[3]=0, float dist_=1.f, float heading_=0.f, float pitch_=0.f, float fovy_=45.f,
43
float near_clip_factor_=0.01f, float far_clip_factor_=100.f);
44
void click(int button, int state, int x, int y);
45
void drag(int x, int y);
46
void return_to_default(void);
47
void transform_mouse(int x, int y, float ray_origin[3], float ray_direction[3]);
48
void get_viewing_direction(float direction[3]);
50
void get_up_vector(float up[3]);
52
void gl_transform(void);
53
void export_rib(std::ostream &output);
56
// same as above, but with orthographic projection
57
struct TargetOrtho3D : public Camera
59
float target[3], dist;
61
float default_target[3], default_dist;
62
float default_heading, default_pitch;
64
float near_clip_factor, far_clip_factor;
65
enum {INACTIVE, ROTATE, TRUCK, DOLLY} action_mode; // @@@@ WHAT ABOUT ZOOMING??? IS WIDTH ALWAYS A FUNCTION OF DIST?
66
int oldmousex, oldmousey;
68
TargetOrtho3D(float target_[3]=0, float dist_=1.0f, float heading_=0.0f, float pitch_=0.0f, float height_factor_=1.0f,
69
float near_clip_factor_=0.01f, float far_clip_factor_=100.0f);
70
void click(int button, int state, int x, int y);
71
void drag(int x, int y);
72
void return_to_default(void);
73
void transform_mouse(int x, int y, float ray_origin[3], float ray_direction[3]);
74
void get_viewing_direction(float direction[3]);
75
void gl_transform(void);
76
void export_rib(std::ostream &output);
79
struct PanZoom2D : public Camera
81
float bottom, left, height;
82
float default_bottom, default_left, default_height;
83
enum {INACTIVE, PAN, ZOOM_IN, ZOOM_OUT} action_mode;
84
int oldmousex, oldmousey;
85
bool moved_since_mouse_down; // to distinuish simple clicks from drags
88
PanZoom2D(float bottom_=0, float left_=0, float height_=1);
89
void click(int button, int state, int x, int y);
90
void drag(int x, int y);
91
void return_to_default(void);
92
void transform_mouse(int x, int y, float coords[2]);
93
void gl_transform(void);
94
void export_rib(std::ostream &output);
95
void display_screen(void);
98
// overlaid user-interface widgets
101
Widget() : dispx(~0), dispy(~0), width(~0), height(~0) {}
103
int dispx, dispy, width, height; // set in display()
106
virtual void display(int x, int y) = 0;
107
// virtual bool click( int state, int x, int y );
108
virtual bool click(int, int, int ) { return false; } // returns true if click handled by widget
109
// virtual void drag(int x, int y) {}
110
virtual void drag(int, int ) {}
113
struct StaticText : public Widget
117
StaticText(const char *text_);
118
void display(int x, int y);
121
StaticText( const StaticText& );
122
StaticText operator=( const StaticText& );
126
struct DynamicText : public Widget
131
DynamicText( const std::string& text_ );
133
void set_color( float r, float g, float b );
135
void display(int x, int y);
138
DynamicText( const DynamicText& );
139
DynamicText operator=( const DynamicText& );
144
struct Button : public Widget
146
enum {UNINVOLVED, SELECTED, HIGHLIGHTED} status;
150
Button(const char *text_, int minwidth_=0);
151
void display(int x, int y);
152
bool click(int state, int x, int y);
153
void drag(int x, int y);
154
virtual void action() {}
157
Button( const Button& );
158
Button operator=( const Button& );
162
struct Slider : public Widget
164
enum {UNINVOLVED, SELECTED} status;
168
int scrollxmin, scrollxmax, scrollymin, scrollymax;
171
Slider(const char *text_, int length_=100, int position_=0, int justify_=0);
172
void display(int x, int y);
173
bool click(int state, int x, int y);
174
void drag(int x, int y);
175
virtual void action() {}
178
Slider( const Slider& );
179
Slider operator=( const Slider& );
183
struct WidgetList : public Widget
187
std::vector<Widget*> list;
188
int downclicked_member;
190
WidgetList(int listindent_=12, bool hidden_=false);
191
void display(int x, int y);
192
bool click(int state, int x, int y);
193
void drag(int x, int y);
197
extern void (*userDisplayFunc)(void);
199
// mouse callbacks for events that Gluvi ignores (control not pressed, or mouse not on an active widget)
200
extern void (*userMouseFunc)(int button, int state, int x, int y);
201
extern void (*userDragFunc)(int x, int y);
203
// user is free to do their own callbacks for everything else except glutReshape()
205
// additional helpful functions
206
void ppm_screenshot(const char *filename_format, ...);
207
void sgi_screenshot(const char *filename_format, ...);
208
void set_generic_lights(void);
209
void set_generic_material(float r, float g, float b, GLenum face=GL_FRONT_AND_BACK);
210
void set_matte_material(float r, float g, float b, GLenum face=GL_FRONT_AND_BACK);
211
//@@@@@@@ USEFUL FUNCTIONALITY:
212
void draw_3d_arrow(const float base[3], const float point[3], float arrow_head_length=0);
213
//void draw_2d_arrow(const Vec2f base, const Vec2f point, float arrow_head_length);
214
void draw_coordinate_grid(float size=1, int spacing=10);
215
void draw_text(const float point[3], const char *text, int fontsize=12);
217
// call init first thing
218
void init(const char *windowtitle, int *argc, char **argv);
221
extern Camera *camera;
222
extern WidgetList root;
223
extern int winwidth, winheight;
226
extern bool taking_screenshot;
227
extern GLuint screenshot_fbo;
229
// then after setting the Gluvi state and doing any of your own set-up, call run()
232
} // end of namespace