~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to extern/eltopo/common/gluvi.h

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef GLUVI_H
2
 
#define GLUVI_H
3
 
 
4
 
#include <iostream>
5
 
#include <vector>
6
 
 
7
 
#ifdef __APPLE__
8
 
#include <GLUT/glut.h> // why does Apple have to put glut.h here...
9
 
#else
10
 
#include <GL/glut.h> // ...when everyone else puts it here?
11
 
#endif
12
 
 
13
 
namespace Gluvi{
14
 
    
15
 
    // the camera capability for Gluvi
16
 
    struct Camera
17
 
    {
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
29
 
    };
30
 
    
31
 
    struct Target3D : public Camera
32
 
    {
33
 
        float target[3], dist;
34
 
        float heading, pitch;
35
 
        float default_target[3], default_dist;
36
 
        float default_heading, default_pitch;
37
 
        float fovy;
38
 
        float near_clip_factor, far_clip_factor;
39
 
        enum {INACTIVE, ROTATE, TRUCK, DOLLY} action_mode;
40
 
        int oldmousex, oldmousey;
41
 
        
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]);
49
 
        
50
 
        void get_up_vector(float up[3]);
51
 
        
52
 
        void gl_transform(void);
53
 
        void export_rib(std::ostream &output);
54
 
    };
55
 
    
56
 
    // same as above, but with orthographic projection
57
 
    struct TargetOrtho3D : public Camera
58
 
    {
59
 
        float target[3], dist;
60
 
        float heading, pitch;
61
 
        float default_target[3], default_dist;
62
 
        float default_heading, default_pitch;
63
 
        float height_factor;
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;
67
 
        
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);
77
 
    };
78
 
    
79
 
    struct PanZoom2D : public Camera
80
 
    {
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
86
 
        int clickx, clicky;
87
 
        
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);
96
 
    };
97
 
    
98
 
    // overlaid user-interface widgets
99
 
    struct Widget
100
 
    {
101
 
        Widget() : dispx(~0), dispy(~0), width(~0), height(~0) {}
102
 
        
103
 
        int dispx, dispy, width, height; // set in display()
104
 
        
105
 
        virtual ~Widget() {}
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 ) {}
111
 
    };
112
 
    
113
 
    struct StaticText : public Widget
114
 
    {
115
 
        const char *text;
116
 
        
117
 
        StaticText(const char *text_);
118
 
        void display(int x, int y);
119
 
        
120
 
    private:
121
 
        StaticText( const StaticText& );
122
 
        StaticText operator=( const StaticText& );
123
 
        
124
 
    };
125
 
    
126
 
    struct DynamicText : public Widget
127
 
    {
128
 
        std::string text;
129
 
        float color[3];
130
 
        
131
 
        DynamicText( const std::string& text_ );
132
 
        
133
 
        void set_color( float r, float g, float b );
134
 
        
135
 
        void display(int x, int y);
136
 
        
137
 
    private:
138
 
        DynamicText( const DynamicText& );
139
 
        DynamicText operator=( const DynamicText& );
140
 
        
141
 
    };
142
 
    
143
 
    
144
 
    struct Button : public Widget
145
 
    {
146
 
        enum {UNINVOLVED, SELECTED, HIGHLIGHTED} status;
147
 
        const char *text;
148
 
        int minwidth;
149
 
        
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() {}
155
 
        
156
 
    private:
157
 
        Button( const Button& );
158
 
        Button operator=( const Button& );
159
 
        
160
 
    };
161
 
    
162
 
    struct Slider : public Widget
163
 
    {
164
 
        enum {UNINVOLVED, SELECTED} status;
165
 
        const char *text;
166
 
        int length, justify;
167
 
        int position;
168
 
        int scrollxmin, scrollxmax, scrollymin, scrollymax;
169
 
        int clickx;
170
 
        
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() {}
176
 
        
177
 
    private:
178
 
        Slider( const Slider& );
179
 
        Slider operator=( const Slider& );
180
 
        
181
 
    };
182
 
    
183
 
    struct WidgetList : public Widget
184
 
    {
185
 
        int indent;
186
 
        bool hidden;
187
 
        std::vector<Widget*> list;
188
 
        int downclicked_member;
189
 
        
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);
194
 
    };
195
 
    
196
 
    // display callback
197
 
    extern void (*userDisplayFunc)(void); 
198
 
    
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);
202
 
    
203
 
    // user is free to do their own callbacks for everything else except glutReshape()
204
 
    
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);
216
 
    
217
 
    // call init first thing
218
 
    void init(const char *windowtitle, int *argc, char **argv);
219
 
    
220
 
    // the Gluvi state
221
 
    extern Camera *camera;
222
 
    extern WidgetList root;
223
 
    extern int winwidth, winheight;
224
 
    extern int windowID;
225
 
    
226
 
    extern bool taking_screenshot;
227
 
    extern GLuint screenshot_fbo;
228
 
    
229
 
    // then after setting the Gluvi state and doing any of your own set-up, call run()
230
 
    void run(void);
231
 
    
232
 
} // end of namespace
233
 
 
234
 
#endif