Subversion Repositories gelsvn

Rev

Rev 324 | Rev 362 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 324 Rev 331
Line 1... Line 1...
1
#include "CGLA/Mat4x4f.h"
1
#include "CGLA/Mat4x4f.h"
2
 
2
 
3
#include "gel_gl.h"
3
#include "gel_gl.h"
4
#include "draw.h"
4
#include "draw.h"
-
 
5
#include "HMesh/FaceCirculator.h"
5
 
6
 
6
using namespace CGLA;
7
using namespace CGLA;
-
 
8
using namespace HMesh;
7
using namespace std;
9
using namespace std;
8
 
10
 
9
namespace 
11
namespace 
10
{
12
{
11
void set_material(const Geometry::Material& material)
13
void set_material(const Geometry::Material& material)
Line 28... Line 30...
28
}
30
}
29
 
31
 
30
namespace GLGraphics
32
namespace GLGraphics
31
{
33
{
32
 
34
 
-
 
35
void draw(Manifold& m, bool per_vertex_norms)
-
 
36
{
-
 
37
		for(FaceIter f=m.faces_begin(); f != m.faces_end(); ++f)
-
 
38
		{
-
 
39
				FaceCirculator fc(f);
-
 
40
				if(!per_vertex_norms) 
-
 
41
						glNormal3fv(normal(f).get());
-
 
42
				glBegin(GL_POLYGON);
-
 
43
				while(!fc.end())
-
 
44
				{
-
 
45
						Vec3f n = normal(fc.get_vertex());
-
 
46
						glNormal3fv(n.get());
-
 
47
						glVertex3fv(fc.get_vertex()->pos.get());
-
 
48
						++fc;
-
 
49
				}
-
 
50
				glEnd();
-
 
51
		}
-
 
52
}
-
 
53
 
-
 
54
 
33
void draw(const Geometry::TriMesh& tm)
55
void draw(const Geometry::TriMesh& tm, bool per_vertex_norms)
34
{
56
{
35
    int old_mat_idx = -1;
57
    int old_mat_idx = -1;
36
    glBegin(GL_TRIANGLES);
58
    glBegin(GL_TRIANGLES);
37
    for(int i=0;i<tm.geometry.no_faces();i++)
59
    for(int i=0;i<tm.geometry.no_faces();i++)
38
    {
60
    {
Line 44... Line 66...
44
            old_mat_idx = tm.mat_idx[i];
66
            old_mat_idx = tm.mat_idx[i];
45
        }
67
        }
46
        Vec3i n_face = tm.normals.face(i);
68
        Vec3i n_face = tm.normals.face(i);
47
        Vec3i g_face = tm.geometry.face(i);
69
        Vec3i g_face = tm.geometry.face(i);
48
        Vec3i t_face = tm.texcoords.face(i);
70
        Vec3i t_face = tm.texcoords.face(i);
-
 
71
 
-
 
72
				if(!per_vertex_norms)
-
 
73
				{
-
 
74
            Vec3f vert0 = tm.geometry.vertex(g_face[0]);
-
 
75
            Vec3f vert1 = tm.geometry.vertex(g_face[1]);
-
 
76
            Vec3f vert2 = tm.geometry.vertex(g_face[2]);
-
 
77
						Vec3f norm = normalize(cross(vert1-vert0, vert2-vert0));
-
 
78
						glNormal3fv(norm.get());
-
 
79
				}
49
        for(int j=0;j<3;j++)
80
        for(int j=0;j<3;j++)
50
        {
81
        {
51
            if(n_face != Geometry::NULL_FACE)
82
						if(per_vertex_norms && n_face != Geometry::NULL_FACE)
52
            {
83
								{
53
                Vec3f norm = tm.normals.vertex(n_face[j]);
84
										Vec3f norm = tm.normals.vertex(n_face[j]);
54
                glNormal3fv(norm.get());
85
										glNormal3fv(norm.get());
55
            }
86
								}
56
            if(t_face != Geometry::NULL_FACE)
87
            if(t_face != Geometry::NULL_FACE)
57
            {
88
            {
58
                Vec3f texc = tm.texcoords.vertex(t_face[j]);
89
                Vec3f texc = tm.texcoords.vertex(t_face[j]);
59
                glTexCoord2fv(texc.get());
90
                glTexCoord2fv(texc.get());
60
            }
91
            }