public void init() {
    particles = new ArrayList(100);
    texCoords = new ArrayList(tileRows * tileCols);
    material = model.mMaterials[texture];
    parent = model.mBones[bone];
    int order = particleType <= 0 ? 0 : -1;
    if (scale.z == 519F) scale.z = 1.5F;
    for (int i = 0; i < tileRows * tileCols; i++) {
      Point2f tc[] = new Point2f[4];
      Point2f a = new Point2f();
      Point2f b = new Point2f();
      int x = i % tileCols;
      int y = i / tileCols;
      a.x = (float) x * (1.0F / (float) tileCols);
      b.x = (float) (x + 1) * (1.0F / (float) tileCols);
      a.y = (float) y * (1.0F / (float) tileRows);
      b.y = (float) (y + 1) * (1.0F / (float) tileRows);
      for (int j = 0; j < 4; j++) {
        int idx = ((j + 4) - order) % 4;
        if (j == 0) tc[idx] = a;
        else if (j == 2) tc[idx] = b;
        else if (j == 1) tc[idx] = new Point2f(b.x, a.y);
        else if (j == 3) tc[idx] = new Point2f(a.x, b.y);
      }

      texCoords.add(tc);
    }
  }
Example #2
0
  public void set(Point2f pixel, Spectrum spectrum) {
    // update maximum
    if (!Helper.CLAMPING) {
      if (spectrum.r > max.r) max.r = spectrum.r;
      if (spectrum.g > max.g) max.g = spectrum.g;
      if (spectrum.b > max.b) max.b = spectrum.b;
    }
    // no values smaller than 0
    if (spectrum.r < 0) spectrum.r = 0;
    if (spectrum.g < 0) spectrum.g = 0;
    if (spectrum.b < 0) spectrum.b = 0;
    if (Helper.CLAMPING) {
      if (spectrum.r > 1) spectrum.r = 1;
      if (spectrum.g > 1) spectrum.g = 1;
      if (spectrum.b > 1) spectrum.b = 1;
    }
    this.image[(int) pixel.getX() - 1][(int) pixel.getY() - 1] = spectrum;

    if (Helper.SHOW_PROGRESS) {
      int i = (int) pixel.getX() - 1;
      int j = (int) pixel.getY() - 1;
      if (Helper.CLAMPING)
        this.img.setRGB(
            i,
            height - 1 - j,
            ((int) (255.f * this.image[i][j].r) << 16)
                | ((int) (255.f * this.image[i][j].g) << 8)
                | ((int) (255.f * this.image[i][j].b)));
      else
        this.img.setRGB(
            i,
            height - 1 - j,
            ((int) (255.f * this.image[i][j].r / max.r) << 16)
                | ((int) (255.f * this.image[i][j].g / max.g) << 8)
                | ((int) (255.f * this.image[i][j].b / max.b)));
    }
  }
Example #3
0
  /** Here we actually draw the scene. */
  public void display(GLAutoDrawable drawable) {
    super.display(drawable);

    System.out.println("GLScene - display");
    GL gl = drawable.getGL();

    try {
      // Update velocities and positions of all text
      float deltaT = 0.1f;
      Point2f tmp = new Point2f();

      for (Iterator<TextInfo> iter = textInfo.iterator(); iter.hasNext(); ) {
        TextInfo info = (TextInfo) iter.next();

        // Randomize things a little bit at run time
        if (random.nextInt(1000) == 0) {
          info.angularVelocity = INIT_ANG_VEL_MAG * (randomAngle() - 180);
          info.velocity = randomVelocity(INIT_VEL_MAG, INIT_VEL_MAG);
        }

        // Now update angles and positions
        info.angle += info.angularVelocity * deltaT;
        tmp.set(info.velocity);
        tmp.scale(deltaT);
        info.position.add(tmp);

        // Update color
        info.curTime += deltaT;
        if (info.curTime > 2 * Math.PI) {
          info.curTime -= 2 * Math.PI;
        }
        int rgb =
            Color.HSBtoRGB(info.h, (float) (0.5 * (1 + Math.sin(info.curTime)) * info.s), info.v);
        info.r = ((rgb >> 16) & 0xFF) / 255.0f;
        info.g = ((rgb >> 8) & 0xFF) / 255.0f;
        info.b = (rgb & 0xFF) / 255.0f;

        // Wrap angles and positions
        if (info.angle < 0) {
          info.angle += 360;
        } else if (info.angle > 360) {
          info.angle -= 360;
        }
        // Use maxTextWidth to avoid popping in/out at edges
        // Would be better to do oriented bounding rectangle computation
        if (info.position.x < -maxTextWidth) {
          info.position.x = info.position.x + glComposite.getCanvas().getWidth() + 2 * maxTextWidth;
        } else if (info.position.x > glComposite.getCanvas().getWidth() + maxTextWidth) {
          info.position.x = info.position.x - glComposite.getCanvas().getWidth() - 2 * maxTextWidth;
        }
        if (info.position.y < -maxTextWidth) {
          info.position.y =
              info.position.y + glComposite.getCanvas().getHeight() + 2 * maxTextWidth;
        } else if (info.position.y > glComposite.getCanvas().getHeight() + maxTextWidth) {
          info.position.y =
              info.position.y - glComposite.getCanvas().getHeight() - 2 * maxTextWidth;
        }
      }

      gl.glClear(GL.GL_COLOR_BUFFER_BIT);
      gl.glMatrixMode(GL.GL_PROJECTION);
      gl.glLoadIdentity();
      glComposite
          .getGLU()
          .gluOrtho2D(
              0, glComposite.getCanvas().getWidth(), 0, glComposite.getCanvas().getHeight());
      gl.glMatrixMode(GL.GL_MODELVIEW);
      gl.glLoadIdentity();

      // Draw the background texture
      backgroundTexture.enable();
      backgroundTexture.bind();
      TextureCoords coords = backgroundTexture.getImageTexCoords();
      int w = glComposite.getCanvas().getWidth();
      int h = glComposite.getCanvas().getHeight();
      float fw = w / 100.0f;
      float fh = h / 100.0f;
      gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);
      gl.glBegin(GL.GL_QUADS);
      gl.glTexCoord2f(fw * coords.left(), fh * coords.bottom());
      gl.glVertex3f(0, 0, 0);
      gl.glTexCoord2f(fw * coords.right(), fh * coords.bottom());
      gl.glVertex3f(w, 0, 0);
      gl.glTexCoord2f(fw * coords.right(), fh * coords.top());
      gl.glVertex3f(w, h, 0);
      gl.glTexCoord2f(fw * coords.left(), fh * coords.top());
      gl.glVertex3f(0, h, 0);
      gl.glEnd();
      backgroundTexture.disable();

      // Render all text
      renderer.beginRendering(w, h);

      // Note we're doing some slightly fancy stuff to position the text.
      // We tell the text renderer to render the text at the origin, and
      // manipulate the modelview matrix to put the text where we want.

      gl.glMatrixMode(GL.GL_MODELVIEW);

      // First render drop shadows
      renderer.setColor(0, 0, 0, 0.5f);
      for (Iterator<TextInfo> iter = textInfo.iterator(); iter.hasNext(); ) {
        TextInfo info = (TextInfo) iter.next();
        gl.glLoadIdentity();
        gl.glTranslatef(
            info.position.x + dropShadowDistance, info.position.y - dropShadowDistance, 0);
        gl.glRotatef(info.angle, 0, 0, 1);
        renderer.draw(info.text, 0, 0);
        renderer.flush();
      }

      // Now render the actual text
      for (Iterator<TextInfo> iter = textInfo.iterator(); iter.hasNext(); ) {
        TextInfo info = (TextInfo) iter.next();
        gl.glLoadIdentity();
        gl.glTranslatef(info.position.x, info.position.y, 0);
        gl.glRotatef(info.angle, 0, 0, 1);
        renderer.setColor(info.r, info.g, info.b, 1);
        renderer.draw(info.text, 0, 0);
        renderer.flush();
      }

      renderer.endRendering();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }