Package horcher.visual

Source Code of horcher.visual.Panel3d

/**22.07.2008
* Jan Gunnar Gleixner
* Horcher
*
*
*/
package horcher.visual;

import java.awt.GraphicsConfiguration;

import javax.media.j3d.Appearance;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.ColoringAttributes;
import javax.media.j3d.LineAttributes;
import javax.media.j3d.Material;
import javax.media.j3d.PointAttributes;
import javax.media.j3d.PointLight;
import javax.media.j3d.PolygonAttributes;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;

import com.sun.j3d.utils.behaviors.vp.OrbitBehavior;
import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.universe.SimpleUniverse;

public class Panel3d extends Canvas3D {
  private static final long serialVersionUID = 1L;
  public static Panel3d createPanel3d() {
    final GraphicsConfiguration config = SimpleUniverse
        .getPreferredConfiguration();

    final Panel3d ret = new Panel3d(config);
    return ret;
  }
  private final BranchGroup branchgroup;

  private final SimpleUniverse universe;

  public Panel3d(final GraphicsConfiguration arg0) {
    super(arg0);
    this.universe = new SimpleUniverse(this);
    this.universe.getViewingPlatform().setNominalViewingTransform();

    // apearence ver�ndern
    final Appearance appear = new Appearance();

    final PointAttributes pointAttr = new PointAttributes();
    pointAttr.setPointAntialiasingEnable(true);
    appear.setPointAttributes(pointAttr);

    final LineAttributes lineAttr = new LineAttributes();
    lineAttr.setLineAntialiasingEnable(true);
    appear.setLineAttributes(lineAttr);

    final PolygonAttributes polyAttr = new PolygonAttributes();
    polyAttr.setPolygonMode(PolygonAttributes.POLYGON_FILL);
    appear.setPolygonAttributes(polyAttr);

    final Color3f orange = new Color3f(1f, 0.5f, 0f);

    final ColoringAttributes colorAttr = new ColoringAttributes();
    colorAttr.setColor(orange);
    colorAttr.setShadeModel(ColoringAttributes.NICEST);
    appear.setColoringAttributes(colorAttr);

    final Material material = new Material();
    material.setAmbientColor(orange);
    material.setDiffuseColor(orange);
    material.setSpecularColor(orange);
    material.setEmissiveColor(orange);
    appear.setMaterial(material);

    final Box box = new Box();
    box.setAppearance(appear);

    final Appearance appear2 = new Appearance();

    final PointAttributes pointAttr2 = new PointAttributes();
    pointAttr2.setPointAntialiasingEnable(true);
    appear2.setPointAttributes(pointAttr2);

    final LineAttributes lineAttr2 = new LineAttributes();
    lineAttr2.setLineAntialiasingEnable(true);
    appear2.setLineAttributes(lineAttr2);

    final PolygonAttributes polyAttr2 = new PolygonAttributes();
    polyAttr2.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    appear2.setPolygonAttributes(polyAttr2);

    final ColoringAttributes colorAttr2 = new ColoringAttributes();
    colorAttr2.setColor(new Color3f(1f, 0.5f, 0f));
    colorAttr2.setShadeModel(ColoringAttributes.NICEST);
    appear2.setColoringAttributes(colorAttr2);

    appear2.setMaterial(material);

    final Box box2 = new Box();
    box2.setAppearance(appear2);

    final PointLight pointLight1 = new PointLight();
    pointLight1.setPosition(2, 2, 2);
    pointLight1.setColor(new Color3f(1f, 1f, 1f));
    pointLight1.setInfluencingBounds(new BoundingSphere(new Point3d(0, 0, 0),
        999));

    final PointLight pointLight2 = new PointLight();
    pointLight2.setPosition(2, 2, -2);
    pointLight2.setColor(new Color3f(1f, 1f, 0f));
    pointLight2.setInfluencingBounds(new BoundingSphere(new Point3d(0, 0, 0),
        999));

    final PointLight pointLight3 = new PointLight();
    pointLight3.setPosition(2, -2, 2);
    pointLight3.setColor(new Color3f(1f, 0f, 1f));
    pointLight3.setInfluencingBounds(new BoundingSphere(new Point3d(0, 0, 0),
        999));

    final PointLight pointLight4 = new PointLight();
    pointLight4.setPosition(-2, 2, 2);
    pointLight4.setColor(new Color3f(1f, 0f, 0f));
    pointLight4.setInfluencingBounds(new BoundingSphere(new Point3d(0, 0, 0),
        999));

    final PointLight pointLight5 = new PointLight();
    pointLight5.setPosition(2, -2, -2);
    pointLight5.setColor(new Color3f(1f, 0f, 0f));
    pointLight5.setInfluencingBounds(new BoundingSphere(new Point3d(0, 0, 0),
        999));

    final PointLight pointLight6 = new PointLight();
    pointLight6.setPosition(-2, 2, -2);
    pointLight6.setColor(new Color3f(0f, 0f, 0f));
    pointLight6.setInfluencingBounds(new BoundingSphere(new Point3d(0, 0, 0),
        999));

    final PointLight pointLight7 = new PointLight();
    pointLight7.setPosition(-2, -2, 2);
    pointLight7.setColor(new Color3f(0f, 0.5f, 1f));
    pointLight7.setInfluencingBounds(new BoundingSphere(new Point3d(0, 0, 0),
        999));

    final PointLight pointLight8 = new PointLight();
    pointLight8.setPosition(-2, -2, -2);
    pointLight8.setColor(new Color3f(0f, 0.5f, 1f));
    pointLight8.setInfluencingBounds(new BoundingSphere(new Point3d(0, 0, 0),
        999));

    // neue Transform Informationen

    // neue Branchgruppe
    this.branchgroup = new BranchGroup();

    // Transformgruppe an Branchgruppe h�ngen
    // branchgroup.addChild(box);
    // branchgroup.addChild(box2);
    this.branchgroup.addChild(new Koordinatensystem3d());

    this.branchgroup.addChild(pointLight1);
    this.branchgroup.addChild(pointLight2);
    this.branchgroup.addChild(pointLight3);
    this.branchgroup.addChild(pointLight4);
    this.branchgroup.addChild(pointLight5);
    this.branchgroup.addChild(pointLight6);
    this.branchgroup.addChild(pointLight7);
    this.branchgroup.addChild(pointLight8);

    final OrbitBehavior orbit = new OrbitBehavior(this,
        OrbitBehavior.REVERSE_ALL); // OrbitBehavior liegt in dem Paket
                                    // com.sun.j3d.utils.behaviors.vp
    orbit.setSchedulingBounds(new BoundingSphere(new Point3d(0, 0, 0), 999));
    this.universe.getViewingPlatform().setViewPlatformBehavior(orbit);
    // ... an das Universum h�ngen
    this.universe.addBranchGraph(this.branchgroup);
  }

  public void addBranchGroup(final BranchGroup branchgroup) {
    this.universe.getLocale().addBranchGraph(branchgroup);
  }

  public void removeBranchGroup(final BranchGroup branchgroup) {
    this.universe.getLocale().removeBranchGraph(branchgroup);
  }
}
TOP

Related Classes of horcher.visual.Panel3d

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.