Example #1
0
 /**
  * Draws only the vertices of the given shape in white. Normals and indices are ignored. TODO:
  * negative W are possible, fix plx?
  *
  * @param shape
  * @param t
  */
 private void drawDotty(Shape shape, Matrix4f t) {
   float[] points = null, colors = null;
   for (VertexElement ve : shape.getVertexData().getElements()) {
     switch (ve.getSemantic()) {
       case POSITION:
         points = ve.getData();
         break;
       case COLOR:
         colors = ve.getData();
         break;
       case NORMAL:
         // DO NOT WANT
         break;
       case TEXCOORD:
         // DO NOT WANT
         break;
     }
   }
   for (int i = 0; i < points.length; i += 3) {
     Point4f v = new Point4f(points[i], points[i + 1], points[i + 2], 1);
     Color3f c = new Color3f(colors[i], colors[i + 1], colors[i + 2]);
     t.transform(v);
     int x = Math.round(v.x / v.w);
     int y = Math.round(v.y / v.w);
     if (x >= 0 && y >= 0 && y < colorBuffer.getHeight() && x < colorBuffer.getWidth())
       drawPointAt(x, y, c.get().getRGB());
   }
 }
Example #2
0
 public void animateHelper(float dt) {
   if (isSelected()) {
     Color3f ic = new Color3f();
     ic.interpolate(color, selectColor, (float) ((float) 0.5 + Math.sin(time * timeScale)));
     material.setDiffuseColor(ic);
     time += dt;
   } else {
     material.setDiffuseColor(color);
     time = 0;
   }
 }
Example #3
0
  /** Draws circular particle using a display list. */
  public void display(GL gl) {
    if (PARTICLE_DISPLAY_LIST < 0) { // MAKE DISPLAY LIST:
      int displayListIndex = gl.glGenLists(1);
      gl.glNewList(displayListIndex, GL.GL_COMPILE);
      drawParticle(gl, new Point3d(), radius); // /particle at origin
      gl.glEndList();
      System.out.println("MADE LIST " + displayListIndex + " : " + gl.glIsList(displayListIndex));
      PARTICLE_DISPLAY_LIST = displayListIndex;
    }

    // / COLOR: DEFAULT WHITE; GREEN IF HIGHLIGHTED; ADD RED IF PINNED
    Color3f c = new Color3f(1, 1, 1); // default: white
    if (pin) {
      c.x = 1f; // add red
      c.y *= 0.2f;
      c.z = 0;
    }
    if (highlight) {
      c.y = 1;
      c.z = 0;
    }
    if (GooParticle.class.isInstance(this)) {
      c.x = 0;
      c.y = 0;
      // now its blue
    }

    gl.glColor3f(c.x, c.y, c.z);

    // / DRAW ORIGIN-CIRCLE TRANSLATED TO "p":
    gl.glPushMatrix();
    gl.glTranslated(x.x, x.y, x.z);
    gl.glCallList(PARTICLE_DISPLAY_LIST);
    gl.glPopMatrix();
  }
Example #4
0
  public void getPropertyComponents(List comps, final ObjectListener listener) {
    visibleCbx = new JCheckBox(getName(), visible);
    float[] rgb = color.get().getRGBComponents(null);
    slider = new JSlider(0, 100, (int) (rgb[0] * 100));

    float[] xyz = new float[3];
    direction.get(xyz);
    directionXFld = makeField("" + xyz[0], listener, "X Direction");
    directionYFld = makeField("" + xyz[1], listener, "Y Direction");
    directionZFld = makeField("" + xyz[2], listener, "Z Direction");

    double[] pxyz = new double[3];
    location.get(pxyz);
    locationXFld = makeField("" + pxyz[0], listener, "");
    locationYFld = makeField("" + pxyz[1], listener, "");
    locationZFld = makeField("" + pxyz[2], listener, "");

    List fldComps =
        Misc.newList(GuiUtils.rLabel("Direction:"), directionXFld, directionYFld, directionZFld);
    //
    // fldComps.addAll(Misc.newList(GuiUtils.rLabel("Location:"),locationXFld,locationYFld,locationZFld));

    comps.add(visibleCbx);
    GuiUtils.tmpInsets = new Insets(0, 2, 0, 0);
    comps.add(
        GuiUtils.vbox(
            slider, GuiUtils.left(GuiUtils.doLayout(fldComps, 4, GuiUtils.WT_N, GuiUtils.WT_N))));

    if (listener != null) {
      visibleCbx.addActionListener(listener);
      slider.addChangeListener(listener);
    }
  }
Example #5
0
 public void brighter() {
   float[] rgb = color.get().getRGBComponents(null);
   rgb[0] = (float) Math.min(rgb[0] + 0.1, 1.0);
   rgb[1] = (float) Math.min(rgb[1] + 0.1, 1.0);
   rgb[2] = (float) Math.min(rgb[2] + 0.1, 1.0);
   color = new Color3f(rgb);
   updateLight();
 }
Example #6
0
  /**
   * Method to access appearance for cells in 3D
   *
   * @param initValue no null if appearance has to be changed according to user value. Using this
   *     mechanism to avoid the creation of new Boolean() just for the checking
   */
  public static void setCellAppearanceValues(Object initValue) {
    Color3f userColor = new Color3f(new Color(User.getColor(User.ColorPrefType.INSTANCE_3D)));

    if (cellApp == null) {
      cellApp = new J3DAppearance(TransparencyAttributes.SCREEN_DOOR, 0, null);

      RenderingAttributes ra = new RenderingAttributes();
      ra.setCapability(RenderingAttributes.ALLOW_VISIBLE_READ);
      ra.setCapability(RenderingAttributes.ALLOW_VISIBLE_WRITE);
      ra.setVisible(J3DUtils.is3DCellBndOn());
      cellApp.setRenderingAttributes(ra);

      // Set up the polygon attributes
      PolygonAttributes pa = new PolygonAttributes();
      pa.setCullFace(PolygonAttributes.CULL_NONE);
      pa.setPolygonMode(PolygonAttributes.POLYGON_LINE);
      cellApp.setPolygonAttributes(pa);

      //            TextureAttributes texAttr = new TextureAttributes();
      //            texAttr.setTextureMode(TextureAttributes.MODULATE);
      //            //texAttr.setTextureColorTable(pattern);
      //            cellApp.setTextureAttributes(texAttr);

      LineAttributes lineAttr = new LineAttributes();
      lineAttr.setLineAntialiasingEnable(true);
      cellApp.setLineAttributes(lineAttr);

      // ** Data for cells
      ColoringAttributes ca = new ColoringAttributes();
      ca.setCapability(ColoringAttributes.ALLOW_COLOR_WRITE);
      ca.setCapability(ColoringAttributes.ALLOW_COLOR_READ);
      ca.setColor(userColor);
      cellApp.setColoringAttributes(ca);
      cellApp.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
      cellApp.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
    } else if (initValue == null) // redoing color only when it was changed in GUI
    {
      ColoringAttributes ca = cellApp.getColoringAttributes();
      Color3f curColor = new Color3f();
      ca.getColor(curColor);
      if (!userColor.equals(curColor)) ca.setColor(userColor);
    }
  }
Example #7
0
  /**
   * Shades a point with the same algorithm used by the {@link <a
   * href="http://surf.sourceforge.net">surf raytracer</a>}.
   *
   * @param hitPoint Intersection point.
   * @param v View vector (from intersection point to eye).
   * @param n Surface normal.
   * @param material Surface material.
   * @return
   */
  protected Color3f shadeWithMaterial(
      Point3d hitPoint,
      Vector3d v,
      Vector3d n,
      Color3f ambientColor,
      LightProducts[] lightProducts) {
    Vector3d l = new Vector3d();
    Vector3d h = new Vector3d();

    Color3f color = new Color3f(ambientColor);

    for (int i = 0; i < dcsd.lightSources.length; i++) {
      LightSource lightSource = dcsd.lightSources[i];

      l.sub(lightSource.getPosition(), hitPoint);
      l.normalize();

      float lambertTerm = (float) n.dot(l);
      if (lambertTerm > 0.0f) {
        // compute diffuse color component
        color.scaleAdd(lambertTerm, lightProducts[i].getDiffuseProduct(), color);

        // compute specular color component
        h.add(l, v);
        h.normalize();

        color.scaleAdd(
            (float)
                Math.pow(Math.max(0.0f, n.dot(h)), lightProducts[i].getMaterial().getShininess()),
            lightProducts[i].getSpecularProduct(),
            color);
      }
    }

    color.clampMax(1.0f);

    return color;
  }
Example #8
0
 public UnshadedMaterial(Color3f color) {
   mColor.set(color);
 }
Example #9
0
  private Color3f antiAliasPixel(
      double ll_u,
      double ll_v,
      double u_incr,
      double v_incr,
      AntiAliasingPattern aap,
      Color3f ulColor,
      Color3f urColor,
      Color3f llColor,
      Color3f lrColor,
      HashMap<java.lang.Double, ColumnSubstitutorPair> csp_hm) {
    // first average pixel-corner colors
    Color3f finalColor;

    // adaptive supersampling
    float thresholdSqr = dcsd.antiAliasingThreshold * dcsd.antiAliasingThreshold;
    if (aap != AntiAliasingPattern.OG_2x2
        && (colorDiffSqr(ulColor, urColor) >= thresholdSqr
            || colorDiffSqr(ulColor, llColor) >= thresholdSqr
            || colorDiffSqr(ulColor, lrColor) >= thresholdSqr
            || colorDiffSqr(urColor, llColor) >= thresholdSqr
            || colorDiffSqr(urColor, lrColor) >= thresholdSqr
            || colorDiffSqr(llColor, lrColor) >= thresholdSqr)) {
      // anti-alias pixel with advanced sampling pattern
      finalColor = new Color3f();
      for (SamplingPoint sp : aap) {
        if (Thread.interrupted()) throw new RenderingInterruptedException();

        Color3f ss_color;
        if (sp.getU() == 0.0 && sp.getV() == 0.0) ss_color = llColor;
        else if (sp.getU() == 0.0 && sp.getV() == 1.0) ss_color = ulColor;
        else if (sp.getU() == 1.0 && sp.getV() == 1.0) ss_color = urColor;
        else if (sp.getU() == 1.0 && sp.getV() == 0.0) ss_color = lrColor;
        else {
          // color of this sample point is not known -> calculate
          double v = ll_v + sp.getV() * v_incr;
          double u = ll_u + sp.getU() * u_incr;
          ColumnSubstitutorPair csp = csp_hm.get(v);
          if (csp == null) {
            csp =
                new ColumnSubstitutorPair(
                    dcsd.surfaceRowSubstitutor.setV(v), dcsd.gradientRowSubstitutor.setV(v));
            csp_hm.put(v, csp);
          }
          ss_color = tracePolynomial(csp.scs, csp.gcs, u, v);
        }
        finalColor.scaleAdd(sp.getWeight(), ss_color, finalColor);

        if (false)
          return new Color3f(
              0, 0, 0); // paint pixels, that are supposed to be anti-aliased in black
      }
    } else {
      finalColor = new Color3f(ulColor);
      finalColor.add(urColor);
      finalColor.add(llColor);
      finalColor.add(lrColor);
      finalColor.scale(0.25f);
    }

    // clamp color, because floating point operations may yield values outside [0,1]
    finalColor.clamp(0f, 1f);
    return finalColor;
  }
Example #10
0
 public Color getBackgroundColor() {
   Color3f bgcolor3f = new Color3f();
   background.getColor(bgcolor3f);
   return bgcolor3f.get();
 }
Example #11
0
 public void changeBackgroundColor(Color newColor) {
   Color3f bgcolor3f = new Color3f();
   bgcolor3f.set(newColor);
   background.setColor(bgcolor3f);
 }