Vector isInAABB ??

Discussion in 'Plugin Development' started by ZeusAllMighty11, Feb 9, 2013.

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

    ZeusAllMighty11

    I can't figure this part out...

    Code:
     
            public void getVectors()
            {
            final double x1 = this.plugin.getConfig().getDouble("Point_1.X");
            final double y1 = this.plugin.getConfig().getDouble("Point_1.Y");
            final double z1 = this.plugin.getConfig().getDouble("Point_1.Z");
     
            final double x2 = this.plugin.getConfig().getDouble("Point_2.X");
            final double y2 = this.plugin.getConfig().getDouble("Point_2.Y");
            final double z2 = this.plugin.getConfig().getDouble("Point_2.Z");
     
            v1 = new Vector(Math.min(x1, x2), Math.min(y1, y2), Math.min(z1, z2));
            v2 = new Vector(Math.max(x1, x2), Math.max(y1, y2), Math.max(z1, z2));
            }
    
    Whenever I check if a player is within the two vectors, it says they are not, when they are.
     
  2. Offline

    RealDope

    Can't really help you with this, but:

    What I do to check if player's are in a cuboid:

    Code:JAVA
    1.  
    2. public boolean isInEndZone(Location location) {
    3. int x1 = areas.getInt("end.1.x");
    4. int x2 = areas.getInt("end.2.x");
    5. int z1 = areas.getInt("end.1.z");
    6. int z2 = areas.getInt("end.2.z");
    7. int y1 = areas.getInt("end.1.y");
    8. int y2 = areas.getInt("end.2.y");
    9.  
    10. double px = location.getX();
    11. double pz = location.getZ();
    12. double py = location.getY();
    13.  
    14. if((px >= x1 && px <= x2) || (px <= x1 && px >= x2)) {
    15. if((pz >= z1 && pz <= z2) || (pz <= z1 && pz >= z2)) {
    16. if((py >= y1 && py <= y2) || (py <= y1 && py >= y2))
    17. return true;
    18. }
    19. }
    20. return false;
    21. }
    22.  
     
  3. Offline

    ZeusAllMighty11

    RealDope

    I get an NPE in that :\


    Edit: Plugin is null, no idea how
     
  4. Offline

    RealDope

    In my code? Or in your own? ZeusAllMighty11

    EDIT: Oh you said plugin is null, show whole class pl0x
     
  5. Offline

    Sabersamus

    Code:java
    1.  
    2. public class ZoneVector {
    3. private final int x;
    4. //These are final because once you make a zonevector you shouldn't move it.
    5. private final int z;
    6.  
    7. public ZoneVector(int x, int z){
    8. this.x = x;
    9. this.z = z;
    10. }
    11.  
    12. public ZoneVector(Location loc){
    13. this(loc.getBlockX(), loc.getBlockZ());
    14. }
    15.  
    16. public boolean isInAABB(ZoneVector min, ZoneVector max){
    17. /* Create a new Vector at the players location, new ZoneVector(player.getLocation());
    18.   * then create min and max, and yeah. you get the rest :P
    19.   */
    20. return ((this.x >= min.x) && (this.z >= min.z) && (this.x <= max.x) && (this.z <= max.z));
    21. }
    22.  
    23. public int getX(){
    24. return x;
    25. }
    26.  
    27. public int getZ(){
    28. return z;
    29. }


    This is how I do it with my zones plugin. Obviously you'd need to change it up to make it work for you.

    I hope this helps :)
     
  6. Offline

    ZeusAllMighty11

    Sabersamus

    Bukkit actually has a .isInAABB() method in the Vector class ;)
     
  7. Offline

    desht

    I presume you're using something like vec.isInAABB(v1, v2); where vec is some other Vector you're creating?

    Your code to set up the bounding vectors looks OK. I'd suggest printing out the x,y,z components of the vector you're checking as well as of the two bounding vectors, and see if anything jumps out at you. The isInAABB() method is really very simple:
    PHP:
    public boolean isInAABB(Vector minVector max) {
       return 
    >= min.&& <= max.&& >= min.&& <= max.&& >= min.&& <= max.z;
    }
    so it must be a basic arithmetic problem somewhere...
     
  8. Offline

    ZeusAllMighty11

    desht Sabersamus

    Guys, thanks for the help but this thread is old and I actually did figure it out myself.
     
  9. Offline

    desht

    Heh. Totally failed to spot the necro there :)
     
  10. Offline

    xa112

    ZeusAllMighty11 I am having a similar issue and was wondering what was your problem :)
     
  11. Offline

    ZeusAllMighty11

    xa112

    The solution I went with was using 2 vectors and checking isInAABB() :)
     
Thread Status:
Not open for further replies.

Share This Page