4 #include <OpenGL/glu.h> 13 GLshape::GLshape() : m_shininess(0.2), m_texture(NULL), m_requestCompile(false), m_shadingList(0), m_wireFrameList(0), m_highlight(false)
47 for (
size_t i=0;
i<nvertices;
i++){
57 for (
size_t i=0;
i<ntriangles;
i++){
60 vertexIndices[i*3+2]);
67 for (
size_t i=0;
i<nnormal;
i++){
82 for (
size_t i=0;
i<ncolors;
i++){
102 for (
size_t i=0;
i<len;
i++){
110 for (
size_t i=0;
i<ncoords;
i++){
119 for (
size_t i=0;
i<len;
i++){
136 if (isWireFrameMode){
143 int list = glGenLists(1);
144 glNewList(list, GL_COMPILE);
147 glEnable(GL_CULL_FACE);
149 glDisable(GL_CULL_FACE);
152 for (
int i=0;
i<3;
i++){
158 bool drawTexture =
false;
165 glTexParameteri(GL_TEXTURE_2D,
166 GL_TEXTURE_WRAP_S, GL_REPEAT);
168 glTexParameteri(GL_TEXTURE_2D,
169 GL_TEXTURE_WRAP_S, GL_CLAMP);
172 glTexParameteri(GL_TEXTURE_2D,
173 GL_TEXTURE_WRAP_T, GL_REPEAT);
175 glTexParameteri(GL_TEXTURE_2D,
176 GL_TEXTURE_WRAP_T, GL_CLAMP);
184 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
185 gluBuild2DMipmaps(GL_TEXTURE_2D, 3,
187 format, GL_UNSIGNED_BYTE,
190 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
191 GL_LINEAR_MIPMAP_LINEAR);
192 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
194 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
196 glEnable(GL_TEXTURE_2D);
199 if (!isWireFrameMode) glBegin(GL_TRIANGLES);
201 float red[] = {1,0,0,1};
202 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red);
204 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
m_diffuse);
206 glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS,
m_shininess);
209 if (isWireFrameMode) glBegin(GL_LINE_LOOP);
219 glNormal3f(scale[0]*n[0], scale[1]*n[1], scale[2]*n[2]);
222 for(
int k=0; k < 3; ++k){
232 glNormal3f(scale[0]*n[0], scale[1]*n[1], scale[2]*n[2]);
241 if (isWireFrameMode) glEnd();
243 if (!isWireFrameMode) glEnd();
244 if (drawTexture) glDisable(GL_TEXTURE_2D);
249 glDisable(GL_LIGHTING);
257 glEnable(GL_LIGHTING);
283 std::vector<Eigen::Vector3i> new_triangles;
284 std::vector<int> new_normalIndices, new_textureCoordIndices;
287 for (
int i=0;
i<3;
i++){
294 std::deque<Eigen::Vector3i> dq_triangles;
296 std::deque<Eigen::Vector3i> dq_normals;
299 for (
int j=0;
j<3;
j++){
313 dq_normals.push_back(n);
314 std::deque<Eigen::Vector3i> dq_textureCoordIndices;
316 dq_textureCoordIndices.push_back(
321 while(dq_triangles.size()){
322 Eigen::Vector3i tri = dq_triangles.front();
323 dq_triangles.pop_front();
324 Eigen::Vector3i n = dq_normals.front();
325 dq_normals.pop_front();
328 tc = dq_textureCoordIndices.front();
329 dq_textureCoordIndices.pop_front();
333 for (
int j=0;
j<3;
j++){
335 for (
int k=0; k<3; k++) e[k] *= scale[k];
340 maxidx = l[0] > l[2] ? 0 : 2;
342 maxidx = l[1] > l[2] ? 1 : 2;
344 if (l[maxidx] <= maxEdgeLen){
345 new_triangles.push_back(tri);
347 for (
int j=0;
j<3;
j++) new_normalIndices.push_back(n[
j]);
349 new_normalIndices.push_back(n[0]);
351 for (
int j=0;
j<3;
j++) new_textureCoordIndices.push_back(tc[
j]);
356 dq_triangles.push_back(
357 Eigen::Vector3i(tri[maxidx], vnew, tri[(maxidx+2)%3]));
358 dq_triangles.push_back(
359 Eigen::Vector3i(vnew,tri[(maxidx+1)%3],tri[(maxidx+2)%3]));
364 dq_normals.push_back(
365 Eigen::Vector3i(n[maxidx], nnew, n[(maxidx+2)%3]));
366 dq_normals.push_back(
367 Eigen::Vector3i(nnew,n[(maxidx+1)%3],n[(maxidx+2)%3]));
369 dq_normals.push_back(n);
370 dq_normals.push_back(n);
377 dq_textureCoordIndices.push_back(
378 Eigen::Vector3i(tc[maxidx], tcnew, tc[(maxidx+2)%3]));
379 dq_textureCoordIndices.push_back(
380 Eigen::Vector3i(tcnew, tc[(maxidx+1)%3], tc[(maxidx+2)%3]));
403 o_min = v; o_max = v;
405 for (
int j=0;
j<3;
j++){
406 if (o_min[
j] > v[
j]) o_min[j] = v[j];
407 if (o_max[j] < v[j]) o_max[j] = v[j];
std::vector< int > m_normalIndices
int doCompile(bool isWireFrameMode)
void divideLargeTriangles(double maxEdgeLen)
void setNormals(unsigned int nnormal, const float *normals)
void computeAABB(const hrp::Vector3 &i_p, const hrp::Matrix33 &i_R, hrp::Vector3 &o_min, hrp::Vector3 &o_max)
void setTexture(GLtexture *texture)
std::vector< Eigen::Vector3f > m_vertices
void setTextureCoordinates(unsigned int len, const float *coordinates)
void setTextureCoordIndices(unsigned int len, const int *coordinates)
void setSpecularColor(float r, float g, float b)
void setVertices(unsigned int nvertices, const float *vertices)
hrp::Matrix33 getRotation()
std::vector< Eigen::Vector3f > m_colors
hrp::Vector3 getPosition()
std::vector< Eigen::Vector3i > m_triangles
void setShininess(float s)
std::vector< int > m_textureCoordIndices
std::vector< Eigen::Vector2f, Eigen::aligned_allocator< Eigen::Vector2f > > m_textureCoordinates
def j(str, encoding="cp932")
void setColors(unsigned int ncolors, const float *colors)
std::vector< Eigen::Vector3f > m_normals
void setTriangles(unsigned int ntriangles, const int *vertexIndices)
void setDiffuseColor(float r, float g, float b, float a)
void highlight(bool flag)
void setNormalIndices(unsigned int len, const int *normalIndices)
std::vector< unsigned char > image
void normalPerVertex(bool flag)