Geometry help!

I want get tow PointArray of the Geometry at different position.

But I always get the same PointArray at different Position.

Here is parts of my program:

//I use PositionInterpolator to move the Geometry via x axis.

//and I have get the Geometry.

Geometry g = myShape.getGeometry(); //myShape is a shape3D from the .obj file

Point3f[] p3f1 = new Point3f[ 360 ];

for( int i = 0; i < 360; i ++ )

{

p3f1[ i ] = new Point3f();

}

if( g instanceof GeometryArray )

{

( ( GeometryArray ) g ).getCoordinates( 0, p3f1 );

}

//Now I'm getting tow PointArray

Point3f[] pArray1 = new Point3f[ 360 ];

Point3f[] pArray2 = new Point3f[ 360 ];

for( int i = 0; i < 306; i ++ )

{

pArray1[ i ] = p3f1[ i ];

pArray1[ i ].x = 0.2f;//set PointArray at the start position of the PositionInterpolator

pArray2[ i ] = p3f1[ i ];//get the PointArray during the moving

}

But When I change pArray1[ i ].x, the pArray2[ i ].x also changed and it also equals 0.2f.

What problem I have met?

How to solve it?

thanks!

[1161 byte] By [pangdodo] at [2007-9-30 21:10:02]
# 1

Hi,

Both pArray1 and pArray2 actually reference p3f1 so you do the changes on p3f1!

Try to set

pArray2[i] = new Point3f(p3f1[i]);

Regards

> I want get tow PointArray of the Geometry at different

> position.

>

> But I always get the same PointArray at different

> Position.

>

> Here is parts of my program:

>

> //I use PositionInterpolator to move the Geometry via

> x axis.

> //and I have get the Geometry.

>

> Geometry g = myShape.getGeometry(); //myShape is a

> shape3D from the .obj file

>

> Point3f[] p3f1 = new Point3f[ 360 ];

> for( int i = 0; i < 360; i ++ )

> {

> p3f1[ i ] = new Point3f();

> }

>

> if( g instanceof GeometryArray )

> {

> ( ( GeometryArray ) g ).getCoordinates( 0, p3f1 );

> }

>

> //Now I'm getting tow PointArray

>

> Point3f[] pArray1 = new Point3f[ 360 ];

> Point3f[] pArray2 = new Point3f[ 360 ];

>

> for( int i = 0; i < 306; i ++ )

> {

> pArray1[ i ] = p3f1[ i ];

> pArray1[ i ].x = 0.2f;//set PointArray at the

> start position of the PositionInterpolator

>

> pArray2[ i ] = p3f1[ i ];//get the PointArray

> during the moving

>

> }

>

> But When I change pArray1[ i ].x, the pArray2[ i ].x

> also changed and it also equals 0.2f.

>

> What problem I have met?

> How to solve it?

>

> thanks!

>

Oesten at 2007-7-7 2:43:06 > top of Java-index,Security,Cryptography...
# 2

You have to do the pArray2[i] = new Point3f(p3f1[i])

before you change the x.value in pArray1

OR also create a new point for pArray1 before changing the value.

> Hi,

>

> Both pArray1 and pArray2 actually reference

> p3f1 so you do the changes on p3f1!

> Try to set

> > pArray2[i] = new Point3f(p3f1[i]);

>

>

> Regards

>

>

> > I want get tow PointArray of the Geometry at

> different

> > position.

> >

> > But I always get the same PointArray at different

> > Position.

> >

> > Here is parts of my program:

> >

> > //I use PositionInterpolator to move the Geometry

> via

> > x axis.

> > //and I have get the Geometry.

> >

> > Geometry g = myShape.getGeometry(); //myShape is a

> > shape3D from the .obj file

> >

> > Point3f[] p3f1 = new Point3f[ 360 ];

> > for( int i = 0; i < 360; i ++ )

> > {

> > p3f1[ i ] = new Point3f();

> > }

> >

> > if( g instanceof GeometryArray )

> > {

> > ( ( GeometryArray ) g ).getCoordinates( 0, p3f1 );

> > }

> >

> > //Now I'm getting tow PointArray

> >

> > Point3f[] pArray1 = new Point3f[ 360 ];

> > Point3f[] pArray2 = new Point3f[ 360 ];

> >

> > for( int i = 0; i < 306; i ++ )

> > {

> > pArray1[ i ] = p3f1[ i ];

> > pArray1[ i ].x = 0.2f;//set PointArray at the

> > start position of the PositionInterpolator

> >

> > pArray2[ i ] = p3f1[ i ];//get the PointArray

> > during the moving

> >

> > }

> >

> > But When I change pArray1[ i ].x, the pArray2[ i ].x

> > also changed and it also equals 0.2f.

> >

> > What problem I have met?

> > How to solve it?

> >

> > thanks!

> >

>

Oesten at 2007-7-7 2:43:06 > top of Java-index,Security,Cryptography...
# 3
Thanks a lot!Problem has solved!
pangdodo at 2007-7-7 2:43:06 > top of Java-index,Security,Cryptography...