Before you begin reading the code below, let it be known that this is how the coordinate system works that the snippet is for:
+X = Right
-Y = Up
+Z = Forward
I’m not very familiar with geometry, but I’m confident in my understanding and research abilities to any information given to me.
public void calculateBoundaries() {
this.lengthXZ = 0;
this.minBoundX = 999999;
this.maxBoundX = -999999;
this.maxBoundY = 0;
this.minBoundY = 0;
this.maxBoundZ = -99999;
this.minBoundZ = 99999;
for (int v = 0; v < this.vertexCount; v++) {
int x = this.vertexX[v];
int y = this.vertexY[v];
int z = this.vertexZ[v];
if (x < this.minBoundX) {
this.minBoundX = x;
}
if (x > this.maxBoundX) {
this.maxBoundX = x;
}
if (z < this.minBoundZ) {
this.minBoundZ = z;
}
if (z > this.maxBoundZ) {
this.maxBoundZ = z;
}
if (-y > this.maxBoundY) {
this.maxBoundY = -y;
}
if (y > this.minBoundY) {
this.minBoundY = y;
}
int lengthSquared = x * x + z * z;
if (lengthSquared > this.lengthXZ) {
this.lengthXZ = lengthSquared;
}
}
this.lengthXZ = (int) Math.sqrt((double) this.lengthXZ);
this.minDepth = (int) Math.sqrt((double) (this.lengthXZ * this.lengthXZ + this.maxBoundY * this.maxBoundY));
this.maxDepth = this.minDepth + (int) Math.sqrt((double) (this.lengthXZ * this.lengthXZ + this.minBoundY * this.minBoundY));
}
I’m trying to understand this more. lengthXZ is later multiplied by the sin(cameraPitch) and cos(cameraPitch) values for some algorithm to check if the model is within the screen. The most important part of this code to me is understanding the assignments to lengthXZ, minDepth, and maxDepth.
minDepth and maxDepth are used for sorting triangles by depth before being drawn.
I did some googling and found Elliptic Paraboloid which has the equation z = Ax^2 + By^2. I feel like it’s related, as the Y and Z coordinates in this application have been flipped, so they must apply in the same way for y = Ax^2 + Bz^2. http://www.math.umn.edu/~rogness/quadrics/ellparab.shtml
By the looks of it, these are the equations for the assignments: (minDepth using maxY and maxDepth using minY was not an oversight)
lengthXZ = sqrt( x^2 + z^2 )
minDepth = sqrt( x^2 + z^2 + maxY^2 )
maxDepth = sqrt( x^2 + z^2 + minY^2 )
Any input is appreciated. Thanks ;D ;D