Hi All,
I am trying to create a background with a color
gradient.
I am working with HelloUniverse example for
this.
I am trying to use Background
geometry.
The problem is that when I give the
branchgroup , to which the geometry is added as an argument to
setGeometry method of Background class ,I cannot see the effect.
The code is :
import java.applet.Applet;
import java.awt.BorderLayout; import java.awt.event.*; import java.awt.Color; import java.awt.GraphicsConfiguration; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.geometry.ColorCube; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; import com.sun.j3d.utils.geometry.Sphere; public class HelloUniverse extends Applet
{
private SimpleUniverse u =
null;
Color3f white = new Color3f(1.0f,1.0f,1.0f); Color3f blue = new Color3f(0.0f,0.0f,1.0f); private final float[] vertices
=
{ 1.0f,-1.0f,1.0f, 1.0f, 1.0f,1.0f, -1.0f, 1.0f,1.0f, -1.0f,-1.0f,1.0f}; public BranchGroup createSceneGraph() { BranchGroup objRoot = new
BranchGroup();
TransformGroup objTrans = new
TransformGroup();
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRoot.addChild(objTrans); // Create a simple Shape3D node;
add it to the scene graph.
objTrans.addChild(new ColorCube(0.4)); Transform3D yAxis = new
Transform3D();
Alpha rotationAlpha = new Alpha(-1, 4000); RotationInterpolator rotator
=
new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI*2.0f); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); rotator.setSchedulingBounds(bounds); objRoot.addChild(rotator); BranchGroup branch = new BranchGroup(); branch.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND); branch.setCapability(BranchGroup.ALLOW_CHILDREN_READ); branch.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE); Shape3D rectangle = new Shape3D(); rectangle.setCapability(Shape3D.ALLOW_GEOMETRY_READ); rectangle.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); rectangle.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); rectangle.setCapability(Shape3D.ALLOW_APPEARANCE_READ); rectangle.setCapability(Shape3D.ALLOW_APPEARANCE_OVERRIDE_WRITE); rectangle.setCapability(Shape3D.ALLOW_APPEARANCE_OVERRIDE_READ); rectangle.setCapability(Shape3D.ALLOW_LOCAL_TO_VWORLD_READ); QuadArray aQuadArray = new
QuadArray(4,QuadArray.COORDINATES|QuadArray.NORMALS|QuadArray.COLOR_3);
aQuadArray.setCapability(QuadArray.ALLOW_COLOR_READ); aQuadArray.setCapability(QuadArray.ALLOW_COLOR_WRITE); aQuadArray.setCapability(QuadArray.ALLOW_COORDINATE_WRITE); aQuadArray.setCapability(QuadArray.ALLOW_COORDINATE_READ); aQuadArray.setCoordinates(0,vertices); Vector3f vector=new Vector3f( 0.0f,0.7f,0.7f); for( int i = 0; i < 4; i++ ) {aQuadArray.setNormal( i,vector);} aQuadArray.setColor(0,white); aQuadArray.setColor(1,white); aQuadArray.setColor(2,blue); aQuadArray.setColor(3,blue);
rectangle.addGeometry(aQuadArray);
branch.addChild(rectangle); Background background = ""
Background();
background.setApplicationBounds(bounds); background.setCapability(Background.ALLOW_GEOMETRY_READ); background.setCapability(Background.ALLOW_GEOMETRY_WRITE); background.setGeometry(branch); objRoot.addChild(background);
objRoot.compile();
return objRoot; }
public HelloUniverse() {
}
public void init() {
setLayout(new
BorderLayout());
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D c = new
Canvas3D(config);
add("Center", c); // Create a simple scene and
attach it to the virtual universe
BranchGroup scene = createSceneGraph(); u = new SimpleUniverse(c); u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);
} public void destroy() {
u.removeAllLocales();
}
public static void main(String[] args) { new MainFrame(new HelloUniverse(), 256, 256); } } |
- Re: [JAVA3D] Creating a Background with a color gradien... Ashwini Chougule
- Re: [JAVA3D] Creating a Background with a color gr... Kevin Glass
- Re: [JAVA3D] Creating a Background with a colo... Ashwini Chougule
- Re: [JAVA3D] Creating a Background with a ... Kevin Glass
- Re: [JAVA3D] Creating a Background wit... Ashwini Chougule
- Re: [JAVA3D] Creating a Backgroun... Kevin Glass
- Re: [JAVA3D] Creating a Backg... Ashwini Chougule
- Re: [JAVA3D] Creating a Background with a color gr... Frederic Barachant