Hi,
In the attached document there is a simple scene: a cone with a sphere over it. I put
a directionnal light over those objects and was expected to see the shadow of the
sphere on the cone. There is no shadow. Could tell me what's wrong or missing in my
code?
Thanks for your help.
_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*;
public class Ombre extends JFrame
{
public BranchGroup createSceneGraph()
{
// Create the root of the branch graph
BranchGroup objRoot = new BranchGroup();
// Create a TransformGroup node for a ligth
TransformGroup objLum = new TransformGroup();
objRoot.addChild(objLum);
// Create a TransformGroup node for a sphere
Transform3D translatorY = new Transform3D();
translatorY.setTranslation(new Vector3f(0.0f,0.4f,0.0f));
TransformGroup objT1 = new TransformGroup(translatorY);
objT1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objLum.addChild(objT1);
// Create a TransformGroup node for a cone
Transform3D rotatorX = new Transform3D();
rotatorX.rotX(Math.PI/6);
rotatorX.setTranslation(new Vector3f(0.0f,-0.4f,0.0f));
TransformGroup objT2 = new TransformGroup(rotatorX);
objT2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objT1.addChild(objT2);
//Definition of scene objects and their appearence
Color3f aColor = new Color3f(1.0f, 1.0f, 1.0f);
Color3f eColor = new Color3f(0.2f, 0.2f, 0.3f);
Color3f dColor = new Color3f(0.5f, 0.5f, 0.5f);
Color3f sColor = new Color3f(0.7f, 0.7f, 0.7f);
Appearance ap=new Appearance();
Material m = new Material(aColor, eColor, dColor, sColor, 128.0f);
ap.setMaterial(m);
Sphere sphere=new Sphere(0.2f,ap);
objT1.addChild(sphere);
Cone cone=new Cone(0.6f,0.1f);
cone.setAppearance(ap);
objT2.addChild(cone);
//Definition of light
DirectionalLight lum=new DirectionalLight(true,
new Color3f(1.0f,1.0f,1.0f),
new Vector3f(0.0f,-1.0f,0.0f));
lum.setInfluencingBounds(new BoundingSphere(new Point3d(),10.0));
lum.addScope(objRoot);
objRoot.addChild(lum);
objRoot.compile();
return objRoot;
}
public Ombre()
{
getContentPane().setLayout(new BorderLayout());
Canvas3D fc = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
getContentPane().add("Center", fc);
// Create a simple scene and attach it to the virtual universe
BranchGroup scene = createSceneGraph();
SimpleUniverse u = new SimpleUniverse();
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);
WindowAdapter wa= new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
};
addWindowListener(wa);
}
public static void main(String s[])
{
Ombre o=new Ombre();
}
}