Example #1
0
  @Override
  public void display(GLAutoDrawable gLDrawable) {
    final GL2 gl = gLDrawable.getGL().getGL2();
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);
    gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
    gl.glLoadIdentity();
    gl.glTranslatef(0.0f, 0.0f, -5.0f);

    // rotate about the three axes
    gl.glRotatef(rotateT, 1.0f, 0.0f, 0.0f);
    gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f);
    gl.glRotatef(rotateT, 0.0f, 0.0f, 1.0f);

    // Draw A Quad
    gl.glBegin(GL2.GL_QUADS);
    gl.glColor3f(0.0f, 1.0f, 1.0f); // set the color of the quad
    gl.glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
    gl.glVertex3f(1.0f, 1.0f, 0.0f); // Top Right
    gl.glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
    gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
    // Done Drawing The Quad
    gl.glEnd();

    // increasing rotation for the next iteration
    rotateT += 0.2f;
  }
Example #2
0
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    gl.glPushMatrix();
    gl.glRotatef(20.0f, 1.0f, 0.0f, 0.0f);

    gl.glPushMatrix();
    gl.glTranslatef(-0.75f, 0.5f, 0.0f);
    gl.glRotatef(90.0f, 1.0f, 0.0f, 0.0f);

    glut.glutSolidTorus(0.275f, 0.85f, 20, 20);
    gl.glPopMatrix();

    gl.glPushMatrix();
    gl.glTranslatef(-0.75f, -0.5f, 0.0f);
    gl.glRotatef(270.0f, 1.0f, 0.0f, 0.0f);
    glut.glutSolidCone(1.0f, 2.0f, 20, 20);
    gl.glPopMatrix();

    gl.glPushMatrix();
    gl.glTranslatef(0.75f, 0.0f, -1.0f);
    glut.glutSolidSphere(1.0f, 20, 20);
    gl.glPopMatrix();

    gl.glPopMatrix();
    gl.glFlush();
  }
Example #3
0
  /** Called back by the animator to perform rendering. */
  @Override
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context
    gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color and depth buffers
    gl.glLoadIdentity(); // reset the model-view matrix

    gl.glTranslatef(0.0f, 0.0f, -12.0f);
    gl.glRotatef(rotateAnleX, 1.0f, 0.0f, 0.0f);
    gl.glRotatef(rotateAnleY, 0.0f, 1.0f, 0.0f);
    gl.glRotatef(rotateAngleZ, 0.0f, 0.0f, 1.0f);

    // need to flip the image
    float textureHeight = textureTop - textureBottom;

    float x1, y1, x2, y2; // used to break the flag into tiny quads

    gl.glBegin(GL_QUADS);
    for (int x = 0; x < numPoints - 1; x++) {
      for (int y = 0; y < numPoints - 1; y++) {
        x1 = (float) x / 44.0f;
        y1 = (float) y / 44.0f;
        x2 = (float) (x + 1) / 44.0f;
        y2 = (float) (y + 1) / 44.0f;

        // Texture need to flip vertically
        gl.glTexCoord2f(x1, y1 * textureHeight + textureBottom);
        gl.glVertex3f(points[x][y][0], points[x][y][1], points[x][y][2]);

        gl.glTexCoord2f(x1, y2 * textureHeight + textureBottom);
        gl.glVertex3f(points[x][y + 1][0], points[x][y + 1][1], points[x][y + 1][2]);

        gl.glTexCoord2f(x2, y2 * textureHeight + textureBottom);
        gl.glVertex3f(points[x + 1][y + 1][0], points[x + 1][y + 1][1], points[x + 1][y + 1][2]);

        gl.glTexCoord2f(x2, y1 * textureHeight + textureBottom);
        gl.glVertex3f(points[x + 1][y][0], points[x + 1][y][1], points[x + 1][y][2]);
      }
    }
    gl.glEnd();

    if (wiggleCount == 2) { // Used To Slow Down The Wave (Every 2nd Frame Only)
      for (int y = 0; y < 45; y++) {
        float tempHold = points[0][y][2]; // Store current value One Left Side Of
        // Wave
        for (int x = 0; x < 44; x++) {
          // Current Wave Value Equals Value To The Right
          points[x][y][2] = points[x + 1][y][2];
        }
        points[44][y][2] = tempHold; // Last Value Becomes The Far Left Stored
        // Value
      }
      wiggleCount = 0; // Set Counter Back To Zero
    }
    wiggleCount++;

    // update the rotational position after each refresh
    rotateAnleX += roateSpeedX;
    rotateAnleY += rotateSpeedY;
    rotateAngleZ += rotateSpeedZ;
  }
  @Override
  public void render(GL2 gl, float trajectory) {
    //		flat = true;

    gl.glPushMatrix();
    {
      gl.glTranslatef(c.x, c.y, c.z);
      gl.glRotatef(trajectory, 0, -1, 0);
      gl.glRotatef((flat) ? -90 : 0, 1, 0, 0);
      gl.glRotatef(rotation, 0, 0, 1);

      Vec3 scale = new Vec3(0.75f, 2.0f, 0);
      if (miniature) scale = scale.multiply(0.5f);
      scale = scale.multiply(0.8f);

      gl.glScalef(scale.x, scale.y, scale.z);
      gl.glTranslatef(0, 0.2f, 0);

      gl.glDepthMask(false);
      gl.glDisable(GL_LIGHTING);
      gl.glEnable(GL_BLEND);
      gl.glEnable(GL_TEXTURE_2D);

      gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE);

      whiteSpark.bind(gl);

      gl.glColor3f(colors[color][0], colors[color][1], colors[color][2]);

      gl.glBegin(GL_QUADS);
      {
        gl.glTexCoord2f(1.0f, 1.0f);
        gl.glVertex3f(-0.5f, -0.5f, 0.0f);
        gl.glTexCoord2f(1.0f, 0.0f);
        gl.glVertex3f(-0.5f, 0.5f, 0.0f);
        gl.glTexCoord2f(0.0f, 0.0f);
        gl.glVertex3f(0.5f, 0.5f, 0.0f);
        gl.glTexCoord2f(0.0f, 1.0f);
        gl.glVertex3f(0.5f, -0.5f, 0.0f);
      }
      gl.glEnd();

      gl.glDisable(GL_BLEND);
      gl.glEnable(GL_LIGHTING);
      gl.glDepthMask(true);

      gl.glColor3f(1, 1, 1);
    }
    gl.glPopMatrix();
  }
Example #5
0
  public void draw(GL2 gl, GLU glu) {
    gl.glColor3f(1f, 0f, .25f);

    // Lamp Stem, cylindrical, a little smaller at the top.
    gl.glPushMatrix();
    gl.glRotatef(-90f, 1f, 0f, 0f); // stand upright (Y)
    glu.gluCylinder(quadric, 1., 1, 3., 10, 1);
    gl.glPopMatrix();

    // Table Top
    gl.glPushMatrix();
    gl.glTranslated(0, 3, 0);
    gl.glRotatef(-90f, 100f, 0f, 0f); // stand upright (Y)
    glu.gluDisk(quadric, 0, 4., 15, 5); // also to be flipped
    gl.glPopMatrix();
  }
Example #6
0
 public void render2d(GL2 g) {
   for (Entry<EntityData, TileEntity> e : entities.entrySet()) {
     EntityData key = e.getKey();
     TileEntity entity = e.getValue();
     g.glPushMatrix();
     switch (key.getType()) {
       case VBORDER:
         g.glRotatef(90, 0, 0, 1);
         BorderData vBorder = (BorderData) entity;
         if (Globals.upCamera) {
           vBorder.render(g, this);
         }
         g.glColor3f(1, 1, 1);
         break;
       case HBORDER:
         BorderData hBorder = (BorderData) entity;
         if (Globals.upCamera) {
           hBorder.render(g, this);
         }
         g.glColor3f(1, 1, 1);
         break;
     }
     g.glPopMatrix();
     g.glColor3f(1, 1, 1);
   }
 }
Example #7
0
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    double eqn[] = {0.0, 1.0, 0.0, 0.0};
    double eqn2[] = {1.0, 0.0, 0.0, 0.0};

    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    gl.glColor3f(1.0f, 1.0f, 1.0f);
    gl.glPushMatrix();
    gl.glTranslatef(0.0f, 0.0f, -5.0f);

    /* clip lower half -- y < 0 */
    gl.glClipPlane(GL2.GL_CLIP_PLANE0, eqn, 0);
    gl.glEnable(GL2.GL_CLIP_PLANE0);
    /* clip left half -- x < 0 */
    gl.glClipPlane(GL2.GL_CLIP_PLANE1, eqn2, 0);
    gl.glEnable(GL2.GL_CLIP_PLANE1);

    gl.glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
    glut.glutWireSphere(1.0, 20, 16);
    gl.glPopMatrix();

    gl.glFlush();
  }
  @Override
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    GLUT glut = new GLUT();
    // limpa o buer
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
    // dene que a matrix é a de modelo
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
    gl.glScalef(delta, delta, delta); // faça a escala de todos objetos

    gl.glPushMatrix(); // armazena a matriz corrente
    gl.glTranslatef(-3, 0, 0);
    gl.glRotatef(beta, 0, 1, 0);
    gl.glRotatef(alpha, 1, 0, 0);
    gl.glColor3f(1, 1, 0);
    glut.glutWireSphere(1, 20, 20);

    // desenha um piso sob a esfera
    gl.glTranslatef(0, -1, 0);
    gl.glScalef(4, 0.1f, 4);
    gl.glColor3f(0, 0, 1);
    glut.glutSolidCube(1.0f);

    gl.glPopMatrix(); // restaura a matriz anterior

    gl.glPushMatrix(); // armazena a matriz corrente
    gl.glTranslatef(3, 0, 0);
    gl.glRotatef(beta, 0, 1, 0);
    gl.glRotatef(alpha, 1, 0, 0);
    gl.glColor3f(1, 0, 0);
    glut.glutWireSphere(1, 20, 20);

    // desenha um piso sob a esfera
    gl.glTranslatef(0, -1, 0);
    gl.glScalef(4, 0.1f, 4);
    gl.glColor3f(0, 1, 0);
    glut.glutSolidCube(1.0f);

    gl.glPopMatrix(); // restaura a matriz anterior
    // força o desenho das primitivas
    gl.glFlush();
  }
Example #9
0
  /**
   * Render the arrow as a line and a _head.
   *
   * @param gl OpenGL Context
   */
  public void render(GL2 gl) {
    // save Light Attributes and remove lighting to get "full" RGB colors
    // gl.glPushAttrib( GL2.GL_LIGHTING_BIT );
    gl.glPushAttrib(GL2.GL_ENABLE_BIT);
    gl.glDisable(GL2.GL_LIGHTING);

    if (_fg_verb) {
      System.out.println(
          "Arrow pos="
              + _pos.toString()
              + "  angZ1="
              + _angZ1
              + "  angY2="
              + _angY2
              + "  length="
              + _length);
      _fg_verb = false;
    }

    // save transformation matrix, then translate and scale.
    gl.glPushMatrix();
    gl.glTranslatef(_pos.x, _pos.y, _pos.z);
    gl.glRotatef(Matrix.rad2Deg(_angZ1), 0, 0, 1); // rotation around 0z
    gl.glRotatef(Matrix.rad2Deg(_angY2), 0, 1, 0); // rotation around 0y

    // draw line
    gl.glColor4f(_color_fg.x, _color_fg.y, _color_fg.z, _color_fg.w);
    gl.glLineWidth(1.0f);
    gl.glBegin(GL.GL_LINES);
    {
      gl.glVertex3f(0, 0, 0);
      gl.glVertex3f(_length, 0, 0);
    }
    gl.glEnd();

    // draw head
    gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL);
    gl.glTranslatef(_length, 0, 0);
    gl.glBegin(GL.GL_TRIANGLES);
    {
      for (float[] face : _head_faces) {
        gl.glVertex3f(face[0], face[1], face[2]);
        gl.glVertex3f(face[3], face[4], face[5]);
        gl.glVertex3f(face[6], face[7], face[8]);
      }
    }
    gl.glEnd();

    // restore transformation matrix
    gl.glPopMatrix();
    // restore attributes
    gl.glPopAttrib();
  }
  // Support Methods
  private void drawPyramid(GL2 gl, GLAutoDrawable drawable, Float x, Float y, Float z) {
    // Pushing to matrix stack
    gl.glPushMatrix();

    // PYRAMID
    // Moves the figure in the (x, y, z)-axis
    gl.glTranslatef(x, y, z);

    // Rotates the pyramid, just for "fun"
    gl.glRotatef(-55.0f, 0.0f, 1.0f, 0.0f);

    // Makes only the outlines
    gl.glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

    // BEGIN Pyramid
    gl.glBegin(GL_TRIANGLES);

    // Pushing current color to stack
    gl.glPushAttrib(GL_ALL_ATTRIB_BITS);

    // Set color to RED
    gl.glColor3f(1.0f, 0.0f, 0.0f);

    // Front triangle
    gl.glVertex3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(-1.0f, -1.0f, 1.0f);
    gl.glVertex3f(1.0f, -1.0f, 1.0f);

    // Right triangle
    gl.glVertex3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(1.0f, -1.0f, 1.0f);
    gl.glVertex3f(1.0f, -1.0f, -1.0f);

    // Left triangle
    gl.glVertex3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(-1.0f, -1.0f, -1.0f);
    gl.glVertex3f(-1.0f, -1.0f, 1.0f);

    // Back triangle
    gl.glVertex3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(1.0f, -1.0f, -1.0f);
    gl.glVertex3f(-1.0f, -1.0f, -1.0f);

    // END Pyramid
    gl.glEnd();

    // Popping state
    gl.glPopAttrib();
    gl.glPopMatrix();
  }
Example #11
0
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    gl.glPushMatrix();
    gl.glRotatef(45.0f, 0.0f, 0.0f, 1.0f);

    gl.glTexGeni(GL2.GL_S, GL2.GL_TEXTURE_GEN_MODE, currentGenMode);
    gl.glTexGendv(GL2.GL_S, currentPlane, currentCoeff, 0);

    gl.glBindTexture(GL2.GL_TEXTURE_1D, texName[0]);
    glut.glutSolidTeapot(2.0f);
    gl.glPopMatrix();
    gl.glFlush();
  }
  @Override
  public void render(GL2 gl, float trajectory) {
    if (!dead) {
      gl.glPushMatrix();
      {
        gl.glTranslatef(bound.c.x, bound.c.y, bound.c.z);
        gl.glRotatef(rotation, 0, -1, 0);
        gl.glScalef(1.5f, 1.5f, 1.5f);

        Shader shader = Shader.getLightModel("texture");
        if (shader != null) shader.enable(gl);

        gl.glCallList(shellList);

        spikeNode.render(gl);
        rimNode.render(gl);
      }
      gl.glPopMatrix();

      Shader.disable(gl);
    } else if (!blast.isEmpty() && !Scene.shadowMode) {
      boolean useHDR = BloomStrobe.isEnabled();

      if (Scene.reflectMode) BloomStrobe.end(gl);

      if (Scene.singleton.enableBloom) renderBlast(gl);
      else BlastParticle.renderList(gl, blast);

      if (useHDR) BloomStrobe.begin(gl);

      Shader.disable(gl);
    }

    if (blastDuration <= 1) blastLight.disable(gl);
    else blastLight.enable(gl);
  }
 public void interact(GL2 gl) {
   gl.glTranslatef(0, 0, z);
   gl.glRotatef(rotx, 1f, 0f, 0f);
   gl.glRotatef(roty, 0f, 1.0f, 0f);
 }
Example #14
0
  private void renderEntities(GL2 g) {
    for (Entry<EntityData, TileEntity> e : entities.entrySet()) {
      EntityData key = e.getKey();
      final int floor = key.getFloor();
      float colorMod = 1;
      if (Globals.upCamera) {
        switch (Globals.floor - floor) {
          case 0:
            colorMod = 1;
            break;
          case 1:
            colorMod = 0.6f;
            break;
          case 2:
            colorMod = 0.25f;
            break;
          default:
            continue;
        }
      }
      TileEntity entity = e.getValue();
      g.glPushMatrix();
      switch (key.getType()) {
        case FLOORROOF:
          g.glTranslatef(4, 0, 3 * floor + getFloorHeight() / Constants.HEIGHT_MOD);
          g.glColor3f(colorMod, colorMod, colorMod);
          entity.render(g, this);
          break;
        case VWALL:
        case VFENCE:
          g.glTranslatef(0, 0, 3 * floor + getVerticalWallHeight() / Constants.HEIGHT_MOD);
          g.glRotatef(90, 0, 0, 1);
          float vdiff = getVerticalWallHeightDiff() / 47f;
          if (vdiff < 0) {
            g.glTranslatef(0, 0, -vdiff * 4f);
          }
          deform(g, vdiff);

          Wall vwall = (Wall) entity;
          if (Globals.upCamera) {
            vwall.data.color.use(g, colorMod);
          } else {
            g.glColor3f(1, 1, 1);
          }
          vwall.render(g, this);
          g.glColor3f(1, 1, 1);
          break;
        case HWALL:
        case HFENCE:
          g.glTranslatef(0, 0, 3 * floor + getHorizontalWallHeight() / Constants.HEIGHT_MOD);
          float hdiff = getHorizontalWallHeightDiff() / 47f;
          if (hdiff < 0) {
            g.glTranslatef(0, 0, -hdiff * 4f);
          }
          deform(g, hdiff);
          Wall hwall = (Wall) entity;
          if (Globals.upCamera) {
            hwall.data.color.use(g, colorMod);
          } else {
            g.glColor3f(1, 1, 1);
          }
          hwall.render(g, this);
          g.glColor3f(1, 1, 1);
          break;
        case OBJECT:
          ObjectEntityData objData = (ObjectEntityData) key;
          ObjectLocation loc = objData.getLocation();
          GameObject obj = (GameObject) entity;
          g.glColor3f(colorMod, colorMod, colorMod);
          g.glTranslatef(
              loc.getHorizontalAlign(),
              loc.getVerticalAlign(),
              3 * floor
                  + getHeight(loc.getHorizontalAlign() / 4f, loc.getVerticalAlign() / 4f)
                      / Constants.HEIGHT_MOD);
          obj.render(g, this);
          break;
      }
      g.glPopMatrix();
      g.glColor3f(1, 1, 1);
    }
  }
Example #15
0
	public void display(GLAutoDrawable gLDrawable) {
		final GL2 gl = gLDrawable.getGL().getGL2();
		gl.glClear(GL.GL_COLOR_BUFFER_BIT);
		gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
		gl.glLoadIdentity();
		gl.glTranslatef(0.0f, 0.0f, -5.0f);
		
		
		
		//for(int i=0;i>3;i++)
		//	kube[i][0][0]=[red,yellow,green,blue,white];
		
		
		// rotate on the three axis
		//gl.glRotatef(rotateT, 1.0f, 0.0f, 0.0f);
		gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f);
		//gl.glRotatef(rotateT, 0.0f, 0.0f, 1.0f);
		// Draw A Quad
		
		for(int i=0;i<=2;i++)
			for(int j=0;j<=2;j++)
				for(int k=0;k<=2;k++)
				{
					kube[i][j][k][0]=green;
					kube[i][j][k][1]=white;
					kube[i][j][k][2]=orange;
					kube[i][j][k][3]=yellow;
					kube[i][j][k][4]=blue;
					kube[i][j][k][5]=red;
				}
		Clr[] tmp=new Clr[3];
		tmp[0]=kube[0][2][2][0];
		tmp[1]=kube[1][2][2][0];
		tmp[2]=kube[2][2][2][0];
		
		kube[0][2][2][0]=kube[2][2][2][1];
		kube[1][2][2][0]=kube[2][2][1][1];
		kube[2][2][2][0]=kube[2][2][0][1];
		
		kube[2][2][2][1]=kube[2][2][0][5];
		kube[2][2][1][1]=kube[1][2][0][5];
		kube[2][2][0][1]=kube[0][2][0][5];
		
		kube[2][2][0][5]=kube[0][2][0][4];
		kube[1][2][0][5]=kube[0][2][1][4];
		kube[0][2][0][5]=kube[0][2][2][4];
		
		kube[0][2][0][4]=tmp[0];
		kube[0][2][1][4]=tmp[1];
		kube[0][2][2][4]=tmp[2];
		
		Clr[] tmp1=new Clr[3];
		tmp1[0]=kube[2][1][2][0];
		tmp1[1]=kube[2][1][1][0];
		tmp1[2]=kube[2][1][0][0];
		
		kube[0][1][2][0]=kube[0][1][0][4];
		kube[1][1][2][0]=kube[0][1][1][4];
		kube[2][1][2][0]=kube[0][1][2][4];
		
		kube[0][1][0][1]=kube[2][1][0][5];
		kube[0][1][1][1]=kube[1][1][0][5];
		kube[0][1][2][1]=kube[0][1][0][5];
		
		kube[2][1][0][5]=kube[2][1][2][4];
		kube[1][1][0][5]=kube[2][1][1][4];
		kube[0][1][0][5]=kube[2][1][0][4];
		
		kube[2][1][2][4]=tmp1[0];
		kube[2][1][1][4]=tmp1[1];
		kube[2][1][0][4]=tmp1[2];
		
		gl.glBegin(GL2.GL_QUADS);
		for(int i=0;i<=2;i++)
			for(int j=0;j<=2;j++)
				for(int k=0;k<=2;k++)
				{
					
					//0
					gl.glColor3f(kube[i][j][k][0].r,kube[i][j][k][0].g,kube[i][j][k][0].b);          
					gl.glVertex3f(-0.3f+(i-1)*0.65f, 0.3f+(j-1)*0.65f, 0.3f+(k-1)*0.65f); // Top Left
					gl.glVertex3f(0.3f+(i-1)*0.65f, 0.3f+(j-1)*0.65f, 0.3f+(k-1)*0.65f); // Top Right
					gl.glVertex3f(0.3f+(i-1)*0.65f, -0.3f+(j-1)*0.65f, 0.3f+(k-1)*0.65f); // Bottom Right
					gl.glVertex3f(-0.3f+(i-1)*0.65f, -0.3f+(j-1)*0.65f, 0.3f+(k-1)*0.65f); // Bottom Left
					
                    //1
					gl.glColor3f(kube[i][j][k][1].r,kube[i][j][k][1].g,kube[i][j][k][1].b); 
					gl.glVertex3f(0.3f+(i-1)*0.65f, 0.3f+(j-1)*0.65f, -0.3f+(k-1)*0.65f); // Top Left
					gl.glVertex3f(0.3f+(i-1)*0.65f, 0.3f+(j-1)*0.65f, 0.3f+(k-1)*0.65f); // Top Right
					gl.glVertex3f(0.3f+(i-1)*0.65f, -0.3f+(j-1)*0.65f, 0.3f+(k-1)*0.65f); // Bottom Right
					gl.glVertex3f(0.3f+(i-1)*0.65f, -0.3f+(j-1)*0.65f, -0.3f+(k-1)*0.65f); // Bottom Left
					
					//2
					gl.glColor3f(kube[i][j][k][2].r,kube[i][j][k][2].g,kube[i][j][k][2].b); 
					gl.glVertex3f(-0.3f+(i-1)*0.65f, 0.3f+(j-1)*0.65f, -0.3f+(k-1)*0.65f); // Top Left
					gl.glVertex3f(-0.3f+(i-1)*0.65f, 0.3f+(j-1)*0.65f, 0.3f+(k-1)*0.65f); // Top Right
					gl.glVertex3f(0.3f+(i-1)*0.65f, 0.3f+(j-1)*0.65f, 0.3f+(k-1)*0.65f); // Bottom Right
					gl.glVertex3f(0.3f+(i-1)*0.65f, 0.3f+(j-1)*0.65f, -0.3f+(k-1)*0.65f); // Bottom Left
						
					//3
					gl.glColor3f(kube[i][j][k][3].r,kube[i][j][k][3].g,kube[i][j][k][3].b); 
					gl.glVertex3f(-0.3f+(i-1)*0.65f, -0.3f+(j-1)*0.65f, -0.3f+(k-1)*0.65f); // Top Left
					gl.glVertex3f(-0.3f+(i-1)*0.65f, -0.3f+(j-1)*0.65f, 0.3f+(k-1)*0.65f); // Top Right
					gl.glVertex3f(0.3f+(i-1)*0.65f, -0.3f+(j-1)*0.65f, 0.3f+(k-1)*0.65f); // Bottom Right
					gl.glVertex3f(0.3f+(i-1)*0.65f, -0.3f+(j-1)*0.65f, -0.3f+(k-1)*0.65f); // Bottom Left
					
					//4
					gl.glColor3f(kube[i][j][k][4].r,kube[i][j][k][4].g,kube[i][j][k][4].b); 
					gl.glVertex3f(-0.3f+(i-1)*0.65f, 0.3f+(j-1)*0.65f, -0.3f+(k-1)*0.65f); // Top Left
					gl.glVertex3f(-0.3f+(i-1)*0.65f, 0.3f+(j-1)*0.65f, 0.3f+(k-1)*0.65f); // Top Right
					gl.glVertex3f(-0.3f+(i-1)*0.65f, -0.3f+(j-1)*0.65f, 0.3f+(k-1)*0.65f); // Bottom Right
					gl.glVertex3f(-0.3f+(i-1)*0.65f, -0.3f+(j-1)*0.65f, -0.3f+(k-1)*0.65f); // Bottom Left
					
					//5
					gl.glColor3f(kube[i][j][k][5].r,kube[i][j][k][5].g,kube[i][j][k][5].b); 
					gl.glVertex3f(-0.3f+(i-1)*0.65f, 0.3f+(j-1)*0.65f, -0.3f+(k-1)*0.65f); // Top Left
					gl.glVertex3f(0.3f+(i-1)*0.65f, 0.3f+(j-1)*0.65f, -0.3f+(k-1)*0.65f); // Top Right
					gl.glVertex3f(0.3f+(i-1)*0.65f, -0.3f+(j-1)*0.65f, -0.3f+(k-1)*0.65f); // Bottom Right
					gl.glVertex3f(-0.3f+(i-1)*0.65f, -0.3f+(j-1)*0.65f, -0.3f+(k-1)*0.65f); // Bottom Left
				}
		// Done Drawing The Quad
		gl.glEnd();

		// increasing rotation for the next iteration
		rotateT += 0.3f;
	}
Example #16
0
  public void display(GLAutoDrawable drawable) {
    update();

    GL2 gl = drawable.getGL().getGL2();
    // Clear Color Buffer, Depth Buffer
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);

    Matrix TmpMatrix = new Matrix(); // Temporary MATRIX Structure ( NEW )
    Vector TmpVector = new Vector(), TmpNormal = new Vector(); // Temporary
    // VECTOR
    // Structures
    // ( NEW )

    gl.glLoadIdentity(); // Reset The Matrix

    if (outlineSmooth) { // Check To See If We Want Anti-Aliased Lines ( NEW
      // )
      gl.glHint(GL2.GL_LINE_SMOOTH_HINT, GL2.GL_NICEST); // Use The Good
      // Calculations
      // ( NEW )
      gl.glEnable(GL2.GL_LINE_SMOOTH); // Enable Anti-Aliasing ( NEW )
    } else
      // We Don't Want Smooth Lines ( NEW )
      gl.glDisable(GL2.GL_LINE_SMOOTH); // Disable Anti-Aliasing ( NEW )

    gl.glTranslatef(0.0f, 0.0f, -2.0f); // Move 2 Units Away From The Screen
    // ( NEW )
    gl.glRotatef(modelAngle, 0.0f, 1.0f, 0.0f); // Rotate The Model On It's
    // Y-Axis ( NEW )

    gl.glGetFloatv(GLMatrixFunc.GL_MODELVIEW_MATRIX, TmpMatrix.Data, 0); // Get
    // The
    // Generated
    // Matrix
    // (
    // NEW
    // )

    // Cel-Shading Code //
    gl.glEnable(GL2.GL_TEXTURE_1D); // Enable 1D Texturing ( NEW )
    gl.glBindTexture(GL2.GL_TEXTURE_1D, shaderTexture[0]); // Bind Our
    // Texture ( NEW
    // )
    gl.glColor3f(1.0f, 1.0f, 1.0f); // Set The Color Of The Model ( NEW )

    gl.glBegin(GL2.GL_TRIANGLES); // Tell OpenGL That We're Drawing
    // Triangles
    // Loop Through Each Polygon
    for (int i = 0; i < polyNum; i++)
      // Loop Through Each Vertex
      for (int j = 0; j < 3; j++) {

        // Fill Up The TmpNormal Structure With
        TmpNormal.X = polyData[i].Verts[j].Nor.X;
        // The Current Vertices' Normal Values
        TmpNormal.Y = polyData[i].Verts[j].Nor.Y;
        TmpNormal.Z = polyData[i].Verts[j].Nor.Z;
        // Rotate This By The Matrix
        TmpMatrix.rotateVector(TmpNormal, TmpVector);
        // Normalize The New Normal
        TmpVector.normalize();

        // Calculate The Shade Value
        float TmpShade = Vector.dotProduct(TmpVector, lightAngle);

        // Clamp The Value to 0 If Negative ( NEW )
        if (TmpShade < 0.0f) {
          TmpShade = 0.0f;
        }
        // Set The Texture Co-ordinate As The Shade Value
        gl.glTexCoord1f(TmpShade);
        // Send The Vertex Position
        gl.glVertex3f(
            polyData[i].Verts[j].Pos.X, polyData[i].Verts[j].Pos.Y, polyData[i].Verts[j].Pos.Z);
      }

    gl.glEnd(); // Tell OpenGL To Finish Drawing
    gl.glDisable(GL2.GL_TEXTURE_1D); // Disable 1D Textures ( NEW )

    // Outline Code
    // Check To See If We Want To Draw The Outline
    if (outlineDraw) {
      // Enable Blending
      gl.glEnable(GL2.GL_BLEND);
      // Set The Blend Mode
      gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);

      // Draw Backfacing Polygons As Wireframes
      gl.glPolygonMode(GL2.GL_BACK, GL2.GL_LINE);
      // Set The Line Width
      gl.glLineWidth(outlineWidth);
      // Don't Draw Any Front-Facing Polygons
      gl.glCullFace(GL2.GL_FRONT);

      // Change The Depth Mode
      gl.glDepthFunc(GL2.GL_LEQUAL);
      // Set The Outline Color
      gl.glColor3fv(outlineColor, 0);

      // Tell OpenGL What We Want To Draw
      gl.glBegin(GL2.GL_TRIANGLES);

      // Loop Through Each Polygon
      for (int i = 0; i < polyNum; i++) {

        // Loop Through Each Vertex
        for (int j = 0; j < 3; j++) {

          // Send The Vertex Position
          gl.glVertex3f(
              polyData[i].Verts[j].Pos.X, polyData[i].Verts[j].Pos.Y, polyData[i].Verts[j].Pos.Z);
        }
      }
      gl.glEnd(); // Tell OpenGL We've Finished
      // Reset The Depth-Testing Mode
      gl.glDepthFunc(GL2.GL_LESS);
      // Reset The Face To Be Culled
      gl.glCullFace(GL2.GL_BACK);
      // Reset Back-Facing Polygon Drawing Mode
      gl.glPolygonMode(GL2.GL_BACK, GL2.GL_FILL);

      // Disable Blending
      gl.glDisable(GL2.GL_BLEND);
    }

    // Check To See If Rotation Is Enabled
    if (modelRotate) {
      // Update Angle Based On The Clock
      modelAngle += .2f;
    }
  }
Example #17
0
 public void apply(GL2 gl) {
   gl.glRotatef(angle, x, y, z);
 }
  public void render(GL2 gl2) {
    int i;

    boolean draw_finger_star = false;
    boolean draw_base_star = false;
    boolean draw_shoulder_to_elbow = false;
    boolean draw_shoulder_star = false;
    boolean draw_elbow_star = false;
    boolean draw_wrist_star = false;
    boolean draw_stl = true;

    // RebuildShoulders(motion_now);

    gl2.glPushMatrix();
    gl2.glTranslated(position.x, position.y, position.z);

    if (draw_stl) {
      // base
      gl2.glPushMatrix();
      gl2.glColor3f(0, 0, 1);
      gl2.glTranslatef(0, 0, BASE_TO_SHOULDER_Z + 0.6f);
      gl2.glRotatef(90, 0, 0, 1);
      gl2.glRotatef(90, 1, 0, 0);
      modelBase.render(gl2);
      gl2.glPopMatrix();

      // arms
      for (i = 0; i < 3; ++i) {
        gl2.glColor3f(1, 0, 1);
        gl2.glPushMatrix();
        gl2.glTranslatef(
            motion_now.arms[i * 2 + 0].shoulder.x,
            motion_now.arms[i * 2 + 0].shoulder.y,
            motion_now.arms[i * 2 + 0].shoulder.z);
        gl2.glRotatef(120.0f * i, 0, 0, 1);
        gl2.glRotatef(90, 0, 1, 0);
        gl2.glRotatef(180 - motion_now.arms[i * 2 + 0].angle, 0, 0, 1);
        modelArm.render(gl2);
        gl2.glPopMatrix();

        gl2.glColor3f(1, 1, 0);
        gl2.glPushMatrix();
        gl2.glTranslatef(
            motion_now.arms[i * 2 + 1].shoulder.x,
            motion_now.arms[i * 2 + 1].shoulder.y,
            motion_now.arms[i * 2 + 1].shoulder.z);
        gl2.glRotatef(120.0f * i, 0, 0, 1);
        gl2.glRotatef(90, 0, 1, 0);
        gl2.glRotatef(+motion_now.arms[i * 2 + 1].angle, 0, 0, 1);
        modelArm.render(gl2);
        gl2.glPopMatrix();
      }
      // top
      gl2.glPushMatrix();
      gl2.glColor3f(0, 1, 0);
      gl2.glTranslatef(motion_now.finger_tip.x, motion_now.finger_tip.y, motion_now.finger_tip.z);
      gl2.glRotatef(motion_now.iku, 1, 0, 0);
      gl2.glRotatef(motion_now.ikv, 0, 1, 0);
      gl2.glRotatef(motion_now.ikw, 0, 0, 1);
      gl2.glRotatef(90, 0, 0, 1);
      gl2.glRotatef(180, 1, 0, 0);
      modelTop.render(gl2);
      gl2.glPopMatrix();
    }

    // draw the forearms

    Cylinder tube = new Cylinder();
    gl2.glColor3f(0.8f, 0.8f, 0.8f);
    tube.setRadius(0.15f);
    for (i = 0; i < 6; ++i) {
      // gl2.glBegin(GL2.GL_LINES);
      // gl2.glColor3f(1,0,0);
      // gl2.glVertex3f(motion_now.arms[i].wrist.x,motion_now.arms[i].wrist.y,motion_now.arms[i].wrist.z);
      // gl2.glColor3f(0,1,0);
      // gl2.glVertex3f(motion_now.arms[i].elbow.x,motion_now.arms[i].elbow.y,motion_now.arms[i].elbow.z);
      // gl2.glEnd();
      tube.SetP1(motion_now.arms[i].wrist);
      tube.SetP2(motion_now.arms[i].elbow);
      PrimitiveSolids.drawCylinder(gl2, tube);
    }

    gl2.glDisable(GL2.GL_LIGHTING);
    // debug info
    gl2.glPushMatrix();
    for (i = 0; i < 6; ++i) {
      gl2.glColor3f(1, 1, 1);
      if (draw_shoulder_star) PrimitiveSolids.drawStar(gl2, motion_now.arms[i].shoulder, 5);
      if (draw_elbow_star) PrimitiveSolids.drawStar(gl2, motion_now.arms[i].elbow, 3);
      if (draw_wrist_star) PrimitiveSolids.drawStar(gl2, motion_now.arms[i].wrist, 1);

      if (draw_shoulder_to_elbow) {
        gl2.glBegin(GL2.GL_LINES);
        gl2.glColor3f(0, 1, 0);
        gl2.glVertex3f(
            motion_now.arms[i].elbow.x, motion_now.arms[i].elbow.y, motion_now.arms[i].elbow.z);
        gl2.glColor3f(0, 0, 1);
        gl2.glVertex3f(
            motion_now.arms[i].shoulder.x,
            motion_now.arms[i].shoulder.y,
            motion_now.arms[i].shoulder.z);
        gl2.glEnd();
      }
    }
    gl2.glPopMatrix();

    if (draw_finger_star) {
      // draw finger orientation
      float s = 2;
      gl2.glBegin(GL2.GL_LINES);
      gl2.glColor3f(1, 1, 1);
      gl2.glVertex3f(motion_now.finger_tip.x, motion_now.finger_tip.y, motion_now.finger_tip.z);
      gl2.glVertex3f(
          motion_now.finger_tip.x + motion_now.finger_forward.x * s,
          motion_now.finger_tip.y + motion_now.finger_forward.y * s,
          motion_now.finger_tip.z + motion_now.finger_forward.z * s);
      gl2.glVertex3f(motion_now.finger_tip.x, motion_now.finger_tip.y, motion_now.finger_tip.z);
      gl2.glVertex3f(
          motion_now.finger_tip.x + motion_now.finger_up.x * s,
          motion_now.finger_tip.y + motion_now.finger_up.y * s,
          motion_now.finger_tip.z + motion_now.finger_up.z * s);
      gl2.glVertex3f(motion_now.finger_tip.x, motion_now.finger_tip.y, motion_now.finger_tip.z);
      gl2.glVertex3f(
          motion_now.finger_tip.x + motion_now.finger_left.x * s,
          motion_now.finger_tip.y + motion_now.finger_left.y * s,
          motion_now.finger_tip.z + motion_now.finger_left.z * s);

      gl2.glEnd();
    }

    if (draw_base_star) {
      // draw finger orientation
      float s = 2;
      gl2.glDisable(GL2.GL_DEPTH_TEST);
      gl2.glBegin(GL2.GL_LINES);
      gl2.glColor3f(1, 0, 0);
      gl2.glVertex3f(motion_now.base.x, motion_now.base.y, motion_now.base.z);
      gl2.glVertex3f(
          motion_now.base.x + motion_now.base_forward.x * s,
          motion_now.base.y + motion_now.base_forward.y * s,
          motion_now.base.z + motion_now.base_forward.z * s);
      gl2.glColor3f(0, 1, 0);
      gl2.glVertex3f(motion_now.base.x, motion_now.base.y, motion_now.base.z);
      gl2.glVertex3f(
          motion_now.base.x + motion_now.base_up.x * s,
          motion_now.base.y + motion_now.base_up.y * s,
          motion_now.base.z + motion_now.base_up.z * s);
      gl2.glColor3f(0, 0, 1);
      gl2.glVertex3f(motion_now.base.x, motion_now.base.y, motion_now.base.z);
      gl2.glVertex3f(
          motion_now.base.x + motion_now.finger_left.x * s,
          motion_now.base.y + motion_now.finger_left.y * s,
          motion_now.base.z + motion_now.finger_left.z * s);

      gl2.glEnd();
      gl2.glEnable(GL2.GL_DEPTH_TEST);
    }

    gl2.glEnable(GL2.GL_LIGHTING);

    gl2.glPopMatrix();
  }
Example #19
0
  /** Called back by the animator to perform rendering. */
  @Override
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context
    gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color and depth buffers

    for (int i = 0; i < stars.length; i++) {
      // Reset the view (x, y, z axes back to normal)
      gl.glLoadIdentity();
      gl.glTranslatef(0.0f, 0.0f, z);

      // The stars are texture quad square drawn on x-y plane and
      // distributed on on x-z plane around the y-axis

      // Initial 90 degree tile in the x-axis, y-axis pointing out of screen
      gl.glRotatef(tilt, 1.0f, 0.0f, 0.0f);
      // Rotate about y-axis (pointing out of screen), initial angle is 0
      gl.glRotatef(stars[i].angle, 0.0f, 1.0f, 0.0f);
      // Translate about the x-axis (pointing right) to its current distance
      gl.glTranslatef(stars[i].distance, 0.0f, 0.0f);

      // The stars have initial angle of 0, and initial distance linearly
      // distributed between 0 and 5.0f

      // Rotate the axes back, so that z-axis is again facing us, to ensure that
      // the quad (with texture) on x-y plane is facing us
      gl.glRotatef(-stars[i].angle, 0.0f, 1.0f, 0.0f);
      gl.glRotatef(-tilt, 1.0f, 0.0f, 0.0f);

      // Take note that without the two rotations and undo, there is only one
      // translation along the x-axis
      // Matrix operation is non-commutative. That is, AB != BA.
      // Hence, ABCB'A' != C

      // Draw the star, which spins on the z axis (pointing out of the screen)
      gl.glRotatef(starSpinAngle, 0.0f, 0.0f, 1.0f);
      // Set the star's color using bytes (why bytes? not float or int?)
      gl.glColor4ub(stars[i].r, stars[i].g, stars[i].b, (byte) 255);
      gl.glBegin(GL_QUADS);
      // draw a square on x-y plane
      gl.glTexCoord2f(textureCoordLeft, textureCoordBottom);
      gl.glVertex3f(-1.0f, -1.0f, 0.0f);
      gl.glTexCoord2f(textureCoordRight, textureCoordBottom);
      gl.glVertex3f(1.0f, -1.0f, 0.0f);
      gl.glTexCoord2f(textureCoordRight, textureCoordTop);
      gl.glVertex3f(1.0f, 1.0f, 0.0f);
      gl.glTexCoord2f(textureCoordLeft, textureCoordTop);
      gl.glVertex3f(-1.0f, 1.0f, 0.0f);
      gl.glEnd();

      // If twinkling, overlay with another drawing of an arbitrary color
      if (twinkleOn) {
        // Assign a color using bytes
        gl.glColor4ub(
            stars[(numStars - i) - 1].r,
            stars[(numStars - i) - 1].g,
            stars[(numStars - i) - 1].b,
            (byte) 255);
        gl.glBegin(GL_QUADS);
        // draw a square on x-y plane
        gl.glTexCoord2f(textureCoordLeft, textureCoordBottom);
        gl.glVertex3f(-1.0f, -1.0f, 0.0f);
        gl.glTexCoord2f(textureCoordRight, textureCoordBottom);
        gl.glVertex3f(1.0f, -1.0f, 0.0f);
        gl.glTexCoord2f(textureCoordRight, textureCoordTop);
        gl.glVertex3f(1.0f, 1.0f, 0.0f);
        gl.glTexCoord2f(textureCoordLeft, textureCoordTop);
        gl.glVertex3f(-1.0f, 1.0f, 0.0f);
        gl.glEnd();
      }

      // Update for the next refresh
      // The star spins about the z-axis (pointing out of the screen), and spiral
      // inwards and collapse towards the center, by increasing the angle on x-y
      // plane and reducing the distance.

      starSpinAngle += 0.01f; // used to spin the stars about the z-axis
      // spiral pattern
      stars[i].angle += (float) i / numStars; // changes the angle of a star
      // collapsing the star to the center
      stars[i].distance -= 0.01f; // changes the distance of a star
      // re-bone at the edge
      if (stars[i].distance < 0.0f) { // Is the star collapsed to the center?
        stars[i].distance += 5.0f; // move to the outer ring
        stars[i].setRandomRGB(); // choose a random color for the star
      }
    }
  }