Hi,

I see two problems with your code:

1) the reason why you don't see the sphere is because you didn't add any
Lights to your scene. Doing something like the following code should
suffice (at least for a test):

DirectionalLight dl = new DirectionalLight();
BoundingSphere bounds = new BoundingSphere();
bounds.setRadius(Double.POSITIVE_INFINITY);
dl.setInfluencingBounds(bounds);
group.addChild(dl);


2) However, note that the SimpleUniverse constructor with no parameters (which you are using) will create its own Canvas3D and window; therefore, your code is not using the Canvas3D that you create. If it did, you would not see anything (not even a window) since you are not displaying your applet window.


Another *potential* problem is that a sphere of radius 4 might be too big to see from the "nominal view transform" position. I haven't tested it but I guess it will be too close or even envelop the view platform.


Hope this helps,


Ricardo Nakamura


At 11:13 7/6/2003, you wrote:


I read a turotial and i am trying to figure out the Java3d

Here is my attempt to create a simple Sphere

-----------------
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.Sphere;
import javax.media.j3d.BranchGroup;
import com.sun.j3d.utils.applet.MainFrame;
import javax.media.j3d.*;
import java.awt.*;


public class MyFirstSphere extends java.applet.Applet {


public MyFirstSphere()

{

SimpleUniverse universe = new SimpleUniverse();

GraphicsConfiguration config = universe.getPreferredConfiguration();


Canvas3D c = new Canvas3D(config);


add("Center", c);

BranchGroup group = new BranchGroup();

group.addChild(new Sphere(4));

universe.getViewingPlatform().setNominalViewingTransform();

universe.addBranchGraph(group);

}

public static void main( String[] args ) {

new MyFirstSphere();

}
----------------------------

The problem is that everything is being compiled coorectly but nothing is
being displayed when i run it

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.486 / Virus Database: 284 - Release Date: 29/5/2003

Reply via email to