Пример #1
0
 // mat4
 protected T setParams(Parameter param, Matrix4 value) {
   if (!programBegan) {
     programBegan = true;
     program.begin();
   }
   program.setUniformMatrix(param.mnemonic(), value);
   return (T) this;
 }
 @Override
 public void render(@NotNull ShaderProgram program) {
   super.render(program);
   if (!isVisible()) return;
   program.setUniformMatrix(MODEL_VIEW, getCombinedTransoformation());
   //        program.setUniformMatrix(NORMAL, getCombinedTransoformation().toNormalMatrix());
   material.apply(program);
   model.render(program);
 }
Пример #3
0
 private void setupMatrices() {
   if (!Gdx.graphics.isGL20Available()) {
     GL10 gl = Gdx.gl10;
     gl.glMatrixMode(GL10.GL_PROJECTION);
     gl.glLoadMatrixf(projectionMatrix.val, 0);
     gl.glMatrixMode(GL10.GL_MODELVIEW);
     gl.glLoadMatrixf(transformMatrix.val, 0);
   } else {
     combinedMatrix.set(projectionMatrix).mul(transformMatrix);
     if (customShader != null) {
       customShader.setUniformMatrix("u_proj", projectionMatrix);
       customShader.setUniformMatrix("u_trans", transformMatrix);
       customShader.setUniformMatrix("u_projTrans", combinedMatrix);
       customShader.setUniformi("u_texture", 0);
     } else {
       shader.setUniformMatrix("u_projectionViewMatrix", combinedMatrix);
       shader.setUniformi("u_texture", 0);
     }
   }
 }
Пример #4
0
  public void flush() {
    // if we've already flushed
    if (idx == 0) return;
    // sends our vertex data to the mesh
    mesh.setVertices(verts);

    // no need for depth...
    Gdx.gl.glDepthMask(false);

    // enable blending, for alpha
    Gdx.gl.glEnable(GL20.GL_BLEND);
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    // number of vertices we need to render
    int vertexCount = (idx / NUM_COMPONENTS);

    cam.update();

    // start the shader before setting any uniforms
    shader.begin();

    // update the projection matrix so our triangles are rendered in 2D
    shader.setUniformMatrix("u_projTrans", cam.combined);

    // render the mesh
    mesh.render(shader, RENDER_TYPE, 0, vertexCount);

    shader.end();

    // re-enable depth to reset states to their default
    Gdx.gl.glDepthMask(true);

    // reset index to zero
    idx = 0;

    // reset verts
    Arrays.fill(verts, 0);
  }
Пример #5
0
 // mat3
 protected T setParam(Parameter param, Matrix3 value) {
   program.begin();
   program.setUniformMatrix(param.mnemonic(), value);
   program.end();
   return (T) this;
 }
Пример #6
0
  public void draw(Matrix4 mat) {
    if (!body.isActive()) {
      return;
    }

    Transform transform = body.getTransform();

    texture.bind();
    shader.begin();
    shader.setUniformMatrix("u_projectionViewMatrix", mat);
    for (FixtureData data : fixtureData) {
      data.updateData(transform);
      data.mesh.render(shader, GL20.GL_TRIANGLE_FAN, 0, data.vertices.length);
    }
    shader.end();

    // chain.getVertex(0, v0);
    // transform.mul(v0);
    // chain.getVertex(1, v1);
    // transform.mul(v1);
    // chain.getVertex(2, v2);
    // transform.mul(v2);
    // chain.getVertex(3, v3);
    // transform.mul(v3);

    // mesh.setVertices(new float[] { -5f, -5f, 0, 0, 1, // bottom left
    // 5f, -5f, 0, 1, 1, // bottom right
    // 5f, 5f, 0, 1, 0, // top right
    // -5f, 5f, 0, 0, 0 }); // top left
    //
    // mesh.setVertices(new float[] { v0.x, v0.y, 0, 0, 1, // bottom left
    // v1.x, v1.y, 0, 1, 1, // bottom right
    // v2.x, v2.y, 0, 1, 0, // top right
    // v3.x, v3.y, 0, 0, 0 }); // top left

    // System.out.println("--");

    // Vector2 before = new Vector2();
    // Vector2 current = new Vector2();
    // Vector2 after = new Vector2();
    // for (int i = 0; i < meshes.length; i++) {
    // Fixture fixture = body.getFixtureList().get(i);
    // PolygonShape poly = (PolygonShape) fixture.getShape();
    //
    // for (int j = 0; j < meshesData[i].length; j += 6) {
    // int polyIndex = j / 6;
    // poly.getVertex(polyIndex, current);
    //
    // // if (scale) {
    // // poly.getVertex(polyIndex == 0 ? poly.getVertexCount() - 1 :
    // polyIndex - 1, before);
    // // poly.getVertex(polyIndex == poly.getVertexCount() - 1 ? 0 :
    // polyIndex + 1, after);
    // //
    // // Vector2D vec1 = new Vector2D(new Point2D(after.x, after.y), new
    // Point2D(current.x, current.y));
    // // Vector2D vec2 = new Vector2D(new Point2D(before.x, before.y), new
    // Point2D(current.x, current.y));
    // //
    // // double a1 = vec1.getAngle();
    // // double a2 = vec2.getAngle();
    // // double diff = a1 - a2;
    // // double angle = (a1 + a2) / 2.0;
    // //
    // // if (diff > 0) {
    // // angle -= Math.PI;
    // // }
    // //
    // // System.out.println("angle1 " + a1 * 180 / Math.PI);
    // // System.out.println("angle2 " + a2 * 180 / Math.PI);
    // // System.out.println("diff " + diff * 180 / Math.PI);
    // // System.out.println("center " + angle * 180 / Math.PI);
    // //
    // // Vector2D sum = new Vector2D(Math.cos(angle) * 0.2, Math.sin(angle) *
    // 0.2);
    // // sum.normalize();
    // //
    // // sum = sum.times(0.2);
    // //
    // // Vector2 newPoint = new Vector2(current.x + (float) sum.getX(),
    // current.y + (float) sum.getY());
    // //
    // // transform.mul(newPoint);
    // //
    // // transform.mul(current);
    // //
    // // // poly.getVertex(polyIndex, newPoint);
    // // // newPoint.mul(1.2f);
    // // // transform.mul(newPoint);
    // //
    // // // batch.begin();
    // // // batch.draw(texture, current.x * 20 + 200, current.y * 20 + 200);
    // // // batch.draw(texture2, newPoint.x * 20 + 200, newPoint.y * 20 +
    // 200);
    // // // batch.end();
    // // }
    //
    // transform.mul(current);
    //
    // meshesData[i][j] = current.x;
    // meshesData[i][j + 1] = current.y;
    // meshesData[i][j + 2] = 0;
    //
    // meshesData[i][j + 3] = colors[(color + i) % colors.length];
    //
    // meshesData[i][j + 4] = (float) Math.random();
    // meshesData[i][j + 5] = (float) Math.random();
    // }
    //
    // // render
    // meshes[i].setVertices(meshesData[i]);
    //
    // shader.begin();
    // shader.setUniformMatrix("u_projectionViewMatrix", mat);
    // texture.bind();
    // meshes[i].render(shader, GL20.GL_TRIANGLE_FAN, 0,
    // poly.getVertexCount());
    // shader.end();
    // }

  }