This is a copy of my program and my intention is to create a
sphere using points but when generate, i get all sorts of points all over the
place.. It does not seems to look like a sphere at all.. I hope that anyone out
there can help me.. I guess the generating of points lies on the
sphereGeometry() section.. Thanks..
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 r = 2;
int xc = 4; int yc = 6; int zc = 4; 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*80)/100);
Point3f[] coordinates;
coordinates = new Point3f[v];
for (int i=0; i<v;
i++)
{ coordinates[i] = new Point3f (); //} //for(int 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);
spany = (yc+r)-(yc); spanz = (zc+r)-(zc); rx =
(randx*spanx);
ry = (randy*spany); rz = (randz*spanz); //+(zc-r); //if
(((rx-xc)*(rx-xc))+((ry-yc)*(ry-yc))+((rz-zc)*(rz-zc)) <= r)
{
coordinates[i].x = rx; coordinates[i].y = ry; coordinates[i].z = rz; //} } PointArray point = new PointArray(v,
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
|
- Re: [JAVA3D] John Wright
- Re: [JAVA3D] John D
- Re: [JAVA3D] Andy Tay
- Re: [JAVA3D] Eric
- Re: [JAVA3D] John D
- Re: [JAVA3D] Andy Tay
- [JAVA3D] Andy Tay
- Re: [JAVA3D] Donald Casteel
- [JAVA3D] IGES Abhishek K. Agrawal
- Re: [JAVA3D] IGES John Sutter
- [JAVA3D] Andy Tay
- [JAVA3D] Bruno Sousa Caiado
- [JAVA3D] Andy Tay
- Re: [JAVA3D] Cromwell Enage
- Re: [JAVA3D] Ahmed Shakil
- [JAVA3D] Andy Tay
- Re: [JAVA3D] Paul James
- [JAVA3D] help me ... please: how to move... z_mailing list
- Re: [JAVA3D] Casteel, Don
- [JAVA3D] Stanislav Panasik
- [JAVA3D] Illarramendi Amilibia, Aitor