Hi all,

Does anyone know how to change the color of a cone in 3D?
Depending on some kind of value the color of the cone need to be changed
without creating a new cone.
All I need to do is to update a specific cone color.

Thanks for your help,

Eric

public class ConeSensor {

  private static float coneSCALE = 1.35f;      // scales size of the sensor
  private BranchGroup coneBG;
  private TransformGroup coneTG;
  private int[] supportedProbeTypes = { Probe.BIO_INFO };
  private Vec vpos;
  private String senName;
  private double evTime;
  private int detectionLevel;
  private double bioMassDensity;
  private ContinuousColorModel ccm = new ContinuousColorModel();
  public int[] getSupportedProbeTypes() { return supportedProbeTypes; }
  private Appearance ap;
  private Material m;

  public ConeSensor(Vec pos, String name, double tcur, int dLevel, double
bioMass) {
    super();
    vpos = pos;
    senName = name;
    evTime = tcur;
    detectionLevel = dLevel;
    bioMassDensity = bioMass;

    createBranchGroup(vpos);
  }

  public BranchGroup getBranchGroup() { return coneBG; }

  private void createBranchGroup(Vec vpos) {

    ap = new Appearance();
    Color3f aColor  = new Color3f(0.1f, 0.1f, 0.1f);
    Color3f eColor  = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f dColor  = new Color3f(0.8f, 0.8f, 0.8f);
    Color3f sColor  = new Color3f(0.0f, 1.0f, 1.0f);

    m = new Material(aColor, eColor, dColor, sColor, 80.0f);

    m.setLightingEnable(true);
    ap.setMaterial(m);
    //Create a Cone
    Cone ConeObj = new Cone(1.0f*Render.MODELSCALE, 2.0f*Render.MODELSCALE,
Cone.GENERATE_NORMALS | Cone.GENERATE_TEXTURE_COORDS, ap);
    // translate the ConeObj
    Transform3D translation = new Transform3D();
    // A 3 element vector that is represented by single precision floating
point x,y,z coordinates.
    // z coordinate set to 1 in order to be above ground
    translation.setTranslation(new Vector3f(80/Render.XSCALE,
25/Render.YSCALE, 0/Render.ZSCALE));
    // A four-element axis angle represented by single-precision floating
point x,y,z,angle components.
    // An axis angle is a rotation of angle (radians) about the vector
(x,y,z).
    // x - the x coordinate
    // y - the y coordinate
    // z - the z coordinate
    // angle - the angle of rotation in radians
    AxisAngle4f rot1 = new AxisAngle4f(90.0f, 90.0f, 90.0f, 90.0f);
    translation.setRotation(rot1);
    TransformGroup tg = new TransformGroup(translation);
    // add the cone to the scene.
    tg.addChild(ConeObj);

    TextureAttributes texAttr = new TextureAttributes();
    texAttr.setTextureMode(TextureAttributes.MODULATE);
    ap.setTextureAttributes(texAttr);

    //Shine it with two lights.
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Color3f lColor2 = new Color3f(0.2f, 0.2f, 0.1f);
    Vector3f lDir1  = new Vector3f(-1.0f, -1.0f, -1.0f);
    Vector3f lDir2  = new Vector3f(0.0f, 0.0f, -1.0f);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2);
    tg.addChild(lgt1);
    tg.addChild(lgt2);

    coneBG = new BranchGroup();

    Transform3D shift = new Transform3D();
    shift.setTranslation(new Vector3f((float)vpos.x, (float)vpos.y,
(float)vpos.z));
    shift.setScale(coneSCALE);
    coneTG = new TransformGroup(shift);
    coneTG.addChild(tg);

    coneBG.addChild(coneTG);
  }

  // sets the position of the cone.  pos is in scaled view coords that we
can use directly
   public void setPosition(Vec pos) {
      System.out.println("In ConeSensor SET POSITION
==============================================");
      //Transform3D t3d = new Transform3D();
      //Vector3f p = new Vector3f((float)pos.x, (float)pos.y, (float)pos.z);
      //t3d.setTranslation(p);
      //coneTG.setTransform(t3d);
   }

   // sets the color of the cone.
   public void setColorStatus(double conc) {
      System.out.println("++++++++++++++++++++++++++++++ In ConeSensor
setColorStatus conc: "+conc);
      ap = new Appearance();
      Color3f aColor  = new Color3f(2.1f, 0.1f, 0.1f);
      Color3f eColor  = new Color3f(3.0f, 0.0f, 0.0f);
      Color3f dColor  = new Color3f(4.8f, 0.8f, 0.8f);
      Color3f sColor  = new Color3f(5.0f, 1.0f, 1.0f);

      m = new Material(aColor, eColor, dColor, sColor, 80.0f);

      //if(conc > 0.0 ) {
      //    Color col = ccm.getColor(conc);
      //    Color3f aaColor = col;
      //    System.out.println("col is: "+col);
      //}
      //           g.setColor(col);
   }
   // sets the color of the cone.
   public void setScale(double conc) {
      System.out.println("In ConeSensor setColorStatus conc: "+conc);
   }
}

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to