Results 1 to 2 of 2

Thread: Grid help

  1. #1
    lolmister is offline Member
    Join Date
    May 2012
    Posts
    11
    Rep Power
    0

    Default 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!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Grid help

    Moved from New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Open Grid Scheduler/Grid Engine
    By java software in forum Java Software
    Replies: 0
    Last Post: 03-27-2012, 07:00 PM
  2. 2D grid
    By ranss41 in forum New To Java
    Replies: 0
    Last Post: 01-06-2012, 04:41 PM
  3. Drawing a grid
    By CrystalMoth in forum Java 2D
    Replies: 11
    Last Post: 01-10-2010, 05:07 AM
  4. How can I square(^2) the pic in the grid
    By racewithferrari in forum New To Java
    Replies: 2
    Last Post: 11-03-2009, 05:27 PM
  5. How can I square(^2) the pic in the grid
    By racewithferrari in forum New To Java
    Replies: 1
    Last Post: 11-01-2009, 10:16 PM

Posting Permissions

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