Пример #1
0
 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;
 }
Пример #2
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;
    }
  }
Пример #3
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);
  }
  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();
  }
Пример #5
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();
  }
Пример #6
0
 public Sphere() {
   size = 10;
   angleOfRotation = 0.0f;
   translate = new Vector3f();
   scale = new Vector3f().makeIdentity();
   rotate = new Vector3f();
   color = new Vector3f((float) Math.random(), (float) Math.random(), (float) Math.random());
 }
Пример #7
0
  public void loadCollisionMask() {
    // float minX = verticies.get(1).x, minY = verticies.get(1).y, minZ =
    // verticies.get(1).z, maxX = verticies.get(1).x, maxY =
    // verticies.get(1).y, maxZ = verticies.get(1).z;

    for (int i = 0; i < verticies.size(); i++) {
      if (verticies.get(i).x < xMin) xMin = verticies.get(i).x;
      else if (verticies.get(i).x > xMax) xMax = verticies.get(i).x;

      if (verticies.get(i).y < yMin) yMin = verticies.get(i).y;
      else if (verticies.get(i).y > yMax) yMax = verticies.get(i).y;

      if (verticies.get(i).z < zMin) zMin = verticies.get(i).z;
      else if (verticies.get(i).z > zMax) zMax = verticies.get(i).z;
    }
    // System.out.println("min:(" + xMin + ", " + yMin + ", " + zMin + ")   max:(" + xMax + ", " +
    // yMax + ", " + zMax + ")");

    maskVerticies.add(new Vector3f(xMin, yMin, zMin)); // Left-Back-Bottom
    maskVerticies.add(new Vector3f(xMin, yMax, zMin)); // Left-Back-Top
    maskVerticies.add(new Vector3f(xMin, yMin, zMax)); // Left-Front-Bottom
    maskVerticies.add(new Vector3f(xMin, yMax, zMax)); // Left-Front-Top
    maskVerticies.add(new Vector3f(xMax, yMin, zMin)); // Right-Back-Bottom
    maskVerticies.add(new Vector3f(xMax, yMax, zMin)); // Right-Back-Top
    maskVerticies.add(new Vector3f(xMax, yMin, zMax)); // Right-Front-Bottom
    maskVerticies.add(new Vector3f(xMax, yMax, zMax)); // Right-Front-Top

    // System.out.println(maskVerticies.size());
    maskNormals.add(new Vector3f(-1, -1, -1)); // Left-Back-Bottom
    maskNormals.get(0).normalise();
    maskNormals.add(new Vector3f(-1, 1, -1)); // Left-Back-Top
    maskNormals.get(1).normalise();
    maskNormals.add(new Vector3f(-1, -1, 1)); // Left-Front-Bottom
    maskNormals.get(2).normalise();
    maskNormals.add(new Vector3f(-1, 1, 1)); // Left-Front-Top
    maskNormals.get(3).normalise();
    maskNormals.add(new Vector3f(1, -1, -1)); // Right-Back-Bottom
    maskNormals.get(4).normalise();
    maskNormals.add(new Vector3f(1, 1, -1)); // Right-Back-Top
    maskNormals.get(5).normalise();
    maskNormals.add(new Vector3f(1, -1, 1)); // Right-Front-Bottom
    maskNormals.get(6).normalise();
    maskNormals.add(new Vector3f(1, 1, 1)); // Right-Front-Top
    maskNormals.get(7).normalise();
    // System.out.println(maskNormals.get(0).x);

    maskFaces.add(new QuadFace(new Vector4f(2, 3, 1, 0), new Vector4f(0, 1, 3, 2)));
    maskFaces.add(new QuadFace(new Vector4f(4, 5, 7, 6), new Vector4f(4, 5, 7, 6)));
    maskFaces.add(new QuadFace(new Vector4f(0, 1, 5, 4), new Vector4f(0, 1, 5, 4)));
    maskFaces.add(new QuadFace(new Vector4f(6, 7, 3, 2), new Vector4f(2, 3, 7, 6)));
    maskFaces.add(new QuadFace(new Vector4f(4, 6, 2, 0), new Vector4f(0, 2, 6, 4)));
    maskFaces.add(new QuadFace(new Vector4f(1, 3, 7, 5), new Vector4f(1, 3, 7, 5)));
    // System.out.println(maskFaces.size());

    xCollisionRadii = Math.abs(xMax - xMin) / 2;
    yCollisionRadii = Math.abs(yMax - yMin) / 2;
    zCollisionRadii = Math.abs(zMax - zMin) / 2;
  }
 public void collid(Vector2f vec) {
   if (Math.abs(vec.x) > Math.abs(vec.y)) {
     this.y += vec.y;
     if (vec.y < 0) inGround = true;
   } else {
     this.x += vec.x;
   }
   collided = true;
 }
Пример #9
0
 public Entity(String file, boolean x) {
   img = new Image(file);
   img.setDimensions(new Coord(42, 42));
   if (x) {
     rot = Math.random() * 90 - 45;
     offset = new Coord((Math.random() - 0.5) * 40, (Math.random() - 0.5) * 40);
   } else {
     rot = 0;
     offset = new Coord();
   }
 }
Пример #10
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))));
       });
 }
Пример #11
0
  private void drawLightningBolt(Entity entity) {
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_LIGHTING);

    glColor3f(0, 0.6f, 1);
    glBegin(GL_QUADS);
    int lastX = 0;
    int lastY = 0;
    for (int i = 0; i < 60; i++) {
      int x = i * 2;
      int y = (int) (Math.sin(i * (Math.PI / 4) - entity.ticksExisted * 2.05f) * 2.5f);

      glColor3f(1, 1f, 1);
      glVertex3d(x + 0, y + 0, 0);
      glVertex3d(x + 0, y + 1, 0);
      glVertex3d(lastX, lastY + 1, 0);
      glVertex3d(lastX, lastY, 0);

      glColor3f(0, 0.6f, 1);
      glVertex3d(x + 0, y + 1, 0);
      glVertex3d(x + 0, y + 1.25, 0);
      glVertex3d(lastX, lastY + 1.25, 0);
      glVertex3d(lastX, lastY + 1, 0);

      glVertex3d(x + 0, y - 0.25, 0);
      glVertex3d(x + 0, y, 0);
      glVertex3d(lastX, lastY, 0);
      glVertex3d(lastX, lastY - 0.25, 0);
      lastX = x;
      lastY = y;
    }
    glEnd();
    glEnable(GL_LIGHTING);
    glEnable(GL_TEXTURE_2D);
  }
Пример #12
0
 @Override
 public void update(Player player, long currentTime) {
   angle =
       (float)
           Math.toDegrees(
               Math.atan2(
                   -(player.getPosition().getZ() - position.getZ()),
                   player.getPosition().getX() - position.getX()));
   angle +=
       (Math.sin(
               ((double) ((currentTime - startTime) % millisecondsToSwivel)
                       / (double) millisecondsToSwivel)
                   * Math.PI
                   * 2)
           * degreesToSwivel);
 }
 public void setupFX() {
   this.particleRed = data.red;
   this.particleGreen = data.green;
   this.particleBlue = data.blue;
   this.particleGravity = 0.0f;
   this.particleMaxAge = ((int) (50.0D / (Math.random() * 0.3D + 0.7D)));
   this.noClip = false;
 }
 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();
 }
 public ElementTextField setMaxLength(short limit) {
   char[] oldText = text;
   text = new char[limit];
   textLength = Math.min(limit, textLength);
   if (oldText != null) {
     System.arraycopy(oldText, 0, text, 0, textLength);
   }
   findRenderStart();
   return this;
 }
Пример #16
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);
 }
Пример #17
0
  @Override
  public void createInner() {
    List<Particle> particles = new LinkedList();
    for (int i = 0; i < 2500; i++) {
      particles.add(
          new Particle(Window3D.pos.add(Vec3.randomSquare(MAX_DIST)), Math.random() * .04 + .06));
    }
    onUpdate(
        dt -> {
          Iterator<Particle> it = particles.iterator();
          while (it.hasNext()) {
            Particle p = it.next();
            p.pos = p.pos.add(Vec3.randomSquare(dt / 5).add(new Vec3(0, 0, -dt)));
            p.pos =
                Window3D.pos.add(
                    p.pos
                        .subtract(Window3D.pos)
                        .perComponent(d -> (d + 3 * MAX_DIST) % (2 * MAX_DIST) - MAX_DIST));
          }
        });

    Sprite s = new Sprite("snowflake2");
    Core.renderLayer(.2)
        .onEvent(
            () -> {
              glEnable(GL_TEXTURE_2D);
              s.getTexture().bind();
              WHITE.glColor();
              glBegin(GL_QUADS);
              particles.forEach(
                  p -> {
                    if (CubeMap.rayCastStream(p.pos, new Vec3(0, 0, 1))
                        .anyMatch(cd -> cd.c != null)) {
                      return;
                    }
                    ;
                    Vec3 towards = p.pos.subtract(Window3D.pos);
                    Vec3 side = towards.cross(Window3D.UP).withLength(p.size / 2);
                    Vec3 snowUp = towards.cross(side).withLength(p.size / 2);
                    Graphics3D.drawQuadFastT(
                        p.pos.add(side).add(snowUp),
                        p.pos.subtract(side).add(snowUp),
                        p.pos.subtract(side).subtract(snowUp),
                        p.pos.add(side).subtract(snowUp));
                  });
              glEnd();
            })
        .addChild(this);
  }
Пример #18
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));
 }
Пример #19
0
  public static void setPerspective(float aspect, float fov, float znear, float zfar) {
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    float f = 1f / (float) Math.tan(Math.toRadians(fov) / 2f);
    float zrange = znear - zfar;

    float[] m = new float[16];

    m[0] = f / aspect;
    m[1] = 0;
    m[2] = 0;
    m[3] = 0;

    m[4] = 0;
    m[5] = f;
    m[6] = 0;
    m[7] = 0;

    m[8] = 0;
    m[9] = 0;
    m[10] = (zfar + znear) / zrange;
    m[11] = (zfar * znear) / zrange;

    m[12] = 0;
    m[13] = 0;
    m[14] = -1f;
    m[15] = 1;

    projection.set(m);

    glLoadMatrixf(projection.get());

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
  }
 public int getVisibleWidth() {
   FontRenderer font = getFontRenderer();
   int width = 0, endX = sizeX - 1;
   for (int i = renderStart; i < textLength; ++i) {
     int charW = font.getCharWidth(text[i]);
     if (!enableStencil && (width + charW) > endX) {
       break;
     }
     width += charW;
     if (width >= endX) {
       width = Math.min(width, endX);
       break;
     }
   }
   return width;
 }
Пример #21
0
 public void tick() {
   if (tilting) {
     if (ticksTilTilt < 10) {
       rot += 1;
       ticksTilTilt++;
     } else if (ticksTilTilt < 20) {
       rot -= 1;
       ticksTilTilt++;
     } else {
       tilting = false;
       ticksTilTilt = (int) (Math.random() * 360);
     }
   } else if (ticksTilTilt == 0) {
     tilting = true;
   } else {
     ticksTilTilt--;
   }
 }
Пример #22
0
 public void step() {
   Util.repeat(detail, i -> heights[i] += .01 * speeds[i]);
   Util.repeat(
       detail - 1,
       i -> {
         deltas[i] = heights[i + 1] - heights[i];
         speeds[i] += deltas[i];
         speeds[i + 1] -= deltas[i];
       });
   Util.repeat(
       detail,
       i -> speeds[i] = speeds[i] * Math.pow(.5, .001) + .01 * (defaultHeight - heights[i]));
   Util.repeat(
       detail - 1,
       i -> {
         heights[i] += deltas[i] * .01;
         heights[i + 1] -= deltas[i] * .01;
       });
 }
Пример #23
0
 /**
  * @param path Path of the .obj file
  * @param index GLUint
  */
 public static void name(String path, int index) {
   int list = glGenLists(index);
   glNewList(list, GL_COMPILE);
   {
     Model m = null;
     try {
       m = OBJLoader.loadModel(new File(path));
     } catch (FileNotFoundException e) {
       e.printStackTrace();
       Display.destroy();
       System.exit(1);
     } catch (IOException e) {
       e.printStackTrace();
       Display.destroy();
       System.exit(1);
     }
     float b;
     //			glColor3f(0.3f, 0.20f, 0.13f);
     b = (float) Math.random();
     glColor3f(b, 0, 0);
     int count = 0;
     glBegin(GL_TRIANGLES);
     for (Face face : m.faces) {
       count++;
       Vector3f n1 = m.normals.get((int) face.normal.x - 1);
       glNormal3f(n1.x, n1.y, n1.z);
       Vector3f v1 = m.vertices.get((int) face.vertex.x - 1);
       glVertex3f(v1.x, v1.y, v1.z);
       Vector3f n2 = m.normals.get((int) face.normal.y - 1);
       glNormal3f(n2.x, n2.y, n2.z);
       Vector3f v2 = m.vertices.get((int) face.vertex.y - 1);
       glVertex3f(v2.x, v2.y, v2.z);
       Vector3f n3 = m.normals.get((int) face.normal.z - 1);
       glNormal3f(n3.x, n3.y, n3.z);
       Vector3f v3 = m.vertices.get((int) face.vertex.z - 1);
       glVertex3f(v3.x, v3.y, v3.z);
     }
     glEnd();
     System.out.println(count);
   }
   glEndList();
 }
Пример #24
0
 public int indexOf(double x) {
   return (int) Math.round((x - position.x + width) * detail / (width * 2));
 }
Пример #25
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();
  }
Пример #26
0
  @Override
  protected void renderComponent(Slider component) {
    translateComponent(component, false);

    // GL settings
    glEnable(GL_BLEND);
    glDisable(GL_CULL_FACE);

    // area & font
    Rectangle area = component.getArea();
    int fontSize = theme.getFontRenderer().FONT_HEIGHT;
    FontRenderer fontRenderer = theme.getFontRenderer();

    // text
    fontRenderer.drawString(
        component.getText(), 0, 0, RenderUtil.toRGBA(component.getForegroundColor()));

    // value
    String content = null;
    switch (component.getValueDisplay()) {
      case DECIMAL:
        content =
            Double.toString(
                (double)
                        (Math.round(component.getValue() / component.getIncrement())
                            * 1000000
                            * (long) (component.getIncrement() * 1000000))
                    / 1000000
                    / 1000000);
        break;
      case INTEGER:
        content = String.format("%,d", Long.valueOf(Math.round(component.getValue())));
        break;
      case PERCENTAGE:
        int percent =
            (int)
                Math.round(
                    (component.getValue() - component.getMinimumValue())
                        / (component.getMaximumValue() - component.getMinimumValue())
                        * 100D);
        content = String.format("%d%%", percent);
      default:
    }
    if (content != null) {
      String suffix = component.getContentSuffix();
      if (suffix != null && !suffix.trim().isEmpty()) content = content.concat(" ").concat(suffix);
      fontRenderer.drawString(
          content,
          component.getWidth() - fontRenderer.getStringWidth(content),
          0,
          RenderUtil.toRGBA(component.getForegroundColor()));
    }
    glDisable(GL_TEXTURE_2D);

    // line
    glColor4f(0.03125f, 0.03125f, 0.03125f, 0.25f);
    glBegin(GL_QUADS);
    {
      glVertex2d(1, fontSize + 4);
      glVertex2d(area.width - 1, fontSize + 4);
      glVertex2d(area.width - 1, area.height - 2);
      glVertex2d(1, area.height - 2);
    }
    glEnd();

    // line shadow
    glLineWidth(1.0f);
    glColor4f(0.125f, 0.125f, 0.125f, 0.5f);
    glBegin(GL_LINE_LOOP);
    {
      glVertex2d(1, fontSize + 4);
      glVertex2d(area.width - 1, fontSize + 4);
      glVertex2d(area.width - 1, area.height - 2);
      glVertex2d(1, area.height - 2);
    }
    glEnd();

    double sliderPercentage =
        (component.getValue() - component.getMinimumValue())
            / (component.getMaximumValue() - component.getMinimumValue());

    // slider
    glColor4f(0.0f + (float) sliderPercentage, 1.0f - (float) sliderPercentage, 0.0f, 0.5f);
    glBegin(GL_QUADS);
    {
      glVertex2d((area.width - 6) * sliderPercentage - 1, fontSize + 1);
      glVertex2d((area.width - 6) * sliderPercentage + 7, fontSize + 1);
      glVertex2d((area.width - 6) * sliderPercentage + 7, area.height + 1);
      glVertex2d((area.width - 6) * sliderPercentage - 1, area.height + 1);
    }
    glEnd();

    // slider shadow
    RenderUtil.boxShadow(
        (area.width - 6) * sliderPercentage - 1,
        fontSize + 1,
        (area.width - 6) * sliderPercentage + 7,
        area.height + 1);

    // GL resets
    glEnable(GL_CULL_FACE);
    glEnable(GL_TEXTURE_2D);
    glDisable(GL_BLEND);

    translateComponent(component, true);
  }
Пример #27
0
 public int d6() {
   return (int) (Math.random() * 6 + 1);
 }
Пример #28
0
  @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);
    }
  }
Пример #30
0
 public RenderEngine() {
   glEnable(GL_DEPTH_TEST);
   projection = new Matrix4().initPerspective((float) Math.toRadians(90), 16f / 9f, 0.001f, 1000);
 }