how to fill a cuboid from one point to another?

Discussion in 'Plugin Development' started by danielmiles, May 2, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    danielmiles

    ok so either im just plain stupid or im looking at this completely wrong. I wanna make it so if i have two points(on the x,z, the y is not needed) i can setup the points and store them in a vector, but i just for the life of me cannot how to properly cycle through the cordinates to place the blocks.

    lets say i have:
    Code:
    Vector v1 = new vector(-5, 0, 7)
    Vector v2 = new vector(3, 0, -2)
    
    how do i setup the two for loops so it will go over all the blocks between those two vectors? the main problem is the negatives...
     
  2. Offline

    Malikk

    loop through all the values between the v1.x and v2.x, and inside that loop through all the values between your 2 z's. Then whatever value each loop is currently on (inside your second loop) is a coordinate between your two locations.
     
  3. Offline

    boomstik101

    this is the quintesential problem in programming. if you want to be a good one, learn this.

    how I fixed the problem:

    make a distance vector that is =v1.subtract(v2), this lets you know how many to go in every direction.


    Code:
    int originalX = v1.getX();
    int totalBlocksNeeded =differenceVector.getX()*differenceVector.getZ()
     
    for (int i = 1; i<=totalBlocksNeeded; i++){
      b.setTypeId(whatever);
      loc.setX(loc.getX()+1);
     
      if(i%(differenceVector.getX())==0){
          loc.setX(originalX);
          loc.setZ(loc.getZ()+1;
      }
      b=loc.getBlock();
    }
    i did something similar to this to make the sides of a 100*100*100 cube.

    I implore you to not copy that (as it probably will not work), but take the idea behind it and learn it until you can crank it out to your hearts content. The idea is as follows: you need to find out how many blocks you need, choose a direction to go in, use a moduli to check to see if you have completed a row (be careful of 0%anything because it will always be 0. thats why my loop starts at 1) then increment the other direction by one.

    hope this helps
     
  4. Offline

    danielmiles

    give an example if the two coords where as shown above? cause trust me i've tried its just the damned negatives that get me..
     
  5. Offline

    boomstik101

    make as distance vector man, there are 8 blocks between the x and 9 blocks between the z
     
  6. Offline

    Malikk

    I'm not going to spoon feed you, but your issue might be that you're always incrementing your counter, so you need to be checking which value is lower before trying to loop through it.
     
  7. Offline

    danielmiles

    boomstik101
    quick question if i have the two vectors like the ones shown above...
    v1.substract(v2); it will come out as (-8,0,9) this refers the blocks needed from v2 to v1 correct?
     
  8. Offline

    boomstik101

    You are making a 8x9 square yes. just run a quick method to make all the values positive. use math.abs(v1.getX());
     
Thread Status:
Not open for further replies.

Share This Page