Subversion Repositories gelsvn

Rev

Rev 656 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 656 Rev 657
Line 7... Line 7...
7
#include "../GL/glew.h"
7
#include "../GL/glew.h"
8
 
8
 
9
#include "../CGLA/Mat4x4f.h"
9
#include "../CGLA/Mat4x4f.h"
10
#include "../CGLA/Vec3d.h"
10
#include "../CGLA/Vec3d.h"
11
#include "../HMesh/Manifold.h"
11
#include "../HMesh/Manifold.h"
-
 
12
#include "../Geometry/TriMesh.h"
12
 
13
 
13
#include "draw.h"
14
#include "draw.h"
14
#include "SinglePassWireframeRenderer.h"
15
#include "SinglePassWireframeRenderer.h"
15
#include "IDBufferWireFrameRenderer.h"
16
#include "IDBufferWireFrameRenderer.h"
16
#include "SOIL.h"
17
#include "SOIL.h"
17
 
18
 
18
namespace GLGraphics
19
namespace GLGraphics
19
{
20
{
20
    using namespace CGLA;
21
    using namespace CGLA;
-
 
22
    using namespace Geometry;
21
    using namespace HMesh;
23
    using namespace HMesh;
22
    using namespace std;
24
    using namespace std;
23
    
25
    
24
    namespace
26
    namespace
25
    {
27
    {
Line 39... Line 41...
39
            glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material.specular);
41
            glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material.specular);
40
            glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, material.shininess);
42
            glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, material.shininess);
41
        }
43
        }
42
    }
44
    }
43
    
45
    
-
 
46
    void draw_ball() {
-
 
47
        static TriMesh mesh;
-
 
48
        if(mesh.geometry.no_vertices()==0)
-
 
49
        {
-
 
50
            GLfloat sphere_verts[] = {0.91358,0,0,-0.91358,0,0,0,0.91358,0,0,-0.91358,0,0,0,0.91358,0,0,-0.91358,0.54321,-0.54321,0.54321,0.54321,0.54321,-0.54321,-0.54321,0.54321,0.54321,-0.54321,-0.54321,-0.54321,0.54321,0.54321,0.54321,-0.54321,0.54321,-0.54321,-0.54321,-0.54321,0.54321,0.54321,-0.54321,-0.54321,0.444444,0,0.814815,0,-0.814815,0.444444,0.814815,-0.444444,0,0.444444,0,-0.814815,0,0.814815,-0.444444,0.814815,0.444444,0,-0.444444,0,0.814815,0,0.814815,0.444444,-0.814815,0.444444,0,-0.444444,0,-0.814815,0,-0.814815,-0.444444,-0.814815,-0.444444,0,0,0.444444,0.814815,0.814815,0,0.444444,0.444444,0.814815,0,0,0.444444,-0.814815,-0.814815,0,-0.444444,-0.444444,0.814815,0,0,-0.444444,0.814815,-0.814815,0,0.444444,-0.444444,-0.814815,0,0,-0.444444,-0.814815,0.814815,0,-0.444444,0.444444,-0.814815,0};
-
 
51
            GLuint sphere_indices[] = {28,11,15,27,5,15,33,7,15,33,13,16,35,4,16,38,7,16,38,14,17,37,1,17,28,7,17,37,14,18,36,6,18,30,8,18,30,12,19,32,3,19,29,8,19,29,11,20,28,1,20,37,8,20,34,13,21,33,5,21,27,9,21,27,11,22,29,3,22,32,9,22,32,12,23,31,2,23,34,9,23,31,12,24,30,6,24,36,10,24,36,14,25,38,4,25,35,10,25,35,13,26,34,2,26,31,10,26,22,9,27,21,5,27,15,11,27,15,7,28,17,1,28,20,11,28,20,8,29,19,3,29,22,11,29,19,8,30,18,6,30,24,12,30,24,10,31,26,2,31,23,12,31,23,9,32,22,3,32,19,12,32,16,7,33,15,5,33,21,13,33,21,9,34,23,2,34,26,13,34,26,10,35,25,4,35,16,13,35,25,10,36,24,6,36,18,14,36,18,8,37,20,1,37,17,14,37,17,7,38,16,4,38,25,14,38};
-
 
52
            
-
 
53
            for(int i=0;i<38;++i) {
-
 
54
                int idx0 = 3*i;
-
 
55
                mesh.geometry.add_vertex(Vec3f(sphere_verts[idx0],sphere_verts[idx0+1],sphere_verts[idx0+2]));
-
 
56
            }
-
 
57
            for(int i=0;i<72;++i) {
-
 
58
                int idx0 = 3*i;
-
 
59
                mesh.geometry.add_face(Vec3i(sphere_indices[idx0]-1,sphere_indices[idx0+1]-1,sphere_indices[idx0+2]-1));
-
 
60
            }
-
 
61
            mesh.compute_normals();
-
 
62
        }
-
 
63
        draw(mesh);
-
 
64
    }
-
 
65
 
-
 
66
    
44
    void draw(const Geometry::IndexedFaceSet& geometry)
67
    void draw(const Geometry::IndexedFaceSet& geometry)
45
    {
68
    {
46
        glBegin(GL_TRIANGLES);
69
        glBegin(GL_TRIANGLES);
47
        for(int i=0;i<geometry.no_faces();i++)
70
        for(int i=0;i<geometry.no_faces();i++)
48
        {
71
        {
Line 232... Line 255...
232
                     &ox, &oy, &oz);
255
                     &ox, &oy, &oz);
233
        
256
        
234
        return Vec3d(ox,oy,oz);
257
        return Vec3d(ox,oy,oz);
235
    }
258
    }
236
 
259
    
-
 
260
    Vec3d world2screen(const Vec3d& p)
-
 
261
    {
-
 
262
        // Enquire about the viewport dimensions
-
 
263
        GLint viewport[4];
-
 
264
        glGetIntegerv(GL_VIEWPORT, viewport);
-
 
265
        // Copy modelview matrix.
-
 
266
        double mvmat[16];
-
 
267
        glGetDoublev(GL_MODELVIEW_MATRIX, mvmat);
-
 
268
        
-
 
269
        // Copy the projection matrix. We assume it is unchanged.
-
 
270
        double prjmat[16];
-
 
271
        glGetDoublev(GL_PROJECTION_MATRIX, prjmat);
-
 
272
        
-
 
273
        // Now unproject the point from screen to world coordinates.
-
 
274
        double ox, oy, oz;
-
 
275
        gluProject(p[0], p[1], p[2],
-
 
276
                   mvmat,prjmat,viewport,
-
 
277
                     &ox, &oy, &oz);
-
 
278
        
-
 
279
        return Vec3d(ox,oy,oz);
-
 
280
    }
-
 
281
 
-
 
282
 
237
    
283
    
238
    
284
    
239
    void draw(const Geometry::AABox& box)
285
    void draw(const Geometry::AABox& box)
240
    {
286
    {
241
        glBegin(GL_QUADS);
287
        glBegin(GL_QUADS);