Example usage for javax.media.j3d LineArray setCoordinates

List of usage examples for javax.media.j3d LineArray setCoordinates

Introduction

In this page you can find the example usage for javax.media.j3d LineArray setCoordinates.

Prototype

public void setCoordinates(int index, float coordinates[]) 

Source Link

Document

Sets the coordinates associated with the vertices starting at the specified index for this object.

Usage

From source file:edu.uci.ics.jung.visualization3d.PluggableRenderContext.java

public PluggableRenderContext() {
    super();//from   w ww.j  a  v a2s.c o  m
    Color3f lightGray = new Color3f(0.7f, 0.7f, 0.7f);
    Color3f black = new Color3f(0, 0, 0);
    Color3f white = new Color3f(1, 1, 1);
    Color3f gray = new Color3f(.2f, .2f, .2f);
    Color3f red = new Color3f(1, 0, 0);
    Color3f yellow = new Color3f(0, 1, 1);
    Material lightGrayMaterial = new Material(lightGray, black, lightGray, white, 100.0f);
    Material blackMaterial = new Material(lightGray, black, black, lightGray, 10.0f);
    Material whiteMaterial = new Material(white, white, white, white, 100.0f);
    Material grayMaterial = new Material(gray, black, gray, gray, 100.0f);
    Material redMaterial = new Material(red, black, red, red, 100.0f);
    Material yellowMaterial = new Material(yellow, black, yellow, yellow, 100.0f);

    final Appearance lightGrayLook = new Appearance();
    lightGrayLook.setMaterial(lightGrayMaterial);
    Appearance blackLook = new Appearance();
    blackLook.setMaterial(blackMaterial);
    Appearance whiteLook = new Appearance();
    whiteLook.setMaterial(whiteMaterial);
    Appearance grayLook = new Appearance();
    grayLook.setMaterial(grayMaterial);

    //      grayLook.setCapability(Appearance.ALLOW_MATERIAL_READ);
    //      grayLook.setCapability(Appearance.ALLOW_MATERIAL_WRITE);

    final Appearance redLook = new Appearance();
    redLook.setMaterial(redMaterial);
    final Appearance yellowLook = new Appearance();
    yellowLook.setMaterial(yellowMaterial);

    final Cylinder cylinder = new Cylinder(1, 1, Cylinder.GENERATE_NORMALS | Cylinder.ENABLE_GEOMETRY_PICKING,
            26, 26, lightGrayLook);
    final Sphere sphere = new Sphere(10, Sphere.GENERATE_NORMALS | Sphere.ENABLE_GEOMETRY_PICKING, redLook);
    final Box box = new Box(10, 10, 10, Box.GENERATE_NORMALS | Box.ENABLE_GEOMETRY_PICKING, redLook);

    this.edgeAppearanceTransformer = new ConstantTransformer(lightGrayLook);
    this.edgeShapeTransformer = new Transformer<Context<Graph<V, E>, E>, Node>() {

        public Node transform(Context<Graph<V, E>, E> ec) {
            LineArray lineArray = new LineArray(2, LineArray.COORDINATES | LineArray.COLOR_3);
            lineArray.setCoordinates(0, new Point3f[] { new Point3f(0, -.5f, 0), new Point3f(0, .5f, 0) });
            lineArray.setColor(0, new Color3f(1, 1, 1));
            lineArray.setColor(1, new Color3f(1, 1, 1));
            Shape3D shape = new Shape3D();
            shape.setGeometry(lineArray);
            return shape;
            //            return new Cylinder(1, 1, 
            //                  Cylinder.GENERATE_NORMALS |
            //                  Cylinder.ENABLE_GEOMETRY_PICKING,
            //                   26, 26, lightGrayLook);
        }
    };
    this.vertexAppearanceTransformer = new ConstantTransformer(redLook);
    this.vertexShapeTransformer = new Transformer<V, Node>() {

        public Node transform(V arg0) {
            return new Sphere(10,
                    Sphere.GENERATE_NORMALS | Sphere.ENABLE_GEOMETRY_PICKING | Sphere.ENABLE_APPEARANCE_MODIFY,
                    redLook);
        }
    };
}

From source file:LineTypes.java

Group createLineTypes() {

    Group lineGroup = new Group();

    Appearance app = new Appearance();
    ColoringAttributes ca = new ColoringAttributes(black, ColoringAttributes.SHADE_FLAT);
    app.setColoringAttributes(ca);/*from   w  w  w. j a v a 2 s .  c  o  m*/

    // Plain line
    Point3f[] plaPts = new Point3f[2];
    plaPts[0] = new Point3f(-0.9f, -0.7f, 0.0f);
    plaPts[1] = new Point3f(-0.5f, 0.7f, 0.0f);
    LineArray pla = new LineArray(2, LineArray.COORDINATES);
    pla.setCoordinates(0, plaPts);
    Shape3D plShape = new Shape3D(pla, app);
    lineGroup.addChild(plShape);

    // line pattern dot
    Point3f[] dotPts = new Point3f[2];
    dotPts[0] = new Point3f(-0.4f, -0.7f, 0.0f);
    dotPts[1] = new Point3f(-0.0f, 0.7f, 0.0f);
    LineArray dot = new LineArray(2, LineArray.COORDINATES);
    dot.setCoordinates(0, dotPts);
    LineAttributes dotLa = new LineAttributes();
    dotLa.setLineWidth(2.0f);
    dotLa.setLinePattern(LineAttributes.PATTERN_DOT);
    Appearance dotApp = new Appearance();
    dotApp.setLineAttributes(dotLa);
    dotApp.setColoringAttributes(ca);
    Shape3D dotShape = new Shape3D(dot, dotApp);
    lineGroup.addChild(dotShape);

    // line pattern dash
    Point3f[] dashPts = new Point3f[2];
    dashPts[0] = new Point3f(-0.0f, -0.7f, 0.0f);
    dashPts[1] = new Point3f(0.4f, 0.7f, 0.0f);
    LineArray dash = new LineArray(2, LineArray.COORDINATES);
    dash.setCoordinates(0, dashPts);
    LineAttributes dashLa = new LineAttributes();
    dashLa.setLineWidth(4.0f);
    dashLa.setLinePattern(LineAttributes.PATTERN_DASH);
    Appearance dashApp = new Appearance();
    dashApp.setLineAttributes(dashLa);
    dashApp.setColoringAttributes(ca);
    Shape3D dashShape = new Shape3D(dash, dashApp);
    lineGroup.addChild(dashShape);

    // line pattern dot-dash
    Point3f[] dotDashPts = new Point3f[2];
    dotDashPts[0] = new Point3f(0.5f, -0.7f, 0.0f);
    dotDashPts[1] = new Point3f(0.9f, 0.7f, 0.0f);
    LineArray dotDash = new LineArray(2, LineArray.COORDINATES);
    dotDash.setCoordinates(0, dotDashPts);
    LineAttributes dotDashLa = new LineAttributes();
    dotDashLa.setLineWidth(4.0f);
    dotDashLa.setLinePattern(LineAttributes.PATTERN_DASH_DOT);
    Appearance dotDashApp = new Appearance();
    dotDashApp.setLineAttributes(dotDashLa);
    dotDashApp.setColoringAttributes(ca);
    Shape3D dotDashShape = new Shape3D(dotDash, dotDashApp);
    lineGroup.addChild(dotDashShape);

    return lineGroup;

}

From source file:IntersectTest.java

public BranchGroup createSceneGraph() {

    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    // Set up the ambient light
    Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);
    AmbientLight ambientLightNode = new AmbientLight(ambientColor);
    ambientLightNode.setInfluencingBounds(bounds);
    objRoot.addChild(ambientLightNode);/*from ww  w . j  ava 2s . c o m*/

    // Set up the directional lights
    Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
    Color3f light2Color = new Color3f(0.3f, 0.3f, 0.4f);
    Vector3f light2Direction = new Vector3f(-6.0f, -2.0f, -1.0f);

    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    objRoot.addChild(light1);

    DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction);
    light2.setInfluencingBounds(bounds);
    objRoot.addChild(light2);

    Transform3D t3 = new Transform3D();

    // Shapes
    for (int x = 0; x < 3; x++) {
        for (int y = 0; y < 3; y++) {
            for (int z = 0; z < 3; z++) {
                t3.setTranslation(new Vector3d(-4 + x * 4.0, -4 + y * 4.0, -20 - z * 4.0));
                TransformGroup objTrans = new TransformGroup(t3);

                objRoot.addChild(objTrans);

                // Create a simple shape leaf node, add it to the scene
                // graph.
                GeometryArray geom = null;

                if (((x + y + z) % 2) == 0) {
                    geom = new RandomColorCube();
                } else {
                    geom = new RandomColorTetrahedron();
                }

                Shape3D shape = new Shape3D(geom);

                // use the utility method to set the capabilities
                PickTool.setCapabilities(shape, PickTool.INTERSECT_FULL);

                objTrans.addChild(shape);
            }
        }
    }

    // Lines
    Point3f[] verts = { new Point3f(-2.0f, 0.0f, 0.0f), new Point3f(2.0f, 0.0f, 0.0f) };
    Color3f grey = new Color3f(0.7f, 0.7f, 0.7f);
    Color3f[] colors = { grey, grey };

    for (int y = 0; y < 5; y++) {
        for (int z = 0; z < 5; z++) {
            t3.setTranslation(new Vector3d(7.0, -4 + y * 2.0, -20.0 - z * 2.0));
            TransformGroup objTrans = new TransformGroup(t3);

            objRoot.addChild(objTrans);

            LineArray la = new LineArray(verts.length, LineArray.COORDINATES | LineArray.COLOR_3);
            la.setCoordinates(0, verts);
            la.setColors(0, colors);

            Shape3D shape = new Shape3D();
            shape.setGeometry(la);

            // use the utility method to set the capabilities
            PickTool.setCapabilities(shape, PickTool.INTERSECT_FULL);

            objTrans.addChild(shape);
        }
    }

    // Points
    for (double x = -2.0; x <= 2.0; x += 1.0) {
        for (double y = -2.0; y <= 2.0; y += 1.0) {
            for (double z = -2.0; z <= 2.0; z += 1.0) {
                t3.setTranslation(new Vector3d(-10.0 + 2.0 * x, 0.0 + 2.0 * y, -20.0 + 2.0 * z));
                TransformGroup objTrans = new TransformGroup(t3);

                objRoot.addChild(objTrans);

                PointArray pa = new PointArray(1, PointArray.COORDINATES | PointArray.COLOR_3);

                pa.setCoordinate(0, new Point3d(0.0, 0.0, 0.0));
                pa.setColor(0, grey);

                Shape3D shape = new Shape3D();
                shape.setGeometry(pa);

                // use the utility method to set the capabilities
                PickTool.setCapabilities(shape, PickTool.INTERSECT_FULL);

                objTrans.addChild(shape);
            }
        }
    }

    return objRoot;
}

From source file:AppearanceExplorer.java

Shape3D createLineArray() {

    Point3f pnt[] = new Point3f[4];
    pnt[0] = new Point3f(-1.0f, -1.0f, 0.0f);
    pnt[1] = new Point3f(1.0f, -1.0f, 0.0f);
    pnt[2] = new Point3f(1.0f, 1.0f, 0.0f);
    pnt[3] = new Point3f(-1.0f, 1.0f, 0.0f);
    Color3f colrs[] = new Color3f[4];
    colrs[0] = black;/*from  ww  w  .j  a  v a2  s .c o m*/
    colrs[1] = white;
    colrs[2] = red;
    colrs[3] = green;

    LineArray la = new LineArray(4, GeometryArray.COORDINATES | GeometryArray.COLOR_3);
    la.setCoordinates(0, pnt);
    la.setColors(0, colrs);

    return new Shape3D(la, appearance);
}