# Thread: Grid help

1. Member Join Date
May 2012
Posts
11
Rep Power
0

## Grid help

I am trying to make a deformable grid, like in Geometry wars, but Im having some trouble. Everything works fine, except all of the points drift to the upper left.

width and height are the width and height of the grid. xx is the x position of a point in the grid, same with yy. The spring method is under this code. friction and springstrenght are doubles.
Here is my Code:
Java Code:
```		for(int i=1; i<width-1;i++)
for(int n=1; n<height-1;n++){
if(Math.abs(xx[i][n]-mouse.x)<100 && Math.abs(yy[i][n]-mouse.y)<100){
double dist = Math.sqrt((xx[i][n]-mouse.x)*(xx[i][n]-mouse.x)+(yy[i][n]-mouse.y)*(yy[i][n]-mouse.y));
double angle = Math.atan2(yy[i][n] - mouse.y, xx[i][n] - mouse.x);
gox[i][n]+=Math.cos(angle)*(100-dist)*.1;
goy[i][n]+=Math.sin(angle)*(100-dist)*.1;
}
spring(i,n,i,n+1);
spring(i,n,i+1,n);
spring(i,n,i-1,n);
spring(i,n,i,n-1);
}
for(int i=0; i<width;i++)
for(int n=0; n<height;n++){
xx[i][n]+=gox[i][n];
yy[i][n]+=goy[i][n];
gox[i][n]=(float) ((gox[i][n]/friction));
goy[i][n]=(float) ((goy[i][n]/friction));
}```
And the spring code:
Java Code:
```public void spring(int i, int n, int x, int y){
double dist = Math.sqrt((xx[i][n]-xx[x][y])*(xx[i][n]-xx[x][y])+(yy[i][n]-yy[x][y])*(yy[i][n]-yy[x][y]));
double angle = Math.atan2(yy[i][n] - yy[x][y], xx[i][n] - xx[x][y]);
gox[i][n]-=Math.cos(angle)*(dist-size)*springstrenght;
goy[i][n]-=Math.sin(angle)*(dist-size)*springstrenght;
}```
Any help would be greatly appreciated!  Reply With Quote

2. ## Re: Grid help

Moved from New to Java

db  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•