MovingBoxBoxCollisionEvaluator class

Пакет: com.hypixel.hytale.server.core.modules.collision

Файл: com/hypixel/hytale/server/core/modules/collision/MovingBoxBoxCollisionEvaluator.java

extends: BlockContactData

implements: IBlockCollisionEvaluator

Поля (16)

МодификаторыТипИмя
protected static final int COLLISION_INSIDE
protected static final int COLLISION_OUTSIDE
protected static final int COLLISION_TOUCH_MAX
protected static final int COLLISION_TOUCH_MIN
public int kind
public double max
public double min
public double normal
public double p
public double tEnter
public double tLeave
protected boolean touching
public boolean touching
public double v
double var5
var5

Методы (29)

МодификаторыВозвратСигнатура
private Collision1Dprivate Collision1D()
private double clampPosprivate double clampPos(double var1)
private void computeTouchOrOutsideprivate void computeTouchOrOutside(double var1, double var3, int var5)
if if(this.cX.kind == 1 && this.cY.kind == 1 && this.cZ.kind == 1)
if if(!this.computeOverlaps)
if if(this.cX.tLeave < this.collisionEnd)
if if(this.cY.tLeave < this.collisionEnd)
if if(this.cZ.tLeave < this.collisionEnd)
if if(this.cX.kind == 0)
if if(this.cY.kind == 0 && this.cY.tEnter > this.collisionStart)
if if(this.cZ.kind == 0 && this.cZ.tEnter > this.collisionStart)
if if(this.checkForOnGround && this.cY.kind == 3)
if if(this.collisionStart > this.collisionEnd)
if if(this.checkForOnGround && this.cY.kind == 3)
if if(var5 >= -1.0E-5)
if if(this.v < var5 - 1.0E-5)
if if(var5 <= 1.0E-5)
if if(this.v > var5 + 1.0E-5)
if if(this.v < 0.0)
if if(this.v != 0.0)
if if(this.tEnter != 0.0 && this.tEnter < 1.0E-8)
public boolean isBoundingBoxCollidingboolean isBoundingBoxColliding(@Nonnull Box var1, double var2, double var4, double var6)
public boolean isCheckForOnGroundboolean isCheckForOnGround()
boolean isCollidingboolean isColliding(double var1, double var3)
public boolean isComputeOverlapsboolean isComputeOverlaps()
public boolean isTouchingboolean isTouching()
public void setCheckForOnGroundvoid setCheckForOnGround(boolean var1)
public void setCollisionEndvoid setCollisionEnd(double var1)
public void setComputeOverlapsvoid setComputeOverlaps(boolean var1)

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.modules.collision;

class="kw">import com.hypixel.hytale.math.shape.Box;
class="kw">import com.hypixel.hytale.math.util.MathUtil;
class="kw">import javax.annotation.Nonnull;
class="kw">import org.joml.Vector3d;

class="kw">public class MovingBoxBoxCollisionEvaluator class="kw">extends BlockContactData class="kw">implements IBlockCollisionEvaluator {
   class="kw">protected boolean touching;
   class="kw">protected Box collider;
   @Nonnull
   class="kw">protected class="kw">final Vector3d pos;
   @Nonnull
   class="kw">protected class="kw">final Vector3d v;
   class="kw">protected boolean checkForOnGround = true;
   class="kw">private boolean computeOverlaps;
   @Nonnull
   class="kw">protected class="kw">final MovingBoxBoxCollisionEvaluator.Collision1D cX;
   @Nonnull
   class="kw">protected class="kw">final MovingBoxBoxCollisionEvaluator.Collision1D cY;
   @Nonnull
   class="kw">protected class="kw">final MovingBoxBoxCollisionEvaluator.Collision1D cZ;

   class="kw">public MovingBoxBoxCollisionEvaluator() {
      this.pos = new Vector3d();
      this.v = new Vector3d();
      this.cX = new MovingBoxBoxCollisionEvaluator.Collision1D();
      this.cY = new MovingBoxBoxCollisionEvaluator.Collision1D();
      this.cZ = new MovingBoxBoxCollisionEvaluator.Collision1D();
   }

   @Override
   class="kw">public double getCollisionStart() {
      class="kw">return this.collisionStart;
   }

   @Override
   class="kw">public void setCollisionData(@Nonnull BlockCollisionData var1, @Nonnull CollisionConfig var2, int var3) {
      var1.setStart(this.collisionPoint, this.collisionStart);
      var1.setEnd(this.collisionEnd, this.collisionNormal);
      var1.setBlockData(var2);
      var1.setDetailBoxIndex(var3);
      var1.setTouchingOverlapping(this.touching, this.isOverlapping());
   }

   class="kw">public boolean isCheckForOnGround() {
      class="kw">return this.checkForOnGround;
   }

   class="kw">public void setCheckForOnGround(boolean var1) {
      this.checkForOnGround = var1;
   }

   class="kw">public boolean isComputeOverlaps() {
      class="kw">return this.computeOverlaps;
   }

   class="kw">public void setComputeOverlaps(boolean var1) {
      this.computeOverlaps = var1;
   }

   @Nonnull
   class="kw">public MovingBoxBoxCollisionEvaluator setCollider(Box var1) {
      this.collider = var1;
      class="kw">return this;
   }

   @Nonnull
   class="kw">public MovingBoxBoxCollisionEvaluator setMove(@Nonnull Vector3d var1, @Nonnull Vector3d var2) {
      this.pos.set(var1);
      this.v.set(var2);
      this.cX.v = var2.x;
      this.cY.v = var2.y;
      this.cZ.v = var2.z;
      class="kw">return this;
   }

   class="kw">public boolean isBoundingBoxColliding(@Nonnull Box var1, double var2, double var4, double var6) {
      this.cX.p = this.pos.x - var2;
      this.cY.p = this.pos.y - var4;
      this.cZ.p = this.pos.z - var6;
      this.onGround = false;
      this.touching = false;
      this.overlapping = false;
      if (!this.cX.isColliding(var1.getMin().x - this.collider.getMax().x, var1.getMax().x - this.collider.getMin().x)) {
         class="kw">return false;
      }

      if (!this.cY.isColliding(var1.getMin().y - this.collider.getMax().y, var1.getMax().y - this.collider.getMin().y)) {
         class="kw">return false;
      }

      if (!this.cZ.isColliding(var1.getMin().z - this.collider.getMax().z, var1.getMax().z - this.collider.getMin().z)) {
         class="kw">return false;
      }

      if (this.cX.kind == 1 && this.cY.kind == 1 && this.cZ.kind == 1) {
         this.overlapping = true;
         if (!this.computeOverlaps) {
            class="kw">return false;
         }

         this.collisionStart = 0.0;
         this.collisionEnd = Double.MAX_VALUE;
         this.collisionNormal.set(0.0, 0.0, 0.0);
         if (this.cX.tLeave < this.collisionEnd) {
            this.collisionEnd = this.cX.tLeave;
            this.collisionNormal.set(this.cX.normal, 0.0, 0.0);
         }

         if (this.cY.tLeave < this.collisionEnd) {
            this.collisionEnd = this.cY.tLeave;
            this.collisionNormal.set(0.0, this.cY.normal, 0.0);
         }

         if (this.cZ.tLeave < this.collisionEnd) {
            this.collisionEnd = this.cZ.tLeave;
            this.collisionNormal.set(0.0, 0.0, this.cZ.normal);
         }

         class="kw">return true;
      } else {
         this.collisionStart = -Double.MAX_VALUE;
         this.collisionEnd = Double.MAX_VALUE;
         if (this.cX.kind == 0) {
            this.collisionNormal.set(this.cX.normal, 0.0, 0.0);
            this.collisionStart = this.cX.tEnter;
         }

         if (this.cY.kind == 0 && this.cY.tEnter > this.collisionStart) {
            this.collisionNormal.set(0.0, this.cY.normal, 0.0);
            this.collisionStart = this.cY.tEnter;
         }

         if (this.cZ.kind == 0 && this.cZ.tEnter > this.collisionStart) {
            this.collisionNormal.set(0.0, 0.0, this.cZ.normal);
            this.collisionStart = this.cZ.tEnter;
         }

         if (!(this.collisionStart > -Double.MAX_VALUE)) {
            if (this.checkForOnGround && this.cY.kind == 3) {
               this.collisionStart = MathUtil.maxValue(this.cX.tEnter, this.cY.tEnter, this.cZ.tEnter);
               this.collisionEnd = MathUtil.minValue(this.cX.tLeave, this.cY.tLeave, this.cZ.tLeave);
               this.collisionPoint.set(this.pos);
               this.collisionPoint.fma(this.collisionStart, this.v);
               this.collisionNormal.set(0.0, this.cY.normal, 0.0);
               this.onGround = true;
               this.touching = true;
            }

            class="kw">return false;
         } else {
            this.collisionEnd = MathUtil.minValue(this.cX.tLeave, this.cY.tLeave, this.cZ.tLeave);
            if (this.collisionStart > this.collisionEnd) {
               class="kw">return false;
            } else {
               this.collisionPoint.set(this.pos);
               this.collisionPoint.fma(this.collisionStart, this.v);
               if (this.checkForOnGround && this.cY.kind == 3) {
                  this.collisionNormal.set(0.0, this.cY.normal, 0.0);
                  this.onGround = true;
                  this.touching = true;
                  class="kw">return false;
               } else {
                  this.touching = this.cX.kind >= 2 || this.cY.kind >= 2 || this.cZ.kind >= 2;
                  class="kw">return !this.touching;
               }
            }
         }
      }
   }

   class="kw">public boolean isTouching() {
      class="kw">return this.touching;
   }

   class="kw">public void setCollisionEnd(double var1) {
      this.collisionEnd = var1;
   }

   class="kw">private class="kw">static class Collision1D {
      class="kw">protected class="kw">static class="kw">final int COLLISION_OUTSIDE = 0;
      class="kw">protected class="kw">static class="kw">final int COLLISION_INSIDE = 1;
      class="kw">protected class="kw">static class="kw">final int COLLISION_TOUCH_MIN = 2;
      class="kw">protected class="kw">static class="kw">final int COLLISION_TOUCH_MAX = 3;
      class="kw">public double p;
      class="kw">public double v;
      class="kw">public double min;
      class="kw">public double max;
      class="kw">public double tEnter;
      class="kw">public double tLeave;
      class="kw">public double normal;
      class="kw">public int kind;
      class="kw">public boolean touching;

      class="kw">private Collision1D() {
      }

      boolean isColliding(double var1, double var3) {
         this.min = var1;
         this.max = var3;
         this.tEnter = -Double.MAX_VALUE;
         this.tLeave = Double.MAX_VALUE;
         this.normal = 0.0;
         this.touching = false;
         double var5 = var1 - this.p;
         if (var5 >= -1.0E-5) {
            if (this.v < var5 - 1.0E-5) {
               class="kw">return false;
            }

            this.normal = -1.0;
            this.computeTouchOrOutside(var3, var5, 2);
            class="kw">return true;
         } else {
            var5 = var3 - this.p;
            if (var5 <= 1.0E-5) {
               if (this.v > var5 + 1.0E-5) {
                  class="kw">return false;
               }

               this.normal = 1.0;
               this.computeTouchOrOutside(var1, var5, 3);
               class="kw">return true;
            } else {
               this.tEnter = 0.0;
               if (this.v < 0.0) {
                  this.tLeave = this.clampPos((var1 - this.p) / this.v);
                  this.normal = 1.0;
               } else if (this.v > 0.0) {
                  this.tLeave = this.clampPos((var3 - this.p) / this.v);
                  this.normal = -1.0;
               }

               this.kind = 1;
               class="kw">return true;
            }
         }
      }

      class="kw">private void computeTouchOrOutside(double var1, double var3, int var5) {
         if (this.v != 0.0) {
            this.tEnter = MathUtil.clamp(var3 / this.v, 0.0, 1.0);
            if (this.tEnter != 0.0 && this.tEnter < 1.0E-8) {
               this.tEnter = 0.0;
            }

            this.tLeave = this.clampPos((var1 - this.p) / this.v);
            this.kind = 0;
         } else {
            this.tEnter = 0.0;
            this.kind = var5;
         }
      }

      class="kw">private double clampPos(double var1) {
         class="kw">return var1 >= 0.0 ? var1 : 0.0;
      }
   }
}