Thanks for your advise but i still couldn't get it running... Now it is
showing me the errors with only...
java.lang.NullPointerException
at FinalProject$Bone.sphereGeometry<Compiled Code>
at FinalProject$Bone.<init><FinalProject.java:27>
at FinalProject.createSceneGraph<FinalProject.java:114>
at FinalProject.<init><FinalProject.java:142>
at java.lang.Class.newInstance0<Native Method>
at java.lang.Class.newInstance<Class.java:239>
at sun.applet.AppletPanel.createApplet<AppletPanel.java:532>
at sun.applet.AppletPanel.runLoader<AppletPanel.java:468>
at sun.applet.AppletPanel.run<Compiled Code>
at java.lang.Thread.run<Thread.java:479>
This is the whole of my source code.. maybe you can help me to run and
hopefully you can help me with my problems thanks alot...
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
public class FinalProject extends Applet {
/////////////////////////////////////////////////
//
// create scene graph branch group
//
public class Bone extends Shape3D{
////////////////////////////////////////////
//
// create Shape3D with geometry and appearance
// the geometry is created in method sphereGeometry
// the appearance is created in method sphereAppearance
//
public Bone() {
this.setGeometry(sphereGeometry());
this.setAppearance(sphereAppearance());
}
private Geometry sphereGeometry() {
int f;
int r = 50;
int xc = 100;
int yc = 100;
int zc = 100;
int v;
int bvol;
float rx, ry, rz, spanx, spany, spanz, randx, randy, randz;
bvol = ((xc+r)-(xc-r))*((yc+r)-(yc-r))*((zc+r)-(zc-r));
v = ((bvol*60)/100);
Point3f[] coordinates;
coordinates = new Point3f[bvol];
for(f = 0; f < v; f++){
randx = 0.0f + (float) (Math.random() * 1.0f);
randy = 0.0f + (float) (Math.random() * 1.0f);
randz = 0.0f + (float) (Math.random() * 1.0f);
spanx = (xc+r)-(xc-r);
spany = (yc+r)-(yc-r);
spanz = (zc+r)-(zc-r);
rx = (randx*spanx)+(xc-r);
ry = (randy*spany)+(yc-r);
rz = (randz*spanz)+(zc-r);
if (((rx-xc)*(rx-xc))+((ry-yc)*(ry-yc))+((rz-zc)*(rz-zc)) <= r) {
coordinates[f].x = rx;
coordinates[f].y = ry;
coordinates[f].z = rz;
}
}
PointArray point = new PointArray(bvol, PointArray.COORDINATES);
point.setCoordinates(0, coordinates);
return point;
} // end of method SphereGeometry in class Bone
////////////////////////////////////////////
//
// create Sphere geometry
//
private Appearance sphereAppearance () {
Appearance appearance = new Appearance();
PolygonAttributes polyAttrib = new PolygonAttributes();
polyAttrib.setPolygonMode(PolygonAttributes.POLYGON_POINT);
appearance.setPolygonAttributes(polyAttrib);
return appearance;
} // end of method sphereAppearance of class Bone
} // end of class Bone
/////////////////////////////////////////////////
//
// create scene graph branch group
//
public BranchGroup createSceneGraph() {
BranchGroup objRoot = new BranchGroup();
// Create the transform group node and initialize it to the
// identity. Enable the TRANSFORM_WRITE capability so that
// our behavior code can modify it at runtime. Add it to the
// root of the subgraph.
TransformGroup objSpin = new TransformGroup();
objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objRoot.addChild(objSpin);
objSpin.addChild(new Bone());
// Create a new Behavior object that will perform the desired
// operation on the specified transform object and add it into
// the scene graph.
Transform3D yAxis = new Transform3D();
Alpha rotationAlpha = new Alpha(-1, 4000);
RotationInterpolator rotator =
new RotationInterpolator(rotationAlpha, objSpin);
BoundingSphere bounds =
new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
rotator.setSchedulingBounds(bounds);
objSpin.addChild(rotator);
// Let Java 3D perform optimizations on this scene graph.
objRoot.compile();
return objRoot;
} // end of CreateSceneGraph method of FinalProject
// Create a simple scene and attach it to the virtual universe
public FinalProject() {
setLayout(new BorderLayout());
Canvas3D canvas3D = new Canvas3D(null);
add("Center", canvas3D);
BranchGroup scene = createSceneGraph();
// SimpleUniverse is a Convenience Utility class
SimpleUniverse simpleU = new SimpleUniverse(canvas3D);
// This will move the ViewPlatform back a bit so the
// objects in the scene can be viewed.
simpleU.getViewingPlatform().setNominalViewingTransform();
simpleU.addBranchGraph(scene);
} // end of FinalProject constructor
// The following allows this to be run as an application
// as well as an applet
public static void main(String[] args) {
Frame frame = new MainFrame(new FinalProject(), 256, 256);
} // end of main method of FinalProject
} // end of class FinalProject
----- Original Message -----
From: John D <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, December 24, 2000 9:58 PM
Subject: Re: [JAVA3D]
> In the Christmas spirit, I looked again. Change your
> equation v = bvol*(60/100); to v = (bvol*60)/100);
> your mixture of ints and floats was resulting in zero.
> Off to service. Good luck.
>
> --- Andy Tay <[EMAIL PROTECTED]> wrote:
> > This is a part of my source code for my project...
> > It is giving me alot of problem and i still couldn't
> > figure how to correct it.. Can any one help me.. It
> > is quite urgent cause my deadline is coming soon...
> >
> > private Geometry sphereGeometry() {
> >
> > int f;
> >
> > int r = 50;
> > int xc = 100;
> > int yc = 100;
> > int zc = 100;
> > int v;
> > int bvol;
> > float rx, ry, rz, spanx, spany, spanz, randx,
> > randy, randz;
> >
> > bvol =
> > ((xc+r)-(xc-r))*((yc+r)-(yc-r))*((zc+r)-(zc-r));
> >
> > v = bvol*(60/100);
> >
> > Point3f[] coordinates;
> >
> > coordinates = new Point3f[bvol];
> >
> > for(f = 0; f < v; f++){
> > randx = 0.0f + (float) (Math.random() * 1.0f);
> > randy = 0.0f + (float) (Math.random() * 1.0f);
> > randz = 0.0f + (float) (Math.random() * 1.0f);
> >
> > spanx = (xc+r)-(xc-r);
> > spany = (yc+r)-(yc-r);
> > spanz = (zc+r)-(zc-r);
> >
> > rx = (randx*spanx)+(xc-r);
> > ry = (randy*spany)+(yc-r);
> > rz = (randz*spanz)+(zc-r);
> >
> > if
> >
> (((rx-xc)*(rx-xc))+((ry-yc)*(ry-yc))+((rz-zc)*(rz-zc))
> > <= r) {
> > coordinates[f].x = rx;
> > coordinates[f].y = ry;
> > coordinates[f].z = rz;
> > }
> > }
> >
> > PointArray point = new PointArray(bvol,
> > PointArray.COORDINATES);
> > point.setCoordinates(0, coordinates);
> >
> > return point;
> >
> > } // end of method SphereGeometry in class Bone
> >
> > When i compile, it doesn't show any problem but when
> > i run, i show me this errors.... I really hope that
> > anyone out that can help me with this problem
> > thanks....
> >
> > java.lang.NullPointerException
> > at
> >
> javax.media.j3d.GeometryArrayRetained.setCoordinates<CompiledCode>
> > at
> >
> javax.media.j3d.GeometryArray.setCoordinates<GeometryArray.java:333>
> > at
> > FinalProject$Bone.sphereGeometry<Compiled Code>
> > at
> > FinalProject$Bone.<init><FinalProject.java:27>
> > at
> > FinalProject.createSceneGraph<FinalProject.java:114>
> > at
> > FinalProject.<init><FinalProject.java:142>
> > at java.lang.Class.newInstance0<Native
> > Method>
> > at
> > java.lang.Class.newInstance<Class.java:239>
> > at
> >
> sun.applet.AppletPanel.createApplet<AppletPanel.java:532>
> > at
> >
> sun.applet.AppletPanel.runLoader<AppletPanel.java:468>
> > at sun.applet.AppletPanel.run<Compiled
> > Code>
> > at java.lang.Thread.run<Thread.java:479>
> >
> > Andy
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Shopping - Thousands of Stores. Millions of Products.
> http://shopping.yahoo.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".