Frustum.java
net.minecraft.client.renderer.culling.Frustum
信息
- 全限定名:net.minecraft.client.renderer.culling.Frustum
- 类型:public class
- 包:net.minecraft.client.renderer.culling
- 源码路径:src/main/java/net/minecraft/client/renderer/culling/Frustum.java
- 起始行号:L13
- 职责:
TODO
字段/常量
-
OFFSET_STEP- 类型:
int - 修饰符:
public static final - 源码定位:
L14 - 说明:
TODO
- 类型:
-
intersection- 类型:
FrustumIntersection - 修饰符:
private final - 源码定位:
L15 - 说明:
TODO
- 类型:
-
matrix- 类型:
Matrix4f - 修饰符:
private final - 源码定位:
L16 - 说明:
TODO
- 类型:
-
viewVector- 类型:
Vector4f - 修饰符:
private - 源码定位:
L17 - 说明:
TODO
- 类型:
-
camX- 类型:
double - 修饰符:
private - 源码定位:
L18 - 说明:
TODO
- 类型:
-
camY- 类型:
double - 修饰符:
private - 源码定位:
L19 - 说明:
TODO
- 类型:
-
camZ- 类型:
double - 修饰符:
private - 源码定位:
L20 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public Frustum(Matrix4fc modelView, Matrix4f projection) @ L22
- 构造器名:Frustum
- 源码定位:L22
- 修饰符:public
参数:
- modelView: Matrix4fc
- projection: Matrix4f
说明:
TODO
public Frustum(Frustum frustum) @ L26
- 构造器名:Frustum
- 源码定位:L26
- 修饰符:public
参数:
- frustum: Frustum
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void set(Frustum frustum) @ L30
- 方法名:set
- 源码定位:L30
- 返回类型:void
- 修饰符:public
参数:
- frustum: Frustum
说明:
TODO
public Frustum offset(float offset) @ L39
- 方法名:offset
- 源码定位:L39
- 返回类型:Frustum
- 修饰符:public
参数:
- offset: float
说明:
TODO
public Frustum offsetToFullyIncludeCameraCube(int cubeSize) @ L46
- 方法名:offsetToFullyIncludeCameraCube
- 源码定位:L46
- 返回类型:Frustum
- 修饰符:public
参数:
- cubeSize: int
说明:
TODO
public void prepare(double camX, double camY, double camZ) @ L73
- 方法名:prepare
- 源码定位:L73
- 返回类型:void
- 修饰符:public
参数:
- camX: double
- camY: double
- camZ: double
说明:
TODO
private void calculateFrustum(Matrix4fc modelView, Matrix4f projection) @ L79
- 方法名:calculateFrustum
- 源码定位:L79
- 返回类型:void
- 修饰符:private
参数:
- modelView: Matrix4fc
- projection: Matrix4f
说明:
TODO
public boolean isVisible(AABB bb) @ L85
- 方法名:isVisible
- 源码定位:L85
- 返回类型:boolean
- 修饰符:public
参数:
- bb: AABB
说明:
TODO
public int cubeInFrustum(BoundingBox bb) @ L90
- 方法名:cubeInFrustum
- 源码定位:L90
- 返回类型:int
- 修饰符:public
参数:
- bb: BoundingBox
说明:
TODO
private int cubeInFrustum(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) @ L94
- 方法名:cubeInFrustum
- 源码定位:L94
- 返回类型:int
- 修饰符:private
参数:
- minX: double
- minY: double
- minZ: double
- maxX: double
- maxY: double
- maxZ: double
说明:
TODO
public boolean pointInFrustum(double x, double y, double z) @ L104
- 方法名:pointInFrustum
- 源码定位:L104
- 返回类型:boolean
- 修饰符:public
参数:
- x: double
- y: double
- z: double
说明:
TODO
public Vector4f[] getFrustumPoints() @ L108
- 方法名:getFrustumPoints
- 源码定位:L108
- 返回类型:Vector4f[]
- 修饰符:public
参数:
- 无
说明:
TODO
public double getCamX() @ L129
- 方法名:getCamX
- 源码定位:L129
- 返回类型:double
- 修饰符:public
参数:
- 无
说明:
TODO
public double getCamY() @ L133
- 方法名:getCamY
- 源码定位:L133
- 返回类型:double
- 修饰符:public
参数:
- 无
说明:
TODO
public double getCamZ() @ L137
- 方法名:getCamZ
- 源码定位:L137
- 返回类型:double
- 修饰符:public
参数:
- 无
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class Frustum {
public static final int OFFSET_STEP = 4;
private final FrustumIntersection intersection = new FrustumIntersection();
private final Matrix4f matrix = new Matrix4f();
private Vector4f viewVector;
private double camX;
private double camY;
private double camZ;
public Frustum(Matrix4fc modelView, Matrix4f projection) {
this.calculateFrustum(modelView, projection);
}
public Frustum(Frustum frustum) {
this.set(frustum);
}
public void set(Frustum frustum) {
this.intersection.set(frustum.matrix);
this.matrix.set(frustum.matrix);
this.camX = frustum.camX;
this.camY = frustum.camY;
this.camZ = frustum.camZ;
this.viewVector = frustum.viewVector;
}
public Frustum offset(float offset) {
this.camX = this.camX + this.viewVector.x * offset;
this.camY = this.camY + this.viewVector.y * offset;
this.camZ = this.camZ + this.viewVector.z * offset;
return this;
}
public Frustum offsetToFullyIncludeCameraCube(int cubeSize) {
double camX1 = Math.floor(this.camX / cubeSize) * cubeSize;
double camY1 = Math.floor(this.camY / cubeSize) * cubeSize;
double camZ1 = Math.floor(this.camZ / cubeSize) * cubeSize;
double camX2 = Math.ceil(this.camX / cubeSize) * cubeSize;
double camY2 = Math.ceil(this.camY / cubeSize) * cubeSize;
for (double camZ2 = Math.ceil(this.camZ / cubeSize) * cubeSize;
this.intersection
.intersectAab(
(float)(camX1 - this.camX),
(float)(camY1 - this.camY),
(float)(camZ1 - this.camZ),
(float)(camX2 - this.camX),
(float)(camY2 - this.camY),
(float)(camZ2 - this.camZ)
)
!= -2;
this.camZ = this.camZ - this.viewVector.z() * 4.0F
) {
this.camX = this.camX - this.viewVector.x() * 4.0F;
this.camY = this.camY - this.viewVector.y() * 4.0F;
}
return this;
}
public void prepare(double camX, double camY, double camZ) {
this.camX = camX;
this.camY = camY;
this.camZ = camZ;
}
private void calculateFrustum(Matrix4fc modelView, Matrix4f projection) {
projection.mul(modelView, this.matrix);
this.intersection.set(this.matrix);
this.viewVector = this.matrix.transformTranspose(new Vector4f(0.0F, 0.0F, 1.0F, 0.0F));
}
public boolean isVisible(AABB bb) {
int intersectionResult = this.cubeInFrustum(bb.minX, bb.minY, bb.minZ, bb.maxX, bb.maxY, bb.maxZ);
return intersectionResult == -2 || intersectionResult == -1;
}
public int cubeInFrustum(BoundingBox bb) {
return this.cubeInFrustum(bb.minX(), bb.minY(), bb.minZ(), bb.maxX() + 1, bb.maxY() + 1, bb.maxZ() + 1);
}
private int cubeInFrustum(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
float x1 = (float)(minX - this.camX);
float y1 = (float)(minY - this.camY);
float z1 = (float)(minZ - this.camZ);
float x2 = (float)(maxX - this.camX);
float y2 = (float)(maxY - this.camY);
float z2 = (float)(maxZ - this.camZ);
return this.intersection.intersectAab(x1, y1, z1, x2, y2, z2);
}
public boolean pointInFrustum(double x, double y, double z) {
return this.intersection.testPoint((float)(x - this.camX), (float)(y - this.camY), (float)(z - this.camZ));
}
public Vector4f[] getFrustumPoints() {
Vector4f[] frustumPoints = new Vector4f[]{
new Vector4f(-1.0F, -1.0F, -1.0F, 1.0F),
new Vector4f(1.0F, -1.0F, -1.0F, 1.0F),
new Vector4f(1.0F, 1.0F, -1.0F, 1.0F),
new Vector4f(-1.0F, 1.0F, -1.0F, 1.0F),
new Vector4f(-1.0F, -1.0F, 1.0F, 1.0F),
new Vector4f(1.0F, -1.0F, 1.0F, 1.0F),
new Vector4f(1.0F, 1.0F, 1.0F, 1.0F),
new Vector4f(-1.0F, 1.0F, 1.0F, 1.0F)
};
Matrix4f clipToWorldMatrix = this.matrix.invert(new Matrix4f());
for (int i = 0; i < 8; i++) {
clipToWorldMatrix.transform(frustumPoints[i]);
frustumPoints[i].div(frustumPoints[i].w());
}
return frustumPoints;
}
public double getCamX() {
return this.camX;
}
public double getCamY() {
return this.camY;
}
public double getCamZ() {
return this.camZ;
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置: