Results 1 to 2 of 2
Thread: Grid help
 05242012, 12:27 AM #1Member
 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<width1;i++) for(int n=1; n<height1;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)*(100dist)*.1; goy[i][n]+=Math.sin(angle)*(100dist)*.1; } spring(i,n,i,n+1); spring(i,n,i+1,n); spring(i,n,i1,n); spring(i,n,i,n1); } 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)); }
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)*(distsize)*springstrenght; goy[i][n]=Math.sin(angle)*(distsize)*springstrenght; }
 05242012, 05:35 AM #2
Similar Threads

Open Grid Scheduler/Grid Engine
By java software in forum Java SoftwareReplies: 0Last Post: 03272012, 07:00 PM 
2D grid
By ranss41 in forum New To JavaReplies: 0Last Post: 01062012, 05:41 PM 
Drawing a grid
By CrystalMoth in forum Java 2DReplies: 11Last Post: 01102010, 06:07 AM 
How can I square(^2) the pic in the grid
By racewithferrari in forum New To JavaReplies: 2Last Post: 11032009, 06:27 PM 
How can I square(^2) the pic in the grid
By racewithferrari in forum New To JavaReplies: 1Last Post: 11012009, 11:16 PM
Bookmarks