Subversion Repositories gelsvn

Rev

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

Rev 178 Rev 299
Line -... Line 1...
-
 
1
#include "CGLA/Mat4x4f.h"
-
 
2
 
1
#include "gel_gl.h"
3
#include "gel_gl.h"
2
#include "draw.h"
4
#include "draw.h"
3
 
5
 
4
using namespace CGLA;
6
using namespace CGLA;
5
using namespace std;
7
using namespace std;
Line 23... Line 25...
23
    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, material.shininess);
25
    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, material.shininess);
24
}
26
}
25
 
27
 
26
}
28
}
27
 
29
 
-
 
30
namespace GLGraphics
-
 
31
{
-
 
32
 
28
void draw(const Geometry::TriMesh& tm)
33
void draw(const Geometry::TriMesh& tm)
29
{
34
{
30
    int old_mat_idx = -1;
35
    int old_mat_idx = -1;
31
    glBegin(GL_TRIANGLES);
36
    glBegin(GL_TRIANGLES);
32
    for(int i=0;i<tm.geometry.no_faces();i++)
37
    for(int i=0;i<tm.geometry.no_faces();i++)
Line 58... Line 63...
58
        }
63
        }
59
    }
64
    }
60
    glEnd();
65
    glEnd();
61
    glDisable(GL_TEXTURE_2D);
66
    glDisable(GL_TEXTURE_2D);
62
}
67
}
-
 
68
 
-
 
69
void draw(const Geometry::AABox& box)
-
 
70
{
-
 
71
	glBegin(GL_QUADS);
-
 
72
	Vec3f norm_neg[] = {Vec3f(0,0,-1), Vec3f(-1,0,0), Vec3f(0,-1,0)};
-
 
73
	Vec3f norm_pos[] = {Vec3f(0,0, 1), Vec3f( 1,0,0), Vec3f(0, 1,0)};
-
 
74
	for(int j=0;j<3;++j)
-
 
75
		{
-
 
76
			glNormal3fv(norm_neg[j].get());
-
 
77
			Vec3f p = box.get_pmin();
-
 
78
			glVertex3f(p[0], p[1], p[2]);
-
 
79
			p[(j+1)%3] = box.get_pmax()[(j+1)%3];
-
 
80
			glVertex3f(p[0], p[1], p[2]);
-
 
81
			p[j] = box.get_pmax()[j];
-
 
82
			glVertex3f(p[0], p[1], p[2]);
-
 
83
			p[(j+1)%3] = box.get_pmin()[(j+1)%3];
-
 
84
			glVertex3f(p[0], p[1], p[2]);
-
 
85
		}
-
 
86
	glEnd();
-
 
87
	glBegin(GL_QUADS);
-
 
88
	for(int j=0;j<3;++j)
-
 
89
		{
-
 
90
			glNormal3fv(norm_pos[j].get());
-
 
91
			Vec3f p = box.get_pmax();
-
 
92
			glVertex3f(p[0], p[1], p[2]);
-
 
93
			p[j] = box.get_pmin()[j];
-
 
94
			glVertex3f(p[0], p[1], p[2]);
-
 
95
			p[(j+1)%3] = box.get_pmin()[(j+1)%3];
-
 
96
			glVertex3f(p[0], p[1], p[2]);
-
 
97
			p[j] = box.get_pmax()[j];
-
 
98
			glVertex3f(p[0], p[1], p[2]);
-
 
99
		}
-
 
100
	glEnd();
-
 
101
}
-
 
102
 
-
 
103
void draw(const Geometry::OBox& box)
-
 
104
{
-
 
105
	Mat4x4f m = identity_Mat4x4f();
-
 
106
	copy_matrix(box.get_rotation(), m);
-
 
107
	glPushMatrix();
-
 
108
	glMultMatrixf(m.get());
-
 
109
	draw(box.get_aabox());
-
 
110
	glPopMatrix();
-
 
111
}
-
 
112
 
-
 
113
/** Draw the tree. The first argument is the level counter, the second
-
 
114
	argument is the level at which to stop drawing. */
-
 
115
template <class BoxType>
-
 
116
void draw(const Geometry::BoundingINode<BoxType>& node, int level, int max_level)
-
 
117
{
-
 
118
  if(level == max_level)
-
 
119
  {
-
 
120
	draw(node); 
-
 
121
	return;
-
 
122
  }
-
 
123
  left->draw(level + 1, max_level);
-
 
124
  right->draw(level + 1, max_level);  
-
 
125
}
-
 
126
 
-
 
127
template <class BoxType>
-
 
128
void draw(const Geometry::BoundingLNode<BoxType>& node, int level, int max_level)
-
 
129
{
-
 
130
#if USE_LEAF_BOXES
-
 
131
	draw(node); 
-
 
132
#endif
-
 
133
}
-
 
134
 
-
 
135
template <class BoxType>
-
 
136
void draw(const Geometry::BoundingTree<BoxType>& tree, int max_level)
-
 
137
{
-
 
138
  draw(*tree.root, 0, max_level);
-
 
139
}
-
 
140
 
-
 
141
}
63
 
142