45 for(
int y=0;y<256;++y)
49 for(
int x=0;x<256;++x)
53 GLubyte c = b+(((s+t)&1)&1)*(255-b);
54 pi[0]=pi[1]=pi[2]=c;pi+=3;
87 const Vector3f &v2,
const Vector3f &color,
CENSPixelMap texture)
113 static int tex_coords[12][6] =
135 dx *= halfExtents[0];
136 dy *= halfExtents[1];
137 dz *= halfExtents[2];
142 vertices.push_back( dx+dy+dz);
143 vertices.push_back(-dx+dy+dz);
144 vertices.push_back( dx-dy+dz);
145 vertices.push_back(-dx-dy+dz);
146 vertices.push_back( dx+dy-dz);
147 vertices.push_back(-dx+dy-dz);
148 vertices.push_back( dx-dy-dz);
149 vertices.push_back(-dx-dy-dz);
153 for(
int x=0; x<12; x++)
186 float lat0 = M_PI * (-float(0.5) + (i - 1) * xtag);
187 float z0 = radius*sin(lat0);
188 float zr0 = radius*cos(lat0);
190 float lat1 = M_PI * (-float(0.5) + i * xtag);
191 float z1 = radius*sin(lat1);
192 float zr1 = radius*cos(lat1);
197 float lng = 2 * M_PI * (j - 1) * ytag;
201 Vector3f ver1(x * zr1, y * zr1, z1);
202 Vector3f ver2(x * zr0, y * zr0, z0);
217 const unsigned int *idx,
218 int nvtxs,
int nidxs,
int ntrns,
220 const Vector3f &color,
234 for (
int i = 0; i < ntrns; i++)
245 int index1 = idx[i1];
246 int index2 = idx[i2];
247 int index3 = idx[i3];
248 assert(index1 < nvtxs &&
252 Vector3f v1 = vtx[index1];
253 Vector3f v2 = vtx[index2];
254 Vector3f v3 = vtx[index3];
256 Vector3f axis = (v3-v1).cross(v2-v1);
263 if(texCoords.size()==0)
268 v1.x()/div, v1.z()/div ));
270 v2.x()/div, v2.z()/div ));
272 v3.x()/div, v3.z()/div ));
276 if(texCoords.size()!=0)
287 const Vector3f &color,
300 if(texCoords.size()!=0)
314 static int indices[12][3] =
329 Vector3f v1 = Vector3f(0,0,0);
330 Vector3f v2 = Vector3f(0,0,0);
331 Vector3f v3 = Vector3f(0,0,0);
332 Vector3f normal = Vector3f(0,0,0);
334 Vector2f t1 = Vector2f(0,0);
335 Vector2f t2 = Vector2f(0,0);
336 Vector2f t3 = Vector2f(0,0);
356 glVertex3f(pt0.x(),pt0.y(),pt0.z());
357 glVertex3f(pt2.x(),pt2.y(),pt2.z());
358 glVertex3f(pt1.x(),pt1.y(),pt1.z());
359 glVertex3f(pt3.x(),pt3.y(),pt3.z());
371 glBegin(GL_TRIANGLES);
374 for (
int i=0;i<si;i++)
387 Vector3f normal = (v3-v1).cross(v2-v1);
389 glNormal3f(normal.x(),normal.y(),normal.z());
393 glTexCoord2f(t1[0],t1[1]);
394 glVertex3f (v1.x(), v1.y(), v1.z());
395 glTexCoord2f(t2[0],t2[1]);
396 glVertex3f (v2.x(), v2.y(), v2.z());
397 glTexCoord2f(t3[0],t3[1]);
398 glVertex3f (v3.x(), v3.y(), v3.z());
412 glBegin(GL_QUAD_STRIP);
421 glNormal3f(v1.x(),v1.y(),v1.z());
422 glTexCoord2f(t1[0],t1[1]);
423 glVertex3f(v1.x(),v1.y(),v1.z());
425 glNormal3f(v2.x(),v2.y(),v2.z());
426 glTexCoord2f(t2[0],t2[1]);
427 glVertex3f(v2.x(),v2.y(),v2.z());
440 glBegin(GL_TRIANGLES);
450 for (
unsigned int i = 0; i <
m_gsVertices.size()/3; i++)
454 v2 = org + rot*m_gsVertices[i*3 + 1];
455 v3 = org + rot*m_gsVertices[i*3 + 2];
456 normal = (v3-v1).cross(v2-v1);
462 glNormal3f(normal.x(),normal.y(),normal.z());
463 glTexCoord2f(t1[0],t1[1]);
464 glVertex3f (v1.x(), v1.y(), v1.z());
465 glTexCoord2f(t2[0],t2[1]);
466 glVertex3f (v2.x(), v2.y(), v2.z());
467 glTexCoord2f(t3[0],t3[1]);
468 glVertex3f (v3.x(), v3.y(), v3.z());
486 Vector3f v1 = Vector3f(0,0,0);
487 Vector3f v2 = Vector3f(0,0,0);
488 Vector3f v3 = Vector3f(0,0,0);
489 Vector3f n1 = Vector3f(0,0,0);
500 glBegin(GL_TRIANGLES);
518 glNormal3f(n1.x(),n1.y(),n1.z());
522 if(texture) glTexCoord2f(t1[0],t1[1]);
523 glVertex3f (v1.x(), v1.y(), v1.z());
524 if(texture) glTexCoord2f(t2[0],t2[1]);
525 glVertex3f (v2.x(), v2.y(), v2.z());
526 if(texture) glTexCoord2f(t3[0],t3[1]);
527 glVertex3f (v3.x(), v3.y(), v3.z());
558 GL_RGB,GL_UNSIGNED_BYTE,
561 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
562 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
563 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
564 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
565 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
568 glBindTexture( GL_TEXTURE_2D, 0 );
Computational Embodied Neuroscience Simulator library.
std::vector< Vector3f > Vertices
void setColor(const Vector3f &color)
void addNormal(const Vector3f &normal)
Vector2f & getTexCoord(int texCoord_index)
void buildAsConvex(const Vertices &vertices, const unsigned int *idx, int nvtxs, int nidxs, int ntrns, const TexCoords &texCoords=CENS_NULL_TEXCOORDS, const Vector3f &color=CENS_NULL_COLOR, CENSPixelMap pixmap=CENS_NULL_PIXMAP)
void buildAsSphere(float radius, const Vector3f &color=CENS_NULL_COLOR, CENSPixelMap pixmap=CENS_NULL_PIXMAP)
std::vector< Vector2f > TexCoords
Vector3f & getNormal(int normal_index)
void addTexCoord(const Vector2f &texCoord)
void setNormals(const Vertices &normals)
void copyimage(const GLubyte *source)
GLubyte * m_gsTextureImage
const int GS_SPHERE_LONGS
void buildAsPlane(const Vector3f &orig, const Vector3f &v1, const Vector3f &v2, const Vector3f &color=CENS_NULL_COLOR, CENSPixelMap pixmap=CENS_NULL_PIXMAP)
Use a byte vector as a matrix.
TexCoords & getTexCoords()
void addVertex(const Vector3f &vertex)
const GLubyte * getData() const
void buildAsSoft(int numTriangles, const TexCoords &texCoords=CENS_NULL_TEXCOORDS, const Vector3f &color=CENS_NULL_COLOR, CENSPixelMap pixmap=CENS_NULL_PIXMAP)
void setVertices(const Vertices &vertices)
Vector3f & getVertex(int vertex_index)
void setTexCoords(const TexCoords &texCoords)
void buildAsBox(const Vector3f &halfExtents, const Vector3f &color=CENS_NULL_COLOR, CENSPixelMap pixmap=CENS_NULL_PIXMAP)
const Vector3f & getColor()
void draw(const Vector3f &org, const Matrix3f &rot)