private void aimAtTarget() {
   if (target == null) return;
   int bowCharge = Minecraft.getMinecraft().thePlayer.getItemInUseDuration();
   velocity = bowCharge / 20;
   velocity = (velocity * velocity + velocity * 2) / 3;
   if (WurstClient.INSTANCE.mods.fastBowMod.isActive()) velocity = 1;
   if (velocity < 0.1) {
     if (target instanceof EntityLivingBase)
       EntityUtils.faceEntityClient((EntityLivingBase) target);
     return;
   }
   if (velocity > 1) velocity = 1;
   double posX =
       target.posX + (target.posX - target.prevPosX) * 5 - Minecraft.getMinecraft().thePlayer.posX;
   double posY =
       target.posY
           + (target.posY - target.prevPosY) * 5
           + target.getEyeHeight()
           - 0.15
           - Minecraft.getMinecraft().thePlayer.posY
           - Minecraft.getMinecraft().thePlayer.getEyeHeight();
   double posZ =
       target.posZ + (target.posZ - target.prevPosZ) * 5 - Minecraft.getMinecraft().thePlayer.posZ;
   float yaw = (float) (Math.atan2(posZ, posX) * 180 / Math.PI) - 90;
   double y2 = Math.sqrt(posX * posX + posZ * posZ);
   float g = 0.006F;
   float tmp =
       (float)
           (velocity * velocity * velocity * velocity
               - g * (g * (y2 * y2) + 2 * posY * (velocity * velocity)));
   float pitch =
       (float) -Math.toDegrees(Math.atan((velocity * velocity - Math.sqrt(tmp)) / (g * y2)));
   Minecraft.getMinecraft().thePlayer.rotationYaw = yaw;
   Minecraft.getMinecraft().thePlayer.rotationPitch = pitch;
 }
Exemple #2
0
 public void splash(double x, double strength, ParticleEmitter drops) {
   int index = indexOf(x);
   speeds[index] = strength * strength / 500;
   Util.repeat(
       (int) (strength * strength) / 2000,
       () -> {
         Vec2 dir = Vec2.fromPolar(Math.random(), Math.random() * Math.PI);
         drops.particles.add(
             new Particle(
                 new Vec2(x, heights[index]).add(dir), dir.multiply(50 * Math.sqrt(strength))));
       });
 }
Exemple #3
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 #4
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;
    }
  }