protected int updateCoordinateBuffers(TaggedAxis1D taggedAxis, int width, int height) {
    List<Tag> tags = taggedAxis.getSortedTags();

    int size = tags.size();

    if (vertexCoords == null || vertexCoords.capacity() < size * 4)
      vertexCoords = Buffers.newDirectFloatBuffer(size * 4);

    if (textureCoords == null || textureCoords.capacity() < size * 2)
      textureCoords = Buffers.newDirectFloatBuffer(size * 2);

    vertexCoords.rewind();
    textureCoords.rewind();

    int x1 = getColorBarMinX(width);
    int x2 = getColorBarMaxX(width);

    int count = 0;
    for (Tag tag : tags) {
      if (tag.hasAttribute(TEX_COORD_ATTR)) {
        float textureCoord = tag.getAttributeFloat(TEX_COORD_ATTR);
        float vertexCoord = (float) taggedAxis.valueToScreenPixel(tag.getValue());

        vertexCoords.put(x1).put(vertexCoord).put(x2).put(vertexCoord);
        textureCoords.put(textureCoord).put(textureCoord);

        count += 2;
      }
    }

    return count;
  }
  protected void initParticles() {
    pAndsBuff.clear();
    velBuff.clear();
    lifespanBuff.clear();
    ageBuff.clear();

    float[] velocity = dir.dot(speed);

    for (int i = 0; i < particleCount; i++) {
      pAndsBuff.put(
          new float[] {
            ((float) Math.random() - 0.5f) * 50f, 50f, ((float) Math.random() - 0.5f) * 50f, 0.016f
          });
      velBuff.put(new float[] {velocity[0], velocity[1], velocity[2], 0f});
      ageBuff.put(0f);

      if (i < startCount) {
        lifespanBuff.put(1f);
      } else {
        lifespanBuff.put(0f);
      }
    }

    pAndsBuff.rewind();
    velBuff.rewind();
    lifespanBuff.rewind();
    ageBuff.rewind();

    newParticles = (int) (birthRate * timeBetweenAni);
  }
  @Override
  protected void paintColorScale(GL2 gl, Axis1D axis, int width, int height) {
    if (colorTexture != null && axis instanceof TaggedAxis1D) {
      TaggedAxis1D taggedAxis = (TaggedAxis1D) axis;

      colorTexture.prepare(gl, 0);

      int count = updateCoordinateBuffers(taggedAxis, width, height);

      gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE);
      gl.glPolygonMode(GL2.GL_FRONT, GL2.GL_FILL);

      gl.glEnable(GL2.GL_TEXTURE_1D);

      gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
      gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY);

      gl.glVertexPointer(2, GL2.GL_FLOAT, 0, vertexCoords.rewind());
      gl.glTexCoordPointer(1, GL2.GL_FLOAT, 0, textureCoords.rewind());

      try {
        gl.glDrawArrays(GL2.GL_QUAD_STRIP, 0, count);
      } finally {
        gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
        gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
        gl.glDisable(GL2.GL_TEXTURE_1D);
      }
    }

    gl.glDisable(GL2.GL_TEXTURE_1D);

    outlineColorQuad(gl, axis, width, height);
  }
Пример #4
0
  public Skybox(String texture) {
    vertexBuffer = BufferUtils.newFloatBuffer(72);
    vertexBuffer.put(
        new float[] {
          -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f,
          -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f, 0.5f,
          0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f,
          0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f,
          0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, -0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f,
          -0.5f, 0.5f, -0.5f, 0.5f
        });
    vertexBuffer.rewind();

    texCoordBuffer = BufferUtils.newFloatBuffer(48);
    texCoordBuffer.put(
        new float[] {
          0.5f, 0.75f, 0.5f, 1.0f, 0.25f, 0.75f, 0.25f, 1.0f, // bottom
          0.25f, 0.75f, 0f, 0.75f, 0.25f, 0.5f, 0f, 0.5f, // left
          0.25f, 0.5f, 0.25f, 0.25f, 0.5f, 0.5f, 0.5f, 0.25f, // top
          0.5f, 0.5f, 0.75f, 0.5f, 0.5f, 0.75f, 0.75f, 0.75f, // right
          0.75f, 0.75f, 0.75f, 0.5f, 1f, 0.75f, 1.0f, 0.5f, // right right
          0.5f, 0.75f, 0.5f, 0.5f, 0.25f, 0.75f, 0.25f, 0.5f, // center
        });
    texCoordBuffer.rewind();

    tex = new Texture(Gdx.files.internal(texture));
    useTexture = true;
  }
 public void useLights(ArrayList<RenderLight> lights, int s, int c) {
   if (unLPos != GL.BadUniformLocation) {
     fbLight.clear();
     Vector3 pos = new Vector3();
     for (int i = 0; i < c; i++) {
       RenderLight rl = lights.get(s + i);
       rl.mWorldTransform.mulPos(pos);
       fbLight.put(pos.x);
       fbLight.put(pos.y);
       fbLight.put(pos.z);
       pos.set(0);
     }
     fbLight.rewind();
     GL20.glUniform3(unLPos, fbLight);
   }
   if (unLIntensity != GL.BadUniformLocation) {
     fbLight.clear();
     for (int i = 0; i < c; i++) {
       RenderLight rl = lights.get(s + i);
       fbLight.put((float) rl.sceneLight.intensity.x);
       fbLight.put((float) rl.sceneLight.intensity.y);
       fbLight.put((float) rl.sceneLight.intensity.z);
     }
     fbLight.rewind();
     GL20.glUniform3(unLIntensity, fbLight);
   }
   if (unLCount != GL.BadUniformLocation) {
     GL20.glUniform1i(unLCount, c);
   }
 }
Пример #6
0
  /**
   * @param object1
   * @param object2
   * @throws Exception
   */
  private void init(SurfaceTriangleList object1, SurfaceTriangleList object2) throws Exception {

    // bruteforce for now
    FloatBuffer ver1 = object1.getTriangleBuffer();
    FloatBuffer ver2 = object2.getTriangleBuffer();

    int cnt1 = object1.getChunkCount();
    int cnt2 = object2.getChunkCount();

    float[] t1 = new float[9];
    float[] t2 = new float[9];
    ver1.rewind();
    ver2.rewind();

    Boolean intersect = false;
    Boolean coplanar = false;
    float[] segment;
    for (int i = 0; i < cnt1; i++) {
      ver1.get(t1);
      for (int j = 0; j < cnt2; j++) {
        ver2.get(t2);
        segment = Collision.triTriIntersect(t1, t2, coplanar, intersect);

        if (coplanar) { // TODO: handle coplanearity
          throw new Exception("coplanearity not yet supported");
        } else if (intersect) {
          tris.add(segment, true);
        }
      }
    }
  }
Пример #7
0
  /**
   * Normalizes weights if needed and finds largest amount of weights used for all vertices in the
   * buffer.
   *
   * @param vertCount amount of vertices
   * @param weightsFloatData weights for vertices
   */
  private int endBoneAssigns(int vertCount, FloatBuffer weightsFloatData) {
    int maxWeightsPerVert = 0;
    weightsFloatData.rewind();
    for (int v = 0; v < vertCount; ++v) {
      float w0 = weightsFloatData.get(),
          w1 = weightsFloatData.get(),
          w2 = weightsFloatData.get(),
          w3 = weightsFloatData.get();

      if (w3 != 0) {
        maxWeightsPerVert = Math.max(maxWeightsPerVert, 4);
      } else if (w2 != 0) {
        maxWeightsPerVert = Math.max(maxWeightsPerVert, 3);
      } else if (w1 != 0) {
        maxWeightsPerVert = Math.max(maxWeightsPerVert, 2);
      } else if (w0 != 0) {
        maxWeightsPerVert = Math.max(maxWeightsPerVert, 1);
      }

      float sum = w0 + w1 + w2 + w3;
      if (sum != 1f && sum != 0.0f) {
        weightsFloatData.position(weightsFloatData.position() - 4);
        // compute new vals based on sum
        float sumToB = 1f / sum;
        weightsFloatData.put(w0 * sumToB);
        weightsFloatData.put(w1 * sumToB);
        weightsFloatData.put(w2 * sumToB);
        weightsFloatData.put(w3 * sumToB);
      }
    }
    weightsFloatData.rewind();

    // mesh.setMaxNumWeights(maxWeightsPerVert);
    return maxWeightsPerVert;
  }
  private static Matrix4f getMatrix(int matrixEnum) {
    Matrix4f matrix = new Matrix4f();

    matrixBuffer.rewind();
    glGetFloat(matrixEnum, matrixBuffer);
    matrixBuffer.rewind();

    matrix.load(matrixBuffer);
    return matrix;
  }
Пример #9
0
  public void init(GL3 gl) {
    if (!initialized) {
      coordinates.rewind();
      colors.rewind();

      GLSLAttrib vAttrib = new GLSLAttrib(coordinates, "MCvertex", GLSLAttrib.SIZE_FLOAT, 3);

      GLSLAttrib cAttrib = new GLSLAttrib(colors, "MCcolor", GLSLAttrib.SIZE_FLOAT, 4);

      vbo = new VBO(gl, vAttrib, cAttrib);
      initialized = true;
    }
  }
Пример #10
0
  public void draw(GL10 gl) {
    // Set our vertex/frag shader program.
    GLES20.glUseProgram(mProgram);

    // Set program handles for drawing.
    // mPositionHandle = GLES20.glGetAttribLocation(mProgram, "a_Position");
    // mTextureCoordinateHandle = GLES20.glGetAttribLocation(mProgram, "a_TexCoordinate");
    mTextureUniformHandle = GLES20.glGetUniformLocation(mProgram, "u_Texture");
    // Set the active texture unit to texture unit 0.
    // GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

    // Bind the texture to this unit.
    // GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);

    vertexBuffer.rewind();
    textureBuffer.rewind();

    // Tell the texture uniform sampler to use this texture in the shader by binding to texture unit
    // 0.
    GLES20.glUniform1i(mTextureUniformHandle, 0);

    // Point to our buffers
    // gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    // gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    // Point to our vertex buffer
    // gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
    // gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vertexBufferPointer);
    // first parameter is the ID number of the attribute of the vertex
    // we set attribute id = 0 to the position and 1 to the texture coordin
    GLES20.glVertexAttribPointer(0, 3, GLES20.GL_FLOAT, false, 0, 0);
    GLES20.glEnableVertexAttribArray(0);

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, textureBufferPointer);
    GLES20.glVertexAttribPointer(1, 2, GLES20.GL_FLOAT, false, 0, 0);
    GLES20.glEnableVertexAttribArray(1);

    // Set the face rotation
    // GLES20.glFrontFace(GL10.GL_CW);

    // Draw the vertices as triangle strip
    GLES20.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);

    System.out.println(GLUtils.getEGLErrorString(gl.glGetError()));

    // Disable the client state before leaving
    // gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    // gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

  }
Пример #11
0
  private void doTransforms(
      FloatBuffer bindBufPos,
      FloatBuffer bindBufNorm,
      FloatBuffer bufPos,
      FloatBuffer bufNorm,
      int start,
      int end,
      Matrix4f transform) {
    TempVars vars = TempVars.get();
    Vector3f pos = vars.vect1;
    Vector3f norm = vars.vect2;

    int length = (end - start) * 3;

    // offset is given in element units
    // convert to be in component units
    int offset = start * 3;
    bindBufPos.rewind();
    bindBufNorm.rewind();
    // bufPos.position(offset);
    // bufNorm.position(offset);
    bindBufPos.get(tmpFloat, 0, length);
    bindBufNorm.get(tmpFloatN, 0, length);
    int index = 0;
    while (index < length) {
      pos.x = tmpFloat[index];
      norm.x = tmpFloatN[index++];
      pos.y = tmpFloat[index];
      norm.y = tmpFloatN[index++];
      pos.z = tmpFloat[index];
      norm.z = tmpFloatN[index];

      transform.mult(pos, pos);
      transform.multNormal(norm, norm);

      index -= 2;
      tmpFloat[index] = pos.x;
      tmpFloatN[index++] = norm.x;
      tmpFloat[index] = pos.y;
      tmpFloatN[index++] = norm.y;
      tmpFloat[index] = pos.z;
      tmpFloatN[index++] = norm.z;
    }
    vars.release();
    bufPos.position(offset);
    // using bulk put as it's faster
    bufPos.put(tmpFloat, 0, length);
    bufNorm.position(offset);
    // using bulk put as it's faster
    bufNorm.put(tmpFloatN, 0, length);
  }
Пример #12
0
  public void orthogonalLineFit(FloatBuffer points) {
    if (points == null) {
      return;
    }

    points.rewind();

    // compute average of points
    int length = points.remaining() / 3;

    BufferUtils.populateFromBuffer(origin, points, 0);
    for (int i = 1; i < length; i++) {
      BufferUtils.populateFromBuffer(compVec1, points, i);
      origin.addLocal(compVec1);
    }

    origin.multLocal(1f / (float) length);

    // compute sums of products
    float sumXX = 0.0f, sumXY = 0.0f, sumXZ = 0.0f;
    float sumYY = 0.0f, sumYZ = 0.0f, sumZZ = 0.0f;

    points.rewind();
    for (int i = 0; i < length; i++) {
      BufferUtils.populateFromBuffer(compVec1, points, i);
      compVec1.subtract(origin, compVec2);
      sumXX += compVec2.x * compVec2.x;
      sumXY += compVec2.x * compVec2.y;
      sumXZ += compVec2.x * compVec2.z;
      sumYY += compVec2.y * compVec2.y;
      sumYZ += compVec2.y * compVec2.z;
      sumZZ += compVec2.z * compVec2.z;
    }

    // find the smallest eigen vector for the direction vector
    compMat1.m00 = sumYY + sumZZ;
    compMat1.m01 = -sumXY;
    compMat1.m02 = -sumXZ;
    compMat1.m10 = -sumXY;
    compMat1.m11 = sumXX + sumZZ;
    compMat1.m12 = -sumYZ;
    compMat1.m20 = -sumXZ;
    compMat1.m21 = -sumYZ;
    compMat1.m22 = sumXX + sumYY;

    compEigen1.calculateEigen(compMat1);
    direction = compEigen1.getEigenVector(0);
  }
Пример #13
0
  private int createTubeVbo(int tube, Color color) {

    float[] c =
        new float[] {color.getBlue() / 255f, color.getGreen() / 255f, color.getRed() / 255f};

    totalNumVerts[tube] = tubes[tube].indeces.length;

    IntBuffer buf = BufferUtils.createIntBuffer(1);
    GL15.glGenBuffers(buf);
    int vbo = buf.get();

    FloatBuffer data = BufferUtils.createFloatBuffer(tubes[tube].indeces.length * 9);

    for (int i = 0; i < tubes[tube].indeces.length; i++) {
      data.put(c);

      Vector3D vertex = tubes[tube].vertices[tubes[tube].indeces[i]];
      Vector3D normal = tubes[tube].normals[tubes[tube].indeces[i]];

      float[] vertexf = new float[] {vertex.x, vertex.y, vertex.z};
      float[] normalf = new float[] {normal.x, normal.y, normal.z};

      data.put(vertexf);
      data.put(normalf);
    }
    data.rewind();

    int bytesPerFloat = Float.SIZE / Byte.SIZE;
    int numBytes = data.capacity() * bytesPerFloat;
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, data, GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    return vbo;
  }
Пример #14
0
  /**
   * Gets a float buffer with given number of elements and random content. The buffer is rewinded
   * after creation.
   *
   * @param i_iNumberOfElements Number of elements to generate for the random buffer
   * @return The randomly filled float buffer.
   */
  public static FloatBuffer getRandomFloatBuffer(int i_iNumberOfElements) {
    FloatBuffer buf = FloatBuffer.allocate(i_iNumberOfElements);
    for (int i = 0; i < i_iNumberOfElements - 1; i++) buf.put(getRandomFloat());
    buf.rewind();

    return buf;
  }
Пример #15
0
  /** Defines the normals of each face of the pyramid. */
  protected void setNormalData() {

    Vector3 normal = new Vector3();
    Vector3 work = new Vector3();

    FloatBuffer norms = BufferUtils.createVector3Buffer(12);

    // side 1
    MathUtil.createNormal(normal, vert0, vert1, peak, work);
    norms.put((float) normal.getX()).put((float) normal.getY()).put((float) normal.getZ());
    norms.put((float) normal.getX()).put((float) normal.getY()).put((float) normal.getZ());
    norms.put((float) normal.getX()).put((float) normal.getY()).put((float) normal.getZ());

    // side 2
    MathUtil.createNormal(normal, vert1, vert2, peak, work);
    norms.put((float) normal.getX()).put((float) normal.getY()).put((float) normal.getZ());
    norms.put((float) normal.getX()).put((float) normal.getY()).put((float) normal.getZ());
    norms.put((float) normal.getX()).put((float) normal.getY()).put((float) normal.getZ());

    // side 3
    MathUtil.createNormal(normal, vert2, vert3, peak, work);
    norms.put((float) normal.getX()).put((float) normal.getY()).put((float) normal.getZ());
    norms.put((float) normal.getX()).put((float) normal.getY()).put((float) normal.getZ());
    norms.put((float) normal.getX()).put((float) normal.getY()).put((float) normal.getZ());

    // side 4
    MathUtil.createNormal(normal, vert3, vert0, peak, work);
    norms.put((float) normal.getX()).put((float) normal.getY()).put((float) normal.getZ());
    norms.put((float) normal.getX()).put((float) normal.getY()).put((float) normal.getZ());
    norms.put((float) normal.getX()).put((float) normal.getY()).put((float) normal.getZ());

    norms.rewind();
    sides.getMeshData().setNormalBuffer(norms);
  }
Пример #16
0
  /**
   * Sets the vertices that make the pyramid. Where the center of the box is the origin and the base
   * and height are set during construction.
   */
  protected void setVertexData() {
    peak = new Vector3(0, 0, 0);
    vert0 = new Vector3(-width / 2, -height / 2, -length);
    vert1 = new Vector3(width / 2, -height / 2, -length);
    vert2 = new Vector3(width / 2, height / 2, -length);
    vert3 = new Vector3(-width / 2, height / 2, -length);

    FloatBuffer verts = BufferUtils.createVector3Buffer(12);

    // side 1
    verts.put((float) vert0.getX()).put((float) vert0.getY()).put((float) vert0.getZ());
    verts.put((float) vert1.getX()).put((float) vert1.getY()).put((float) vert1.getZ());
    verts.put((float) peak.getX()).put((float) peak.getY()).put((float) peak.getZ());

    // side 2
    verts.put((float) vert1.getX()).put((float) vert1.getY()).put((float) vert1.getZ());
    verts.put((float) vert2.getX()).put((float) vert2.getY()).put((float) vert2.getZ());
    verts.put((float) peak.getX()).put((float) peak.getY()).put((float) peak.getZ());

    // side 3
    verts.put((float) vert2.getX()).put((float) vert2.getY()).put((float) vert2.getZ());
    verts.put((float) vert3.getX()).put((float) vert3.getY()).put((float) vert3.getZ());
    verts.put((float) peak.getX()).put((float) peak.getY()).put((float) peak.getZ());

    // side 4
    verts.put((float) vert3.getX()).put((float) vert3.getY()).put((float) vert3.getZ());
    verts.put((float) vert0.getX()).put((float) vert0.getY()).put((float) vert0.getZ());
    verts.put((float) peak.getX()).put((float) peak.getY()).put((float) peak.getZ());

    verts.rewind();
    sides.getMeshData().setVertexBuffer(verts);
  }
Пример #17
0
  private void setupPointers(GL2 gl) {
    int vertices[] = new int[] {25, 25, 100, 325, 175, 25, 175, 325, 250, 25, 325, 325};
    float colors[] =
        new float[] {
          1.0f, 0.2f, 0.2f, 0.2f, 0.2f, 1.0f, 0.8f, 1.0f, 0.2f, 0.75f, 0.75f, 0.75f, 0.35f, 0.35f,
          0.35f, 0.5f, 0.5f, 0.5f
        };

    if (verticesBuf == null) { // IntBuffer tmpVerticesBuf
      verticesBuf = GLBuffers.newDirectIntBuffer(vertices.length);
      verticesBuf.put(vertices);
    }
    if (colorsBuf == null) {
      colorsBuf = GLBuffers.newDirectFloatBuffer(colors.length);
      colorsBuf.put(colors);
    }
    verticesBuf.rewind();
    colorsBuf.rewind();
    //
    gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL2.GL_COLOR_ARRAY);
    //
    gl.glVertexPointer(2, GL2.GL_INT, 0, verticesBuf);
    gl.glColorPointer(3, GL.GL_FLOAT, 0, colorsBuf);
  }
Пример #18
0
 /*
  * (non-Javadoc)
  *
  * @see syn3d.nodes.xith3d.ShapeNodeXith3D#setAppearanceForHighlight(boolean)
  */
 public void setAppearanceForHighlight(boolean on) {
   if (colors == null) return; // parent constructor
   // Great by ref color buffer = just modify the thing and it is OK!
   float[] color = getColorForOrder(groupIdx, on ? 1 : 0);
   colors.rewind();
   int l3 = plates.length * 3;
   for (int i = 0; i < l3; i += 3) colors.put(color);
 }
Пример #19
0
 public void setTexture(float s, float t) {
   textures.put(s);
   textures.put(t);
   addedTextures++;
   if (addedTextures >= numberOfVertex) {
     textures.rewind();
   }
 }
Пример #20
0
 /**
  * method to convert a Java float array to a FloatBuffer (Java NIO API)
  *
  * @param array
  * @return
  */
 private static FloatBuffer FloatArrayToFloatBuffer(float[] array) {
   FloatBuffer fb = BufferUtil.newFloatBuffer(array.length);
   for (int i = 0; i < array.length; i++) {
     fb.put(array[i]);
   }
   fb.rewind();
   return fb;
 }
Пример #21
0
 /**
  * Gets a colxrow intead of row x col
  *
  * @return
  */
 public FloatBuffer getFloatBuffer() {
   buffer16.clear();
   // give col x row ordering
   for (int col = 0; col < 4; col++) {
     for (int row = 0; row < 4; row++) buffer16.put((float) matrix4x4[row][col]);
   }
   buffer16.rewind();
   return buffer16;
 }
Пример #22
0
 public void setVertex(float x, float y, float z) {
   vertices.put(x);
   vertices.put(y);
   vertices.put(z);
   addedVertex++;
   if (addedVertex >= numberOfVertex) {
     vertices.rewind();
   }
 }
 /**
  * Calculates a minimum bounding sphere for the set of points. The algorithm was originally found
  * at
  * http://www.flipcode.com/cgi-bin/msg.cgi?showThread=COTD-SmallestEnclosingSpheres&forum=cotd&id=-1
  * in C++ and translated to java by Cep21
  *
  * @param points The points to calculate the minimum bounds from.
  */
 public void calcWelzl(FloatBuffer points) {
   if (center == null) {
     center = new Vector3f();
   }
   FloatBuffer buf = BufferUtils.createFloatBuffer(points.limit());
   points.rewind();
   buf.put(points);
   buf.flip();
   recurseMini(buf, buf.limit() / 3, 0, 0);
 }
Пример #24
0
  /**
   * Gets a float buffer from a float array. The float buffer will be rewinded after its creation.
   *
   * @param i_sourceFloatArray Array to create the float buffer from.
   * @return A float buffer with the same elements as the source array.
   */
  public static FloatBuffer buffer2Array(float[] i_sourceFloatArray) {
    FloatBuffer buf = FloatBuffer.allocate(i_sourceFloatArray.length);

    for (float f : i_sourceFloatArray) {
      buf.put(f);
    }

    buf.rewind();
    return buf;
  }
Пример #25
0
 public void setColor(float r, float g, float b, float alpha) {
   colors.put(r);
   colors.put(g);
   colors.put(b);
   colors.put(alpha);
   addedColors++;
   if (addedColors >= numberOfVertex) {
     colors.rewind();
   }
 }
Пример #26
0
  /**
   * Nudges an entire object in the given direction through manipulation of its vertices rather than
   * position of the Spatial itself.
   *
   * @param s The Spatial to move.
   * @param x The amount of x units to move the object.
   * @param y The amount of y units to move the object.
   * @param z The amount of z units to move the object.
   */
  public static void adjustObject(Spatial s, float x, float y, float z) {
    logger.info("Moving " + s.getName() + " " + x + "," + y + "," + z);
    if (s instanceof TriMesh) {
      FloatBuffer vb = ((TriMesh) s).getVertexBuffer();
      vb.rewind();

      float[] floatArray = new float[vb.capacity()];

      for (int i = 0; i < ((TriMesh) s).getTriangleCount(); i++) {
        floatArray[i * 3] = vb.get(i * 3) + x;
        floatArray[i * 3] = vb.get(i * 3 + 1) + y;
        floatArray[i * 3] = vb.get(i * 3 + 2) + z;
      }

      FloatBuffer newBuffer = FloatBuffer.allocate(vb.capacity());
      newBuffer.put(floatArray);
      ((TriMesh) s).setVertexBuffer(newBuffer);
    }
    if (s instanceof QuadMesh) {
      FloatBuffer vb = ((QuadMesh) s).getVertexBuffer();
      vb.rewind();

      float[] floatArray = new float[vb.capacity()];

      for (int i = 0; i < ((QuadMesh) s).getQuadCount(); i++) {
        floatArray[i * 4] = vb.get(i * 4) + x;
        floatArray[i * 4] = vb.get(i * 4 + 1) + y;
        floatArray[i * 4] = vb.get(i * 4 + 2) + z;
      }

      FloatBuffer newBuffer = FloatBuffer.allocate(vb.capacity());
      newBuffer.put(floatArray);
      ((QuadMesh) s).setVertexBuffer(newBuffer);
    }
    if (s instanceof Node) {
      if (((Node) s).getChildren() != null) {
        for (Spatial child : ((Node) s).getChildren()) {
          adjustObject(child, x, y, z);
        }
      }
    }
  }
Пример #27
0
  public void CreateWall() {
    vertexBuffer = BufferUtils.newFloatBuffer(72);

    vertexBuffer.put(
        new float[] {
          -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f,
          -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f, 0.5f,
          0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f,
          0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f,
          0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, -0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f,
          -0.5f, 0.5f, -0.5f, 0.5f
        });
    vertexBuffer.rewind();

    texCoordBuffer = BufferUtils.newFloatBuffer(8);
    texCoordBuffer.put(new float[] {0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f});
    texCoordBuffer.rewind();

    // tex = new Texture(Gdx.files.internal("textures/block.jpg"));
  }
Пример #28
0
  public static void create(int vertexPointer) {

    CannonGraphic.vertexPointer = vertexPointer;

    // VERTEX ARRAY IS FILLED HERE
    float[] array = {-20f, 60f, -20f, -60f, 20f, -60f, 20f, 60f};

    vertexBuffer = BufferUtils.newFloatBuffer(8);
    vertexBuffer.put(array);
    vertexBuffer.rewind();
  }
Пример #29
0
  /**
   * Update Frustum
   *
   * @param gm GameResources
   */
  public void calculateFrustum(Matrix4f projectionMatrix, Camera camera) {
    float[] clip = new float[16];

    Matrix4f.mul(projectionMatrix, Maths.createViewMatrix(camera), clip_);
    clip_b.rewind();
    clip_.store(clip_b);
    clip_b.rewind();
    clip_b.get(clip);

    m_Frustum[RIGHT][A] = clip[3] - clip[0];
    m_Frustum[RIGHT][B] = clip[7] - clip[4];
    m_Frustum[RIGHT][C] = clip[11] - clip[8];
    m_Frustum[RIGHT][D] = clip[15] - clip[12];
    normalizePlane(m_Frustum, RIGHT);
    m_Frustum[LEFT][A] = clip[3] + clip[0];
    m_Frustum[LEFT][B] = clip[7] + clip[4];
    m_Frustum[LEFT][C] = clip[11] + clip[8];
    m_Frustum[LEFT][D] = clip[15] + clip[12];
    normalizePlane(m_Frustum, LEFT);
    m_Frustum[BOTTOM][A] = clip[3] + clip[1];
    m_Frustum[BOTTOM][B] = clip[7] + clip[5];
    m_Frustum[BOTTOM][C] = clip[11] + clip[9];
    m_Frustum[BOTTOM][D] = clip[15] + clip[13];
    normalizePlane(m_Frustum, BOTTOM);
    m_Frustum[TOP][A] = clip[3] - clip[1];
    m_Frustum[TOP][B] = clip[7] - clip[5];
    m_Frustum[TOP][C] = clip[11] - clip[9];
    m_Frustum[TOP][D] = clip[15] - clip[13];
    normalizePlane(m_Frustum, TOP);
    m_Frustum[BACK][A] = clip[3] - clip[2];
    m_Frustum[BACK][B] = clip[7] - clip[6];
    m_Frustum[BACK][C] = clip[11] - clip[10];
    m_Frustum[BACK][D] = clip[15] - clip[14];
    normalizePlane(m_Frustum, BACK);
    m_Frustum[FRONT][A] = clip[3] + clip[2];
    m_Frustum[FRONT][B] = clip[7] + clip[6];
    m_Frustum[FRONT][C] = clip[11] + clip[10];
    m_Frustum[FRONT][D] = clip[15] + clip[14];

    normalizePlane(m_Frustum, FRONT);
  }
 private static void writeColorBuffer(List<VertexData> vertices, ColorRGBA[] cols, Mesh mesh) {
   FloatBuffer colors = BufferUtils.createFloatBuffer(vertices.size() * 4);
   colors.rewind();
   for (ColorRGBA color : cols) {
     colors.put(color.r);
     colors.put(color.g);
     colors.put(color.b);
     colors.put(color.a);
   }
   mesh.clearBuffer(Type.Color);
   mesh.setBuffer(Type.Color, 4, colors);
 }