Java use a method multiple times but with changed parameters -


i have method reads coordinates file , uses them render gameobject @ specified coordinates writen on file, code looks this:

public void processtext()  {               string file_name = "c:/users/server/desktop/texttext.txt";      try     {                    processcoords file = new processcoords(file_name);         string[] arylines = file.openfile();          int i;         (i = 0; < arylines.length; i++)         {             system.out.println(arylines[i]);                                   if(arylines[i].startswith("makegrass:")) {                     string arguments = arylines[i].substring(arylines[i].indexof(":")+1, arylines[i].length());                     string[] argarray = arguments.substring(1, arguments.length() - 2).split(" ");                      this.makegrass(double.parsedouble(argarray[0]),                                     double.parsedouble(argarray[1]),                                     double.parsedouble(argarray[2]));             }         }        } catch(ioexception e) {         system.out.println(e.getmessage());     }  } 

and text file have 1 line:

makegrass:(x y z)           // example makegrass:(1.22334 0.0 9.66678) 

this works fine now.. there's no point in making 1 single object. want able have many objects want multiple coordinates, text file might this:

makegrass:(0.0 1.0 5.0)  makegrass:(8.0 1.0 2.0)  makegrass:(4.0 1.0 7.0)  makegrass:(0.0 1.0 2.0)  makegrass:(2.0 1.0 7.0)  makegrass:(5.0 1.0 6.0)  

at moment use code this.makegrass once , grass model placed @ coordinates of first line (the other lines cause graphical glitch being put ontop of each other)

my question here how have write code gives me this.makegrass multiple times: want render grass model @ respective makegrass coordinates many times there makegrass coordinates provided in text file, how can that?

thanks help!

edit: asked more information.. here is:

public class vegetation extends gamecomponent { private game game;  gameobject grassleaf1 = new gameobject(); mesh grassleaf1mesh = new mesh("grassleaf1.obj"); material grassleaf1material = new material (new texture("grassuvtex.png"), 1, 8, new texture("grassuvtex_nrm.jpg"), new texture("grassuvtex_disp.jpg"), 0.008f, -0.5f); meshrenderer grassleaf1renderer = new meshrenderer(grassleaf1mesh, grassleaf1material);  public vegetation(game game) {     this.game = game; }  public void makegrass(double posx, double posy, double posz)  {            grassleaf1.addcomponent(grassleaf1renderer);     grassleaf1.gettransform().getpos().set((float)posx, (float)posy, (float)posz);     grassleaf1.gettransform().setscale(new vector3f (2, 2, 2));     grassleaf1.gettransform().setrot(new quaternion(new vector3f(0, 1, 0), (float) math.toradians(0)));          game.addobject(grassleaf1);  }     public void processtext()  {        grassleaf1.addcomponent(new savegrass());     grassleaf1.addcomponent(new objectmanipulator(4.0f));       string file_name = "c:/users/server/desktop/texttext.txt";      try     {                    processcoords file = new processcoords(file_name);         string[] arylines = file.openfile();          int i;         (i = 0; < arylines.length; i++)         {             system.out.println(arylines[i]);                                   if(arylines[i].startswith("makegrass:")) {                     string arguments = arylines[i].substring(arylines[i].indexof(":")+1, arylines[i].length());                     string[] argarray = arguments.substring(1, arguments.length() - 2).split(" ");                      this.makegrass(double.parsedouble(argarray[0]),                                     double.parsedouble(argarray[1]),                                     double.parsedouble(argarray[2]));             }         }        } catch(ioexception e) {         system.out.println(e.getmessage());     }  } } 

the vegetation class handles creating grass model , reading coordinates of text file. here said text file:

makegrass:(0.6 1.0 2.8) makegrass:(5.6 1.0 9.8) makegrass:(2.6 1.0 4.8) makegrass:(7.6 1.0 3.8) makegrass:(0.6 1.0 2.8) makegrass:(0.6 1.0 4.8) makegrass:(2.6 1.0 2.8) makegrass:(0.6 1.0 0.8) 

now should enable me render 8 grass models @ different positions when hit run can see this:

http://www.pic-upload.de/view-27752444/untitled.png.html

the grass super shiny because other grass models being placed @ location.. went wrong..

okay i've found mistake make grass function messed up, needs this:

public void makegrass(double posx, double posy, double posz)  {            gameobject grassleaf1 = new gameobject();     mesh grassleaf1mesh = new mesh("grassleaf1.obj");     material grassleaf1material = new material     (new texture("grassuvtex.png"), 1, 8, new texture("grassuvtex_nrm.jpg"), new texture("grassuvtex_disp.jpg"), 0.008f, -0.5f);     meshrenderer grassleaf1renderer = new meshrenderer(grassleaf1mesh, grassleaf1material);     grassleaf1.addcomponent(grassleaf1renderer);     grassleaf1.gettransform().getpos().set((float)posx, (float)posy, (float)posz);     grassleaf1.gettransform().setscale(new vector3f (2, 2, 2));     grassleaf1.gettransform().setrot(new quaternion(new vector3f(0, 1, 0), (float) math.toradians(0)));          game.addobject(grassleaf1); }    

only strange once i've added code makegrass method lost input methods.. strange not of problem now..

i'm getting wanted now.. here's final result , basis of world editor. thank much, you've helped me!

here's showoff picture: http://www.pic-upload.de/view-27752521/showoff.png.html

i'm sure i'll more enough @ moment know , can extend world editor on own, lot have helped me far, can return favour time!


Comments