1.Yes,I have tried using just one color instead of using a gradient.
2.Now,I did as u suggested.:
a>From the code ,removed the part to set the Normals.
b>Changed the vertices to the one u suggested.
It still does not work.
Instead if I add the same branch group to the objRoot,I get the desired
effect but is is just a geometry added to the scenegraph whereas I want the
geometry to be set to the background node.I want the background to be as
far as possible.
Here is the code in which I can add the QuadArray as a geometry to objRoot
.Plz see it's working.
I am not able to add this same geometry to the Background node,why?
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.*;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
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,0.0f,
1.0f, 1.0f,0.0f,
-1.0f, 1.0f,0.0f,
-1.0f,-1.0f,0.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.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);
aQuadArray.setColor(0,white);
aQuadArray.setColor(1,blue);
aQuadArray.setColor(2,blue);
aQuadArray.setColor(3,white);
rectangle.setGeometry(aQuadArray);
branch.addChild(rectangle);
Background background = new Background();
background.setApplicationBounds(bounds);
background.setCapability(Background.ALLOW_GEOMETRY_READ);
background.setCapability(Background.ALLOW_GEOMETRY_WRITE);
/*These lines do not give the result
background.setGeometry(branch);
objRoot.addChild(bg);*/
/*Instead Here if I add the branchgroup I can see the effect*/
objRoot.addChild(branch);
objRoot.compile();
return objRoot;
}//end of function createScenegraph
public HelloUniverse() {
}//end of constructor
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);
}//end of init
public void destroy() {
u.removeAllLocales();
}//end of destroy
public static void main(String[] args) {
new MainFrame(new HelloUniverse(), 256, 256);
}//end of main
}//end of class
----- Original Message -----
From: "Kevin Glass" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, February 13, 2003 1:15 PM
Subject: Re: [JAVA3D] Creating a Background with a color gradient
> By single colour I actually meant using just one colour on your vertices.
> Instead of attempting to get a gradient.
>
> Also are your normals right, I mean the vector(0.0,0.7,0.7). You using
> nominal viewing transform, which means +Z goes into the screen (is that
> right anyone?). First off this means that your normals wouldn't point
> towards the screen.
>
> I also think you're vertices are a bit dubious. You want this background
> to appear infront of you? As far as possible away? I'd go for something
> like this:
>
> private final float[] vertices =
> {-0.5f, -0.5f, 0.5f,
> 0.5f, -0.5f, 0.5f,
> 0.5f, 0.5f, 0.5f,
> -0.5f, 0.5f, 0.5f};
>
> This should form a rectangle on the Z axis as far back into the screen as
> possible? I suggest either not setting the normals, or setting them to to
> (0.0,0.0,-1.0)
>
> HTH,
>
> Kev
>
> > Single color->U mean setting a color to the background and then adding
> > the background node to objRoot.Yes ,I tried that and it works .
> >
> > Also,about the geometry I have tried changing the coordinates of the
> > QuadArray.
> > Note: vertices array was changed to->
> > private final float[] vertices =
> > { 0.5f,0.0f,0.0f, 0.0f, 0.5f,0.0f, -0.5f, 0.0f,0.0f,
> > 0.0f,-0.5f,0.0f};
> > It still does not work .
> > Can u suggest something,please.
> > P.S:I got another reply about creating an image having color
> > gradient,with Buffered Image.I have used that and it was a succesful
> > process but there are some speed issues due to which I cannot use this
> > method.
> >
> >
> > ----- Original Message -----
> > From: "Kevin Glass" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Wednesday, February 12, 2003 5:43 PM
> > Subject: Re: [JAVA3D] Creating a Background with a color gradient
> >
> >
> </SNIP>
>
> --
> Jose UML - http://www.newdawnsoftware.com/jose
> Pondering RPG - http://pondering.newdawnsoftware.com
>
>
===========================================================================
> 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".
===========================================================================
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".