Exemple #1
0
  public void shoot() {
    // this is very similar to the above method
    int maxIterations = 500;
    float newX = 0, newY = 0, newZ = 0;

    for (int i = 0; i < maxIterations; i += 1) {
      newX =
          -(controller.getX()
              + (float)
                  (-(i)
                      * (Math.sin(Math.toRadians(controller.getAngleX())))
                      * (Math.cos(Math.toRadians(controller.getAngleY())))));
      newY =
          -(controller.getY()
              + (float) (-(i) * (Math.sin(Math.toRadians(controller.getAngleY())))));
      newZ =
          -(controller.getZ()
              + (float)
                  ((i)
                      * (Math.cos(Math.toRadians(controller.getAngleX())))
                      * (Math.cos(Math.toRadians(controller.getAngleY())))));

      if (checkShootZombie(newX, newY, newZ)) break;
    }
  }
  public void renderParticle(
      Tessellator tess, float ptt, float rotX, float rotXZ, float rotZ, float rotYZ, float rotXY) {
    brightness = brightnessFade.updateFade(particleAge);

    float progress = (float) particleAge / particleMaxAge;

    // tess.draw();

    // glPushMatrix();

    glDepthMask(false);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    Minecraft.getMinecraft().renderEngine.bindTexture(tex);

    float scale = data.size;

    float[] pos = FXHelper.trackingParticleLocale(this, ptt);
    float[] rot = new float[] {rotX, rotXZ, rotZ, rotYZ, rotXY};

    pos[0] += data.xRad * Math.cos(2 * Math.PI * progress);
    pos[1] += 0.5 * data.yRad * Math.cos(2 * Math.PI * progress) * Math.sin(2 * Math.PI * progress);
    pos[2] += data.zRad * Math.sin(2 * Math.PI * progress);

    draw(tess, pos, scale, rot);

    glDisable(GL_BLEND);
    glDepthMask(true);

    // glPopMatrix();
    Minecraft.getMinecraft().renderEngine.bindTexture(FXHelper.getParticleTexture());

    // tess.startDrawingQuads();
  }
Exemple #3
0
  public static void renderSphere(Vector3f center, float radius, Vector3f colour) {
    glPushAttrib(GL_ENABLE_BIT);
    {
      glDisable(GL_TEXTURE_2D); // Texture 2D is disabled so no textures are incorporated
      glDisable(GL_LIGHTING); // Lighting is turned off for 2D
      glBegin(GL_LINE_LOOP);
      {
        glColor3f(colour.x, colour.y, colour.z);
        for (int i = 0; i < 360; i++) {
          double degInRad = i * Math.PI / 180;
          glVertex3f(
              (float) (center.x + Math.cos(degInRad) * radius),
              (float) (center.y + Math.sin(degInRad) * radius),
              center.z);
        }
      }
      glEnd();

      glBegin(GL_LINE_LOOP);
      {
        glColor3f(colour.x, colour.y, colour.z);
        for (int i = 0; i < 360; i++) {
          double degInRad = i * Math.PI / 180;
          glVertex3f(
              center.x,
              (float) (center.y + Math.cos(degInRad) * radius),
              (float) (center.z + Math.sin(degInRad) * radius));
        }
      }
      glEnd();
    }
    glPopAttrib();
  }
Exemple #4
0
  public void draw() {
    float x = 0, y = 0, z = 0, X = (float) -Math.PI, Y = 0.0f, Z = 0.0f;
    Vector3f first = new Vector3f();
    Vector3f second = new Vector3f();
    Vector3f thrird = new Vector3f();

    glPushMatrix();
    {
      glTranslatef(translate.getX(), translate.getY(), translate.getZ());
      glRotatef(angleOfRotation, rotate.getX(), rotate.getY(), rotate.getZ());
      glScalef(scale.getX(), scale.getY(), scale.getZ());
      glColor3f(color.getX(), color.getY(), color.getY());
      glDisable(GL_CULL_FACE);
      glLineWidth(10);

      glBegin(GL_LINE_STRIP);
      {
        while (X < 2 * Math.PI) {
          while (Y < 2 * Math.PI) {
            x = size * (float) Math.cos(X) * (float) Math.cos(Y);
            y = size * (float) Math.cos(X) * (float) Math.sin(Y);
            z = size * (float) Math.sin(X);
            glVertex3f(x, y, z);

            first.setX(x);
            first.setY(y);
            first.setZ(z);

            x = size * (float) Math.cos(X) * (float) Math.cos(Y);
            y = size * (float) Math.cos(X) * (float) Math.sin(Y);
            z = size * (float) Math.sin(X);
            glVertex3f(x, y, z);

            second.setX(x);
            second.setY(y);
            second.setZ(z);

            x = size * (float) Math.cos(X) * (float) Math.cos(Y);
            y = size * (float) Math.cos(X) * (float) Math.sin(Y);
            z = size * (float) Math.sin(X);
            glVertex3f(x, y, z);
            Y += 0.1;

            thrird.setX(x);
            thrird.setY(y);
            thrird.setZ(z);

            first = thrird.crossProduct(first, second, thrird);
            glNormal3f(first.getX(), first.getY(), first.getZ());
          }
          Y = 0;
          X += 0.1;
        }
      }
      glEnd();
      glEnable(GL_CULL_FACE);
      glLineWidth(1);
    }
    glPopMatrix();
  }
Exemple #5
0
  /** x, y, z, fov, aspectRatio, zNear, zFar */
  public Camera(long window, Vec3 position, float fov, float aspectRatio, float zNear, float zFar) {

    this.window = window;
    this.position = position;
    this.fov = fov;
    this.zNear = zNear;
    this.zFar = zFar;

    float sine, cotangent, deltaZ;
    float radians = fov / 2 * (float) Math.PI / 180;

    deltaZ = zFar - zNear;
    sine = (float) Math.sin(radians);

    if ((deltaZ == 0) || (sine == 0) || (aspectRatio == 0)) {
      return;
    }

    cotangent = (float) Math.cos(radians) / sine;

    matrix = BufferUtils.createFloatBuffer(16);
    int oldPos = matrix.position();
    matrix.put(IDENTITY_MATRIX);
    matrix.position(oldPos);

    matrix.put(0 * 4 + 0, cotangent / aspectRatio);
    matrix.put(1 * 4 + 1, cotangent);
    matrix.put(2 * 4 + 2, -(zFar + zNear) / deltaZ);
    matrix.put(2 * 4 + 3, -1);
    matrix.put(3 * 4 + 2, -2 * zNear * zFar / deltaZ);
    matrix.put(3 * 4 + 3, 0);
  }
Exemple #6
0
 public void addZombie() {
   // adds a zombie where the player is looking
   float newX = 0, newZ = 0;
   newX =
       -(controller.getX()
           + (float)
               (-(100)
                   * (Math.sin(Math.toRadians(controller.getAngleX())))
                   * (Math.cos(Math.toRadians(controller.getAngleY())))));
   newZ =
       -(controller.getZ()
           + (float)
               ((100)
                   * (Math.cos(Math.toRadians(controller.getAngleX())))
                   * (Math.cos(Math.toRadians(controller.getAngleY())))));
   zombies.add(new Zombie(controller, zombieM, newX, newZ));
 }
 private void drawPlanetOrbit(Planet planet, double radius) {
   glDisable(GL_TEXTURE_2D);
   glPolygonMode(GL_FRONT, GL_LINE);
   Tessellator.instance.startDrawing(GL_LINES);
   Tessellator.instance.setColorRGBA_F(
       Planet.getGuiColor(planet).getFloatR() * 0.1f,
       Planet.getGuiColor(planet).getFloatG() * 0.1f,
       Planet.getGuiColor(planet).getFloatB() * 0.1f,
       Planet.getGuiColor(planet).getFloatA() * 0.1f);
   for (int i = 0; i < 32; i++) {
     double angleStep = (Math.PI * 2) / 32;
     Tessellator.instance.addVertex(
         Math.sin(angleStep * i) * radius, 0, Math.cos(angleStep * i) * radius);
     Tessellator.instance.addVertex(
         Math.sin(angleStep * (i + 1)) * radius, 0, Math.cos(angleStep * (i + 1)) * radius);
   }
   Tessellator.instance.draw();
 }
Exemple #8
0
 @Override
 public void draw(Canvas canvas) {
   Color currColor = canvas.getColor();
   canvas.setColor(mColor);
   int centerX = mX + mRadius;
   int centerY = mY + mRadius;
   double twicePi = 2.0 * Math.PI;
   glPushMatrix();
   glBegin(GL_TRIANGLE_FAN); // BEGIN ROUND
   glVertex2f(centerX, centerY); // center of circle
   for (int i = 0; i <= ROUND_DRAWING_ACCURACY; i++) {
     glVertex2f(
         (float) (centerX + (mRadius * Math.cos(i * twicePi / ROUND_DRAWING_ACCURACY))),
         (float) (centerY + (mRadius * Math.sin(i * twicePi / ROUND_DRAWING_ACCURACY))));
   }
   glEnd(); // END
   glPopMatrix();
   canvas.setColor(currColor);
 }
  @Override
  protected void render() {

    float lineRadius = radius + LINE_LENGTH;

    // Draw outer circle
    glRender(
        new GLRenderable() {
          @Override
          public void render() {
            //				glEnable(GL_STENCIL_TEST);
            //				glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
            //				glStencilFunc(GL_NOTEQUAL, 1, 1);
            glEnable(GL_BLEND);
            glEnable(GL_TEXTURE_2D);
            glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
            glBlendFunc(GL_SRC_ALPHA, GL_ONE);
            glPushMatrix();
            glTranslatef(getOffset().getX() + x, getOffset().getY() + y, 0.0f);
            Res.getSolidTexture().render();
          }
        });

    outerRing.setRadius(radius);
    outerRing.setAlpha((int) (255.0f * alpha));
    outerRing.render(this);

    // Draw crosshair lines at the edge of the circle
    glRender(
        new GLRenderable() {
          @Override
          public void render() {
            glRotatef(outerAngle, 0.0f, 0.0f, 1.0f);
            Res.getBeamTexture().render();
          }
        });
    beam.setWidth(LINE_WIDTH + 1.0f);
    for (int i = 0; i < 32; i += 8) {
      beam.setLocation(
          (float) Math.cos(i * Math.PI / 16.0) * (radius + 0.5f),
          (float) Math.sin(i * Math.PI / 16.0) * (radius + 0.5f),
          (float) Math.cos(i * Math.PI / 16.0) * lineRadius,
          (float) Math.sin(i * Math.PI / 16.0) * lineRadius);
      beam.render(this);
    }

    glRender(
        new GLRenderable() {
          @Override
          public void render() {
            glPopMatrix();
            glPushMatrix();
            glTranslatef(getOffset().getX() + x, getOffset().getY() + y, 0.0f);
            glRotatef(innerAngle, 0.0f, 0.0f, 1.0f);
            Res.getDashTexture().render();
          }
        });

    innerRing.setRadius(INNER_SIZE);
    innerRing.setAlpha((int) (255.0f * alpha * OUTER_ALPHA_MULT));
    innerRing.render(this);

    glRender(
        new GLRenderable() {
          @Override
          public void render() {
            Res.getBeamTexture().render();
          }
        });

    for (int i = 0; i < 32; i += 4) {
      beam.setLocation(
          (float) Math.cos(i * Math.PI / 16.0) * (INNER_SIZE - LINE_WIDTH - 0.5f),
          (float) Math.sin(i * Math.PI / 16.0) * (INNER_SIZE - LINE_WIDTH - 0.5f),
          (float) Math.cos(i * Math.PI / 16.0) * INNER_LINE_RADIUS,
          (float) Math.sin(i * Math.PI / 16.0) * INNER_LINE_RADIUS);
      beam.render(this);
    }

    glRender(
        new GLRenderable() {
          @Override
          public void render() {
            glPopMatrix();
            //				glDisable(GL_STENCIL_TEST);
          }
        });
  }
  @Override
  public void renderBody(
      Galaxy galaxy,
      SpaceBody spaceBody,
      TileEntityMachineStarMap starMap,
      float partialTicks,
      float distance) {
    if (spaceBody instanceof Star) {

      Star star = (Star) spaceBody;
      random.setSeed(star.getSeed());

      double time = Minecraft.getMinecraft().theWorld.getWorldTime();

      glPushMatrix();
      glScaled(star.getSize(), star.getSize(), star.getSize());

      bindTexture(ClientProxy.renderHandler.getRenderParticlesHandler().getAdditiveTextureSheet());
      Tessellator.instance.startDrawingQuads();
      RenderUtils.tessalateParticle(
          Minecraft.getMinecraft().renderViewEntity,
          star_icon,
          star.getSize(),
          Vec3.createVectorHelper(0, 0, 0),
          Reference.COLOR_HOLO_YELLOW.getFloatR() * 0.1f,
          Reference.COLOR_HOLO_YELLOW.getFloatG() * 0.1f,
          Reference.COLOR_HOLO_YELLOW.getFloatB() * 0.1f,
          Reference.COLOR_HOLO_YELLOW.getFloatA() * 0.1f);
      Tessellator.instance.draw();

      RenderUtils.applyColorWithMultipy(new GuiColor(star.getColor()), 0.25f * (1f / distance));
      glPolygonMode(GL_FRONT, GL_LINE);
      glDisable(GL_TEXTURE_2D);
      double s = 0.9 + Math.sin(time * 0.01) * 0.1;
      glScaled(s, s, s);
      sphere_model.renderAll();
      glPolygonMode(GL_FRONT, GL_POINT);
      glPointSize(10 / (float) Math.max(0.1, distance));

      sphere_model.renderAll();
      if (Minecraft.getMinecraft().theWorld.getWorldTime() % 120 > 80) {
        double t = ((Minecraft.getMinecraft().theWorld.getWorldTime() % 120) - 80) / 40d;
        RenderUtils.applyColorWithMultipy(
            Reference.COLOR_HOLO_YELLOW, (float) MOMathHelper.easeIn(1 - t, 0, 0.1, 1));
        s = MOMathHelper.easeIn(t, 0.0, 10, 1);
        glScaled(1 + s, 1 + s, 1 + s);
        sphere_model.renderAll();
      }
      glPopMatrix();
      glPolygonMode(GL_FRONT, GL_LINE);

      int planetID = 0;
      for (Planet planet : star.getPlanets()) {
        float sizeMultiply = 1;
        if (starMap.getDestination().equals(planet)) {
          sizeMultiply = 1.2f;
        }

        glDisable(GL_ALPHA_TEST);
        GuiColor planetColor = Planet.getGuiColor(planet);
        random.setSeed(planet.getSeed());

        glPushMatrix();
        double axisRotation = random.nextInt(30) - 15;
        glRotated(axisRotation, 1, 0, 0);
        double radius = planet.getOrbit() * 2 + (star.getSize() / 2 + 0.1);
        float planetSize = planet.getSize();
        drawPlanetOrbit(planet, radius);

        glTranslated(
            Math.sin(time * 0.001 + 10 * planetID) * radius,
            0,
            Math.cos(time * 0.001 + 10 * planetID) * radius);

        glPolygonMode(GL_FRONT, GL_FILL);
        glEnable(GL_TEXTURE_2D);

        if (starMap.getDestination().equals(planet)) {
          bindTexture(
              ClientProxy.renderHandler.getRenderParticlesHandler().getAdditiveTextureSheet());
          Tessellator.instance.startDrawingQuads();
          RenderUtils.tessalateParticle(
              Minecraft.getMinecraft().renderViewEntity,
              selectedIcon,
              planet.getSize() * 0.15f * sizeMultiply,
              Vec3.createVectorHelper(0, 0, 0),
              planetColor);
          Tessellator.instance.draw();
        }

        if (starMap.getGalaxyPosition().equals(planet)) {
          bindTexture(
              ClientProxy.renderHandler.getRenderParticlesHandler().getAdditiveTextureSheet());
          Tessellator.instance.startDrawingQuads();
          RenderUtils.tessalateParticle(
              Minecraft.getMinecraft().renderViewEntity,
              currentIcon,
              planet.getSize() * 0.25f,
              Vec3.createVectorHelper(0, 0, 0),
              planetColor);
          Tessellator.instance.draw();
        }

        glPushMatrix();
        glRotated(-axisRotation, 1, 0, 0);
        RenderUtils.rotateTo(Minecraft.getMinecraft().renderViewEntity);
        drawPlanetInfo(planet);
        glPopMatrix();
        glPolygonMode(GL_FRONT, GL_LINE);
        glDisable(GL_TEXTURE_2D);

        RenderUtils.applyColorWithMultipy(planetColor, 0.3f * (1f / distance));
        glRotated(100, 1, 0, 0);
        glRotated(time * 2, 0, 0, 1);
        sphere.draw(
            planetSize * 0.1f * sizeMultiply,
            (int) (16 + planetSize * 2),
            (int) (8 + planetSize * 2));
        planetID++;
        glPopMatrix();
      }
      glEnable(GL_TEXTURE_2D);
      glPolygonMode(GL_FRONT, GL_FILL);
    }
  }
Exemple #11
0
  /**
   * Draw a gear wheel. You'll probably want to call this function when building a display list
   * since we do a lot of trig here.
   *
   * @param inner_radius radius of hole at center
   * @param outer_radius radius at center of teeth
   * @param width width of gear
   * @param teeth number of teeth
   * @param tooth_depth depth of tooth
   */
  private void gear(
      float inner_radius, float outer_radius, float width, int teeth, float tooth_depth) {
    int i;
    float r0, r1, r2;
    float angle, da;
    float u, v, len;

    r0 = inner_radius;
    r1 = outer_radius - tooth_depth / 2.0f;
    r2 = outer_radius + tooth_depth / 2.0f;

    da = 2.0f * (float) Math.PI / teeth / 4.0f;

    glShadeModel(GL_FLAT);

    glNormal3f(0.0f, 0.0f, 1.0f);

    /* draw front face */
    glBegin(GL_QUAD_STRIP);
    for (i = 0; i <= teeth; i++) {
      angle = i * 2.0f * (float) Math.PI / teeth;
      glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f);
      glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f);
      if (i < teeth) {
        glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f);
        glVertex3f(
            r1 * (float) Math.cos(angle + 3.0f * da),
            r1 * (float) Math.sin(angle + 3.0f * da),
            width * 0.5f);
      }
    }
    glEnd();

    /* draw front sides of teeth */
    glBegin(GL_QUADS);
    for (i = 0; i < teeth; i++) {
      angle = i * 2.0f * (float) Math.PI / teeth;
      glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f);
      glVertex3f(
          r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), width * 0.5f);
      glVertex3f(
          r2 * (float) Math.cos(angle + 2.0f * da),
          r2 * (float) Math.sin(angle + 2.0f * da),
          width * 0.5f);
      glVertex3f(
          r1 * (float) Math.cos(angle + 3.0f * da),
          r1 * (float) Math.sin(angle + 3.0f * da),
          width * 0.5f);
    }
    glEnd();

    /* draw back face */
    glBegin(GL_QUAD_STRIP);
    for (i = 0; i <= teeth; i++) {
      angle = i * 2.0f * (float) Math.PI / teeth;
      glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f);
      glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f);
      glVertex3f(
          r1 * (float) Math.cos(angle + 3 * da),
          r1 * (float) Math.sin(angle + 3 * da),
          -width * 0.5f);
      glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f);
    }
    glEnd();

    /* draw back sides of teeth */
    glBegin(GL_QUADS);
    for (i = 0; i < teeth; i++) {
      angle = i * 2.0f * (float) Math.PI / teeth;
      glVertex3f(
          r1 * (float) Math.cos(angle + 3 * da),
          r1 * (float) Math.sin(angle + 3 * da),
          -width * 0.5f);
      glVertex3f(
          r2 * (float) Math.cos(angle + 2 * da),
          r2 * (float) Math.sin(angle + 2 * da),
          -width * 0.5f);
      glVertex3f(
          r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), -width * 0.5f);
      glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f);
    }
    glEnd();

    /* draw outward faces of teeth */
    glBegin(GL_QUAD_STRIP);
    for (i = 0; i < teeth; i++) {
      angle = i * 2.0f * (float) Math.PI / teeth;
      glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f);
      glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f);
      u = r2 * (float) Math.cos(angle + da) - r1 * (float) Math.cos(angle);
      v = r2 * (float) Math.sin(angle + da) - r1 * (float) Math.sin(angle);
      len = (float) Math.sqrt(u * u + v * v);
      u /= len;
      v /= len;
      glNormal3f(v, -u, 0.0f);
      glVertex3f(
          r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), width * 0.5f);
      glVertex3f(
          r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), -width * 0.5f);
      glNormal3f((float) Math.cos(angle), (float) Math.sin(angle), 0.0f);
      glVertex3f(
          r2 * (float) Math.cos(angle + 2 * da),
          r2 * (float) Math.sin(angle + 2 * da),
          width * 0.5f);
      glVertex3f(
          r2 * (float) Math.cos(angle + 2 * da),
          r2 * (float) Math.sin(angle + 2 * da),
          -width * 0.5f);
      u = r1 * (float) Math.cos(angle + 3 * da) - r2 * (float) Math.cos(angle + 2 * da);
      v = r1 * (float) Math.sin(angle + 3 * da) - r2 * (float) Math.sin(angle + 2 * da);
      glNormal3f(v, -u, 0.0f);
      glVertex3f(
          r1 * (float) Math.cos(angle + 3 * da),
          r1 * (float) Math.sin(angle + 3 * da),
          width * 0.5f);
      glVertex3f(
          r1 * (float) Math.cos(angle + 3 * da),
          r1 * (float) Math.sin(angle + 3 * da),
          -width * 0.5f);
      glNormal3f((float) Math.cos(angle), (float) Math.sin(angle), 0.0f);
    }
    glVertex3f(r1 * (float) Math.cos(0), r1 * (float) Math.sin(0), width * 0.5f);
    glVertex3f(r1 * (float) Math.cos(0), r1 * (float) Math.sin(0), -width * 0.5f);
    glEnd();

    glShadeModel(GL_SMOOTH);

    /* draw inside radius cylinder */
    glBegin(GL_QUAD_STRIP);
    for (i = 0; i <= teeth; i++) {
      angle = i * 2.0f * (float) Math.PI / teeth;
      glNormal3f(-(float) Math.cos(angle), -(float) Math.sin(angle), 0.0f);
      glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f);
      glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f);
    }
    glEnd();
  }
Exemple #12
0
  public void checkSelected() {
    // this method highlights a cube if it is being looked at
    // I use a method of ray tracing to check along the players line of sight
    if (controller.getSelectedWeapon() != 1) return;

    boolean anythingSelected = false;
    int maxIterations = 500;

    float newX = 0, newY = 0, newZ = 0;

    for (int i = 0; i < maxIterations; i += 1) {
      newX =
          -(controller.getX()
              + (float)
                  (-(i)
                      * (Math.sin(Math.toRadians(controller.getAngleX())))
                      * (Math.cos(Math.toRadians(controller.getAngleY())))));
      newY =
          -(controller.getY()
              + (float) (-(i) * (Math.sin(Math.toRadians(controller.getAngleY())))));
      newZ =
          -(controller.getZ()
              + (float)
                  ((i)
                      * (Math.cos(Math.toRadians(controller.getAngleX())))
                      * (Math.cos(Math.toRadians(controller.getAngleY())))));

      if (collisionLooking(-newX, -newY, -newZ)) {
        Cube selected = getCube(-(int) newX, -(int) newY, -(int) newZ);
        int[][] sides = new int[6][3];
        float[] differences = new float[6];
        for (int j = 0; j < sides.length; j++) {
          sides[j] = selected.getSideMid(j);
        }

        for (int j = 0; j < sides.length; j++) {
          differences[j] =
              (float)
                  Math.sqrt(
                      Math.pow((sides[j][0] - newX), 2)
                          + Math.pow((sides[j][1] - newY), 2)
                          + Math.pow((sides[j][2] - newZ), 2));
        }

        float smallest = differences[0];
        for (int j = 0; j < differences.length; j++) {
          if (differences[j] < smallest) smallest = differences[j];
        }

        int side = -1;

        for (int j = 0; j < differences.length; j++) {
          if (differences[j] == smallest) side = j;
        }

        selected.selectedSide[side] = true;

        selectedCube = selected;
        selectedSide = side;
        anythingSelected = true;

        break;
      }
    }

    if (!anythingSelected) {
      selectedCube = null;
      selectedSide = -1;
    }
  }
Exemple #13
0
  @Override
  public void init() throws IOException {

    super.init();
    camera = new Camera(true);
    camera.setPosition(-17f, 20f, 17f, 0, 0, 0, 0, 1, 0);
    float df = 100.0f;

    // Precalculate the Sine and Cosine Lookup Tables.
    // Basically, loop through 360 Degrees and assign the Radian
    // value to each array index (which represents the Degree).
    for (int i = 0; i < 360; i++) {
      g_fSinTable[i] = (float) Math.sin(AR_DegToRad(i));
      g_fCosTable[i] = (float) Math.cos(AR_DegToRad(i));
    }

    pObj = new Sphere();
    pObj.setOrientation(GLU_OUTSIDE);

    Octree.debug = new BoundingBox();
    // Turn lighting on initially
    Octree.turnLighting = true;

    // The current amount of end nodes in our tree (The nodes with vertices stored in them)
    Octree.totalNodesCount = 0;

    // This stores the amount of nodes that are in the frustum
    Octree.totalNodesDrawn = 0;

    // The maximum amount of triangles per node.  If a node has equal or less
    // than this, stop subdividing and store the face indices in that node
    Octree.maxTriangles = 800;

    // The maximum amount of subdivisions allowed (Levels of subdivision)
    Octree.maxSubdivisions = 5;

    // The number of Nodes we've checked for collision.
    Octree.numNodesCollided = 0;

    // Wheter the Object is Colliding with anything in the World or not.
    octree.setObjectColliding(false);

    // Wheter we test the whole world for collision or just the nodes we are in.
    Octree.octreeCollisionDetection = true;

    LoadWorld();

    // for(int i=0; i < g_World.getNumOfMaterials(); i++)
    // {
    //	System.out.println(g_World.getMaterials(i).getName() + " indice " + i);

    // }

    // for(int i=0; i < g_World.getNumOfObjects(); i++)
    // {
    //	System.out.println(g_World.getObject(i).getName());
    //	System.out.println(g_World.getObject(i).getMaterialID());
    // System.out.println(g_World.getPObject(i).getMaterialID());
    // }

    // System.out.println(g_World.getPMaterials(12).getColor()[0] + " " +
    // g_World.getPMaterials(12).getColor()[1]
    //                    + " " + g_World.getPMaterials(12).getColor()[2]);
    // System.out.println(g_World.getPMaterials(g_World.getPObject(6).getMaterialID()));

    inputManager = new InputManager();

    createGameActions();

    posLuz1F = Conversion.allocFloats(posLuz1);

    // Define a cor de fundo da janela de visualização como preto
    glClearColor(0, 0, 0, 1);

    // Ajusta iluminação
    glLight(GL_LIGHT0, GL_AMBIENT, Conversion.allocFloats(luzAmb1));
    glLight(GL_LIGHT0, GL_DIFFUSE, Conversion.allocFloats(luzDif1));
    glLight(GL_LIGHT0, GL_SPECULAR, Conversion.allocFloats(luzEsp1));

    // Habilita todas as fontes de luz
    glEnable(GL_LIGHT0);

    glEnable(GL_LIGHTING);
    // Agora posiciona demais fontes de luz
    glLight(GL_LIGHT0, GL_POSITION, posLuz1F);

    // Habilita Z-Buffer
    glEnable(GL_DEPTH_TEST);

    // Seleciona o modo de GL_COLOR_MATERIAL
    // glColorMaterial(GL_FRONT, GL_DIFFUSE);
    glEnable(GL_COLOR_MATERIAL);
    glMaterial(GL_FRONT, GL_SPECULAR, Conversion.allocFloats(spec));
    glMaterialf(GL_FRONT, GL_SHININESS, df);
  }