public void update() {
      dynamicsWorld.stepSimulation(Gdx.graphics.getDeltaTime(), 5);

      GL10 gl = Gdx.gl10;

      for (int i = 0; i < entities.size; i++) {
        final Entity entity = entities.get(i);
        gl.glPushMatrix();
        gl.glMultMatrixf(entity.worldTransform.transform.val, 0);
        gl.glColor4f(entity.color.r, entity.color.g, entity.color.b, entity.color.a);
        entity.mesh.render(GL10.GL_TRIANGLES);
        gl.glPopMatrix();
      }
    }
Example #2
0
  /**
   * This method is responsible for OpenGL rendering mechanism. Adds lighting to the world. Checks
   * rigidBody map for proper collisionshapes (like SphereShape or BoxShape).
   */
  public void render(float delta) {
    float[] light_ambient = new float[] {1.5f, 1.5f, 1.5f, 1.5f};
    float[] light_diffuse = new float[] {1.0f, 1.0f, 1.0f, 1.0f};
    float[] light_specular = new float[] {1.0f, 1.0f, 1.0f, 1.0f};
    float[] light_position0 = new float[] {1.0f, 10.0f, 1.0f, 0.0f};
    light_position0[0] = position.x + 10;
    light_position0[1] = position.y;
    light_position0[2] = position.z;
    float x = 0.0f, z = 0.0f;

    GL10 gl = Gdx.graphics.getGL10();
    deltaTime = Gdx.graphics.getDeltaTime();

    Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    Gdx.graphics.getGL11().glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, light_ambient, 0);
    Gdx.graphics.getGL11().glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, light_diffuse, 0);
    Gdx.graphics.getGL11().glLightfv(GL10.GL_LIGHT0, GL10.GL_SPECULAR, light_specular, 0);
    Gdx.graphics.getGL11().glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, light_position0, 0);

    Gdx.graphics.getGL11().glEnable(GL10.GL_LIGHTING);
    Gdx.graphics.getGL11().glEnable(GL10.GL_LIGHT0);

    Gdx.gl.glEnable(GL10.GL_DEPTH_TEST);

    Gdx.gl.glEnable(GL10.GL_CULL_FACE);
    Gdx.gl.glEnable(GL10.GL_TEXTURE_2D);

    startTime = System.nanoTime();
    rigidBody = physics.doSimulation(deltaTime, 1);
    endTime = (System.nanoTime() - startTime) / 1000000000.0f;

    for (RigidBody body : rigidBody.values()) {

      if (body.geometry.shape.getType() == ShapeType.BOX_SHAPE_PROXYTYPE) {
        gl.glPushMatrix();

        body.motionState.resultSimulation.getOpenGLMatrix(glMat);
        gl.glMultMatrixf(glMat, 0);

        wallShapeZ = (BoxShape) body.geometry.shape;

        wood.bind();
        gl.glRotatef(270, 1, 0, 0);
        gl.glScalef(7, 7, 7);
        wall.render(GL10.GL_TRIANGLES);
        gl.glPopMatrix();
      }

      if (body.geometry.shape.getType() == ShapeType.STATIC_PLANE_PROXYTYPE) {
        gl.glPushMatrix();

        body.motionState.resultSimulation.getOpenGLMatrix(glMat);
        gl.glMultMatrixf(glMat, 0);

        groundShape = (StaticPlaneShape) body.geometry.shape;

        stone.bind();
        gl.glRotatef(270, 1, 0, 0);
        gl.glScalef(6f, 6f, 6f);
        plane.render(GL10.GL_TRIANGLES);
        gl.glPopMatrix();
      }

      if (body.geometry.shape.getType() == ShapeType.SPHERE_SHAPE_PROXYTYPE) {

        gl.glPushMatrix();

        sphereMovement(body);

        body.motionState.resultSimulation.getOpenGLMatrix(glMat);
        gl.glMultMatrixf(glMat, 0);

        x = body.motionState.resultSimulation.originPoint.x;
        z = body.motionState.resultSimulation.originPoint.z;

        if ((x >= 19.0 && x <= 26.5) && (z >= 8.4 && z <= 8.6)) {
          Gdx.app.log("Zwyciestwo", "lolol");
        }

        if (indexior == 0) black.bind();
        else if (indexior == 1) green.bind();
        else if (indexior == 2) pink.bind();
        else if (indexior == 3) steel.bind();
        else if (indexior == 4) maja.bind();

        sphere.render(GL10.GL_TRIANGLES);
        gl.glPopMatrix();
        cameraSetup(body);
      }
    }

    if (Gdx.input.justTouched()) {
      FileHandle fh = Gdx.files.local("ala.txt");
      fh.writeString(
          String.valueOf(x) + " " + String.valueOf(z) + " " + String.valueOf(indexior), false);
      game.setScreen(new MenuScreen(game));
    }

    gl.glPushMatrix();
    gl.glTranslatef(22.0f, -10.0f, 8.5f);
    gl.glScalef(1.0f, 1.0f, 1.0f);
    gl.glRotatef(270, 1, 0, 0);
    aim.bind();
    target.render(GL10.GL_TRIANGLES);
    gl.glPopMatrix();

    gl.glDisable(GL10.GL_CULL_FACE);
    gl.glDisable(GL10.GL_DEPTH_TEST);
  }