Exemple #1
0
  /**
   * Transforms position of a block, so that it get's rendered at correct point. If you wish to draw
   * a block at a point, pass it to this method once you have called pushTransformMatrix() and draw
   * it at the result instead
   *
   * @param vec bottom-left corner of the place where you want to draw
   * @param result result is stored here: coordinates that you should use so the rotation matrix
   *     moves it to correct place. Use null to create new vector.
   * @return result
   */
  public Vector3f transform(Vector3f vec, Vector3f result) {
    if (result == null) result = new Vector3f();

    result.set(vec.x + .5f, vec.y + .5f, vec.z + .5f);
    MathUtils.multiplyPos(invertedRotation, result);
    result.set(result.x - .5f, result.y - .5f, result.z - .5f);
    return result;
  }
Exemple #2
0
  public void update(float delta, Vector3f emitterPos) {

    lifetime -= delta;
    if (lifetime < 0) {
      return;
    }

    a.set(acceleration);
    a.scale(delta);
    velocity = Vector3f.add(velocity, a, velocity);

    v.set(velocity);
    v.scale(delta);
    position = Vector3f.add(position, v, position);

    verticesBuffer = setupStream(position, emitterPos);
  }
  public static void loadDataContainer(
      TerrainDataContainer dest, float[][] map, int x, int y, int size) {
    float[][] harray = new float[size - 2][size - 2];
    float q = Chunk.CHUNK_SIZE / (float) (size - 3);
    int bSize = (size - 2) * (size - 2);
    FloatBuffer vBuff = BufferUtils.createFloatBuffer(bSize * 4);
    FloatBuffer tBuff = BufferUtils.createFloatBuffer(bSize * 2);
    FloatBuffer nBuff = BufferUtils.createFloatBuffer(bSize * 3);
    int iAmount = 6 * (size - 3) * (size - 3);
    IntBuffer iBuff = BufferUtils.createIntBuffer(iAmount);
    for (int pX = 0; pX < size - 2; pX++)
      for (int pZ = 0; pZ < size - 2; pZ++) {
        harray[pX][pZ] = map[x + pX + 1][y + pZ + 1];
        vBuff.put(pX * q);
        vBuff.put(map[x + pX + 1][y + pZ + 1]);
        vBuff.put(pZ * q);
        vBuff.put(1);
        tBuff.put((pX / (float) (size - 3)) * Chunk.TEXTURES);
        tBuff.put((pZ / (float) (size - 3)) * Chunk.TEXTURES);
        float hU = map[x + pX + 1][y + pZ + 2];
        float hD = map[x + pX + 1][y + pZ];
        float hL = map[x + pX][y + pZ + 1];
        float hR = map[x + pX + 2][y + pZ + 1];
        temp.set(hL - hR, 2f, hD - hU);
        temp.normalise(temp);
        nBuff.put(temp.x);
        nBuff.put(temp.y);
        nBuff.put(temp.z);
        if (pX < size - 3 && pZ < size - 3) {
          iBuff.put((pZ + 1) * (size - 2) + pX);
          iBuff.put(pZ * (size - 2) + pX);
          iBuff.put(pZ * (size - 2) + pX + 1);

          iBuff.put((pZ + 1) * (size - 2) + pX + 1);
          iBuff.put((pZ + 1) * (size - 2) + pX);
          iBuff.put(pZ * (size - 2) + pX + 1);
        }
      }
    vBuff.flip();
    tBuff.flip();
    nBuff.flip();
    iBuff.flip();
    dest.load(vBuff, tBuff, nBuff, iBuff, iAmount, q, harray);
  }
Exemple #4
0
  /**
   * Creates rotation matrix accord to current rotation and pushes it into GlStateManager. Don't
   * forget to pop (remove) it once you are done rendering with this rotation.
   */
  public void pushTransformMatrix() {
    GlStateManager.pushMatrix();
    // add operations in reverse order

    // first, rotate forward vector to rotForward
    float angle1 = Vector3f.angle(forward, rotForward);
    MathUtils.cross(forward, rotForward, tmp1);
    tmp1.normalise();

    // rotate up and rotate up
    tmpMatrix.setIdentity();
    tmpMatrix.rotate(angle1, tmp1);
    MathUtils.multiplyVec(tmpMatrix, up, tmp2);

    // L.s("Diff1: " + MathUtils.distanceSquared(up, tmp2));
    // L.s("Diff2: " + MathUtils.distanceSquared(rotUp, tmp3));

    // second, rotate up to rotUp
    float angle2 = Vector3f.angle(tmp2, rotUp);
    // L.s("Angle2: " + angle2);
    if (Math.abs(angle2) < Math.PI) {
      MathUtils.cross(tmp2, rotUp, tmp2);
      tmp2.normalise();
    } else {
      // full 180 degree rotation, use rotForward instead
      tmp2.set(rotForward);
    }
    // L.s("Tmp2: " + tmp2 + ", atan: " + Math.atan2(tmp2.z, tmp2.x) * MathUtils.radToDeg);
    GlStateManager.rotate(angle2 * MathUtils.radToDegF, tmp2.x, tmp2.y, tmp2.z); // */

    GlStateManager.rotate(angle1 * MathUtils.radToDegF, tmp1.x, tmp1.y, tmp1.z); // */

    invertedRotation.setIdentity();
    invertedRotation.rotate(angle2, tmp2);
    invertedRotation.rotate(angle1, tmp1);
    invertedRotation.invert();
  }
Exemple #5
0
 public void reset() {
   rotForward.set(forward);
   rotUp.set(up);
   rotRight.set(right);
 }
 @Override
 public void setRotation(float x, float y, float z) {
   if (rotation == null) rotation.set(x, y, z);
   else rotation.set(x, y, z);
 }
 @Override
 public void setPosition(float x, float y, float z) {
   if (position == null) position.set(x, y, z);
   else position.set(x, y, z);
 }
 public void setTarget(Vector3f vector3f) {
   target.set(vector3f);
 }
Exemple #9
0
  public void updateALSound(ALChannel[] chans, SoundLoop[] entities) {
    for (int i = 0; i < chans.length; i++) {
      ALChannel ch = chans[i];

      // Detect end of playback so channel can be freed
      if (ch.source_playing && !isPlaying(ch.chanIndex)) {
        ch.source_playing = false;
        ch.sfx = null;
      }

      Vector3f origin = ch.origin;
      if (origin == null || !ch.fixed_origin) {
        origin = entities[ch.entNum].origin;
        velocity.set(entities[ch.entNum].velocity);
      } else {
        velocity.set(0, 0, 0);
      }

      if (ch.dirty) {
        if (ch.sfx != null) {
          // Start

          int result =
              playAsSoundAt(
                  ch.sfx.getBufferID(),
                  ch.chanIndex,
                  1.0f,
                  1.0f,
                  ch.loop,
                  origin.x,
                  origin.y,
                  origin.z,
                  velocity.x,
                  velocity.y,
                  velocity.z,
                  false);

          if (result == -1) {
            ch.source_playing = false;
            ch.sfx = null;
          } else {
            ch.source_playing = true;
          }

        } else {
          if (ch.source_playing && ch.sfx == null) {
            // Stop
            stopSource(ch.chanIndex);
            ch.source_playing = false;
          }
        }
        ch.dirty = false;
      } else {
        if (ch.source_playing) {
          // Update source position & velocity
          updateSource(
              ch.chanIndex, origin.x, origin.y, origin.z, velocity.x, velocity.y, velocity.z);
        }
      }
    }
  }