Saeed,

It's been a long time since I looked at light directions but my guess is
that your problem is that you have a flat object (all points have z = 0)
and your light is shining straight at the *edge* of your object not on
your object!

As a test just to make sure everything else is working try making your
ambient light 1.0,1.0,1.0 and make sure your object shows up as white.

To test out directions of lights add a second light that is coming from
an opposite direction (you don't want your light shining on the back of
your object or you'll be stuck with the same problem) (also give the
lights some Z offset so that they are definitely shining on your
object).  Then just goof around with it a bit and you should be able to
start understanding how it is working.

- John Wright
Starfire Research

Saeed Ansari wrote:
Hi,
I have attached the source code that I have problem with.
Can you tell me what is the problem ?

Regards,
Saeed


import javax.media.j3d.*; import java.awt.*; import javax.vecmath.*; import com.sun.j3d.utils.universe.*; import com.sun.j3d.utils.behaviors.vp.OrbitBehavior; import com.sun.j3d.utils.geometry.GeometryInfo; import com.sun.j3d.utils.geometry.Triangulator; import com.sun.j3d.utils.geometry.NormalGenerator; import com.sun.j3d.utils.geometry.Stripifier;




class TriangleTest extends Frame{ private Canvas3D c3d; private BranchGroup bg; private SimpleUniverse su; private TransformGroup tg; public TriangleTest(){ c3d=new Canvas3D(SimpleUniverse.getPreferredConfiguration()); bg=new BranchGroup(); su=new SimpleUniverse(); tg=new TransformGroup(); } void exe(){ add("Center",c3d); setSize(600,600); Point3d[] points = new Point3d[] { new Point3d(0, 0, 0),new Point3d(1, 0, 0), new Point3d(.5, .5, 0),new Point3d(1, 0, 0), new Point3d(1, 1, 0), new Point3d(.5, .5, 0), new Point3d(1, 1, 0),new Point3d(0, 1, 0), new Point3d(.5, .5, 0),new Point3d(0, 1, 0), new Point3d(0, 0, 0),new Point3d(.5, .5, 0) //new Point3d(-.5, 0, 0), };


// INTERACTION BoundingSphere bounds = new BoundingSphere(new Point3d(0.0f,0.0f,0.0f), 100); ViewingPlatform viewingPlatform = su.getViewingPlatform(); OrbitBehavior orbit = new OrbitBehavior( c3d, OrbitBehavior.REVERSE_ALL); orbit.setSchedulingBounds(bounds); viewingPlatform.setViewPlatformBehavior(orbit);

        //     GEOMETRY
        Shape3D part = new Shape3D();
        TriangleArray geometry = new 
TriangleArray(12,TriangleArray.COORDINATES|TriangleArray.COLOR_3);
        su.getViewingPlatform().setNominalViewingTransform();
        geometry.setCoordinates(0, points);
        part.setGeometry(geometry);
        for (int i=0;i<12;i++)
            geometry.setColor(i,new Color3f(Color.BLUE));
        //     APPEARANCE
        Appearance appearance = new Appearance();
        ColoringAttributes ca = new ColoringAttributes();
        ca.setColor(new Color3f(Color.BLUE));
        appearance.setColoringAttributes(ca);


// LIGHTING Material mat=new Material(); Color3f lightColor = new Color3f (.6f, 0.2f, 0.5f); Vector3f light1Direction = new Vector3f (0.5f, 0.5f, 0.0f); mat.setAmbientColor(new Color3f(0.0f,0.0f,1.0f)); mat.setDiffuseColor(new Color3f(0.7f,0.7f,0.7f)); mat.setSpecularColor(new Color3f(0.7f,0.7f,0.7f)); DirectionalLight light1 = new DirectionalLight (lightColor, light1Direction); light1.setInfluencingBounds (bounds); AmbientLight ambientLightNode = new AmbientLight (lightColor); ambientLightNode.setInfluencingBounds (bounds);

        //   SETTING
        appearance.setMaterial(mat);
        part.setAppearance(appearance);

        tg.addChild(part);
        tg.addChild (light1);
        tg.addChild (ambientLightNode);
        bg.addChild(tg);
        bg.compile();
        su.addBranchGraph(bg);

    }
    public static void main(String args[]){
         TriangleTest t=new TriangleTest();
         t.exe();
    }
}

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