// get the color value at the given point
  public Vec3 getColor(Vec3 p, Vec3 n, Vec3 d, Vec3 difCol, Vec3 spCol, int exp) {
    Vec3 color = new Vec3(0, 0, 0);
    Vec3 l = getDir().negate();
    Ray newRay = new Ray(p, l);
    HitRecord srec = new HitRecord();

    if (Data.getSettings().isA()) {
      if (Data.hasIntersection(newRay, 0.001, Double.POSITIVE_INFINITY, srec)) {
        // System.out.println("In shadow");
        return color;
      } else {
        l = l.normalize();

        if (Data.getSettings().isD()) {
          double nDotl = n.dotProduct(l);
          color = color.addVec(difCol.multScalar(i * Math.max(0, nDotl)));
        }

        if (Data.getSettings().isS()) {
          Vec3 h = l.subVec(d).normalize();
          double nDotH = n.dotProduct(h);
          color = color.addVec(spCol.multScalar(i * Math.pow(Math.max(0, nDotH), exp)));
        }
      }
    } else {
      l = l.normalize();

      if (Data.getSettings().isD()) {
        double nDotl = n.dotProduct(l);
        color = color.addVec(difCol.multScalar(i * Math.max(0, nDotl)));
      }

      if (Data.getSettings().isS()) {
        Vec3 h = l.subVec(d).normalize();
        double nDotH = n.dotProduct(h);
        color = color.addVec(spCol.multScalar(i * Math.pow(Math.max(0, nDotH), exp)));
      }
    }

    return color;
  }
示例#2
0
  /** Returns a vector indicating the direction and intensity of fluid flow. */
  private Vec3 getFlowVector(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) {
    Vec3 var5 = Vec3.getVec3Pool().getVecFromPool(0.0D, 0.0D, 0.0D);
    int var6 = this.getEffectiveFlowDecay(par1IBlockAccess, par2, par3, par4);

    for (int var7 = 0; var7 < 4; ++var7) {
      int var8 = par2;
      int var10 = par4;

      if (var7 == 0) {
        var8 = par2 - 1;
      }

      if (var7 == 1) {
        var10 = par4 - 1;
      }

      if (var7 == 2) {
        ++var8;
      }

      if (var7 == 3) {
        ++var10;
      }

      int var11 = this.getEffectiveFlowDecay(par1IBlockAccess, var8, par3, var10);
      int var12;

      if (var11 < 0) {
        if (!par1IBlockAccess.getBlockMaterial(var8, par3, var10).blocksMovement()) {
          var11 = this.getEffectiveFlowDecay(par1IBlockAccess, var8, par3 - 1, var10);

          if (var11 >= 0) {
            var12 = var11 - (var6 - 8);
            var5 =
                var5.addVector(
                    (double) ((var8 - par2) * var12),
                    (double) ((par3 - par3) * var12),
                    (double) ((var10 - par4) * var12));
          }
        }
      } else if (var11 >= 0) {
        var12 = var11 - var6;
        var5 =
            var5.addVector(
                (double) ((var8 - par2) * var12),
                (double) ((par3 - par3) * var12),
                (double) ((var10 - par4) * var12));
      }
    }

    if (par1IBlockAccess.getBlockMetadata(par2, par3, par4) >= 8) {
      boolean var13 = false;

      if (var13 || this.isBlockSolid(par1IBlockAccess, par2, par3, par4 - 1, 2)) {
        var13 = true;
      }

      if (var13 || this.isBlockSolid(par1IBlockAccess, par2, par3, par4 + 1, 3)) {
        var13 = true;
      }

      if (var13 || this.isBlockSolid(par1IBlockAccess, par2 - 1, par3, par4, 4)) {
        var13 = true;
      }

      if (var13 || this.isBlockSolid(par1IBlockAccess, par2 + 1, par3, par4, 5)) {
        var13 = true;
      }

      if (var13 || this.isBlockSolid(par1IBlockAccess, par2, par3 + 1, par4 - 1, 2)) {
        var13 = true;
      }

      if (var13 || this.isBlockSolid(par1IBlockAccess, par2, par3 + 1, par4 + 1, 3)) {
        var13 = true;
      }

      if (var13 || this.isBlockSolid(par1IBlockAccess, par2 - 1, par3 + 1, par4, 4)) {
        var13 = true;
      }

      if (var13 || this.isBlockSolid(par1IBlockAccess, par2 + 1, par3 + 1, par4, 5)) {
        var13 = true;
      }

      if (var13) {
        var5 = var5.normalize().addVector(0.0D, -6.0D, 0.0D);
      }
    }

    var5 = var5.normalize();
    return var5;
  }
  public void draw(GL2 gl) {
    if (particles.size() == 0) return;
    switch (blendMode) {
      case 0: // '\0'
        gl.glDisable(3042);
        gl.glDisable(3008);
        break;

      case 1: // '\001'
        gl.glEnable(3042);
        gl.glDisable(3008);
        gl.glBlendFunc(768, 1);
        break;

      case 2: // '\002'
        gl.glEnable(3042);
        gl.glDisable(3008);
        gl.glBlendFunc(770, 1);
        break;

      case 3: // '\003'
        gl.glDisable(3042);
        gl.glEnable(3008);
        break;

      case 4: // '\004'
        gl.glEnable(3042);
        gl.glDisable(3008);
        gl.glBlendFunc(770, 1);
        break;
    }
    gl.glBindTexture(3553, model.mMaterials[texture].mTextureId);
    gl.glPushMatrix();
    if (particleType == 0 || particleType == 2) {
      if ((flags & 0x1000) == 0) {
        Vec3 view = new Vec3(viewer.getCamera().getPosition());
        view.normalize();
        Vec3 right = Vec3.cross(view, new Vec3(0.0F, 0.0F, 1.0F)).normalize();
        Vec3 up = Vec3.cross(right, view).normalize();
        int tcStart = 0;
        if (flags == 0x40019) tcStart++;
        gl.glBegin(7);
        int count = particles.size();
        Vec3 pos = new Vec3();
        Vec3 cPos = new Vec3();
        Vec3 ofs = new Vec3();
        for (int i = 0; i < count; i++) {
          Particle p = (Particle) particles.get(i);
          if (p.tile < texCoords.size()) {
            gl.glColor4f(p.color.x, p.color.y, p.color.z, p.color.w);
            Point2f tc[] = (Point2f[]) texCoords.get(p.tile);
            Vec3.add(right, up, ofs);
            cPos.set(p.pos);
            Vec3.sub(cPos, ofs.scale(p.size), pos);
            gl.glTexCoord2f(tc[tcStart % 4].x, tc[tcStart % 4].y);
            gl.glVertex3f(pos.x, pos.y, pos.z);
            Vec3.sub(right, up, ofs);
            Vec3.add(cPos, ofs.scale(p.size), pos);
            gl.glTexCoord2f(tc[(tcStart + 1) % 4].x, tc[(tcStart + 1) % 4].y);
            gl.glVertex3f(pos.x, pos.y, pos.z);
            Vec3.add(right, up, ofs);
            Vec3.add(cPos, ofs.scale(p.size), pos);
            gl.glTexCoord2f(tc[(tcStart + 2) % 4].x, tc[(tcStart + 2) % 4].y);
            gl.glVertex3f(pos.x, pos.y, pos.z);
            Vec3.sub(right, up, ofs);
            Vec3.sub(cPos, ofs.scale(p.size), pos);
            gl.glTexCoord2f(tc[(tcStart + 3) % 4].x, tc[(tcStart + 3) % 4].y);
            gl.glVertex3f(pos.x, pos.y, pos.z);
          }
        }

        gl.glEnd();
      } else {
        gl.glBegin(7);
        int count = particles.size();
        Vec3 pos = new Vec3();
        Vec3 ofs = new Vec3();
        for (int i = 0; i < count; i++) {
          Particle p = (Particle) particles.get(i);
          if (p.tile < texCoords.size()) {
            gl.glColor4f(p.color.x, p.color.y, p.color.z, p.color.w);
            Point2f tc[] = (Point2f[]) texCoords.get(p.tile);
            Vec3.add(p.pos, Vec3.scale(p.corners[0], p.size, ofs), pos);
            gl.glTexCoord2f(tc[0].x, tc[0].y);
            gl.glVertex3f(pos.x, pos.y, pos.z);
            Vec3.add(p.pos, Vec3.scale(p.corners[1], p.size, ofs), pos);
            gl.glTexCoord2f(tc[1].x, tc[1].y);
            gl.glVertex3f(pos.x, pos.y, pos.z);
            Vec3.add(p.pos, Vec3.scale(p.corners[2], p.size, ofs), pos);
            gl.glTexCoord2f(tc[2].x, tc[2].y);
            gl.glVertex3f(pos.x, pos.y, pos.z);
            Vec3.add(p.pos, Vec3.scale(p.corners[3], p.size, ofs), pos);
            gl.glTexCoord2f(tc[3].x, tc[3].y);
            gl.glVertex3f(pos.x, pos.y, pos.z);
          }
        }

        gl.glEnd();
      }
    } else if (particleType == 1) {
      gl.glBegin(7);
      int count = particles.size();
      Vec3 pos = new Vec3();
      Vec3 ofs = new Vec3();
      float f = 1.0F;
      Vec3 bv0 = new Vec3(-f, f, 0.0F);
      Vec3 bv1 = new Vec3(f, f, 0.0F);
      for (int i = 0; i < count; i++) {
        Particle p = (Particle) particles.get(i);
        if (p.tile >= texCoords.size() - 1) break;
        gl.glColor4f(p.color.x, p.color.y, p.color.z, p.color.w);
        Point2f tc[] = (Point2f[]) texCoords.get(p.tile);
        Vec3.add(p.pos, Vec3.scale(bv0, p.size, ofs), pos);
        gl.glTexCoord2f(tc[0].x, tc[0].y);
        gl.glVertex3f(pos.x, pos.y, pos.z);
        Vec3.add(p.pos, Vec3.scale(bv1, p.size, ofs), pos);
        gl.glTexCoord2f(tc[1].x, tc[1].y);
        gl.glVertex3f(pos.x, pos.y, pos.z);
        Vec3.add(p.origin, Vec3.scale(bv1, p.size, ofs), pos);
        gl.glTexCoord2f(tc[2].x, tc[2].y);
        gl.glVertex3f(pos.x, pos.y, pos.z);
        Vec3.add(p.origin, Vec3.scale(bv0, p.size, ofs), pos);
        gl.glTexCoord2f(tc[3].x, tc[3].y);
        gl.glVertex3f(pos.x, pos.y, pos.z);
      }

      gl.glEnd();
    }
    gl.glPopMatrix();
  }