Paul,

I'm not seeing what you are, Andy is using the int [v] to create the
Point3f[] array.
He goes on to create the individual Point3f with  "coordinates[i] = new
Point3f ();"     so I don't see a problem with the Point3f.

Andy,

I don't see where you are using a float to create the array in the code you
posted. If you are trying to change "int v" from what you've shown to "float
v" , you will get that error unless you use an explicit cast like the error
message says. Casting a float to an int is simple:

  coordinates = new Point3f[(int)v];
here's the cast---------------------^

However from your code, I can't see why you'd want "v" to be a float.

Also...

The code you posted compiles and runs fine. However I'm curious why you are
generating so many points that end up wasted at the origin. By changing the
code to recalculate the random coordinates if they fall outside the radius,
then entering them into the Point3f only if they fall within the radius,
every point will be used  [see revised code below, the do-while loop]

Anyway I hope this helps.
Don

---------------------revised code------------------------

private Geometry sphereGeometry()
                        {

                        int r = 5;
                        int xc = 0;
                        int yc = 0;
                        int zc = 0;
                        int v;
                        int bvol;
                        float rx, ry, rz, spanx, spany, spanz;

                        bvol =
((xc+r)-(xc-r))*((yc+r)-(yc-r))*((zc+r)-(zc-r));

                        v = (bvol*20);

                        Point3f[] coordinates;

                        coordinates = new Point3f[v];

                        spanx = (xc+r)-(xc-r);
                        spany = (yc+r)-(yc-r);
                        spanz = (zc+r)-(zc-r);



                        for (int i=0; i<v; i++)
                                {
                                coordinates[i] = new Point3f ();

                                do
                                        {
                                        rx = (xc-r) + (float) (Math.random()
* spanx);
                                        ry = (yc-r) + (float) (Math.random()
* spany);
                                        rz = (zc-r) + (float) (Math.random()
* spanz);

}while(((rx-xc)*(rx-xc))+((ry-yc)*(ry-yc))+((rz-zc)*(rz-zc)) > ((r)*(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



-----Original Message-----
From: Paul James [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 18, 2001 4:48 AM
To: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
Subject: Re: [JAVA3D]


Hi Andy,

You can't construct a point3f with a single value, you need to specify
three, (one for each axis), to make up the co-ordinate.

If you want to cast the int into a float you can turn it into an Integer and
then use Integer.floatValue(); but you'll still need the two other values to
make the point3f.

Any help?

Paul James



-----Original Message-----
From: Andy Tay [mailto:[EMAIL PROTECTED]]
Sent: mercoledì 17 gennaio 2001 20.53
To: [EMAIL PROTECTED]
Subject: [JAVA3D]


Does anyone knows how to set all my int values to float.. Cos i try to
change my int v; to float but they show me an error that say

 Incompatible type for new. Explicit cast needed to convert float to int.
 coordinates = new Point3f[v];

Andy

private Geometry sphereGeometry() {

  int r = 1;
  int xc = 0;
  int yc = 0;
  int zc = 0;
  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*200);

  Point3f[] coordinates;

  coordinates = new Point3f[v];

  spanx = (xc+r)-(xc-r);
  spany = (yc+r)-(yc-r);
  spanz = (zc+r)-(zc-r);



  for (int i=0; i<v; i++)
  {
  coordinates[i] = new Point3f ();
  //}

  //for(int f=0; f<v; f++){
   randx = (xc-r) + (float) (Math.random() * spanx);
   randy = (yc-r) + (float) (Math.random() * spany);
   randz = (zc-r) + (float) (Math.random() * spanz);

   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)*(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

===========================================================================
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".

Reply via email to