Difference between revisions of "Getting Worldspace Bounds"

From JPCT
Jump to: navigation, search

Deprecated: assert(): Calling assert() with a string argument is deprecated in /usr/home/ws10522/public_html/wiki/includes/diff/DairikiDiff.php on line 861

Deprecated: assert(): Calling assert() with a string argument is deprecated in /usr/home/ws10522/public_html/wiki/includes/diff/DairikiDiff.php on line 862

Deprecated: assert(): Calling assert() with a string argument is deprecated in /usr/home/ws10522/public_html/wiki/includes/diff/DairikiDiff.php on line 587

Deprecated: assert(): Calling assert() with a string argument is deprecated in /usr/home/ws10522/public_html/wiki/includes/diff/DairikiDiff.php on line 587

Deprecated: assert(): Calling assert() with a string argument is deprecated in /usr/home/ws10522/public_html/wiki/includes/diff/DairikiDiff.php on line 241

Deprecated: assert(): Calling assert() with a string argument is deprecated in /usr/home/ws10522/public_html/wiki/includes/diff/DairikiDiff.php on line 242

Deprecated: assert(): Calling assert() with a string argument is deprecated in /usr/home/ws10522/public_html/wiki/includes/diff/DairikiDiff.php on line 954

Deprecated: assert(): Calling assert() with a string argument is deprecated in /usr/home/ws10522/public_html/wiki/includes/diff/DairikiDiff.php on line 954

Deprecated: assert(): Calling assert() with a string argument is deprecated in /usr/home/ws10522/public_html/wiki/includes/diff/DairikiDiff.php on line 954
(Created page with 'This method is formatted to return a bounding box in 6 floats, exactly as Mesh.getBounds() does, but whose min and max values are values in worldspace. public float[] getWo…')
 
Line 1: Line 1:
 
This method is formatted to return a bounding box in 6 floats, exactly as Mesh.getBounds() does, but whose min and max values are values in worldspace.
 
This method is formatted to return a bounding box in 6 floats, exactly as Mesh.getBounds() does, but whose min and max values are values in worldspace.
 
+
<pre>
 
     public float[] getWorldSpaceBounds() {
 
     public float[] getWorldSpaceBounds() {
 
float[] objectSpaceBounds = terrain.getMesh().getBoundingBox();
 
float[] objectSpaceBounds = terrain.getMesh().getBoundingBox();
Line 34: Line 34:
 
return worldSpaceBounds;
 
return worldSpaceBounds;
 
     }
 
     }
 +
</pre>

Revision as of 23:33, 8 October 2011

This method is formatted to return a bounding box in 6 floats, exactly as Mesh.getBounds() does, but whose min and max values are values in worldspace.

     public float[] getWorldSpaceBounds() {
	float[] objectSpaceBounds = terrain.getMesh().getBoundingBox();
	SimpleVector mins = new SimpleVector(objectSpaceBounds[0], objectSpaceBounds[2], objectSpaceBounds[4]);
	SimpleVector maxs = new SimpleVector(objectSpaceBounds[1], objectSpaceBounds[3], objectSpaceBounds[5]);
	SimpleVector[] p = new SimpleVector[8];
	p[0] = new SimpleVector(mins.x, mins.y, maxs.z); p[1] = new SimpleVector(mins.x, mins.y, mins.z); p[2] = new SimpleVector(maxs.x, mins.y, mins.z);
	p[3] = new SimpleVector(maxs.x, mins.y, maxs.z); p[4] = new SimpleVector(maxs.x, maxs.y, mins.z);
	p[5] = new SimpleVector(maxs.x, maxs.y, maxs.z); p[6] = new SimpleVector(mins.x, maxs.y, mins.z); p[7] = new SimpleVector(mins.x, maxs.x, maxs.z);
	float minX = Float.MAX_VALUE, minY = Float.MAX_VALUE, minZ = Float.MAX_VALUE, maxX = Float.MIN_VALUE, maxY = Float.MIN_VALUE, maxZ = Float.MIN_VALUE;
	for (int i = 0; i < 8; i++) {
	     p[i].matMul(terrain.getWorldTransformation());
	     if (p[i].x < minX)
		minX = p[i].x;
	     if (p[i].y < minY)
		minY = p[i].y;
	     if (p[i].z < minZ)
		minZ = p[i].z;
	     if (p[i].x > maxX)
		maxX = p[i].x;
	     if (p[i].y > maxY)
		maxY = p[i].y;
	     if (p[i].z > maxZ)
		maxZ = p[i].z;
	}
	float[] worldSpaceBounds = new float[6];
	worldSpaceBounds[0] = minX;
	worldSpaceBounds[2] = minY;
	worldSpaceBounds[4] = minZ;
	worldSpaceBounds[1] = maxX;
	worldSpaceBounds[3] = maxY;
	worldSpaceBounds[5] = maxZ;
	return worldSpaceBounds;
     }