Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv19493/src/net/sourceforge/bprocessor/model
Modified Files:
Camera.java
Log Message:
Better approximation of BoundingSphere
Index: Camera.java
===================================================================
RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Camera.java,v
retrieving revision 1.48
retrieving revision 1.49
diff -C2 -d -r1.48 -r1.49
*** Camera.java 11 Dec 2007 13:24:44 -0000 1.48
--- Camera.java 11 Dec 2007 14:34:07 -0000 1.49
***************
*** 583,591 ****
/**
! * Computes a crude approximation of boundinsphere in linear time
* @param vertices collection of vertices
* @return bounding sphere
*/
public static BoundingSphere from(Collection<Vertex> vertices) {
BoundingBox box = BoundingBox.from(vertices);
Vertex v1 = box.min;
--- 583,663 ----
/**
! * Computes an approximation of boundinsphere in linear time
! * Algorithm by Jack Ritter in "Graphics Gems"
* @param vertices collection of vertices
* @return bounding sphere
*/
public static BoundingSphere from(Collection<Vertex> vertices) {
+ Vertex xmin = new Vertex(Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE);
+ Vertex xmax = new Vertex(-10000, -10000, -10000);
+ Vertex ymin = xmin;
+ Vertex ymax = xmax;
+ Vertex zmin = xmin;
+ Vertex zmax = xmax;
+
+ for (Vertex current : vertices) {
+ if (current.x < xmin.x) {
+ xmin = current;
+ }
+ if (current.x > xmax.x) {
+ xmax = current;
+ }
+ if (current.y < ymin.y) {
+ ymin = current;
+ }
+ if (current.y > ymax.y) {
+ ymax = current;
+ }
+ if (current.z < zmin.z) {
+ zmin = current;
+ }
+ if (current.z > zmax.z) {
+ zmax = current;
+ }
+ }
+ Vertex xspan = xmax.minus(xmin);
+ Vertex yspan = ymax.minus(ymin);
+ Vertex zspan = zmax.minus(zmin);
+
+
+ double dia = xspan.length();
+ Vertex v1 = xmin;
+ Vertex v2 = xmax;
+
+ if (yspan.length() > dia) {
+ dia = yspan.length();
+ v1 = ymin;
+ v2 = ymax;
+ }
+ if (zspan.length() > dia) {
+ dia = zspan.length();
+ v1 = zmin;
+ v2 = zmax;
+ }
+
+ Vertex center = v1.add(v2).scale(0.5);
+ double radius = 0.1;
+
+ for (Vertex current : vertices) {
+ Vertex d = current.minus(center);
+ double length = d.length();
+ if (length > radius) {
+ radius = (radius + length) / 2;
+ double diff = length - radius;
+ center = center.add(d.scale(diff / length));
+ }
+ }
+ if (radius < 0.00001) {
+ radius = 0.5;
+ }
+ return new BoundingSphere(center, radius);
+ }
+
+ /**
+ * Computes a crude approximation of boundinsphere in linear time
+ * @param vertices collection of vertices
+ * @return bounding sphere
+ */
+ public static BoundingSphere from1(Collection<Vertex> vertices) {
BoundingBox box = BoundingBox.from(vertices);
Vertex v1 = box.min;
***************
*** 607,611 ****
/**
! * Computes a better approximation of boundinsphere in quadratic time
* @param vertices collection of vertices
* @return bounding sphere
--- 679,683 ----
/**
! * Computes an approximation of boundinsphere in quadratic time
* @param vertices collection of vertices
* @return bounding sphere
|