Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2021
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.30 KB | None | 0 0
  1. package net.minecraft.client.renderer.culling;
  2.  
  3. import net.minecraft.util.math.AxisAlignedBB;
  4. import net.minecraft.util.math.vector.Matrix4f;
  5. import net.minecraft.util.math.vector.Vector4f;
  6. import net.minecraftforge.api.distmarker.Dist;
  7. import net.minecraftforge.api.distmarker.OnlyIn;
  8.  
  9. @OnlyIn(Dist.CLIENT)
  10. public class ClippingHelper {
  11.    private final Vector4f[] frustumData = new Vector4f[6];
  12.    private double camX;
  13.    private double camY;
  14.    private double camZ;
  15.  
  16.    public ClippingHelper(Matrix4f p_i226026_1_, Matrix4f p_i226026_2_) {
  17.       this.calculateFrustum(p_i226026_1_, p_i226026_2_);
  18.    }
  19.  
  20.    public void prepare(double p_228952_1_, double p_228952_3_, double p_228952_5_) {
  21.       this.camX = p_228952_1_;
  22.       this.camY = p_228952_3_;
  23.       this.camZ = p_228952_5_;
  24.    }
  25.  
  26.    private void calculateFrustum(Matrix4f p_228956_1_, Matrix4f p_228956_2_) {
  27.       Matrix4f matrix4f = p_228956_2_.copy();
  28.       matrix4f.multiply(p_228956_1_);
  29.       matrix4f.transpose();
  30.       this.getPlane(matrix4f, -1, 0, 0, 0);
  31.       this.getPlane(matrix4f, 1, 0, 0, 1);
  32.       this.getPlane(matrix4f, 0, -1, 0, 2);
  33.       this.getPlane(matrix4f, 0, 1, 0, 3);
  34.       this.getPlane(matrix4f, 0, 0, -1, 4);
  35.       this.getPlane(matrix4f, 0, 0, 1, 5);
  36.    }
  37.  
  38.    private void getPlane(Matrix4f p_228955_1_, int p_228955_2_, int p_228955_3_, int p_228955_4_, int p_228955_5_) {
  39.       Vector4f vector4f = new Vector4f((float)p_228955_2_, (float)p_228955_3_, (float)p_228955_4_, 1.0F);
  40.       vector4f.transform(p_228955_1_);
  41.       vector4f.normalize();
  42.       this.frustumData[p_228955_5_] = vector4f;
  43.    }
  44.  
  45.    public boolean isVisible(AxisAlignedBB p_228957_1_) {
  46.       return this.cubeInFrustum(p_228957_1_.minX, p_228957_1_.minY, p_228957_1_.minZ, p_228957_1_.maxX, p_228957_1_.maxY, p_228957_1_.maxZ);
  47.    }
  48.  
  49.    private boolean cubeInFrustum(double p_228953_1_, double p_228953_3_, double p_228953_5_, double p_228953_7_, double p_228953_9_, double p_228953_11_) {
  50.       float f = (float)(p_228953_1_ - this.camX);
  51.       float f1 = (float)(p_228953_3_ - this.camY);
  52.       float f2 = (float)(p_228953_5_ - this.camZ);
  53.       float f3 = (float)(p_228953_7_ - this.camX);
  54.       float f4 = (float)(p_228953_9_ - this.camY);
  55.       float f5 = (float)(p_228953_11_ - this.camZ);
  56.       return this.cubeInFrustum(f, f1, f2, f3, f4, f5);
  57.    }
  58.  
  59.    private boolean cubeInFrustum(float p_228954_1_, float p_228954_2_, float p_228954_3_, float p_228954_4_, float p_228954_5_, float p_228954_6_) {
  60.       for(int i = 0; i < 6; ++i) {
  61.          Vector4f vector4f = this.frustumData[i];
  62.          if (!(vector4f.dot(new Vector4f(p_228954_1_, p_228954_2_, p_228954_3_, 1.0F)) > 0.0F) && !(vector4f.dot(new Vector4f(p_228954_4_, p_228954_2_, p_228954_3_, 1.0F)) > 0.0F) && !(vector4f.dot(new Vector4f(p_228954_1_, p_228954_5_, p_228954_3_, 1.0F)) > 0.0F) && !(vector4f.dot(new Vector4f(p_228954_4_, p_228954_5_, p_228954_3_, 1.0F)) > 0.0F) && !(vector4f.dot(new Vector4f(p_228954_1_, p_228954_2_, p_228954_6_, 1.0F)) > 0.0F) && !(vector4f.dot(new Vector4f(p_228954_4_, p_228954_2_, p_228954_6_, 1.0F)) > 0.0F) && !(vector4f.dot(new Vector4f(p_228954_1_, p_228954_5_, p_228954_6_, 1.0F)) > 0.0F) && !(vector4f.dot(new Vector4f(p_228954_4_, p_228954_5_, p_228954_6_, 1.0F)) > 0.0F)) {
  63.             return false;
  64.          }
  65.       }
  66.  
  67.       return true;
  68.    }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement