Subversion Repositories gelsvn

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
671 khor 1
//
2
//  glut_main.cpp
3
//  GEL
4
//
5
//  Created by J. Andreas Bærentzen on 04/10/13.
6
//
7
//
8
 
9
#include "glut_main.h"
10
 
11
/*
12
 *  MeshEdit is a small application which allows you to load and edit a mesh.
13
 *  The mesh will be stored in GEL's half edge based Manifold data structure.
14
 *  A number of editing operations are supported. Most of these are accessible from the
15
 *  console that pops up when you hit 'esc'.
16
 *
17
 *  Created by J. Andreas Bærentzen on 15/08/08.
18
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
19
 *
20
 */
21
 
22
#include <string>
23
#include <iostream>
24
#include <vector>
25
#include <algorithm>
26
#include <queue>
27
 
679 janba 28
#include <GEL/GL/glew.h>
29
#ifdef __APPLE__
30
#include <GLUT/glut.h>
31
#else
32
#include <GL/glut.h>
33
#endif
671 khor 34
 
679 janba 35
#include <GEL/GLGraphics/Console.h>
36
#include <GEL/HMesh/harmonics.h>
37
#include <GEL/GLGraphics/MeshEditor.h>
671 khor 38
 
679 janba 39
#include <GEL/CGLA/eigensolution.h>
40
#include <GEL/CGLA/Vec2d.h>
41
#include <GEL/CGLA/Vec3d.h>
42
#include <GEL/CGLA/Mat3x3d.h>
43
#include <GEL/CGLA/Mat2x2d.h>
44
#include <GEL/CGLA/Mat2x3d.h>
45
#include <GEL/CGLA/Mat4x4d.h>
671 khor 46
 
679 janba 47
#include <GEL/LinAlg/Matrix.h>
48
#include <GEL/LinAlg/Vector.h>
49
#include <GEL/LinAlg/LapackFunc.h>
671 khor 50
 
679 janba 51
#include <GEL/HMesh/Manifold.h>
52
#include <GEL/HMesh/AttributeVector.h>
53
#include <GEL/HMesh/mesh_optimization.h>
54
#include <GEL/HMesh/curvature.h>
55
#include <GEL/HMesh/triangulate.h>
56
#include <GEL/HMesh/flatten.h>
57
#include <GEL/HMesh/dual.h>
58
#include <GEL/HMesh/load.h>
59
#include <GEL/HMesh/quadric_simplify.h>
60
#include <GEL/HMesh/smooth.h>
61
#include <GEL/HMesh/x3d_save.h>
62
#include <GEL/HMesh/obj_save.h>
63
#include <GEL/HMesh/off_save.h>
64
#include <GEL/HMesh/mesh_optimization.h>
65
#include <GEL/HMesh/triangulate.h>
66
#include <GEL/HMesh/cleanup.h>
67
#include <GEL/HMesh/cleanup.h>
68
#include <GEL/HMesh/refine_edges.h>
69
#include <GEL/HMesh/subdivision.h>
671 khor 70
 
679 janba 71
#include <GEL/Util/Timer.h>
72
#include <GEL/Util/ArgExtracter.h>
671 khor 73
 
74
 
75
using namespace std;
76
using namespace HMesh;
77
using namespace Geometry;
78
using namespace GLGraphics;
79
using namespace CGLA;
80
using namespace Util;
81
using namespace LinAlg;
82
 
679 janba 83
MeshEditor me;
671 khor 84
 
85
void reshape(int W, int H)
86
{
679 janba 87
    me.reshape(W,H);
671 khor 88
}
89
 
90
Console::variable<string> display_render_mode("normal");
91
Console::variable<int> display_smooth_shading(true);
92
Console::variable<float> display_gamma(2.2);
93
 
94
void display()
95
{
96
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
97
 
98
 
679 janba 99
    me.display();
671 khor 100
 
101
    glutSwapBuffers();
102
}
103
 
104
void animate()
105
{
106
    //usleep( (int)1e4 );
679 janba 107
    me.try_spinning_ball();
671 khor 108
    glutPostRedisplay();
109
}
110
 
111
 
112
void mouse(int button, int state, int x, int y)
113
{
114
    Vec2i pos(x,y);
115
    if (state==GLUT_DOWN)
116
    {
117
        if (button==GLUT_LEFT_BUTTON && glutGetModifiers() == 0)
679 janba 118
           me.grab_ball(ROTATE_ACTION,pos);
671 khor 119
        else if (button==GLUT_MIDDLE_BUTTON || glutGetModifiers() == GLUT_ACTIVE_CTRL)
679 janba 120
            me.grab_ball(ZOOM_ACTION,pos);
671 khor 121
        else if (button==GLUT_RIGHT_BUTTON || glutGetModifiers() == GLUT_ACTIVE_ALT)
679 janba 122
            me.grab_ball(PAN_ACTION,pos);
671 khor 123
    }
124
    else if (state==GLUT_UP)
679 janba 125
        me.release_ball();
671 khor 126
}
127
 
128
void motion(int x, int y) {
129
    Vec2i pos(x,y);
679 janba 130
    me.roll_ball(Vec2i(x,y));
671 khor 131
}
132
 
133
 
134
void keyboard_spec(int key, int x, int y)
135
{
679 janba 136
    switch (key) {
137
        case GLUT_KEY_UP:
138
            me.key_up();
139
            break;
140
        case GLUT_KEY_DOWN:
141
            me.key_down();
142
            break;
143
        case GLUT_KEY_LEFT:
144
            me.key_left();
145
            break;
146
        case GLUT_KEY_RIGHT:
147
            me.key_right();
148
            break;
149
        case GLUT_KEY_HOME:
150
            me.key_home();
151
            break;
152
        case GLUT_KEY_END:
153
            me.key_end();
154
            break;
155
 
156
        default:
157
            break;
158
    }
671 khor 159
    glutPostRedisplay();
160
}
161
 
162
 
163
void keyboard(unsigned char key, int x, int y)
164
{
679 janba 165
    me.keyparse(key);
671 khor 166
    glutPostRedisplay();
167
}
168
 
169
void init_glut(int argc, char** argv)
170
{
171
    glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_DEPTH|GLUT_ALPHA);
172
    glutInitWindowSize(WINX, WINY);
173
    glutInit(&argc, argv);
174
    glutCreateWindow("MeshEdit");
175
    glutDisplayFunc(display);
176
    glutKeyboardFunc(keyboard);
177
    glutSpecialFunc(keyboard_spec);
178
    glutReshapeFunc(reshape);
179
    glutMouseFunc(mouse);
180
    glutMotionFunc(motion);
181
    glutIdleFunc(animate);
182
}
183
void init_gl()
184
{
185
    glewInit();
186
    glEnable(GL_CULL_FACE);
187
    glCullFace(GL_BACK);
188
    glEnable(GL_LIGHTING);
189
    glEnable(GL_LIGHT0);
190
    glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
191
 
192
    // Set the value of a uniform
193
    //glUniform2f(glGetUniformLocation(prog_P0,"WIN_SCALE"), win_size_x/2.0, win_size_y/2.0);
194
 
195
    glMatrixMode(GL_MODELVIEW);
196
    glLoadIdentity();
197
    glClearColor(1,1,1, 0.f);
198
    glColor4f(1.0f, 1.0f, 1.0f, 0.f);
199
    float material[4] = {1,1,1,1};
200
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material);
201
    glEnable(GL_DEPTH_TEST);
202
 
203
}
204
 
679 janba 205
int main(int argc, char** argv)
671 khor 206
{
207
    ArgExtracter ae(argc, argv);
208
 
209
    init_glut(argc, argv);
210
    init_gl();
679 janba 211
 
212
    me.init();
671 khor 213
 
214
    glutMainLoop();
215
    return 0;
216
}
217
 
218
 
219
 
220
 
221