コード例 #1
0
ファイル: wall.cpp プロジェクト: Dragmaf93/MarioMaze3d
void Wall::render()
{
    glBindTexture(GL_TEXTURE_2D, textureId);
    glEnable(GL_TEXTURE_2D);
    glMaterialfv(GL_FRONT, GL_DIFFUSE,material);

    glPushMatrix();
    glTranslatef(positionX,positionY,positionZ);


    glColor4f(1.0, 1.0, 1.0, 1.0);
    for (int i=0; i<dimension; i++)
    {
      if (!horizontal)
      {
        if (i > 0)
        glTranslated(5.0, 0.0, 0.0);
      //lato sud
        glBegin(GL_QUADS);
         glNormal3f(0.0f, -1.0f, 0.0f);
      glTexCoord2d (0, 0);
      glVertex3d(0.0, 0.0, 0.0);
      glTexCoord2d (1, 0);
      glVertex3d(5.0, 0.0, 0.0);
      glTexCoord2d (1, 1);
      glVertex3d(5.0, 0.0, HEIGHT);
      glTexCoord2d (0, 1);
      glVertex3d(0.0, 0.0, HEIGHT);

      glColor4f(0.59, 0.46, 0.32, 1.0);

//      glNormal3f(0.0f, 1.0f, 0.0f);
//      glTexCoord2d (0, 0);
      glVertex3d(0.0, 0.0, HEIGHT);
//      glTexCoord2d (1, 0);
      glVertex3d(5.0, 0.0, HEIGHT);
//      glTexCoord2d (1, 1);
      glVertex3d(5.0, 5.0, HEIGHT);
//      glTexCoord2d (0, 1);
      glVertex3d(0.0, 5.0, HEIGHT);

      //lato nord
      glColor4f(1.0, 1.0, 1.0, 1.0);
      glNormal3f(0.0f, 1.0f, 0.0f);
      glTexCoord2d (0, 0);
      glVertex3d(0.0, 5.0, 0.0);
      glTexCoord2d (1, 0);
      glVertex3d(5.0, 5.0, 0.0);
      glTexCoord2d (1, 1);
      glVertex3d(5.0, 5.0, HEIGHT);
      glTexCoord2d (0, 1);
      glVertex3d(0.0, 5.0, HEIGHT);
      glColor4f(0.59, 0.46, 0.32, 1.0);

//      glNormal3f(0.0f, 0.0f, 1.0f);
//      glTexCoord2d (0, 0);
      glVertex3d(0.0, 0.0, 0.0);
//      glTexCoord2d (1, 0);
      glVertex3d(5.0, 0.0, 0.0);
//      glTexCoord2d (1, 1);
      glVertex3d(5.0, 5.0, 0.0);
//      glTexCoord2d (0, 1);
      glVertex3d(0.0, 5.0, 0.0);

      //lato ovest
      glColor4f(1.0, 1.0, 1.0, 1.0);
      glNormal3f(-1.0f, 0.0f, 0.0f);
      glTexCoord2d (0, 0);
      glVertex3d(0.0, 0.0, 0.0);
      glTexCoord2d (0, 1);
      glVertex3d(0.0, 0.0, HEIGHT);
      glTexCoord2d (1, 1);
      glVertex3d(0.0, 5.0, HEIGHT);
      glTexCoord2d (1, 0);
      glVertex3d(0.0, 5.0, 0.0);
//lato est
      glNormal3f(1.0f, 0.0f, 0.0f);
      glTexCoord2d (0, 0);
      glVertex3d(5.0, 0.0, 0.0);
      glTexCoord2d (0, 1);
      glVertex3d(5.0, 0.0, HEIGHT);
      glTexCoord2d (1, 1);
      glVertex3d(5.0, 5.0, HEIGHT);
      glTexCoord2d (1, 0);
      glVertex3d(5.0, 5.0, 0.0);
        glEnd();
      }
      if (horizontal)
      {

        if (i > 0)
      glTranslated(0.0, 5.0, 0.0);

        glBegin(GL_QUADS);
//lato ovest
        glNormal3f(-1.0f, 0.0f, 0.0f);
      glTexCoord2d (0, 0);
      glVertex3d(0.0, 0.0, 0.0);
      glTexCoord2d (1, 0);
      glVertex3d(0.0, 5.0, 0.0);
      glTexCoord2d (1, 1);
      glVertex3d(0.0, 5.0, HEIGHT);
      glTexCoord2d (0, 1);
      glVertex3d(0.0, 0.0, HEIGHT);

      glColor4f(0.59, 0.46, 0.32, 1.0);
//      glNormal3f(0.0f, 1.0f, 0.0f);
//      glTexCoord2d (0, 0);
      glVertex3d(0.0, 0.0, HEIGHT);
//      glTexCoord2d (1, 0);
      glVertex3d(0.0, 5.0, HEIGHT);
//      glTexCoord2d (1, 1);
      glVertex3d(5.0, 5.0, HEIGHT);
//      glTexCoord2d (0, 1);
      glVertex3d(5.0, 0.0, HEIGHT);
      glColor4f(1.0, 1.0, 1.0, 1.0);

      //lato est
      glNormal3f(1.0f, 0.0f, 0.0f);
      glTexCoord2d (0, 0);
      glVertex3d(5.0, 0.0, 0.0);
      glTexCoord2d (1, 0);
      glVertex3d(5.0, 5.0, 0.0);
      glTexCoord2d (1, 1);
      glVertex3d(5.0, 5.0, HEIGHT);
      glTexCoord2d (0, 1);
      glVertex3d(5.0, 0.0, HEIGHT);

      glColor4f(0.59, 0.46, 0.32, 1.0);
//    glNormal3f(0.0f, 0.0f, 1.0f);
//     glTexCoord2d (0, 0);
      glVertex3d(0.0, 0.0, 0.0);
//      glTexCoord2d (1, 0);
      glVertex3d(0.0, 5.0, 0.0);
//      glTexCoord2d (1, 1);
      glVertex3d(5.0, 5.0, 0.0);
//      glTexCoord2d (0, 1);
      glVertex3d(5.0, 0.0, 0.0);

      //lato sud
      glColor4f(1.0, 1.0, 1.0, 1.0);
      glNormal3f(0.0f, -1.0f, 0.0f);
      glTexCoord2d (0, 0);
      glVertex3d(0.0, 0.0, 0.0);
      glTexCoord2d (0, 1);
      glVertex3d(0.0, 0.0, HEIGHT);
      glTexCoord2d (1, 1);
      glVertex3d(5.0, 0.0, HEIGHT);
      glTexCoord2d (1, 0);
      glVertex3d(5.0, 0.0, 0.0);
//lato nord
      glNormal3f(0.0f, 1.0f, 0.0f);
      glTexCoord2d (0, 0);
      glVertex3d(0.0, 5.0, 0.0);
      glTexCoord2d (0, 1);
      glVertex3d(0.0, 5.0, HEIGHT);
      glTexCoord2d (1, 1);
      glVertex3d(5.0, 5.0, HEIGHT);
      glTexCoord2d (1, 0);
      glVertex3d(5.0, 5.0, 0.0);
        glEnd();
      }

    }

    glPopMatrix();
    glDisable(GL_TEXTURE_2D);
}
コード例 #2
0
ファイル: render_helper.c プロジェクト: SeMo810/CSCI-4229
/* Render a multi-colored cube at the given position, scale, and rotation. */
void rh_draw_cube(VEC3 pos, VEC3 scale, VEC3 rot, TEXTURE *texture)
{
  glPushMatrix();
  _apply_transforms(pos, scale, rot);
  if (texture)
  {
    glEnable(GL_TEXTURE_2D);
    tex_use_texture(*texture);
  }

  glBegin(GL_QUADS);

    /* +X face */
    if (texture)
      glColor3d(1, 1, 1);
    else
      glColor3d(1, 0, 0); /* Red */
    glNormal3d(1.0, 0.0, 0.0);
    if (texture) glTexCoord2d(0, 0);
    glVertex3d(0.5, 0.5, 0.5);
    if (texture) glTexCoord2d(1, 0);
    glVertex3d(0.5, 0.5, -0.5);
    if (texture) glTexCoord2d(1, 1);
    glVertex3d(0.5, -0.5, -0.5);
    if (texture) glTexCoord2d(0, 1);
    glVertex3d(0.5, -0.5, 0.5);
    /* -X face */
    if (texture)
      glColor3d(1, 1, 1);
    else
      glColor3d(0, 1, 0); /* Green */
    glNormal3d(-1.0, 0.0, 0.0);
    if (texture) glTexCoord2d(0, 0);
    glVertex3d(-0.5, 0.5, -0.5);
    if (texture) glTexCoord2d(1, 0);
    glVertex3d(-0.5, 0.5, 0.5);
    if (texture) glTexCoord2d(1, 1);
    glVertex3d(-0.5, -0.5, 0.5);
    if (texture) glTexCoord2d(0, 1);
    glVertex3d(-0.5, -0.5, -0.5);

    /* +Y face */
    if (texture)
      glColor3d(1, 1, 1);
    else
      glColor3d(0, 0, 1); /* Blue */
    glNormal3d(0.0, 1.0, 0.0);
    if (texture) glTexCoord2d(0, 0);
    glVertex3d(-0.5, 0.5, -0.5);
    if (texture) glTexCoord2d(1, 0);
    glVertex3d(0.5, 0.5, -0.5);
    if (texture) glTexCoord2d(1, 1);
    glVertex3d(0.5, 0.5, 0.5);
    if (texture) glTexCoord2d(0, 1);
    glVertex3d(-0.5, 0.5, 0.5);
    /* -Y face */
    if (texture)
      glColor3d(1, 1, 1);
    else
      glColor3d(1, 1, 0); /* Yellow */
    glNormal3d(0.0, -1.0, 0.0);
    if (texture) glTexCoord2d(0, 0);
    glVertex3d(0.5, -0.5, -0.5);
    if (texture) glTexCoord2d(1, 0);
    glVertex3d(-0.5, -0.5, -0.5);
    if (texture) glTexCoord2d(1, 1);
    glVertex3d(-0.5, -0.5, 0.5);
    if (texture) glTexCoord2d(0, 1);
    glVertex3d(0.5, -0.5, 0.5);

    /* +Z face */
    if (texture)
      glColor3d(1, 1, 1);
    else
      glColor3d(1, 0, 1); /* Magenta */
    glNormal3d(0.0, 0.0, 1.0);
    if (texture) glTexCoord2d(0, 0);
    glVertex3d(-0.5, 0.5, 0.5);
    if (texture) glTexCoord2d(1, 0);
    glVertex3d(0.5, 0.5, 0.5);
    if (texture) glTexCoord2d(1, 1);
    glVertex3d(0.5, -0.5, 0.5);
    if (texture) glTexCoord2d(0, 1);
    glVertex3d(-0.5, -0.5, 0.5);
    /* -Z face */
    if (texture)
      glColor3d(1, 1, 1);
    else
      glColor3d(0, 1, 1); /* Cyan */
    glNormal3d(0.0, 0.0, -1.0);
    if (texture) glTexCoord2d(0, 0);
    glVertex3d(0.5, 0.5, -0.5);
    if (texture) glTexCoord2d(1, 0);
    glVertex3d(-0.5, 0.5, -0.5);
    if (texture) glTexCoord2d(1, 1);
    glVertex3d(-0.5, -0.5, -0.5);
    if (texture) glTexCoord2d(0, 1);
    glVertex3d(0.5, -0.5, -0.5);

  glEnd();

  if (texture)
  {
    tex_clear_texture();
    glDisable(GL_TEXTURE_2D);
  }

  glPopMatrix();
}
コード例 #3
0
ファイル: glwidget.cpp プロジェクト: RSATom/Qt
GLuint GLWidget::makeGear(const GLfloat *reflectance, GLdouble innerRadius,
                          GLdouble outerRadius, GLdouble thickness,
                          GLdouble toothSize, GLint toothCount)
{
    GLuint list = glGenLists(1);
    glNewList(list, GL_COMPILE);
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, reflectance);

    GLdouble r0 = innerRadius;
    GLdouble r1 = outerRadius - toothSize / 2.0;
    GLdouble r2 = outerRadius + toothSize / 2.0;
    GLdouble toothAngle = 2 * M_PI / toothCount;
    GLdouble delta = toothAngle / 4.0;
    GLdouble z = thickness / 2.0;

    glShadeModel(GL_FLAT);

    for (int i = 0; i < 2; ++i) {
        GLdouble sign = (i == 0) ? +1.0 : -1.0;

        glNormal3d(0.0, 0.0, sign);

        glBegin(GL_QUAD_STRIP);
        for (int j = 0; j <= toothCount; ++j) {
            GLdouble angle = j * toothAngle;
            glVertex3d(r0 * cos(angle), r0 * sin(angle), sign * z);
            glVertex3d(r1 * cos(angle), r1 * sin(angle), sign * z);
            glVertex3d(r0 * cos(angle), r0 * sin(angle), sign * z);
            glVertex3d(r1 * cos(angle + 3 * delta), r1 * sin(angle + 3 * delta), sign * z);
        }
        glEnd();

        glBegin(GL_QUADS);
        for (int j = 0; j < toothCount; ++j) {
            GLdouble angle = j * toothAngle;
            glVertex3d(r1 * cos(angle), r1 * sin(angle), sign * z);
            glVertex3d(r2 * cos(angle + delta), r2 * sin(angle + delta), sign * z);
            glVertex3d(r2 * cos(angle + 2 * delta), r2 * sin(angle + 2 * delta), sign * z);
            glVertex3d(r1 * cos(angle + 3 * delta), r1 * sin(angle + 3 * delta), sign * z);
        }
        glEnd();
    }

    glBegin(GL_QUAD_STRIP);
    for (int i = 0; i < toothCount; ++i) {
        for (int j = 0; j < 2; ++j) {
            GLdouble angle = (i + j / 2.0) * toothAngle;
            GLdouble s1 = r1;
            GLdouble s2 = r2;
            if (j == 1)
                qSwap(s1, s2);

            glNormal3d(cos(angle), sin(angle), 0.0);
            glVertex3d(s1 * cos(angle), s1 * sin(angle), +z);
            glVertex3d(s1 * cos(angle), s1 * sin(angle), -z);

            glNormal3d(s2 * sin(angle + delta) - s1 * sin(angle),
                       s1 * cos(angle) - s2 * cos(angle + delta), 0.0);
            glVertex3d(s2 * cos(angle + delta), s2 * sin(angle + delta), +z);
            glVertex3d(s2 * cos(angle + delta), s2 * sin(angle + delta), -z);
        }
    }
    glVertex3d(r1, 0.0, +z);
    glVertex3d(r1, 0.0, -z);
    glEnd();

    glShadeModel(GL_SMOOTH);

    glBegin(GL_QUAD_STRIP);
    for (int i = 0; i <= toothCount; ++i) {
        GLdouble angle = i * toothAngle;
        glNormal3d(-cos(angle), -sin(angle), 0.0);
        glVertex3d(r0 * cos(angle), r0 * sin(angle), +z);
        glVertex3d(r0 * cos(angle), r0 * sin(angle), -z);
    }
    glEnd();

    glEndList();

    return list;
}
コード例 #4
0
void OpenGLMethods::paintCubeToOpenGLList(int xLow, int yLow, int zLow, int xHigh, int yHigh, int zHigh,
    int listID, bool paintFullCube, int scale, int offsetX, int offsetY, int offsetZ,
    int r, int g, int b, bool beginList, bool endList)
{
  GLUquadricObj* pQuadric = gluNewQuadric();

  if(beginList)
    glNewList(listID, GL_COMPILE_AND_EXECUTE);

  float xH = transformCoordinates(scale, offsetX, xHigh);
  float yH = transformCoordinates(scale, offsetY, yHigh);
  float zH = transformCoordinates(scale, offsetZ, zHigh);
  float xL = transformCoordinates(scale, offsetX, xLow);
  float yL = transformCoordinates(scale, offsetY, yLow);
  float zL = transformCoordinates(scale, offsetZ, zLow);

  glBegin(GL_LINE_LOOP);
  glColor3ub((unsigned char)r, (unsigned char)g, (unsigned char)b);
  glVertex3d(xL, yL, zL);
  glVertex3d(xH, yL, zL);
  glVertex3d(xH, yH, zL);
  glVertex3d(xL, yH, zL);
  glEnd();

  if(paintFullCube)
  {
    glBegin(GL_LINE_LOOP);
    glVertex3d(xL, yL, zH);
    glVertex3d(xH, yL, zH);
    glVertex3d(xH, yH, zH);
    glVertex3d(xL, yH, zH);
    glEnd();

    glBegin(GL_LINES);

    glVertex3d(xL, yL, zL);
    glVertex3d(xL, yL, zH);
    glVertex3d(xH, yL, zL);
    glVertex3d(xH, yL, zH);
    glVertex3d(xH, yH, zL);
    glVertex3d(xH, yH, zH);
    glVertex3d(xL, yH, zL);
    glVertex3d(xL, yH, zH);

    glEnd();
  }
  if(endList)
    glEndList();

  gluDeleteQuadric(pQuadric);
}
コード例 #5
0
void display(void)
{	
	//define the material of the object
	float no_mat[] = { 0.0, 0.0, 0.0, 1.0 };
	float mat_red[] = { 1.0, 0.2, 0.1, 1.0 };
	float mat_orange[] = { 0.7, 0.5, 0.1, 1.0 };
	float mat_yellow[] = { 0.8, 0.8, 0.1, 1.0 };
	float mat_green[] = { 0.0, 1.0, 0.0, 1.0 };
	float mat_blue[] = { 0.1, 0.1, 0.8, 1.0 };
	float mat_purple[] = { 0.8, .1, 0.8, 1.0 };
	float no_shininess[] = { 0.0 };
	float low_shininess[] = { 5.0 };
	float high_shininess[] = { 100.0 };
	float mat_bright[] = {1.0, 0.7, 0.1, 1.0};
	
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glColor3f(1.0, 1.0, 1.0);    //set color of rectangle
	
	glTranslatef(0.0, 0.0, -6.0);    //set origin of shape (5 units into the distance)
	
	glPushMatrix(); 
	glTranslatef(-2.0, 0.0, -2.0); 
	glLightfv(GL_LIGHT1, GL_POSITION, pos); //spot light1
	glRotatef(rotX1, 1.0, 0.0, 0.0); 
	//glutSolidSphere(0.8, 10, 10);
	glMaterialfv(GL_FRONT, GL_AMBIENT, mat_blue);
	glMaterialfv(GL_FRONT, GL_SPECULAR, mat_orange); 
	glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess); 
	glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_green);
	glMaterialfv(GL_FRONT, GL_EMISSION, no_mat); 
	glutSolidSphere(0.45, 10, 10);
	//glutSolidCube(.5);	
	glRotatef(rotX1, 1.0, 0.0, 0.0); 
	glTranslatef(.0, 1.0, .0);
	//glutWireCube(.1);	   
	glMaterialfv(GL_FRONT, GL_AMBIENT, mat_orange);
	glMaterialfv(GL_FRONT, GL_SPECULAR, mat_green); 
	glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess); 
	glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_blue);
	glMaterialfv(GL_FRONT, GL_EMISSION, no_mat); 
	glutSolidCube(.1);	
	glPopMatrix(); 
	
	glPushMatrix(); 
	glTranslatef(2.0, 0.0, -2.0); 
	glLightfv(GL_LIGHT2, GL_POSITION, pos); //spot light2
	glRotatef(-rotX1, 1.0, 0.0, 0.0); 
	//	glutSolidTorus(0.3, 0.8, 32, 32);
	glMaterialfv(GL_FRONT, GL_AMBIENT, mat_red);
	glMaterialfv(GL_FRONT, GL_SPECULAR, mat_orange); 
	glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess); 
	glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_orange);
	glMaterialfv(GL_FRONT, GL_EMISSION, no_mat); 
	glutSolidSphere(0.45, 10, 10);
	//glutSolidCube(.5);	
	glPopMatrix(); 
	
	glPushMatrix(); 		
	glTranslatef(2.0, 0.0, -2.0); 
	glRotatef(-rotX1, .0, .0, 1.0); 
	glTranslatef(.0, 1.0, .0);
	glRotatef(-rotX1, .0, 1.0, .0); 
	glMaterialfv(GL_FRONT, GL_AMBIENT, mat_purple);
	glMaterialfv(GL_FRONT, GL_SPECULAR, mat_orange); 
	glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess); 
	glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_blue);
	glMaterialfv(GL_FRONT, GL_EMISSION, no_mat); 	
	glutSolidCube(.2);	
	glPopMatrix(); 
	
	glPushMatrix(); 
//	glTranslatef(-3.0, -3, -2.0); 
//	glRotatef(rotX1, 1.0, 0.0, 0.0); 
	glTranslatef(.0, 1, .0); 
	glRotatef(rotX1, .0, 0.0, 1.0); 
	glTranslatef(2.5, .1, 0.0);
	glLightfv(GL_LIGHT0, GL_POSITION, pos); // sun light
	glMaterialfv(GL_FRONT, GL_AMBIENT, mat_red);
	glMaterialfv(GL_FRONT, GL_SPECULAR, mat_orange); 
	glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess); 
	glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_red);
	glMaterialfv(GL_FRONT, GL_EMISSION, mat_bright); 
	glutSolidSphere(0.15, 10, 10);	 // Sun
	glPopMatrix();            //end matrix
 	
	//printNormal(1.0, 0.0, 0.0, 0.0, 1.0, 0.0);
	
	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_yellow);
	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_red); 
	glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, low_shininess); 
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_purple);
	glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, no_mat); 
	
	for (int z = -14; z <= 14; z ++){		
		
		glBegin(GL_QUAD_STRIP);
		for (int x = -8; x <= 8; x ++){

			vec3 p0; vec3 p1; vec3 p2; 
			p0.x = x;
			p0.y = -2;
			p0.z = z;		
			p1.x = x;
			p1.y = -2;
			p1.z = z + 1;
			p2.x = x + 1;
			p2.y = -2;
			p2.z = z;
			vec3 norm = calulateVector(p0, p1, p2);
			glNormal3d(norm.x, norm.y, norm.z);
			
			glVertex3d(x, sin(z+1) * (sin(3.3*x))-2, z+1);
			glVertex3d(x, sin(z) * (sin(3.3*x))-2, z);		
		}
		glEnd();

	}	
	
	glutSwapBuffers();
	
	rotX1 += .05;	
}
コード例 #6
0
ファイル: draw.cpp プロジェクト: jfloreza/UCM
void draw_solid_tube (double len, double rt, double rb, int nfaces, bool smooth)
{
	glEnable(GL_COLOR_MATERIAL);
	if(App->wireframe){glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);}
	else
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	
   if ( rb<=0 ) rb=MINRADIUS;
   if ( rt<=0 ) rt=MINRADIUS;
   if ( nfaces<3 ) nfaces = 3;
   glColor3f(0.8, 1.5, 0.3);
   
   // compute vertical axis:
   double dang = (2.0*PI)/double(nfaces);
   double ang = 0;

   // we will use len as half the length:
   len = len/2;

   // initial points:
   double ibx=rb, iby=-len, ibz=0; // bottom
   double itx=rt, ity=+len, itz=0; // top

   // current points start as the initial points:
   double cbx=ibx, cby=iby, cbz=ibz; // bottom
   double ctx=itx, cty=ity, ctz=itz; // top

   // declare the "next points" to form the cylinder lines:
   double nbx, nby, nbz; // bottom
   double ntx, nty, ntz; // top

   //declare vector variables
   double utx, uty, utz, vtx, vty, vtz;
   double px, py, pz, qx, qy, qz;

   //declar normal vector variables
   double notx, noty, notz;
   double pnx, pny, pnz;

   //lengths for normals
   double tlen, plen;

   // compute the points all around body:
   int i=1;
   while(i <= nfaces)
   { // rotate the current points:
        if ( i<nfaces ) // normal rotation for intermediate points
         { ang += dang;
           double ca = cos(ang);
           double sa = sin(ang);
           nbx=ca*rb; nby=cby; nbz=sa*rb;
           ntx=ca*rt; nty=cty; ntz=sa*rt;
         }
        else // to make a perfect closure, the last points are exactly the first ones
         { nbx=ibx; nby=iby; nbz=ibz;
           ntx=itx; nty=ity; ntz=itz;
         }

		//Calculating vectors and normals for upper and lower parts
		utx = ntx - ctx;
		uty = nty - cty;
		utz = ntz - ctz;

		vtx = 0 - ctx;
		vty = len - cty;
		vtz = 0 - ctz;

		//Normal for faces
		px = nbx - cbx;
		py = nby - cby;
		pz = nbz - cbz;

		qx = ctx - cbx;
		qy = cty - cby;
		qz = ctz - cbz;

		//Cross products for normal vectors U X V
		notx = (uty * vtz) - (utz * vty);
		noty = (utz * vtx) - (utx * vtz);
		notz = (utx * vty) - (uty * vtx);
		tlen = sqrt( (notx * notx) + (noty * noty) + (notz * notz) );

		//Polygon is P X Q
		pnx = (px * qz) - (pz * qy);
		pny = (pz * qx) - (px * qz);
		pnz = (px * qy) - (py * qx);
		plen = sqrt( (pnx * pnx) + (pny * pny) + (pnz * pnz) );
		

		//Normalize, checking for division by zero
		if(tlen == 0)tlen = 1;
		notx /= tlen;
		noty /= tlen;
		notz /= tlen;

		if(plen == 0)plen = 1;
		px /= plen;
		py /= plen;
		pz /= plen; //*/


		/*/Testing for normal vector
		glBegin( GL_LINES );
		glVertex3d(0, 0, 0);
		glVertex3d(px, py, pz);
		glEnd(); //*/

		//Start drawing
		glBegin ( GL_TRIANGLES );
		glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);

		
		if(!smooth)
		{
			//draw top polygons
			glNormal3d(-notx, -noty, -notz);
			glVertex3d(ctx, cty, ctz);
			glVertex3d(ntx, nty, ntz);
			glVertex3d(0, len, 0);

			//draw bottom polygons
			glNormal3d(notx, noty, notz);
			glVertex3d(cbx, cby, cbz);
			glVertex3d(nbx, nby, nbz);
			glVertex3d(0, -len, 0);

			//draw faces
			glNormal3d(-pnx, -pny, -pnz);

			glVertex3d(ctx, cty, ctz);
			glVertex3d(ntx, nty, ntz);
			glVertex3d(cbx, cby, cbz);

			glVertex3d(cbx, cby, cbz);
			glVertex3d(nbx, nby, nbz);
			glVertex3d(ntx, nty, ntz);
		}

		if(smooth)
		{
			//draw top polygons
			glNormal3d(ctx, cty, ctz);
			glVertex3d(ctx, cty, ctz);

			glNormal3d(ntx, nty, ntz);
			glVertex3d(ntx, nty, ntz);

			glNormal3d(0, len, 0);
			glVertex3d(0, len, 0);

			//draw bottom polygons
			glNormal3d(cbx, cby, cbz);
			glVertex3d(cbx, cby, cbz);

			glNormal3d(nbx, nby, nbz);
			glVertex3d(nbx, nby, nbz);

			glNormal3d(0, -len, 0);
			glVertex3d(0, -len, 0);

			//draw faces
			glNormal3d(ctx, cty, ctz);
			glVertex3d(ctx, cty, ctz);

			glNormal3d(ntx, nty, ntz);
			glVertex3d(ntx, nty, ntz);

			glNormal3d(cbx, cby, cbz);
			glVertex3d(cbx, cby, cbz);

			glNormal3d(cbx, cby, cbz);
			glVertex3d(cbx, cby, cbz);

			glNormal3d(nbx, nby, nbz);
			glVertex3d(nbx, nby, nbz);

			glNormal3d(ntx, nty, ntz);
			glVertex3d(ntx, nty, ntz);
		}

        // update current points:
        cbx=nbx; cby=nby; cbz=nbz;
        ctx=ntx; cty=nty; ctz=ntz;
        
        // increment side counter:
        i++;
      }

   // done
   glEnd();

   glBegin(GL_POINTS);
   glColor3d(1, 1, 1);
   glVertex3d(8.0, 8.0, 8.0);
   glEnd();

}
コード例 #7
0
/*!
    \fn Processor::Render(int persistence,bool al,bool pc,bool vo,bool sk,bool mo,bool allindflag,int pnum,int rank,bool wf,bool fs)
 */
void Processor::Render(int persistence,bool alphaShape,bool allPockets,bool onlyPockets,bool onlyVoids,bool skinSurface,bool mouths,bool allindflag,int pnum,int rank,bool wireFrame,
                       bool alphaSkinSurface,bool alphaSkinWireFrame,bool smoothShading,bool skinWireFrame,bool pocketWireFrame, bool powerDiag,
                       bool cHull, bool cHullWF, bool cHullNorm, bool showPath, bool showSpaceFill)
{
        glEnable(GL_NORMALIZE);
        if(alcx)
        {
                alcx->Render(rank,alphaShape,wireFrame,alphaSkinSurface,smoothShading,alphaSkinWireFrame);

                if (onlyVoids || onlyPockets || allPockets)
                {
                        if(allindflag)
                        {
                                pocket->Render(alcx->delcx,vertexList,PocketNMouths,allPockets,onlyPockets,onlyVoids,skinSurface,persistence,rank,smoothShading,skinWireFrame,mouths,pocketWireFrame);
                        }
                        else
                        {
                                pocket->RenderSingle(alcx->delcx,vertexList,PocketNMouths,allPockets,onlyPockets,onlyVoids,skinSurface,persistence,rank,pnum,smoothShading,skinWireFrame,mouths,pocketWireFrame);
                        }
                }
                if (mouths)
                {
                        if (!onlyVoids)
                        {
                                if(allindflag)
                                {
                                        mouth->Render(alcx->delcx,vertexList,persistence);
                                }
                                else
                                {
                                        mouth->RenderMouthOfPocket(alcx->delcx,vertexList,persistence,pnum);
                                }
                        }
                }

            glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, LightMaterial::MatAmb[3]);
            glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, LightMaterial::MatDiff[3]);
            glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, LightMaterial::MatSpec[3]);
            glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, LightMaterial::MatShin[3]);
            glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, LightMaterial::MatEmission);

            if(proteinRenderer->init() && showSpaceFill){
                proteinRenderer->render();
            }
            powerDiagram->render(powerDiag, showPath);

            glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, LightMaterial::MatAmb[3]);
            glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, LightMaterial::MatDiff[3]);
            glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, LightMaterial::MatSpec[3]);
            glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, LightMaterial::MatShin[3]);
            glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, LightMaterial::MatEmission);

            glEnable(GL_COLOR_MATERIAL);
            if(cHull){
                glLineWidth(1);
                glColor3d(0.2, 0.6, 0.2);
                if(cHullWF){
                    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
                }else{
                    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
                }

                if (glIsList(cHullId) == GL_FALSE){
                    cHullId = glGenLists(1);
                    glNewList(cHullId, GL_COMPILE_AND_EXECUTE);

                    glBegin(GL_TRIANGLES);
                    for(int i=1; i< alcx->delcx->DeluanayTrigs.size(); i++){
                        Triangle tri = alcx->delcx->DeluanayTrigs[i];
                        if(tri.Hull){
                            glNormal3d(tri.Normal->X, tri.Normal->Y, tri.Normal->Z);
                            for(int j=1;j<4;j++){
                                Vector3 v = alcx->vertexList[tri.Corners[j]].getCoordVector();
                                glVertex3d(v.X, v.Y, v.Z);
                            }
                        }
                    }
                    glEnd();

                    glEndList();
                } else {
                    glCallList(cHullId);
                }
                if(cHullNorm){
                    if(glIsList(cHullNormId) == GL_FALSE){
                        cHullNormId = glGenLists(1);
                        glNewList(cHullNormId, GL_COMPILE_AND_EXECUTE);

                        //======= Drawing Normals of Convex Hull Tris =================

                        glColor3d(1,0,0);
                        glLineWidth(2);
                        glBegin(GL_LINES);
                        for(int i=1; i< alcx->delcx->DeluanayTrigs.size(); i++){
                            Triangle tri = alcx->delcx->DeluanayTrigs[i];
                            if(tri.Hull){
                                glNormal3d(tri.Normal->X, tri.Normal->Y, tri.Normal->Z);
                                Vector3 center;
                                for(int j=1; j<4; j++){
                                    Vertex v = alcx->vertexList[tri.Corners[j]];
                                    Vector3 coord = v.getCoordVector();
                                    Vector3::Sum(&center, &coord, &center);
                                }
                                Vector3::Scale(&center, &center, 1/3.0);
                                glVertex3d(center.X, center.Y, center.Z);
                                Vector3::Sum(&center, tri.Normal, &center);
                                Vector3::Sum(&center, tri.Normal, &center);
                                glVertex3d(center.X, center.Y, center.Z);
                            }
                        }
                        glEnd();

                        glEndList();
                    } else {
                        glCallList(cHullNormId);
                    }
                }
            }
            glDisable(GL_COLOR_MATERIAL);
            glDisable(GL_NORMALIZE);
        }
}
コード例 #8
0
static void display(void)
{
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );

    glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();
	glTranslatef( 0.0, 0.0, - camera_distance );
	glRotatef( - camera_pitch, 1.0, 0.0, 0.0 );
	glRotatef( - camera_yaw, 0.0, 1.0, 0.0 );

	float  light0_position[] = { 10.0, 10.0, 10.0, 1.0 };
	glLightfv( GL_LIGHT0, GL_POSITION, light0_position );

	float  size = 1.5f;
	int  num_x = 10, num_z = 10;
	double  ox, oz;

	// the tiled floor
	glBegin( GL_QUADS );
		glNormal3d( 0.0, 1.0, 0.0 );
		ox = -(num_x * size) / 2;
		for ( int x=0; x<num_x; x++, ox+=size )
		{
			oz = -(num_z * size) / 2;
			for ( int z=0; z<num_z; z++, oz+=size )
			{
				if ( ((x + z) % 2) == 0 )
					glColor3f( 1.0, 1.0, 1.0 );
				else
					glColor3f( 0.7, 0.7, 0.7 );
				glVertex3d( ox, 0.0, oz );
				glVertex3d( ox, 0.0, oz+size );
				glVertex3d( ox+size, 0.0, oz+size );
				glVertex3d( ox+size, 0.0, oz );
			}
		}
	glEnd();

#ifdef TEST_IK
	// the target
	if (bvhani){
		static GLUquadricObj *quad_obj = gluNewQuadric();
		glPushMatrix();		
		glTranslated( target_x, target_y, target_z );
		glColor3f( 1.0f, 0.788f, 0.055f );
		gluSphere(quad_obj, 2*animation_scale, 16, 8);	
		glPopMatrix();
	}
#endif

	glColor3f( 1.0f, 0.0f, 0.0f );
	if ( bvhani )
		bvhani->renderFigure(frame_no, animation_scale, animation_flag);				

	char messages[3][64];
	if ( bvhani ) {
		sprintf( messages[0], "Time  : %.2fs", animation_time );
        sprintf( messages[1], "Frame : %d", frame_no );        
        sprintf( messages[2], "Animation : %s", animation_flag_string[animation_flag] );
        drawMessage(0, messages, 3);
    } else {
		sprintf( messages[0], "Press L key to load a BVH file" );
        drawMessage(0, messages, 1);
    }    
    

    glutSwapBuffers();
}
コード例 #9
0
ファイル: Platforms.cpp プロジェクト: XUbiker/LonelyIsland
GLuint Platform::MakePlatform (double x, double y, double z)
{
	GLuint list = glGenLists(1);
	glNewList(list, GL_COMPILE);
		glColor3d(1.0, 0.0, 0.0);
		glBegin(GL_QUAD_STRIP);
		// 1-2-3-4
		glVertex3d (x + w/2, y - h/2, z + w/2);
		glVertex3d (x + w/2, y + h/2, z + w/2);
		glVertex3d (x - w/2, y - h/2, z + w/2);
		glVertex3d (x - w/2, y + h/2, z + w/2);
		// 4-3-7-8
		glVertex3d (x - w/2, y - h/2, z - w/2);
		glVertex3d (x - w/2, y + h/2, z - w/2);
		// 8-7-6-5
		glVertex3d (x + w/2, y - h/2, z - w/2);
		glVertex3d (x + w/2, y + h/2, z - w/2);
		// 5-6-2-1
		glVertex3d (x + w/2, y - h/2, z + w/2);
		glVertex3d (x + w/2, y + h/2, z + w/2);
		glEnd();
		glBegin(GL_QUADS);
		// 2-6-7-3
		glVertex3d (x + w/2, y + h/2, z + w/2);
		glVertex3d (x + w/2, y + h/2, z - w/2);
		glVertex3d (x - w/2, y + h/2, z - w/2);
		glVertex3d (x - w/2, y + h/2, z + w/2);
		// 1-4-8-5
		glVertex3d (x + w/2, y - h/2, z + w/2);
		glVertex3d (x - w/2, y - h/2, z + w/2);
		glVertex3d (x - w/2, y - h/2, z - w/2);
		glVertex3d (x + w/2, y - h/2, z - w/2);
		glEnd();
	glEndList();
	return list;
}
コード例 #10
0
void 
SMRBasicRenderer::draw ()
{
	GLuint Shader = 0;
	// load/get shader info
	switch(m_renderStyle)
	{
	case toon:
		Shader = getShader("toonShader");
		break;
	case gooch:
		Shader = getShader("goochShader");
		break;
	}

	bool useShader = isGLSLSupported() && Shader ;
	SMRVector3 tmp, tmp2;
		
	glPushAttrib (GL_POLYGON_BIT);
	glEnable (GL_CULL_FACE);

	// first switch to absolute if needed
	m_skeleton->setMode(ABSOLUTEMODE);	

	glPushMatrix();
	glScaled(m_scaleFactor,m_scaleFactor,m_scaleFactor);

	if (useShader)
	{
		if( GLEW_VERSION_2_0 )
			glUseProgram( Shader );
		else if( GLEW_VERSION_1_5 ) 
			glUseProgramObjectARB( Shader );

		glPolygonMode (GL_BACK, GL_FILL);
		glCullFace (GL_FRONT);
		double size = 0.0001 ;
		for(unsigned int i = 0; i < m_skeleton->getNumJoints(); ++i ) {
			if( m_skeleton->getJoint(i)->getParentName()!="") {
				tmp = m_skeleton->getJoint(i)->getPosition();
				tmp2 = m_skeleton->getJointByName(m_skeleton->getJoint(i)->getParentName())->getPosition();
				size  = drawCylinder(tmp2,tmp,16,size,0.1f);
				if (m_skeleton->getJoint(i)->isEndJoint() )
				{	
					SMRVector3 end = m_skeleton->getJoint(i)->getEndLength();
					//m_skeleton->getJoint(i)->getOrientation().rotate( end );
					//drawCylinder(tmp,tmp+end,16,size,0.0f);
					drawCylinder(tmp,end,16,size,0.0f);
        }
			}
		}
		if( GLEW_VERSION_2_0 )
			glUseProgram( 0 );
		else if( GLEW_VERSION_1_5 ) 
			glUseProgramObjectARB( 0 );

		/*
		* draw back-facing polygons as red lines
		*/

		/* disable lighting for outlining */
		glPushAttrib (GL_LIGHTING_BIT | GL_LINE_BIT | GL_DEPTH_BUFFER_BIT);
		glDisable (GL_LIGHTING);

		glPolygonMode (GL_FRONT, GL_LINE);
		glCullFace (GL_BACK);

		glDepthFunc (GL_LEQUAL);
		glLineWidth (5.0f);


		/* draw wire object */
		glColor3f (0.05f, 0.0f, 0.0f);
		{double size = 0.0001 ;
		for(unsigned int i = 0; i < m_skeleton->getNumJoints(); ++i ) {
			if( m_skeleton->getJoint(i)->getParentName()!="") {
				tmp = m_skeleton->getJoint(i)->getPosition();
				tmp2 = m_skeleton->getJointByName(m_skeleton->getJoint(i)->getParentName())->getPosition();
				size  = drawCylinder(tmp2,tmp,16,size,0.1f);
				glPushMatrix();
				  glTranslated(tmp2.X(),tmp2.Y(),tmp2.Z());
				  SMRQuaternion orient = m_skeleton->getJoint(i)->getOrientation();
				  SMRVector3 axis = orient.getRotationAxis();
				  double angle = orient.getRotationAngle();
				  double axisi[3] = {axis.X(),axis.Y(),axis.Z()};
				  glRotated(angle*180/M_PI,axis.X(),axis.Y(),axis.Z());
				  //drawAxis(4.0);
				glPopMatrix();
				if (m_skeleton->getJoint(i)->isEndJoint() )
				{			
					SMRVector3 end = m_skeleton->getJoint(i)->getEndLength();
					//m_skeleton->getJoint(i)->getOrientation().rotate( end );
					//drawCylinder(tmp,tmp+end,16,size,0.0f);
          drawCylinder(tmp,end,16,size,0.0f);
				}
			}
		}
		}
		/* GL_LIGHTING_BIT | GL_LINE_BIT | GL_DEPTH_BUFFER_BIT */
		glPopAttrib ();
		/* GL_POLYGON_BIT */
		glPopAttrib ();
	}
	//else
	{
		//Draw each bone
		glBegin( GL_LINES );
		for(unsigned int i = 0; i < m_skeleton->getNumJoints(); ++i ) {
			if( m_skeleton->getJoint(i)->getParentName()!="") {
				tmp = m_skeleton->getJoint(i)->getPosition();
				tmp2 = m_skeleton->getJointByName(m_skeleton->getJoint(i)->getParentName())->getPosition();
				glVertex3d( tmp2.m_x,tmp2.m_y ,tmp2.m_z);
				glVertex3d( tmp.m_x,tmp.m_y,tmp.m_z );
			}
		}
		glEnd();
	}
	glPopMatrix();
}
コード例 #11
0
ファイル: pose.cpp プロジェクト: semajrolyat/gwucs6555
//------------------------------------------------------------------------------
// Spline Functions
//------------------------------------------------------------------------------
void draw_spline( const ECubicSplineBasis& basis ) {

    glPushMatrix();

    Eigen::MatrixXd M;

    GLfloat material_Ka[4] = { 0.0, 0.0, 0.0, 1.0 };
    GLfloat material_Kd[4] = { 0.0, 0.0, 0.0, 1.0 };
    GLfloat material_Ks[4] = { 0.0, 0.0, 0.0, 1.0 };
    GLfloat material_Ke[4] = { 0.0, 0.0, 0.0, 1.0 };
    GLfloat material_Se   = 10;

    switch( basis ) {
    case CUBIC_SPLINE_CATMULLROM:
    default:
        material_Ka[0] = catmullrom_Ka(0);
        material_Ka[1] = catmullrom_Ka(1);
        material_Ka[2] = catmullrom_Ka(2);

        material_Kd[0] = catmullrom_Kd(0);
        material_Kd[1] = catmullrom_Kd(1);
        material_Kd[2] = catmullrom_Kd(2);

        material_Ks[0] = catmullrom_Ks(0);
        material_Ks[1] = catmullrom_Ks(1);
        material_Ks[2] = catmullrom_Ks(2);

        material_Ke[0] = catmullrom_Ke(0);
        material_Ke[1] = catmullrom_Ke(1);
        material_Ke[2] = catmullrom_Ke(2);

        M = catmullrom_M;
        break;
    case CUBIC_SPLINE_B:
        material_Ka[0] = bspline_Ka(0);
        material_Ka[1] = bspline_Ka(1);
        material_Ka[2] = bspline_Ka(2);

        material_Kd[0] = bspline_Kd(0);
        material_Kd[1] = bspline_Kd(1);
        material_Kd[2] = bspline_Kd(2);

        material_Ks[0] = bspline_Ks(0);
        material_Ks[1] = bspline_Ks(1);
        material_Ks[2] = bspline_Ks(2);

        material_Ke[0] = bspline_Ke(0);
        material_Ke[1] = bspline_Ke(1);
        material_Ke[2] = bspline_Ke(2);

        M = bspline_M;
        break;
    }
    glMaterialfv(GL_FRONT, GL_AMBIENT, material_Ka);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, material_Kd);
    glMaterialfv(GL_FRONT, GL_SPECULAR, material_Ks);
    glMaterialfv(GL_FRONT, GL_EMISSION, material_Ke);
    glMaterialf(GL_FRONT, GL_SHININESS, material_Se);


    Vector3 vi, vi1;
    unsigned int n = cplist.size();

    glLineWidth( line_width );

    glBegin(GL_LINES);

    for( unsigned int i = 2; i < n-1; i++ ) {
        Eigen::MatrixXd C = CubicSpline::blend( M, cplist, i );

        std::vector<Vector3> points;
        for( double u = 0.0; u < 1.0; u += 0.1 ) {
            points.push_back( CubicSpline::position( C, u ) );
        }
        points.push_back( CubicSpline::position( C, 1.0 ) );

        for( std::vector<Vector3>::iterator it = points.begin(); it != points.end(); it++ ) {
            if( it == points.begin() ) {
                vi = *it;
            } else {
                vi1 = *it;

                glVertex3d( vi.x(), vi.y(), vi.z() );
                glVertex3d( vi1.x(), vi1.y(), vi1.z() );

                vi = *it;
            }
        }
    }
    glEnd();

    glPopMatrix();

}
コード例 #12
0
double drawCylinder(SMRVector3 _begin, SMRVector3 _end, unsigned int _step, double _sizeBeg, double _sizeEnd)
{
	// angular displacement
	double stepRad = 2*M_PI/_step;
	// temporary points
	SMRVector3 tmp1, tmp2,tmp3,tmp4;
        SMRVector3 noise(0.0001f,0.0001f,0.0001f);
	SMRVector3 unit = _end - _begin + noise;
	double length = unit.norm();
	unit.normalize();
	SMRVector3 ortho = SMRVector3(-unit.m_y, unit.m_x, 0);
	ortho.normalize();
	// draw begin cap
	//tmp1 = ortho * length * _sizeBeg;
	tmp1 = ortho * _sizeBeg;
	glBegin(GL_TRIANGLE_FAN);
	glNormal3d(-unit.m_x,-unit.m_y,-unit.m_z);
	glVertex3d(_begin.m_x,_begin.m_y,_begin.m_z);
	for (unsigned int i = 0 ; i <=_step ; i++){
		tmp2 = tmp1;
		SMRQuaternion quat(unit,double(i*stepRad));
		//quat = RotationQuaternion(unit,double(i*stepDeg) );
		quat.rotate(tmp2);
		tmp2 = tmp2 + _begin;
		glVertex3d(tmp2.m_x,tmp2.m_y,tmp2.m_z);
	}
	glEnd();
	// draw cylinder
	//tmp1 = ortho * length * _sizeBeg;
	tmp1 = ortho * _sizeBeg;
	tmp3 = ortho * length * _sizeEnd;
	glBegin(GL_TRIANGLE_STRIP);
	glNormal3d(ortho.m_x,ortho.m_y,ortho.m_z);
	glVertex3d(_begin.m_x + tmp1.m_x,_begin.m_y + tmp1.m_y,_begin.m_z + tmp1.m_z);
	glVertex3d(_end.m_x + tmp3.m_x,_end.m_y + tmp3.m_y,_end.m_z + tmp3.m_z);
	for (unsigned int i = 0 ; i <=_step ; i++){
		tmp2 = tmp1;
		tmp4 = tmp3;
		SMRQuaternion quat(unit,double(i*stepRad));
		//quat = RotationQuaternion(unit,double(i*stepDeg) );
		quat.rotate(tmp2);
		quat.rotate(tmp4);
		SMRVector3 tmp5 = tmp2;tmp5.normalize();
		glNormal3d(tmp5.m_x,tmp5.m_y,tmp5.m_z);
		glVertex3d(_begin.m_x + tmp2.m_x,_begin.m_y + tmp2.m_y,_begin.m_z + tmp2.m_z);
		glVertex3d(_end.m_x + tmp4.m_x,_end.m_y + tmp4.m_y,_end.m_z + tmp4.m_z);
	}
	glEnd();
	// draw end cap
	tmp1 = ortho * length * _sizeEnd;
	glBegin(GL_TRIANGLE_FAN);
	glNormal3d(unit.m_x,unit.m_y,unit.m_z);
	glVertex3d(_end.m_x,_end.m_y,_end.m_z);
	for (unsigned int i = 0 ; i <=_step ; i++){
		tmp2 = tmp1;
		SMRQuaternion quat(unit,double(i*stepRad));
		//quat = RotationQuaternion(unit,double(i*stepDeg) );
		quat.rotate(tmp2);
		tmp2 = tmp2 + _end;
		glVertex3d(tmp2.m_x,tmp2.m_y,tmp2.m_z);
	}
	glEnd();

	return (length * _sizeEnd)+0.0001;
}
コード例 #13
0
void GUItable::PrivateDraw()
{
	glDisable(GL_TEXTURE_2D);
		glColor4f(0.0, 0.0, 0.0, 0.4f);	
	glBegin(GL_QUADS);		
		glTexCoord2d(0.0f, 0.0f);
		glVertex3f(10, 10, 0);
		glTexCoord2d(0.0f, 1.0);		
		glVertex3f(10, h-10, 0);		
		glTexCoord2d(1.0, 1.0);		
		glVertex3d(w-10, h-10, 0);
		glTexCoord2d(1.0f, 0.0f);		
		glVertex3f(w-10, 10, 0);		
	glEnd();
	glColor3f(1.0, 1.0, 1.0);
	glEnable(GL_TEXTURE_2D);
	glCallList(displayList);
	
	int inSet=16;
	
	if(w<200)
		inSet=0;

	glColor4f(1.0,1.0,1.0,1.0f);
	
	if(!header.empty())
	{
		int size=header.size();
		float headerPos=0;

		for(int i=0; i<size; i++)
		{
			header[i].position=headerPos*w+inSet;
			guifont->PrintColor(header[i].position, 10, header[i].title);

			headerPos+=header[i].size;
		}
		
		glBindTexture(GL_TEXTURE_2D, 0);
		glBegin(GL_LINES);
			glVertex3f(max(4, inSet/2.0), 10+rowHeight, 0);
			glVertex3f(width-max(4, inSet/2.0), 10+rowHeight, 0);		
		glEnd();

		for(int i=0; i<numLines && (i+position)<numEntries; i++)
		{
			if((i+position)==selected)
				glColor4f(1.0,0.4f,0.4f,1.0f);

			string line=data[i+position];
			size_t tabPos=line.find("\t");
			int j=0;

			while(tabPos!=string::npos)
			{
				string contents=line.substr(0, tabPos);

				guifont->Print(header[j].position, (i+2)*rowHeight, contents);

				line=line.substr(tabPos+1, string::npos);
				tabPos=line.find("\t");
				j++;
			}
			guifont->Print(header[j].position, (i+2)*rowHeight, line.substr(0, tabPos));

			glColor4f(1.0,1.0,1.0,1.0f);

		}
	}
	else
	{
		for(int i=0; i<numLines && (i+position)<numEntries; i++)
		{
			if((i+position)==selected)
				glColor4f(1.0,0.4f,0.4f,1.0f);

			guifont->Print(inSet, (i+1)*rowHeight, data[i+position]);			
			glColor4f(1.0,1.0,1.0,1.0f);
		}
	}
}
コード例 #14
0
ファイル: draw.c プロジェクト: AhmedAMohamed/graphviz
static void DrawBezier(xdot_point* pts, int filled, int param)
{
    /*copied from NEHE */
    /*Written by: David Nikdel ( [email protected] ) */
    double Ax = pts[0].x;
    double Ay = pts[0].y;
    double Az = pts[0].z;
    double Bx = pts[1].x;
    double By = pts[1].y;
    double Bz = pts[1].z;
    double Cx = pts[2].x;
    double Cy = pts[2].y;
    double Cz = pts[2].z;
    double Dx = pts[3].x;
    double Dy = pts[3].y;
    double Dz = pts[3].z;
    double X;
    double Y;
    double Z;
    int i = 0;			//loop index
    // Variable
    double a = 1.0;
    double b = 1.0 - a;
    /* Tell OGL to start drawing a line strip */
    glLineWidth(view->LineWidth);
    if (!filled) {

	if (param == 0)
	    glColor4f(view->penColor.R, view->penColor.G, view->penColor.B,
		      view->penColor.A);
	else if (param == 1)		//selected
	    glColor4f(view->selectedNodeColor.R, view->selectedNodeColor.G,
		      view->selectedNodeColor.B,
		      view->selectedNodeColor.A);
	glBegin(GL_LINE_STRIP);
    } else {
	if (param == 0)
	    glColor4f(view->fillColor.R, view->fillColor.G,
		      view->fillColor.B, view->penColor.A);
	else if (param == 1)		//selected
	    glColor4f(view->selectedNodeColor.R, view->selectedNodeColor.G,
		      view->selectedNodeColor.B,
		      view->selectedNodeColor.A);
	glBegin(GL_POLYGON);
    }
    /* We will not actually draw a curve, but we will divide the curve into small
       points and draw a line between each point. If the points are close enough, it
       will appear as a curved line. 20 points are plenty, and since the variable goes
       from 1.0 to 0.0 we must change it by 1/20 = 0.05 each time */
    for (i = 0; i <= 20; i++) {
	// Get a point on the curve
	X = Ax * a * a * a + Bx * 3 * a * a * b + Cx * 3 * a * b * b +
	    Dx * b * b * b;
	Y = Ay * a * a * a + By * 3 * a * a * b + Cy * 3 * a * b * b +
	    Dy * b * b * b;
	Z = Az * a * a * a + Bz * 3 * a * a * b + Cz * 3 * a * b * b +
	    Dz * b * b * b;
	// Draw the line from point to point (assuming OGL is set up properly)
	glVertex3d(X, Y, Z + view->Topview->global_z);
	// Change the variable
	a -= 0.05;
	b = 1.0 - a;
    }
// Tell OGL to stop drawing the line strip
    glEnd();
}
コード例 #15
0
ファイル: draw.cpp プロジェクト: jfloreza/UCM
void draw_wire_tube ( double len, double rt, double rb, int nfaces )
 {
   if ( rb<=0 ) rb=MINRADIUS;
   if ( rt<=0 ) rt=MINRADIUS;
   if ( nfaces<3 ) nfaces = 3;
   
   // compute vertical axis:
   double dang = (2.0*PI)/double(nfaces);
   double ang = 0;

   // we will use len as half the length:
   len = len/2;

   // initial points:
   double ibx=rb, iby=-len, ibz=0; // bottom
   double itx=rt, ity=+len, itz=0; // top

   // current points start as the initial points:
   double cbx=ibx, cby=iby, cbz=ibz; // bottom
   double ctx=itx, cty=ity, ctz=itz; // top

   // declare the "next points" to form the cylinder lines:
   double nbx, nby, nbz; // bottom
   double ntx, nty, ntz; // top

   // compute the points all around body:
   int i=1;
   glBegin ( GL_LINES );
   do { // rotate the current points:
        if ( i<nfaces ) // normal rotation for intermediate points
         { ang += dang;
           double ca = cos(ang);
           double sa = sin(ang);
           nbx=ca*rb; nby=cby; nbz=sa*rb;
           ntx=ca*rt; nty=cty; ntz=sa*rt;
         }
        else // to make a perfect closure, the last points are exactly the first ones
         { nbx=ibx; nby=iby; nbz=ibz;
           ntx=itx; nty=ity; ntz=itz;
         }

        // draw bottom boundary:
        glVertex3d ( cbx, cby, cbz ); glVertex3d ( nbx, nby, nbz );
        // draw top boundary:
        glVertex3d ( ctx, cty, ctz ); glVertex3d ( ntx, nty, ntz );
        // draw vertical line:
        glVertex3d ( cbx, cby, cbz ); glVertex3d ( ctx, cty, ctz );
        // draw top and bottom line to center (optional):
        glVertex3d ( ctx, cty, ctz ); glVertex3d ( 0, +len, 0 );
        glVertex3d ( cbx, cby, cbz ); glVertex3d ( 0, -len, 0 );

        // update current points:
        cbx=nbx; cby=nby; cbz=nbz;
        ctx=ntx; cty=nty; ctz=ntz;
        
        // increment side counter:
        i++;
      } while ( i<=nfaces );

   // done
   glEnd();
 }
コード例 #16
0
ファイル: Platforms.cpp プロジェクト: XUbiker/LonelyIsland
GLuint Platform::MakeCube (double x, double y, double z)
{
	GLuint list = glGenLists(1);
	glNewList(list, GL_COMPILE);
		glBegin(GL_QUADS);
		glColor3d(1.0, 1.0, 1.0);
		// 5-7-6-4
		glTexCoord2d(0,0);
		glVertex3d(x + w/2, y - h/2, z + w/2);
		glTexCoord2d(1,0);
		glVertex3d(x + w/2, y + h/2, z + w/2);
		glTexCoord2d(1,1);
		glVertex3d(x - w/2, y + h/2, z + w/2);
		glTexCoord2d(0,1);
		glVertex3d(x - w/2, y - h/2, z + w/2);
		// 4-6-2-0
		glTexCoord2d(0,0);
		glVertex3d(x - w/2, y - h/2, z + w/2);
		glTexCoord2d(1,0);
		glVertex3d(x - w/2, y + h/2, z + w/2);
		glTexCoord2d(1,1);
		glVertex3d(x - w/2, y + h/2, z - w/2);
		glTexCoord2d(0,1);
		glVertex3d(x - w/2, y - h/2, z - w/2);
		// 0-2-3-1
		glTexCoord2d(0,0);
		glVertex3d(x - w/2, y - h/2, z - w/2);
		glTexCoord2d(1,0);
		glVertex3d(x - w/2, y + h/2, z - w/2);
		glTexCoord2d(1,1);
		glVertex3d(x + w/2, y + h/2, z - w/2);
		glTexCoord2d(0,1);
		glVertex3d(x + w/2, y - h/2, z - w/2);
		// 1-3-7-5
		glTexCoord2d(0,0);
		glVertex3d(x + w/2, y - h/2, z - w/2);
		glTexCoord2d(1,0);
		glVertex3d(x + w/2, y + h/2, z - w/2);
		glTexCoord2d(1,1);
		glVertex3d(x + w/2, y + h/2, z + w/2);
		glTexCoord2d(0,1);
		glVertex3d(x + w/2, y - h/2, z + w/2);
		// 7-3-2-6
		glTexCoord2d(0,0);
		glVertex3d(x + w/2, y + h/2, z + w/2);
		glTexCoord2d(1,0);
		glVertex3d(x + w/2, y + h/2, z - w/2);
		glTexCoord2d(1,1);
		glVertex3d(x - w/2, y + h/2, z - w/2);
		glTexCoord2d(0,1);
		glVertex3d(x - w/2, y + h/2, z + w/2);
		// 5-4-0-1
		glTexCoord2d(0,0);
		glVertex3d(x + w/2, y - h/2, z + w/2);
		glTexCoord2d(1,0);
		glVertex3d(x - w/2, y - h/2, z + w/2);
		glTexCoord2d(1,1);
		glVertex3d(x - w/2, y - h/2, z - w/2);
		glTexCoord2d(0,1);
		glVertex3d(x + w/2, y - h/2, z - w/2);
		glEnd();
	glEndList();
	return 1;
}
コード例 #17
0
ファイル: draw.cpp プロジェクト: jfloreza/UCM
void draw_axis ( double r )
 {
	 glDisable(GL_LIGHTING);
   double d=r/20.0;
   glBegin ( GL_LINES );

   glColor3f ( 1, 0, 0 );		
   glVertex3d ( -r, 0, 0 ); glVertex3d ( r, 0, 0 );
   glVertex3d ( r-d, -d, 0 ); glVertex3d ( r, 0, 0 );
   glVertex3d ( r-d, d, 0 ); glVertex3d ( r, 0, 0 );

   glColor3f ( 0, 1, 0 );		
   glVertex3d ( 0, -r, 0 ); glVertex3d ( 0, r, 0 );
   glVertex3d ( 0, r-d, -d ); glVertex3d ( 0, r, 0 );
   glVertex3d ( 0, r-d, d ); glVertex3d ( 0, r, 0 );

   glColor3f ( 0, 0, 1 );		
   glVertex3d ( 0, 0, -r ); glVertex3d ( 0, 0, r );
   glVertex3d ( 0, -d, r-d ); glVertex3d ( 0, 0, r );
   glVertex3d ( 0, d, r-d ); glVertex3d ( 0, 0, r );

   glEnd();
 }
コード例 #18
0
ファイル: layer.cpp プロジェクト: keesj/repsnapper
void Layer::DrawRulers(const Vector2d &point)
{
  Vector2d x0(Min.x()-10, point.y());
  Vector2d x1(Max.x()+10, point.y());
  Vector2d y0(point.x(), Min.y()-10);
  Vector2d y1(point.x(), Max.y()+10);

  // cut axes with layer polygons
  vector<Intersection> xint, yint;
  Intersection hit;
  hit.p = Vector2d(Min.x(),point.y()); hit.d = 10;
  xint.push_back(hit);
  hit.p = Vector2d(Max.x(),point.y()); hit.d = Max.x()-Min.x()+10;
  xint.push_back(hit);
  hit.p = Vector2d(point.x(),Min.y()); hit.d = 10;
  yint.push_back(hit);
  hit.p = Vector2d(point.x(),Max.y()); hit.d = Max.y()-Min.y()+10;
  yint.push_back(hit);

  for(size_t p=0; p<polygons.size();p++) {
    vector<Intersection> lint = polygons[p].lineIntersections(x0,x1,0.1);
    xint.insert(xint.end(),lint.begin(),lint.end());
    lint = polygons[p].lineIntersections(y0,y1,0.1);
    yint.insert(yint.end(),lint.begin(),lint.end());
  }
  //cerr << xint.size() << " - "<< xint.size() << endl;
  std::sort(xint.begin(),xint.end());
  std::sort(yint.begin(),yint.end());

  glColor4f(1.,1.,1.,1.);
  glLineWidth(1);
  glBegin(GL_LINES);
  // draw lines
  glVertex3d(Min.x(), x0.y(), Z);
  glVertex3d(Max.x(), x1.y(), Z);
  glVertex3d(y0.x(), Min.y(), Z);
  glVertex3d(y1.x(), Max.y(), Z);
  // draw ticks
  double ticksize=2;
  for(guint i = 0; i<xint.size(); i++) {
    glVertex3d(xint[i].p.x(), xint[i].p.y()-ticksize, Z);
    glVertex3d(xint[i].p.x(), xint[i].p.y()+ticksize, Z);
  }
  for(guint i = 0; i<yint.size(); i++) {
    glVertex3d(yint[i].p.x()-ticksize, yint[i].p.y(), Z);
    glVertex3d(yint[i].p.x()+ticksize, yint[i].p.y(), Z);
  }
  // draw BBox
  glVertex3d(Min.x(), Min.y(), Z);
  glVertex3d(Max.x(), Min.y(), Z);
  glVertex3d(Max.x(), Min.y(), Z);
  glVertex3d(Max.x(), Max.y(), Z);
  glVertex3d(Max.x(), Max.y(), Z);
  glVertex3d(Min.x(), Max.y(), Z);
  glVertex3d(Min.x(), Max.y(), Z);
  glVertex3d(Min.x(), Min.y(), Z);
  glEnd();
  // draw numbers
  ostringstream val;
  val.precision(1);
  for(guint i = 1; i<xint.size(); i++) {
    val.str("");
    double v = xint[i].p.x()-xint[i-1].p.x();
    val << fixed << v;
    Render::draw_string(Vector3d((xint[i].p.x()+xint[i-1].p.x())/2.,
				 xint[i].p.y()+1,Z),
			val.str());
  }
  for(guint i = 1; i<yint.size(); i++) {
    val.str("");
    double v = yint[i].p.y()-yint[i-1].p.y();
    val << fixed << v;
    Render::draw_string(Vector3d(yint[i].p.x()+1,(yint[i].p.y()+yint[i-1].p.y())/2.,Z),
			val.str());
  }

}
コード例 #19
0
ファイル: ex06.c プロジェクト: jchan1e/graphics
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   const double len=2.0;  //  Length of axes
   //  Light position and colors
   float Ambient[]   = {0.3,0.3,0.3,1.0};
   float Diffuse[]   = {1.0,1.0,1.0,1.0};
   float Specular[]  = {1.0,1.0,1.0,1.0};
   float Position[]  = {(float)(2*Cos(zh)),Ylight,(float)(2*Sin(zh)),1.0};

   //  Erase the window and the depth buffer
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

   //  Enable Z-buffering in OpenGL
   glEnable(GL_DEPTH_TEST);

   //  Undo previous transformations
   glLoadIdentity();
   //  Perspective - set eye position
   if (proj)
   {
      float Ex = -2*dim*Sin(th)*Cos(ph);
      float Ey = +2*dim        *Sin(ph);
      float Ez = +2*dim*Cos(th)*Cos(ph);
      gluLookAt(Ex,Ey,Ez , 0,0,0 , 0,Cos(ph),0);
   }
   //  Orthogonal - set world orientation
   else
   {
      glRotatef(ph,1,0,0);
      glRotatef(th,0,1,0);
   }

   //  Draw light position as sphere
   //  This uses the fixed pipeline
   glColor3f(1,1,1);
   glPushMatrix();
   glTranslated(Position[0],Position[1],Position[2]);
   glutSolidSphere(0.03,10,10);
   glPopMatrix();

   //  Fixed pipeline
   if (mode==0)
   {
      //  OpenGL should normalize normal vectors
      glEnable(GL_NORMALIZE);
      //  Enable lighting
      glEnable(GL_LIGHTING);
      //  glColor sets ambient and diffuse color materials
      glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
      glEnable(GL_COLOR_MATERIAL);
      //  Enable light 0
      glEnable(GL_LIGHT0);
      //  Set ambient, diffuse, specular components and position of light 0
      glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient);
      glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse);
      glLightfv(GL_LIGHT0,GL_SPECULAR,Specular);
      glLightfv(GL_LIGHT0,GL_POSITION,Position);

      //  Enable textures
      glEnable(GL_TEXTURE_2D);
      glBindTexture(GL_TEXTURE_2D,crate);

      //  Enabe arrays
      glEnableClientState(GL_VERTEX_ARRAY);
      glEnableClientState(GL_NORMAL_ARRAY);
      glEnableClientState(GL_COLOR_ARRAY);
      glEnableClientState(GL_TEXTURE_COORD_ARRAY);

      //  Set pointers
      glVertexPointer  (4,GL_FLOAT,12*sizeof(GLfloat),cube_data);
      glNormalPointer  (  GL_FLOAT,12*sizeof(GLfloat),cube_data+4);
      glColorPointer   (3,GL_FLOAT,12*sizeof(GLfloat),cube_data+7);
      glTexCoordPointer(2,GL_FLOAT,12*sizeof(GLfloat),cube_data+10);

      //  Draw the cube
      glDrawArrays(GL_TRIANGLES,0,cube_size);

      //  Disable arrays
      glDisableClientState(GL_VERTEX_ARRAY);
      glDisableClientState(GL_NORMAL_ARRAY);
      glDisableClientState(GL_COLOR_ARRAY);
      glDisableClientState(GL_TEXTURE_COORD_ARRAY);

      //  Disable textures
      glDisable(GL_TEXTURE_2D);
   }
   //  OpenGL 4 style shaders
   else
   {
      int loc;
      float ModelViewMatrix[16];
      float ProjectionMatrix[16];
      glGetFloatv(GL_PROJECTION_MATRIX,ProjectionMatrix);
      glGetFloatv(GL_MODELVIEW_MATRIX,ModelViewMatrix);

      // Use our shader
      glUseProgram(shader);

      //  Set Modelview and Projection Matrix
      loc = glGetUniformLocation(shader, "ModelViewMatrix");
      if (loc>=0) glUniformMatrix4fv(loc,1,GL_FALSE,ModelViewMatrix);
      loc = glGetUniformLocation(shader, "ProjectionMatrix");
      if (loc>=0) glUniformMatrix4fv(loc,1,GL_FALSE,ProjectionMatrix);

      //  Select cube buffer
      glBindBuffer(GL_ARRAY_BUFFER,cube_buffer);
      //   Attribute 0: vertex coordinate (vec4) at offset 0
      glEnableVertexAttribArray(0);
      glVertexAttribPointer(0,4,GL_FLOAT,GL_FALSE,12*sizeof(float),(void*)0);
      //   Attribute 1:  vertex color (vec3) offset 7 floats
      glEnableVertexAttribArray(1);
      glVertexAttribPointer(1,3,GL_FLOAT,GL_FALSE,12*sizeof(float),(void*)(7*sizeof(float)));

      // Draw the cube
      glDrawArrays(GL_TRIANGLES,0,cube_size);

      //  Disable vertex arrays
      glDisableVertexAttribArray(0);
      glDisableVertexAttribArray(1);

      //  Unbind this buffer
      glBindBuffer(GL_ARRAY_BUFFER,0);

      // Back to fixed pipeline
      glUseProgram(0);
   }

   //  Draw axes - no lighting from here on
   glDisable(GL_LIGHTING);
   glColor3f(1,1,1);
   if (axes)
   {
      glBegin(GL_LINES);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(len,0.0,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,len,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,0.0,len);
      glEnd();
      //  Label axes
      glRasterPos3d(len,0.0,0.0);
      Print("X");
      glRasterPos3d(0.0,len,0.0);
      Print("Y");
      glRasterPos3d(0.0,0.0,len);
      Print("Z");
   }
   //  Display parameters
   glWindowPos2i(5,5);
   Print("FPS=%d Dim=%.1f Projection=%s Mode=%s",
     FramesPerSecond(),dim,proj?"Perpective":"Orthogonal",text[mode]);
   //  Render the scene and make it visible
   ErrCheck("display");
   glFlush();
   glutSwapBuffers();
}
コード例 #20
0
ファイル: layer.cpp プロジェクト: keesj/repsnapper
void Layer::Draw(const Settings &settings)
{

#if 0
  // test single area expolys
  vector<ExPoly> expolys = Clipping::getExPolys(polygons);
  draw_polys(expolys, GL_LINE_LOOP, 1, 3, RED, 1);
  cerr << expolys.size() << endl;

  Infill exinf(this, 1.);
  exinf.setName("infill");
  double infilldistance = settings.GetInfillDistance(thickness,
						     settings.Slicing.InfillPercent);

  exinf.addPolys(Z, expolys, HexInfill,
		 infilldistance, infilldistance, 0.4);
  draw_polys(exinf.infillpolys, GL_LINE_LOOP, 1, 3,
	     (exinf.cached?BLUEGREEN:GREEN), 1);
  return;
#endif

  bool randomized = settings.get_boolean("Display","RandomizedLines");
  bool filledpolygons = settings.get_boolean("Display","DisplayFilledAreas");
  // glEnable(GL_LINE_SMOOTH);
  // glHint(GL_LINE_SMOOTH_HINT,  GL_NICEST);
  draw_polys(polygons, GL_LINE_LOOP, 1, 3, RED, 1, randomized);
  draw_polys(polygons, GL_POINTS,    1, 3, RED, 1, randomized);

  if(settings.get_boolean("Display","DrawCPOutlineNumbers"))
    for(size_t p=0; p<polygons.size();p++)
      {
	ostringstream oss;
	oss << p;
	Vector2d center = polygons[p].getCenter();
	Render::draw_string(Vector3d(center.x(), center.y(), Z), oss.str());
      }

  draw_poly(hullPolygon,    GL_LINE_LOOP, 3, 3, ORANGE,  0.5, randomized);
  draw_polys(skirtPolygons, GL_LINE_LOOP, 3, 3, YELLOW,  1, randomized);
  draw_polys(shellPolygons, GL_LINE_LOOP, 1, 3, YELLOW2, 1, randomized);
  draw_polys(thinPolygons,  GL_LINE_LOOP, 2, 3, YELLOW,  1, randomized);

  glColor4f(0.5,0.9,1,1);
  glLineWidth(1);
  double zs = Z;
  for(size_t s=0;s<skins;s++) {
    for(size_t p=0; p < skinPolygons.size();p++) {
      //cerr << s << ": " << p << " _ " << zs << endl;
      skinPolygons[p].draw(GL_LINE_LOOP, zs, randomized);
    }
    zs-=thickness/skins;
  }
  draw_polys(fillPolygons,         GL_LINE_LOOP, 1, 3, WHITE, 0.6, randomized);
  if (supportPolygons.size()>0) {
    if (filledpolygons)
      draw_polys_surface(supportPolygons,  Min, Max, Z, thickness/2., BLUE2, 0.4);
    draw_polys(supportPolygons,      GL_LINE_LOOP, 3, 3, BLUE2, 1,   randomized);
    if(settings.get_boolean("Display","DrawVertexNumbers"))
      for(size_t p=0; p<supportPolygons.size();p++)
	supportPolygons[p].drawVertexNumbers();
  } // else
    // draw_polys(toSupportPolygons,    GL_LINE_LOOP, 1, 1, BLUE2, 1,   randomized);
  draw_polys(bridgePolygons,       GL_LINE_LOOP, 3, 3, RED2,  0.7, randomized);
  draw_polys(fullFillPolygons,     GL_LINE_LOOP, 1, 1, GREY,  0.6, randomized);
  draw_polys(decorPolygons,        GL_LINE_LOOP, 1, 3, WHITE, 1,   randomized);
  draw_polys(skinFullFillPolygons, GL_LINE_LOOP, 1, 3, GREY,  0.6, randomized);
  if (filledpolygons) {
    draw_polys_surface(fullFillPolygons,  Min, Max, Z, thickness/2., GREEN, 0.5);
    draw_polys_surface(decorPolygons,  Min, Max, Z, thickness/2., GREY, 0.2);
  }
  if(settings.get_boolean("Display","DisplayinFill"))
    {
      if (filledpolygons)
	draw_polys_surface(fillPolygons,  Min, Max, Z, thickness/2., GREEN2, 0.25);
      bool DebugInfill = settings.get_boolean("Display","DisplayDebuginFill");
      if (normalInfill)
	draw_polys(normalInfill->infillpolys, GL_LINE_LOOP, 1, 3,
		   (normalInfill->cached?BLUEGREEN:GREEN), 1, randomized);
      if(DebugInfill && normalInfill->cached)
	draw_polys(normalInfill->getCachedPattern(Z), GL_LINE_LOOP, 1, 3,
		   ORANGE, 0.5, randomized);
      if (thinInfill)
	draw_polys(thinInfill->infillpolys, GL_LINE_LOOP, 1, 3,
		   GREEN, 1, randomized);
      if (fullInfill)
	draw_polys(fullInfill->infillpolys, GL_LINE_LOOP, 1, 3,
		   (fullInfill->cached?BLUEGREEN:GREEN), 0.8, randomized);
      if (skirtInfill)
	draw_polys(skirtInfill->infillpolys, GL_LINE_LOOP, 1, 3,
		   YELLOW, 0.6, randomized);
      if(DebugInfill && fullInfill->cached)
	draw_polys(fullInfill->getCachedPattern(Z), GL_LINE_LOOP, 1, 3,
		   ORANGE, 0.5, randomized);
      if (decorInfill)
	draw_polys(decorInfill->infillpolys, GL_LINE_LOOP, 1, 3,
		   (decorInfill->cached?BLUEGREEN:GREEN), 0.8, randomized);
      if(DebugInfill && decorInfill->cached)
	draw_polys(decorInfill->getCachedPattern(Z), GL_LINE_LOOP, 1, 3,
		   ORANGE, 0.5, randomized);
      uint bridgecount = bridgeInfills.size();
      if (bridgecount>0)
	for (uint i = 0; i<bridgecount; i++)
	  draw_polys(bridgeInfills[i]->infillpolys, GL_LINE_LOOP, 2, 3,
		     RED3,0.9, randomized);
      if (supportInfill)
	draw_polys(supportInfill->infillpolys, GL_LINE_LOOP, 1, 3,
		   (supportInfill->cached?BLUEGREEN:GREEN), 0.8, randomized);
      if(DebugInfill && supportInfill->cached)
	draw_polys(supportInfill->getCachedPattern(Z), GL_LINE_LOOP, 1, 3,
		   ORANGE, 0.5, randomized);
      for(size_t s=0;s<skinFullInfills.size();s++)
	draw_polys(skinFullInfills[s]->infillpolys, GL_LINE_LOOP, 1, 3,
		   (skinFullInfills[s]->cached?BLUEGREEN:GREEN), 0.6, randomized);
    }
  //draw_polys(GetInnerShell(), GL_LINE_LOOP, 2, 3, WHITE,  1);
  glLineWidth(1);
  if(settings.get_boolean("Display","DrawCPVertexNumbers")) // poly vertex numbers
    for(size_t p=0; p<polygons.size();p++)
      polygons[p].drawVertexNumbers();
      //polygons[p].drawVertexAngles();

  if(settings.get_boolean("Display","DrawCPLineNumbers"))  // poly line numbers
    for(size_t p=0; p<polygons.size();p++)
      polygons[p].drawLineNumbers();

  if(settings.get_boolean("Display","DrawVertexNumbers")) { // infill vertex numbers
    for(size_t p=0; p<fillPolygons.size();p++)
      fillPolygons[p].drawVertexNumbers();
    for(size_t p=0; p<fullFillPolygons.size();p++)
      fullFillPolygons[p].drawVertexNumbers();
    for(size_t p=0; p<decorPolygons.size();p++)
      decorPolygons[p].drawVertexNumbers();
    for(size_t p=0; p<shellPolygons.size();p++)
      for(size_t q=0; q<shellPolygons[p].size();q++)
	shellPolygons[p][q].drawVertexNumbers();
  }


  if (settings.get_boolean("Display","ShowLayerOverhang")) {
    draw_polys(bridgePillars,        GL_LINE_LOOP, 3, 3, YELLOW,0.7, randomized);
    if (previous!=NULL) {
      vector<Poly> overhangs = getOverhangs();
      draw_polys(overhangs, GL_LINE_LOOP, 1, 3, VIOLET, 0.8, randomized);
      //draw_polys_surface(overhangs, Min, Max, Z, thickness/5, VIOLET , 0.5);

      Cairo::RefPtr<Cairo::ImageSurface> surface;
      Cairo::RefPtr<Cairo::Context>      context;
      if (rasterpolys(overhangs, Min, Max, thickness/5, surface, context))
	if(surface!=0) {
	  glColor4f(RED[0],RED[1],RED[2], 0.5);
	  glDrawCairoSurface(surface, Min, Max, Z);
	  glColor4f(RED[0],RED[1],RED[2], 0.6);
	  glPointSize(3);
 	  glBegin(GL_POINTS);
 	  for (double x = Min.x(); x<Max.x(); x+=thickness)
	    for (double y = Min.y(); y<Max.y(); y+=thickness)
	      if (getCairoSurfaceDatapoint(surface, Min, Max, Vector2d(x,y))!=0)
	  	glVertex3d(x,y,Z);
	  glEnd();
	}
    }
  }

#if 0
  // test point-in-polygons
  const vector<Poly> *polys = GetOuterShell();
  glColor4f(RED[0],RED[1],RED[2], 0.6);
  glPointSize(3);
  glBegin(GL_POINTS);
  for (double x = Min.x(); x<Max.x(); x+=thickness/1)
    for (double y = Min.y(); y<Max.y(); y+=thickness/1) {
      bool inpoly = false;
      for (uint i=0; i<polys->size(); i++) {
	if ((*polys)[i].vertexInside(Vector2d(x,y))){
	  inpoly=true; break;
	}
      }
      if (inpoly)
	glVertex3d(x,y,Z);
      // else
      //   glColor4f(0.3,0.3,0.3, 0.6);
    }
  glEnd();
#endif

}
コード例 #21
0
void ShaderSilhouetteSimple::drawPost(void)
{
	if(updateConnectivity) 
		findChains();
	
	glLineWidth((GLfloat) lineWidth);
	// draw all lines
	glDisable(GL_LIGHTING);
	glColor4f((GLfloat) color[0],(GLfloat) color[1],(GLfloat) color[2],(GLfloat) color[3]);
	if(!useLoops)
	{
		for(unsigned int i=0;i<(contours->chains).size();i++)
		{
			int isVisble[3] = {1,1,1};
			if(useVisibility) 
			{
				if(cameraPosChanged || !gmIsZero((velocity->v[i]).lengthSquared())) 
				{
					isVisble[0] = vis->getVisibility(myCameraPosition, i);
					isVisble[1] = vis->getVisibility(myCameraPosition, (contours->chains)[i].n1);
					isVisble[2] = vis->getVisibility(myCameraPosition, (contours->chains)[i].n2);
				}				
				else
				{
					isVisble[0] = vis->getVisibility(i);
					isVisble[1] = vis->getVisibility((contours->chains)[i].n1);
					isVisble[2] = vis->getVisibility((contours->chains)[i].n2);
				}
				
			}//end if use visibility
			gmVector3 v1,v2,vi;
			if(isVisble[1] == 1)
				v1 = position->getPosition((contours->chains)[i].n1);
			if(isVisble[2] == 1)
				v2 = position->getPosition((contours->chains)[i].n2);
			if(isVisble[0] == 1)
				vi = position->getPosition(i);
			
			glBegin(GL_LINES);
			
			{
				if(isVisble[0] == 1 && isVisble[1] == 1)
				{
					glVertex3d(v1[0],v1[1],v1[2]);
					glVertex3d(vi[0],vi[1],vi[2]);
				}
				if(isVisble[0] == 1 && isVisble[2] == 1)	
				{
					glVertex3d(v2[0],v2[1],v2[2]);
					glVertex3d(vi[0],vi[1],vi[2]);
				}
			}
			glEnd();
		}//end for 
	}//end if not useLoops
	 //if the connectivity is used draw the loops after checking the visibility 
	 //of the loops
	else
	{
		std::vector<Loop>::const_iterator loops_iter;
		Loop::const_iterator loop_iter, loop_iter_next;
		int isVisble1 =1;
		int isVisble2 =1;
				
		glBegin(GL_LINES);
		for(loops_iter = (contours->loops).begin(); loops_iter != (contours->loops).end(); loops_iter++)
		{
			glColor3f(1,0,0);
			
			loop_iter_next = loops_iter->begin();
			loop_iter_next++;
			for(loop_iter = loops_iter->begin(); loop_iter_next != loops_iter->end(); loop_iter++)
			{
				if(useVisibility) 
				{
					if(cameraPosChanged || !gmIsZero((velocity->v[*loop_iter]).lengthSquared()))
					{
						isVisble1 = vis->getVisibility(myCameraPosition, *loop_iter);
						isVisble2 = vis->getVisibility(myCameraPosition, *loop_iter_next);
					}
					else
					{
						isVisble1 = vis->getVisibility(*loop_iter);
						isVisble2 = vis->getVisibility(*loop_iter_next);
					}
					//end if use visibility	
				}				
				if((isVisble1 == 1) && (isVisble2 == 1))
				{
					gmVector3 v1(position->getPosition(*loop_iter));
					gmVector3 v2(position->getPosition(*loop_iter_next));
					glVertex3d(v1[0],v1[1],v1[2]);
					glVertex3d(v2[0],v2[1],v2[2]);
				}
				loop_iter_next++;
			}//end loop iter

			/*Close loop*/

			if(useVisibility) 
				{
					if(cameraPosChanged)
					{
						isVisble1 = vis->getVisibility(myCameraPosition, (*loops_iter)[loops_iter->size()-1]);
						isVisble2 = vis->getVisibility(myCameraPosition, *(loops_iter->begin()));
					}
					else
					{
						isVisble1 = vis->getVisibility((*loops_iter)[loops_iter->size()-1]);
						isVisble2 = vis->getVisibility(*(loops_iter->begin()));
					}
					//end if use visibility	
				}				
				if((isVisble1 == 1) && (isVisble2 == 1))
				{
					gmVector3 v1(position->getPosition((*loops_iter)[loops_iter->size()-1]));
					gmVector3 v2(position->getPosition( *(loops_iter->begin())));
					glVertex3d(v1[0],v1[1],v1[2]);
					glVertex3d(v2[0],v2[1],v2[2]);
				}

			 //draw arrow to show the loop orientation
			if(!useVisibility && loops_iter->size()>2 )
			{
				gmVector3 v1(position->getPosition(*(loops_iter->begin())));
				gmVector3 v2(position->getPosition((*loops_iter)[2]));
				
				gmVector3 vup = v1 + 0.25 * /*averageLength * */  cross(tangentAttr->getVector(*(loops_iter->begin())),
																  (*myCameraPosition - v1)).normalize();
				gmVector3 vdown = 2 * v1 - vup;
				
				glColor3f(0,1,0);
				glVertex3d(vup[0],vup[1],vup[2]);
				glVertex3d(v2[0],v2[1],v2[2]);
				glVertex3d(vdown[0],vdown[1],vdown[2]);
				glVertex3d(v2[0],v2[1],v2[2]);
			}
		}//end loops iter
		glEnd();
	}//end else if useLoops
	glEnable(GL_LIGHTING);
}
コード例 #22
0
ファイル: LEDCube.cpp プロジェクト: djch123/LEDCube
void LEDCube::draw()
{
    if (colors == nullptr)
    {
        return;
    }
    
    glMatrixMode(GL_MODELVIEW);  // make sure we're in Modelview mode

    // draw a sphere after translation
    // make sure to get back to the former matrix when finish drawing
    glPushMatrix();
    
    Matrix4 glMatrix = model2world;
    glMatrix.transpose();
    glLoadMatrixd(glMatrix.getPointer());
    
    glPointSize(pointSize);
    
    glColor3d(1, 1, 1); // white frame
    
    // draw while frame
    glBegin(GL_LINE_STRIP);
    
    glVertex3d(-cubeLength/2 - 5, -cubeWidth/2 - 5, -cubeDepth/2 - 5);
    glVertex3d(-cubeLength/2 - 5, cubeWidth/2 + 5, -cubeDepth/2 - 5);
    glVertex3d(cubeLength/2 + 5, cubeWidth/2 + 5, -cubeDepth/2 - 5);
    glVertex3d(cubeLength/2 + 5, -cubeWidth/2 - 5, -cubeDepth/2 - 5);
    glVertex3d(-cubeLength/2 - 5, -cubeWidth/2 - 5, -cubeDepth/2 - 5);
    glVertex3d(-cubeLength/2 - 5, -cubeWidth/2 - 5, cubeDepth/2 + 5);
    glVertex3d(cubeLength/2 + 5, -cubeWidth/2 - 5, cubeDepth/2 + 5);
    glVertex3d(cubeLength/2 + 5, cubeWidth/2 + 5, cubeDepth/2 + 5);
    glVertex3d(-cubeLength/2 - 5, cubeWidth/2 + 5, cubeDepth/2 + 5);
    glVertex3d(-cubeLength/2 - 5, -cubeWidth/2 - 5, cubeDepth/2 + 5);
    
    glEnd();
    
    glBegin(GL_LINES);
    
    glVertex3d(-cubeLength/2 - 5, cubeWidth/2 + 5, cubeDepth/2 + 5);
    glVertex3d(-cubeLength/2 - 5, cubeWidth/2 + 5, -cubeDepth/2 - 5);
    
    glVertex3d(cubeLength/2 + 5, cubeWidth/2 + 5, cubeDepth/2 + 5);
    glVertex3d(cubeLength/2 + 5, cubeWidth/2 + 5, -cubeDepth/2 - 5);
    
    glVertex3d(cubeLength/2 + 5, -cubeWidth/2 - 5, cubeDepth/2 + 5);
    glVertex3d(cubeLength/2 + 5, -cubeWidth/2 - 5, -cubeDepth/2 - 5);
    
    glEnd();
    
    
    // draw spheres
    glBegin(GL_POINTS);
    
    unsigned int color;
    unsigned int R, G, B, W;
    
    for (int z = 0; z < LED_DEPTH; ++z)
    {
        for (int x = 0; x < LED_LENGTH; ++x)
        {
            for (int y = 0; y < LED_WIDTH; ++y)
            {
                color = colors[z * LED_WIDTH * LED_LENGTH + x * LED_WIDTH + y];
                if (color == 0)
                {
                    continue;
                }
                W = color & 0xFF;
                color >>= 8;
                B = color & 0xFF;
                color >>= 8;
                G = color & 0xFF;
                color >>= 8;
                R = color & 0xFF;
                
                glColor4d(1.0 * (R+W) / 0X100, 1.0 * (G+W) / 0x100, 1.0 * (B+W) / 0x100, LED_ALPHA);
                glVertex3d(-cubeLength/2 + LED_LEN_INTERVAL * x, -cubeWidth/2 + LED_WID_INTERVAL * y, -cubeDepth/2 + LED_DEP_INTERVAL * z);
            }
        }
    }
    
    glEnd();
    
    glPopMatrix();
}
コード例 #23
0
void OpenGLMethods::paintImagePixelsToOpenGLList(const DebugImage& image, int colorModel, int zComponent, bool polygons, int listID, int x1, int x2, int y1, int y2)
{
  // Build a new list
  ::glNewList(listID, GL_COMPILE_AND_EXECUTE);

  if(polygons)
  {
    glPolygonMode(GL_FRONT, GL_FILL);
    glPolygonMode(GL_BACK, GL_FILL);
    glBegin(GL_QUADS);
  }
  else
    glBegin(GL_POINTS);

  TImage<PixelTypes::BGRAPixel> rgbImage(image.getImageWidth(), image.height);
  image.convertToBGRA(rgbImage[0]);

  ColorChannels* convertedImage;
  bool allocated = false;
  switch(colorModel)
  {
    case 0: //yuv
      if(image.type == PixelTypes::YUV)
      {
        convertedImage = const_cast<ColorChannels*>(image.getView<ColorChannels>()[0]);
      }
      else
      {
        convertedImage = new ColorChannels[rgbImage.width * rgbImage.height];
        allocated = true;
        PixelTypes::YUVPixel* dest = reinterpret_cast<PixelTypes::YUVPixel*>(convertedImage);
        switch(image.type)
        {
          case PixelTypes::BGRA:
            for(const PixelTypes::BGRAPixel* src = image.getView<PixelTypes::BGRAPixel>()[0], *srcEnd = image.getView<PixelTypes::BGRAPixel>()[image.height]; src < srcEnd; src++, dest++)
              ColorModelConversions::fromRGBToYUV(src->r, src->g, src->b, dest->y, dest->u, dest->v);
            break;
          case PixelTypes::RGB:
            for(const PixelTypes::RGBPixel* src = image.getView<PixelTypes::RGBPixel>()[0], *srcEnd = image.getView<PixelTypes::RGBPixel>()[image.height]; src < srcEnd; src++, dest++)
              ColorModelConversions::fromRGBToYUV(src->r, src->g, src->b, dest->y, dest->u, dest->v);
            break;
          case PixelTypes::YUYV:
            for(const PixelTypes::YUYVPixel* src = image.getView<PixelTypes::YUYVPixel>()[0], *srcEnd = image.getView<PixelTypes::YUYVPixel>()[image.height]; src < srcEnd; src++, dest++)
            {
              dest->y = src->y0;
              dest->u = src->u;
              dest->v = src->v;
              dest++;
              dest->y = src->y1;
              dest->u = src->u;
              dest->v = src->v;
            }
            break;
          case PixelTypes::Colored:
            for(const PixelTypes::BGRAPixel* src = rgbImage[0], *srcEnd = rgbImage[rgbImage.height]; src < srcEnd; src++, dest++)
              ColorModelConversions::fromRGBToYUV(src->r, src->g, src->b, dest->y, dest->u, dest->v);
            break;
          case PixelTypes::Grayscale:
            for(const PixelTypes::GrayscaledPixel* src = image.getView<PixelTypes::GrayscaledPixel>()[0], *srcEnd = image.getView<PixelTypes::GrayscaledPixel>()[image.height]; src < srcEnd; src++, dest++)
            {
              dest->y = *src;
              dest->u = dest->v = 128;
            }
            break;
          default:
            ASSERT(false);
        }
      }
      break;
    case 1: //rgb
      convertedImage = reinterpret_cast<ColorChannels*>(rgbImage[0]);
      break;
    case 2: //hsi
      convertedImage = new ColorChannels[rgbImage.width * rgbImage.height];
      allocated = true;
      PixelTypes::HSIPixel* dest = reinterpret_cast<PixelTypes::HSIPixel*>(convertedImage);
      for(const PixelTypes::BGRAPixel* src = rgbImage[0], *srcEnd = rgbImage[rgbImage.height]; src < srcEnd; src++, dest++)
        ColorModelConversions::fromRGBToHSI(src->r, src->g, src->b, dest->h, dest->s, dest->i);
      break;
  }

  float tmp = 2.0f / 255.0f;
  float x, y, xn, yn;
  float z00, z01, z10, z11;

  for(int j = y1; j < y2 - 2; j++)
  {
    for(int i = x1; i < x2 - 2; i++)
    {
      if(zComponent == -1)
      {
        unsigned char* channels = convertedImage[j * rgbImage.width + i].channels;
        if(colorModel == 0) //(padding is at 0 by yuv)
          channels++;
        x = -1.0f + channels[2] * tmp;
        y = -1.0f + channels[0] * tmp;
        z00 = -1.0f + channels[1] * tmp;
        glColor3ub(rgbImage[j][i].r, rgbImage[j][i].g, rgbImage[j][i].b);
        glVertex3d(x, y, z00);
      }
      else
      {
        x = (+i - rgbImage.width / 2.f) * tmp;
        y = (-j + rgbImage.height / 2.f) * tmp;
        xn = (+i + 1 - rgbImage.width / 2.f) * tmp;
        yn = (-j - 1 + rgbImage.height / 2.f) * tmp;
        z00 = (-0.5f + convertedImage[j * rgbImage.width + i].channels[zComponent] * tmp / 2);
        if(polygons)
        {
          z01 = -0.5f + convertedImage[(j + 1) * rgbImage.width + i].channels[zComponent] * tmp / 2;
          z10 = -0.5f + convertedImage[j * rgbImage.width + i + 1].channels[zComponent] * tmp / 2;
          z11 = -0.5f + convertedImage[(j + 1) * rgbImage.width + i + 1].channels[zComponent] * tmp / 2;
          glColor3ub(rgbImage[j][i].r, rgbImage[j][i].g, rgbImage[j][i].b);
          glVertex3d(x, y, z00);

          glColor3ub(rgbImage[j][i + 1].r, rgbImage[j][i + 1].g, rgbImage[j][i + 1].b);
          glVertex3d(xn, y, z10);

          glColor3ub(rgbImage[j + 1][i + 1].r, rgbImage[j + 1][i + 1].g, rgbImage[j + 1][i + 1].b);
          glVertex3d(xn, yn, z11);

          glColor3ub(rgbImage[j + 1][i].r, rgbImage[j + 1][i].g, rgbImage[j + 1][i].b);
          glVertex3d(x, yn, z01);
        }
        else
        {
          glColor3ub(rgbImage[j][i].r, rgbImage[j][i].g, rgbImage[j][i].b);
          glVertex3d(x, y, z00);
        }
      }
    }
  }

  if(allocated)
  {
    delete[] convertedImage;
  }

  glEnd();
  glPolygonMode(GL_FRONT, GL_LINE);
  glPolygonMode(GL_BACK, GL_LINE);
  ::glEndList();
}
コード例 #24
0
ファイル: vizualizer.cpp プロジェクト: sabzar/ERIC
void client::Vizualizer::draw() {
	
	#pragma region Settings

	glClear(GL_COLOR_BUFFER_BIT);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	//glOrtho(0.0, this->width_, this->height_, 0.0, -1, 1);
	glViewport(0, 0, width_, height_);
	gluPerspective(45.0f, width_/height_, 0.1f, maxScale);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity(); 

	#pragma endregion

	gluLookAt(eyeX, eyeY, eyeZ, eyeX, eyeY, -1, 0, 1, 0);

	#pragma region Axes

	glColor3f(1.0f, 0.0f, 0.0f);
	glBegin(GL_LINES);
	glVertex3d(0, 0, 0);	
	glVertex3d(10, 0, 0);	
	glEnd();

	glColor3f(0.0f, 1.0f, 0.0f);
	glBegin(GL_LINES);
	glVertex3d(0, 0, 0);	
	glVertex3d(0, 10, 0);	
	glEnd();

	glColor3f(0.0f, 0.0f, 1.0f);
	glBegin(GL_LINES);
	glVertex3d(0, 0, 0);	
	glVertex3d(0, 0, 10);	
	glEnd();

	#pragma endregion	

	for(int i = 0; i < clouds_.size(); i++){

		if(modes_[i] == client::POINTS)
			glPointSize(pointSizes_[i]);
		else 
			glLineWidth(pointSizes_[i]);

		glColor4f(colors_[i].r, colors_[i].g, colors_[i].b, colors_[i].alpha);		
		glBegin(modes_[i]);

		for(client::PointCloud::iterator it = clouds_[i].begin(); it != clouds_[i].end(); ++it){
			glVertex3d(it.x() / 20, it.y()/20, 0);
		}

		glEnd();
	}

	//rreturn to default
	glLineWidth(1.0f);
	glPointSize(1.0f);

	//glFlush();

	glutSwapBuffers();	
}
コード例 #25
0
ファイル: final.c プロジェクト: untra/final_project
  /*
  *  OpenGL (GLUT) calls this routine to display the scene
  */
  void display()
  {
    int i;
    double fall;
    const double len=10.0;  //  Length of axes
    //  Erase the window and the depth buffer
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    //  Enable Z-buffering in OpenGL
    glEnable(GL_DEPTH_TEST);
    //  Undo previous transformations
    glLoadIdentity();

    if(mode == 0)
    {
        //Set up perspective projection
        double Ex = 2*dim*Sin(th)*Cos(ph);
        double Ey = 2*dim*Sin(ph);
        double Ez = -2*dim*Cos(th)*Cos(ph);
        gluLookAt(Ex,Ey,Ez ,0,0,0, 0,Cos(ph),0);
    }
    else
    {
        //Set up first person projection
        double Cx = -2*dim*Sin(th)*Cos(ph) + xOffset;
        double Cy = 2*dim*Sin(ph) + yOffset;
        double Cz = 2*dim*Cos(th)*Cos(ph) + zOffset;
        gluLookAt(xOffset,yOffset,zOffset ,Cx,Cy,Cz, 0,Cos(ph),0);
    }

    //  Light switch
    if (light)
    {
      //  Translate intensity to color vectors
      float Ambient[]   = {0.1,0.1,0.1,1.0};
      float Diffuse[]   = {0.3,0.3,0.3,1};
      float Specular[]  = {0.2,0.2,0.2,1};
      float white[]     = {1,1,1,1};
      // float red[]     = {1,0,0,1};
      // float green[]     = {0,1,0,1};
      // float blue[]     = {0,0,1,1};
      //  Light direction
      float Position[6][4]  = {
        {68*Cos(idle[0])-38,30,20 , 1},
        {68*Cos(idle[1])-38,31,40 , 1},
        {68*Cos(idle[2])-38,32,60 , 1},
        {68*Cos(idle[3])-38,33,80 , 1},
        {68*Cos(idle[4])-38,34,100 , 1},
        {bowling_ball_x(4),bowling_ball_y(4),bowling_ball_z[4] , 1},
      };
      // printf("%f | %f | %f\n" , Position[0] , Position[1] , Position[2]    );
      //  Draw light position as ball (still no lighting here)
      ball(Position[0][0],Position[0][1],Position[0][2],1,white);
      // ball(Position[1][0],Position[1][1],Position[1][2],1,red);
      // ball(Position[2][0],Position[2][1],Position[2][2],1,green);
      // ball(Position[3][0],Position[3][1],Position[3][2],1,blue);
      // ball(Position[4][0],Position[4][1],Position[4][2],1,white);

      //  Enable lighting
      glEnable(GL_LIGHTING);
      //  Enable lighting with normalization
      glEnable(GL_NORMALIZE);

      //  Location of viewer for specular calculations
      glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,local);

      glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
      glEnable(GL_COLOR_MATERIAL);
      //  Enable light 0

      //  Set ambient, diffuse, specular components and position of light 0
      glEnable(GL_LIGHT0);
      glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient);
      glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse);
      glLightfv(GL_LIGHT0,GL_SPECULAR,Specular);
      glLightfv(GL_LIGHT0,GL_POSITION,Position[0]);
      glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,32.0f);
      // glEnable(GL_LIGHT1);
      // glLightfv(GL_LIGHT1,GL_AMBIENT ,Ambient);
      // glLightfv(GL_LIGHT1,GL_DIFFUSE ,Diffuse);
      // glLightfv(GL_LIGHT1,GL_SPECULAR,Specular);
      // glLightfv(GL_LIGHT1,GL_POSITION,Position[1]);
      glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,white);
      glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
      //  Set ambient, diffuse, specular components and position of light 1

      // glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,32.0f);
      // glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,red);
      // glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
      // //  Set ambient, diffuse, specular components and position of light 2
      // glEnable(GL_LIGHT2);
      // glLightfv(GL_LIGHT2,GL_AMBIENT ,Ambient);
      // glLightfv(GL_LIGHT2,GL_DIFFUSE ,Diffuse);
      // glLightfv(GL_LIGHT2,GL_SPECULAR,Specular);
      // glLightfv(GL_LIGHT2,GL_POSITION,Position[2]);
      // glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,32.0f);
      // glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,green);
      // glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
      // //  Set ambient, diffuse, specular components and position of light 3
      // glEnable(GL_LIGHT3);
      // glLightfv(GL_LIGHT3,GL_AMBIENT ,Ambient);
      // glLightfv(GL_LIGHT3,GL_DIFFUSE ,Diffuse);
      // glLightfv(GL_LIGHT3,GL_SPECULAR,Specular);
      // glLightfv(GL_LIGHT3,GL_POSITION,Position[3]);
      // glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,32.0f);
      // glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,blue);
      // glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
      // //  Set ambient, diffuse, specular components and position of light 4
      // glEnable(GL_LIGHT4);
      // glLightfv(GL_LIGHT4,GL_AMBIENT ,Ambient);
      // glLightfv(GL_LIGHT4,GL_DIFFUSE ,Diffuse);
      // glLightfv(GL_LIGHT4,GL_SPECULAR,Specular);
      // glLightfv(GL_LIGHT4,GL_POSITION,Position[4]);
      // glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,32.0f);
      // glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,white);
      // glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
      // //  Set ambient, diffuse, specular components and position of light 5
      // glEnable(GL_LIGHT5);
      // glLightfv(GL_LIGHT5,GL_AMBIENT ,Ambient);
      // glLightfv(GL_LIGHT5,GL_DIFFUSE ,Diffuse);
      // glLightfv(GL_LIGHT5,GL_SPECULAR,Specular);
      // glLightfv(GL_LIGHT5,GL_POSITION,Position[5]);
      // glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,32.0f);
      // glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,colors[4]);
      // glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
    }
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);


    wall(33.5,0,-30,10,12,10,0,180,wall_texture);
    wall(33.5,0,0,10,12,10,0,180,wall_texture);
    wall(33.5,0,30,10,12,10,0,180,wall_texture);
    wall(33.5,0,60,10,12,10,0,180,wall_texture);
    wall(33.5,0,90,10,12,10,0,180,wall_texture);
    wall(33.5,0,120,10,12,10,0,180,wall_texture);
    mural(-2,0,-10, 12,12,10 , 0, 0, mural_texture[0], light);
    mural(-38,0,-10, 12,12,10 , 0, 0, mural_texture[1], light);
    mural(-74,0,-10, 12,12,10 , 0, 0, mural_texture[2], light);
    mural(-110,0,-10, 12,12,10 , 0, 0, mural_texture[3], light);
    for(i = 0 ; i < 8 ; i++)
    {
      fall = explosion[i] > 180 ? (double)explosion[i]/180.0 : 0;
      fall = fall*fall;
      pins(pin_x[i],reset[i] - fall,0,1,1,1,0,explosion[i]);
    }
    double_lane(0,0,0,1,1,1,0,0,floor_texture, cieling_texture, duct_texture);
    double_lane(-36,0,0,1,1,1,0,0,floor_texture, cieling_texture, duct_texture);
    double_lane(-72,0,0,1,1,1,0,0,floor_texture, cieling_texture, duct_texture);
    double_lane(-108,0,0,1,1,1,0,0,floor_texture, cieling_texture, duct_texture);
    wall(-110.5,0,-60,10,12,10,0,0,wall_texture);
    wall(-110.5,0,-30,10,12,10,0,0,wall_texture);
    wall(-110.5,0,0,10,12,10,0,0,wall_texture);
    wall(-110.5,0,30,10,12,10,0,0,wall_texture);
    wall(-110.5,0,60,10,12,10,0,0,wall_texture);
    wall(-110.5,0,90,10,12,10,0,0,wall_texture);
    for(i = 0 ; i < 8 ; i++)
    {
      bowling_ball(bowling_ball_x(i),bowling_ball_y(i),bowling_ball_z[i],1,1,1,ball_ph[i],ball_texture, colors[i]);
    }

    //enable textures


    //  disbale lighting from here on
    if (light)
    {
      glDisable(GL_LIGHTING);
    }
    //  Draw axes
    glColor3f(1,1,1);
    if (axes)
    {
      glBegin(GL_LINES);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(len,0.0,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,len,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,0.0,len);
      glEnd();
      //  Label axes
      glRasterPos3d(len,0.0,0.0);
      Print("X");
      glRasterPos3d(0.0,len,0.0);
      Print("Y");
      glRasterPos3d(0.0,0.0,len);
      Print("Z");
    }

      glWindowPos2i(5,5);
      if(mode == 0)
      {
          Print("Projection Type: Perspective");
          glWindowPos2i(5,25);
          Print("Dimension: %.0f", dim);
      }
      else
      {
          Print("Projection Type: First Person");
          glWindowPos2i(5,25);
          Print("User Location: { %.3f, %.3f, %.3f }", xOffset, yOffset, zOffset);
      }

      //Render scene
      glFlush();
      glutSwapBuffers();
  }
コード例 #26
0
void Graphics::draw(Object3D &satelliteObj,Particle* particlesArray = NULL,int particlesNumber = 0)
{
    // colors
    static GLubyte purple[] = {255,150,255,0};
    // static GLubyte grey[] = {150,150,150,0};
    static GLubyte red[] = {255,0,0,0};
    static GLubyte green[] = {0,255,0,0};
    static GLubyte blue[] = {0,0,255,0};

    glClearColor(255,255,255,0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Projections matrix processing
    static float ratio = (float)width/(float)height;
    static double diameter = satelliteObj.radius*2;
    static GLdouble zNear = ELECTRONS_GENERATIVE_SPHERE_RADIUS*2;
    static GLdouble zFar = -ELECTRONS_GENERATIVE_SPHERE_RADIUS*2;
    static GLdouble left = satelliteObj.center.x - diameter;
    static GLdouble right = satelliteObj.center.x + diameter;
    static GLdouble bottom = satelliteObj.center.y - diameter;
    static GLdouble top = satelliteObj.center.y + diameter;
    static bool firstTimeCall = true;

    if (firstTimeCall) {
        firstTimeCall = false;
        viewerPosition.z = -1.5*diameter;
        if (ratio < 1.0) { // width < height
            bottom /= ratio;
            top /= ratio;
        } else {
            left *= ratio;
            right *= ratio;
        }
    }

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(left*zoomFactor,right*zoomFactor,bottom*zoomFactor,top*zoomFactor,zNear,zFar);

    // Modelview matrix processing
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    /* Move down the z-axis. */
    gluLookAt(viewerPosition.x, viewerPosition.y, viewerPosition.z,
              satelliteObj.center.x, satelliteObj.center.y, satelliteObj.center.z,
              0.0, 1.0, 0.0);

    /* Rotation by mouse */
    if (rotationAngles[0])
        glRotated(rotationAngles[0],0,1,0);
    if (rotationAngles[1])
        glRotated(rotationAngles[1],1,0,0);

    // draw axes:
    if (drawAxes) {
        glBegin(GL_LINES);
        glColor4ubv(red); glVertex3d(0,0,0); glVertex3d(1.5*diameter,0,0);
        glColor4ubv(green); glVertex3d(0,0,0); glVertex3d(0,1.5*diameter,0);
        glColor4ubv(blue); glVertex3d(0,0,0); glVertex3d(0,0,1.5*diameter);
        glEnd();
    }

    // draw the particles
    if (particlesArray != NULL) {
        glBegin(GL_POINTS);
        for(int i = 0;i < particlesNumber;++i) {
            if (particlesArray[i].behaviour == PARTICLE_WILL_INTERSECT_OBJ) {
                glColor4ubv(green);
            } else {
                glColor4ubv((particlesArray[i].type == PTYPE_ELECTRON)? blue: red); // this will colorize electrons to blue, ions to red
            }

            if (particlesArray[i].getPreviousStates()->size() != 0) {
                glBegin(GL_LINE_STRIP);
                for(auto it = particlesArray[i].getPreviousStates()->begin();
                        it != particlesArray[i].getPreviousStates()->end();++it)
                    glVertex3f((*it).x,(*it).y,(*it).z);
                glVertex3f(particlesArray[i].x,particlesArray[i].y,particlesArray[i].z);
                glEnd();
            } else {
                glVertex3f(particlesArray[i].x,particlesArray[i].y,particlesArray[i].z);
            }
        }
        glEnd();
    }

    // draw the object
    glColor4ubv(purple);
    vector<PlaneType> *coords = satelliteObj.polygons;
    for(vector<PlaneType>::iterator it = coords->begin();it != coords->end();it++) {
        glBegin(GL_LINE_LOOP);
        for(int i = 0;i < 3;i++)
            glVertex3d((*it).set[i].x,(*it).set[i].y,(*it).set[i].z);
        glEnd();
    }

    SDL_GL_SwapBuffers();
}
コード例 #27
0
void Font::DrawText3D( std::string text, const Pos3D *pos, uint8_t align, float r, float g, float b, float a, double scale )
{
	if( ! Initialized )
		return;
	
	if( LoadedTime.ElapsedSeconds() > Raptor::Game->Res.ResetTime.ElapsedSeconds() )
		InitFont();
	
	GLdouble x = 0., y = 0.;
	Pos3D tl, tr, br, bl;
	
	// Adjust for text vertical alignment.
	int text_height = TextHeight( text );
	switch( align )
	{
		case ALIGN_MIDDLE_LEFT:
		case ALIGN_MIDDLE_CENTER:
		case ALIGN_MIDDLE_RIGHT:
			y -= text_height / 2;
			break;
		case ALIGN_BASELINE_LEFT:
		case ALIGN_BASELINE_CENTER:
		case ALIGN_BASELINE_RIGHT:
			y -= Ascent;
			break;
		case ALIGN_BOTTOM_LEFT:
		case ALIGN_BOTTOM_CENTER:
		case ALIGN_BOTTOM_RIGHT:
			y -= text_height;
			break;
	}
	
	GLdouble left = 0., right = 0.;
	GLdouble top = 0., bottom = 0.;
	GLfloat tex_min_x = 0.f, tex_min_y = 0.f;
	GLfloat tex_max_x = 0.f, tex_max_y = 0.f;
	GLdouble min_x = 0.;
	GLdouble base_left = x;
	
	glPushAttrib( GL_ALL_ATTRIB_BITS );
	
	glEnable( GL_BLEND );
	glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
	
	glEnable( GL_TEXTURE_2D );
	glColor4f( r, g, b, a );
	
	// Adjust for text horizontal alignment.
	int line_width = LineWidth( text );
	switch( align )
	{
		case ALIGN_TOP_CENTER:
		case ALIGN_MIDDLE_CENTER:
		case ALIGN_BASELINE_CENTER:
		case ALIGN_BOTTOM_CENTER:
			x -= line_width / 2;
			break;
		case ALIGN_TOP_RIGHT:
		case ALIGN_MIDDLE_RIGHT:
		case ALIGN_BASELINE_RIGHT:
		case ALIGN_BOTTOM_RIGHT:
			x -= line_width;
			break;
	}
	
	const char *text_ptr = text.c_str();
	while( *text_ptr != '\0' )
	{
		if( *text_ptr == '\n' )
		{
			x = base_left;
			y += LineSkip;
			
			// Adjust for text horizontal alignment.
			line_width = LineWidth( text_ptr + 1 );
			switch( align )
			{
				case ALIGN_TOP_CENTER:
				case ALIGN_MIDDLE_CENTER:
				case ALIGN_BASELINE_CENTER:
				case ALIGN_BOTTOM_CENTER:
					x -= line_width / 2;
					break;
				case ALIGN_TOP_RIGHT:
				case ALIGN_MIDDLE_RIGHT:
				case ALIGN_BASELINE_RIGHT:
				case ALIGN_BOTTOM_RIGHT:
					x -= line_width;
					break;
			}
		}
		else
		{
			LoadChar( *text_ptr );
			
			tex_min_x = Glyphs[ (unsigned char) *text_ptr ].TexMinX;
			tex_min_y = Glyphs[ (unsigned char) *text_ptr ].TexMinY;
			tex_max_x = Glyphs[ (unsigned char) *text_ptr ].TexMaxX;
			tex_max_y = Glyphs[ (unsigned char) *text_ptr ].TexMaxY;
			
			min_x = Glyphs[ (unsigned char) *text_ptr ].MinX;
			
			left = x + min_x;
			right = x + Glyphs[ (unsigned char) *text_ptr ].Pic->w + min_x;
			top = y;
			bottom = y + Glyphs[ (unsigned char) *text_ptr ].Pic->h;
			
			tl.Copy( pos );
			tl.MoveAlong( &(pos->Right), left * scale );
			tl.MoveAlong( &(pos->Up), -top * scale );
			tr.Copy( pos );
			tr.MoveAlong( &(pos->Right), right * scale );
			tr.MoveAlong( &(pos->Up), -top * scale );
			br.Copy( pos );
			br.MoveAlong( &(pos->Right), right * scale );
			br.MoveAlong( &(pos->Up), -bottom * scale );
			bl.Copy( pos );
			bl.MoveAlong( &(pos->Right), left * scale );
			bl.MoveAlong( &(pos->Up), -bottom * scale );
			
			glBindTexture( GL_TEXTURE_2D, Glyphs[ (unsigned char) *text_ptr ].Tex );
			
			glBegin( GL_QUADS );
				glTexCoord2f( tex_min_x, tex_min_y ); glVertex3d( tl.X, tl.Y, tl.Z );
				glTexCoord2f( tex_max_x, tex_min_y ); glVertex3d( tr.X, tr.Y, tr.Z );
				glTexCoord2f( tex_max_x, tex_max_y ); glVertex3d( br.X, br.Y, br.Z );
				glTexCoord2f( tex_min_x, tex_max_y ); glVertex3d( bl.X, bl.Y, bl.Z );
			glEnd();
			
			x += Glyphs[ (unsigned char) *text_ptr ].Advance;
		}
		
		text_ptr ++;
	}
	
	glPopAttrib();
}
コード例 #28
0
void dpMarionette::drawElbowPoint(ofTexture &tex, const ramNode &nodeA, const ramNode &nodeB, const ramNode &nodeC, int width, int resolution, bool isLEFT){

	ofNode parent[3];
	parent[0] = nodeA;
	parent[1] = nodeB;
	parent[2] = nodeC;

	ofNode subParent[2];
	subParent[0].setParent(parent[1]);
	subParent[1].setParent(parent[2]);

	if (isLEFT){
		subParent[0].setPosition(-12.0, 0.0, 0.0);
		subParent[1].setPosition( 12.0, 0.0, 0.0);
	}else{
		subParent[0].setPosition( 12.0, 0.0, 0.0);
		subParent[1].setPosition(-12.0, 0.0, 0.0);
	}

	ofNode child[4];
	child[0].setParent(parent[0]);
	child[1].setParent(parent[0]);

	if (isLEFT){
		child[2].setGlobalPosition(subParent[1].getGlobalPosition().
								   interpolate(subParent[0].getGlobalPosition(), 0.0));
		child[3].setGlobalPosition(subParent[1].getGlobalPosition().
								   interpolate(subParent[0].getGlobalPosition(), 0.2));
	}else{
		child[2].setGlobalPosition(subParent[1].getGlobalPosition().
								   interpolate(subParent[0].getGlobalPosition(), 0.2));
		child[3].setGlobalPosition(subParent[1].getGlobalPosition().
								   interpolate(subParent[0].getGlobalPosition(), 0.0));
	}

	child[0].setPosition( width/2.0, 0.0, 0.0);
	child[1].setPosition(-width/2.0, 0.0, 0.0);



	ofVec2f texSize = ofVec2f(tex.getWidth(),tex.getHeight());
	ofVec3f targA,targB;
	float sliceP;

	tex.bind();
	glBegin(GL_TRIANGLE_STRIP);
	for (int i = 0;i < resolution + 1;i++){
		sliceP = i/float(resolution);
		targA = child[0].getGlobalPosition().interpolated(child[2].getGlobalPosition(),
														  sliceP);
		targB = child[1].getGlobalPosition().interpolated(child[3].getGlobalPosition(),
														  sliceP);

		glTexCoord2d(0.0, texSize.y * (1.0 - sliceP));
		glVertex3d(targA.x, targA.y, targA.z);
		glTexCoord2d(texSize.x, texSize.y * (1.0 - sliceP));
		glVertex3d(targB.x, targB.y, targB.z);

	}
	glEnd();
	tex.unbind();

	ofVec3f guideA = subParent[0].getGlobalPosition().interpolate(subParent[1].getGlobalPosition(),
																  5.0);
	ofVec3f guideB = subParent[1].getGlobalPosition().interpolate(subParent[0].getGlobalPosition(),
																  5.0);

}
コード例 #29
0
ファイル: freeglut_geometry.c プロジェクト: jiapei100/mrpt
/*
 * Draws a solid sphere
 */
void FGAPIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks)
{
    int i,j;

    /* Adjust z and radius as stacks are drawn. */

    double z0,z1;
    double r0,r1;

    /* Pre-computed circle */

    double *sint1,*cost1;
    double *sint2,*cost2;

    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSphere" );

    fghCircleTable(&sint1,&cost1,-slices);
    fghCircleTable(&sint2,&cost2,stacks*2);

    /* The top stack is covered with a triangle fan */

    z0 = 1.0;
    z1 = cost2[(stacks>0)?1:0];
    r0 = 0.0;
    r1 = sint2[(stacks>0)?1:0];

    glBegin(GL_TRIANGLE_FAN);

        glNormal3d(0,0,1);
        glVertex3d(0,0,radius);

        for (j=slices; j>=0; j--)
        {
            glNormal3d(cost1[j]*r1,        sint1[j]*r1,        z1       );
            glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
        }

    glEnd();

    /* Cover each stack with a quad strip, except the top and bottom stacks */

    for( i=1; i<stacks-1; i++ )
    {
        z0 = z1; z1 = cost2[i+1];
        r0 = r1; r1 = sint2[i+1];

        glBegin(GL_QUAD_STRIP);

            for(j=0; j<=slices; j++)
            {
                glNormal3d(cost1[j]*r1,        sint1[j]*r1,        z1       );
                glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
                glNormal3d(cost1[j]*r0,        sint1[j]*r0,        z0       );
                glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
            }

        glEnd();
    }

    /* The bottom stack is covered with a triangle fan */

    z0 = z1;
    r0 = r1;

    glBegin(GL_TRIANGLE_FAN);

        glNormal3d(0,0,-1);
        glVertex3d(0,0,-radius);

        for (j=0; j<=slices; j++)
        {
            glNormal3d(cost1[j]*r0,        sint1[j]*r0,        z0       );
            glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
        }

    glEnd();

    /* Release sin and cos tables */

    free(sint1);
    free(cost1);
    free(sint2);
    free(cost2);
}
コード例 #30
0
void ClientWidget::paintGL()
{
    frames+=1;
    qDebug()<<ENCAPS(tr("gl paint start"));
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90,(float)width()/(float)height(),0.1,1000);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
//**************************************************************************************************SCENE
    float l[]={-2,0,1,1};
    glLightfv(GL_LIGHT0,GL_POSITION,l);
    l[0]=-l[0];
    glLightfv(GL_LIGHT1,GL_POSITION,l);
    lightingprogram.bind();
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHTING);
    glColor4f(0.8,0.8,0.8,1);
    glLoadIdentity();
    gluLookAt(me.position.x(), me.position.y(),      me.position.z(),
              me.position.x(), me.position.y(),      me.position.z()+1.0f,
              0, 1, 0);
    glTranslatef(-0.1,0.2,0.5);
    glRotated(180,0,1,0);
    glRotated(30,1,0,0);
    glRotated(5,0,0,1);
    GLfloat whiteSpecularMaterial[] = {1.0, 1.0, 1.0};
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, whiteSpecularMaterial);
    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS,128);
    teapot.render();
    glLoadIdentity();
    gluLookAt(me.position.x(), me.position.y(),      me.position.z(),
              me.position.x(), me.position.y(),      me.position.z()+1.0f,
              0, 1, 0);
    glTranslatef(0.1,-0.2,1);
    glColor4f(0.8,0.8,0.8,1);
    glScaled(0.05,0.05,0.05);
    glRotated(90,1,0,0);
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, whiteSpecularMaterial);
    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS,128);
    bunny.render();
    lightingprogram.release();
//**************************************************************************************************HUD
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0,width(),0, height(), -1, -1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();					// Reset The Current Modelview Matrix
    glDisable(GL_LIGHTING);
    glDisable(GL_DEPTH_TEST);
    glColor4f(1,1,1,1);
    if(hudtex){
        glEnable( GL_TEXTURE_2D );
        glBindTexture( GL_TEXTURE_2D, hudtex );
        glBegin(GL_QUADS);
        glTexCoord2d(0.0,0.0); glVertex3d(-1.0,-1.0,-1);
        glTexCoord2d(1.0,0.0); glVertex3d( 1.0,-1.0,-1);
        glTexCoord2d(1.0,1.0); glVertex3d( 1.0, 1.0,-1);
        glTexCoord2d(0.0,1.0); glVertex3d(-1.0, 1.0,-1);
        glEnd();
        glDisable( GL_TEXTURE_2D );
    }
    renderFont(font,fps,10,10,CWRF_LEFT,CWRF_TOP);
    renderFont(font,clock,10,10,CWRF_RIGHT,CWRF_BOTTOM);
    qDebug()<<ENCAPS(tr("gl paint end"));
}