Exemplo n.º 1
0
Arquivo: Box.java Projeto: RMMJR/g3m
  private void createMesh(Color color) {

    float[] v = {
      (float) _lower._x,
      (float) _lower._y,
      (float) _lower._z,
      (float) _lower._x,
      (float) _upper._y,
      (float) _lower._z,
      (float) _lower._x,
      (float) _upper._y,
      (float) _upper._z,
      (float) _lower._x,
      (float) _lower._y,
      (float) _upper._z,
      (float) _upper._x,
      (float) _lower._y,
      (float) _lower._z,
      (float) _upper._x,
      (float) _upper._y,
      (float) _lower._z,
      (float) _upper._x,
      (float) _upper._y,
      (float) _upper._z,
      (float) _upper._x,
      (float) _lower._y,
      (float) _upper._z
    };

    short[] i = {
      0, 1, 1, 2, 2, 3, 3, 0, 1, 5, 5, 6, 6, 2, 2, 1, 5, 4, 4, 7, 7, 6, 6, 5, 4, 0, 0, 3, 3, 7, 7,
      4, 3, 2, 2, 6, 6, 7, 7, 3, 0, 1, 1, 5, 5, 4, 4, 0
    };

    FloatBufferBuilderFromCartesian3D vertices =
        new FloatBufferBuilderFromCartesian3D(CenterStrategy.firstVertex(), Vector3D.zero());
    ShortBufferBuilder indices = new ShortBufferBuilder();

    final int numVertices = 8;
    for (int n = 0; n < numVertices; n++) {
      vertices.add(v[n * 3], v[n * 3 + 1], v[n * 3 + 2]);
    }

    final int numIndices = 48;
    for (int n = 0; n < numIndices; n++) {
      indices.add(i[n]);
    }

    _mesh =
        new IndexedMesh(
            GLPrimitive.lines(),
            true,
            vertices.getCenter(),
            vertices.create(),
            indices.create(),
            1,
            1,
            color);
  }
Exemplo n.º 2
0
  private Mesh createMesh(G3MRenderContext rc) {
    final int numStrides = 5;

    FloatBufferBuilderFromCartesian3D vertices =
        FloatBufferBuilderFromCartesian3D.builderWithoutCenter();

    FloatBufferBuilderFromColor colors = new FloatBufferBuilderFromColor();
    ShortBufferBuilder indices = new ShortBufferBuilder();

    int indicesCounter = 0;

    final float innerRadius = 0F;

    //  const float r2=50;
    final Camera camera = rc.getCurrentCamera();
    final int viewPortWidth = camera.getViewPortWidth();
    final int viewPortHeight = camera.getViewPortHeight();
    final int minSize = (viewPortWidth < viewPortHeight) ? viewPortWidth : viewPortHeight;
    final float outerRadius = minSize / 15.0f;

    final IMathUtils mu = IMathUtils.instance();

    for (int step = 0; step <= numStrides; step++) {
      final double angle = (double) step * 2 * DefineConstants.PI / numStrides;
      final double c = mu.cos(angle);
      final double s = mu.sin(angle);

      vertices.add((innerRadius * c), (innerRadius * s), 0);
      vertices.add((outerRadius * c), (outerRadius * s), 0);

      indices.add((short) (indicesCounter++));
      indices.add((short) (indicesCounter++));

      //    float col = (float) (1.0 * step / numStrides);
      //    if (col>1) {
      //      colors.add(1, 1, 1, 0);
      //      colors.add(1, 1, 1, 0);
      //    }
      //    else {
      //      colors.add(1, 1, 1, 1 - col);
      //      colors.add(1, 1, 1, 1 - col);
      //    }

      //    colors.add(Color::red().wheelStep(numStrides, step));
      //    colors.add(Color::red().wheelStep(numStrides, step));

      colors.add(1, 1, 1, 1);
      colors.add(1, 1, 1, 0);
    }

    // the two last indices
    indices.add((short) 0);
    indices.add((short) 1);

    Mesh result =
        new IndexedMesh(
            GLPrimitive.triangleStrip(),
            true,
            vertices.getCenter(),
            vertices.create(),
            indices.create(),
            1,
            1,
            null,
            colors.create());
    if (vertices != null) vertices.dispose();

    return result;
  }