I am working with a robot in vrml-eai.
recently i heard about java3d and i switched over to java3d since the
interface between a 3dworld and java applet is more clear here.
forget all these.
 Now i started building the robot with IndexedQuadArray as oppsed to
IndexedFaceSet. First of all I created a cube . but when i am rotating it
using pickingbehaviour all face are not appearing correctly.

some faces are rendered at a particular position only.i am a newb.
please help me.
i am enclosing the source.

 B V S N MURTHY

**************************************************************
import java.applet.Applet;
import java.awt.BorderLayout;

import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.media.j3d.Leaf.*;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.picking.*;
import javax.media.j3d.IndexedGeometryArray.*;



public class Quad1 extends Applet {

public void init() {

        setLayout(new BorderLayout());
        Canvas3D c = new Canvas3D(null);
        add("Center", c);

        BranchGroup scene = createSceneGraph(c);
        SimpleUniverse u = new SimpleUniverse(c);

        u.getViewingPlatform().setNominalViewingTransform();
        u.addBranchGraph(scene);
    }

public BranchGroup createSceneGraph(Canvas3D canvas) {

        BranchGroup objRoot = new BranchGroup();
        createLights (objRoot,canvas);

        Transform3D spin = new Transform3D();
        Transform3D tempspin = new Transform3D();

        Appearance earthApp = new Appearance();
        Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
        Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
        earthApp.setMaterial(new Material(white, black, white, black,
1.0f));

        spin.rotY(Math.PI/4.0d);
        tempspin.rotX(Math.PI/5.0d);
        spin.mul(tempspin);
        TransformGroup objTrans = new TransformGroup(spin);
        objRoot.addChild(objTrans);
        int[] ii = new int[4];
        for(int i=0;i<4;i++)ii[i]=i;


        IndexedQuadArray bb = new
IndexedQuadArray(8,IndexedQuadArray.COORDINATES |
IndexedQuadArray.COLOR_3,24);
        bb.setCoordinate(0, new Point3f(0.0f, 0.0f, 0.0f));
        bb.setCoordinate(1, new Point3f(0.4f, 0.0f, 0.0f));
        bb.setCoordinate(2, new Point3f(0.4f, 0.4f, 0.0f));
        bb.setCoordinate(3, new Point3f(0.0f, 0.4f, 0.0f));

        bb.setCoordinate(4, new Point3f(0.0f, 0.0f, 0.4f));
        bb.setCoordinate(5, new Point3f(0.4f, 0.0f, 0.4f));
        bb.setCoordinate(6, new Point3f(0.4f, 0.4f, 0.4f));
        bb.setCoordinate(7, new Point3f(0.0f, 0.4f, 0.4f));

        bb.setCoordinateIndex(0,0);
        bb.setCoordinateIndex(1,1);
        bb.setCoordinateIndex(2,2);
        bb.setCoordinateIndex(3,3);

        bb.setCoordinateIndex(4,2);
        bb.setCoordinateIndex(5,1);
        bb.setCoordinateIndex(6,5);
        bb.setCoordinateIndex(7,6);

        bb.setCoordinateIndex(8,4);
        bb.setCoordinateIndex(9,5);
        bb.setCoordinateIndex(10,6);
        bb.setCoordinateIndex(11,7);

        bb.setCoordinateIndex(12,2);
        bb.setCoordinateIndex(13,6);
        bb.setCoordinateIndex(14,7);
        bb.setCoordinateIndex(15,3);

        bb.setCoordinateIndex(16,3);
        bb.setCoordinateIndex(17,0);
        bb.setCoordinateIndex(18,4);
        bb.setCoordinateIndex(19,7);

        bb.setCoordinateIndex(20,0);
        bb.setCoordinateIndex(21,1);
        bb.setCoordinateIndex(22,5);
        bb.setCoordinateIndex(23,4);

        bb.setColor(0,new Color3f(1.0f,0.0f,1.0f));
        bb.setColor(4,new Color3f(1.0f,0.0f,1.0f));
        bb.setColor(2,new Color3f(1.0f,1.0f,0.0f));
        bb.setColor(1,new Color3f(0.0f,1.0f,1.0f));
        Shape3D ss = new Shape3D(bb);

        objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        objTrans.setCapability(TransformGroup.ENABLE_PICK_REPORTING);

        objTrans.addChild(ss);
        objRoot.compile();
        return objRoot;
    }
private void createLights(BranchGroup graphRoot,Canvas3D canvas) {

        // Create a bounds for the light source influence




        BoundingSphere bounds = new BoundingSphere(new
Point3d(0.0,0.0,0.0), 100.0);
        // Set up the global, ambient light
        Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);
        AmbientLight aLgt = new AmbientLight(alColor);
        aLgt.setInfluencingBounds(bounds);
        graphRoot.addChild(aLgt);
        // Set up the directional (infinite) light source
        Color3f lColor1 = new Color3f(0.9f, 0.9f, 0.9f);
        Vector3f lDir1  = new Vector3f(1.0f, 1.0f, -1.0f);
        DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
        lgt1.setInfluencingBounds(bounds);

        PickRotateBehavior behavior = new PickRotateBehavior(graphRoot,
canvas, bounds,

PickObject.USE_BOUNDS);
    graphRoot.addChild(behavior);

    PickZoomBehavior behavior2 = new PickZoomBehavior(graphRoot, canvas,
bounds,

PickObject.USE_BOUNDS);
    graphRoot.addChild(behavior2);
    PickTranslateBehavior behavior3 = new PickTranslateBehavior(graphRoot,
canvas, bounds,

PickObject.USE_BOUNDS);
    graphRoot.addChild(behavior3);



        graphRoot.addChild(lgt1);
    }

}

===========================================================================
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