00001
00002
00003
00004
00005
00006
00007
00008
00009
#ifndef _LOGO_H
00010
#define _LOGO_H
00011
00012
#include <gtkmm.h>
00013
00014
#include <gtkglmm.h>
00015
00016
00018
00019
00020
00022
00023
namespace Logo
00024 {
00025
00026
class Scene;
00027
00028
00029
00030
00031
00032
class View :
public sigc::trackable
00033 {
00034
friend class Scene;
00035
00036
public:
00037
static const float NEAR_CLIP;
00038
static const float FAR_CLIP;
00039
00040
static const float INIT_POS_X;
00041
static const float INIT_POS_Y;
00042
static const float INIT_POS_Z;
00043
00044
static const float INIT_AXIS_X;
00045
static const float INIT_AXIS_Y;
00046
static const float INIT_AXIS_Z;
00047
static const float INIT_ANGLE;
00048
00049
static const float INIT_SCALE;
00050
00051
static const float SCALE_MAX;
00052
static const float SCALE_MIN;
00053
00054
public:
00055 View();
00056
virtual ~View();
00057
00058
public:
00059
void frustum(
int w,
int h);
00060
00061
void xform();
00062
00063
void reset();
00064
00065
void set_pos(
float x,
float y,
float z)
00066 { m_Pos[0] = x; m_Pos[1] = y; m_Pos[2] = z; }
00067
00068
void set_quat(
float q0,
float q1,
float q2,
float q3)
00069 { m_Quat[0] = q0; m_Quat[1] = q1; m_Quat[2] = q2; m_Quat[3] = q3; }
00070
00071
void set_scale(
float scale)
00072 { m_Scale = scale; }
00073
00074
protected:
00075
00076
virtual bool on_button_press_event(GdkEventButton* event, Scene* scene);
00077
virtual bool on_motion_notify_event(GdkEventMotion* event, Scene* scene);
00078
00079
private:
00080
float m_Pos[3];
00081
float m_Quat[4];
00082
float m_Scale;
00083
00084
float m_BeginX;
00085
float m_BeginY;
00086
00087 };
00088
00089
00090
00091
00092
00093
00094
class Model
00095 {
00096
friend class Scene;
00097
00098
public:
00099
enum DisplayList {
00100 CUBE = 1,
00101 G_FORWARD,
00102 G_BACKWARD,
00103 T_FORWARD,
00104 T_BACKWARD,
00105 K_FORWARD,
00106 K_BACKWARD
00107 };
00108
00109
static const float MAT_SPECULAR[4];
00110
static const float MAT_SHININESS[1];
00111
static const float MAT_BLACK[4];
00112
static const float MAT_RED[4];
00113
static const float MAT_GREEN[4];
00114
static const float MAT_BLUE[4];
00115
00116
static const unsigned int DEFAULT_ROT_COUNT;
00117
00118
public:
00119
explicit Model(
unsigned int rot_count = DEFAULT_ROT_COUNT,
00120
bool enable_anim =
true);
00121
virtual ~Model();
00122
00123
private:
00124
void init_gl();
00125
00126
public:
00127
void draw();
00128
00129
void enable_anim()
00130 { m_EnableAnim =
true; }
00131
00132
void disable_anim()
00133 { m_EnableAnim =
false; }
00134
00135
bool anim_is_enabled()
const
00136
{
return m_EnableAnim; }
00137
00138
void reset_anim();
00139
00140
void set_pos(
float x,
float y,
float z)
00141 { m_Pos[0] = x; m_Pos[1] = y; m_Pos[2] = z; }
00142
00143
void set_quat(
float q0,
float q1,
float q2,
float q3)
00144 { m_Quat[0] = q0; m_Quat[1] = q1; m_Quat[2] = q2; m_Quat[3] = q3; }
00145
00146
private:
00147
00148
struct RotMode
00149 {
00150
float *axis;
00151
float sign;
00152 };
00153
00154
static const RotMode ROT_MODE[];
00155
00156
private:
00157
unsigned int m_RotCount;
00158
00159
bool m_EnableAnim;
00160
unsigned int m_Mode;
00161
unsigned int m_Counter;
00162
00163
float m_Pos[3];
00164
float m_Quat[4];
00165
00166 };
00167
00168
00169
00170
00171
00172
00173
class Scene :
public Gtk::GL::DrawingArea
00174 {
00175
friend class View;
00176
friend class Model;
00177
00178
public:
00179
static const unsigned int TIMEOUT_INTERVAL;
00180
00181
00182
static const float CLEAR_COLOR[4];
00183
static const float CLEAR_DEPTH;
00184
00185
static const float LIGHT0_POSITION[4];
00186
static const float LIGHT0_DIFFUSE[4];
00187
static const float LIGHT0_SPECULAR[4];
00188
00189
public:
00190
explicit Scene(
unsigned int rot_count = Model::DEFAULT_ROT_COUNT,
00191
bool enable_anim =
true);
00192
virtual ~Scene();
00193
00194
protected:
00195
00196
virtual void on_realize();
00197
virtual bool on_configure_event(GdkEventConfigure* event);
00198
virtual bool on_expose_event(GdkEventExpose* event);
00199
virtual bool on_button_press_event(GdkEventButton* event);
00200
virtual bool on_map_event(GdkEventAny* event);
00201
virtual bool on_unmap_event(GdkEventAny* event);
00202
virtual bool on_visibility_notify_event(GdkEventVisibility* event);
00203
virtual bool on_timeout();
00204
00205
public:
00206
00207
void invalidate() {
00208 get_window()->invalidate_rect(get_allocation(),
false);
00209 }
00210
00211
00212
void update()
00213 { get_window()->process_updates(
false); }
00214
00215
protected:
00216
00217 sigc::connection m_ConnectionTimeout;
00218
00219
void timeout_add();
00220
void timeout_remove();
00221
00222
public:
00223
00224
bool anim_is_enabled()
const
00225
{
return m_Model.anim_is_enabled(); }
00226
00227
void toggle_anim();
00228
00229
void init_anim();
00230
00231
protected:
00232 Gtk::Menu* create_popup_menu();
00233
00234
protected:
00235
00236 Gtk::Menu* m_Menu;
00237
00238
protected:
00239
00240 View m_View;
00241 Model m_Model;
00242
00243 };
00244
00245
00246
00247
00248
00249
00250
class Application :
public Gtk::Window
00251 {
00252
public:
00253
static const Glib::ustring APP_NAME;
00254
00255
public:
00256
explicit Application(
unsigned int rot_count = Model::DEFAULT_ROT_COUNT,
00257
bool enable_anim =
true);
00258
virtual ~Application();
00259
00260
protected:
00261
00262
virtual void on_button_quit_clicked();
00263
virtual bool on_key_press_event(GdkEventKey* event);
00264
00265
protected:
00266
00267 Gtk::VBox m_VBox;
00268 Scene m_Scene;
00269 Gtk::Button m_ButtonQuit;
00270 };
00271
00272
00273 }
00274
00275
00276
#endif // _LOGO_H