[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Camera.java, 1.51, 1.52 Command.java
Status: Pre-Alpha
Brought to you by:
henryml
|
From: Michael L. <he...@us...> - 2007-12-12 09:39:01
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv5390/src/net/sourceforge/bprocessor/model Modified Files: Camera.java Command.java Log Message: moved bounding sphere code to command Index: Camera.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Camera.java,v retrieving revision 1.51 retrieving revision 1.52 diff -C2 -d -r1.51 -r1.52 *** Camera.java 12 Dec 2007 09:34:16 -0000 1.51 --- Camera.java 12 Dec 2007 09:38:34 -0000 1.52 *************** *** 477,682 **** /** - * Represents a bounding box - * - */ - private static class BoundingBox { - private Vertex xmin; - private Vertex xmax; - private Vertex ymin; - private Vertex ymax; - private Vertex zmin; - private Vertex zmax; - - /** - * Constructs bounding box for - * @param vertices Collection - */ - public BoundingBox(Collection<Vertex> vertices) { - compute(vertices); - } - - /** - * Compute boudning box - * @param vertices collection of vertices - */ - public void compute(Collection<Vertex> vertices) { - xmin = new Vertex(Double.POSITIVE_INFINITY, - Double.POSITIVE_INFINITY, - Double.POSITIVE_INFINITY); - xmax = new Vertex(Double.NEGATIVE_INFINITY, - Double.NEGATIVE_INFINITY, - Double.NEGATIVE_INFINITY); - ymin = xmin; - ymax = xmax; - zmin = xmin; - 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; - } - } - } - - /** - * - * @return vertex - */ - public Vertex xmin() { - return xmin; - } - - /** - * - * @return vertex - */ - public Vertex xmax() { - return xmax; - } - - /** - * - * @return vertex - */ - public Vertex ymin() { - return ymin; - } - - /** - * - * @return vertex - */ - public Vertex ymax() { - return ymax; - } - - /** - * - * @return vertex - */ - public Vertex zmin() { - return zmin; - } - - /** - * - * @return vertex - */ - public Vertex zmax() { - return zmax; - } - } - - /** - * Represents a bounding sphere - * - */ - private static class BoundingSphere { - private Vertex center; - private double radius; - - /** - * Constructs a bounding sphere for specified vertices - * @param vertices collection of vertices - */ - public BoundingSphere(Collection<Vertex> vertices) { - compute(vertices); - } - - /** - * Constructs a bounding sphere - * @param center center - * @param radius radius - */ - public BoundingSphere(Vertex center, double radius) { - this.center = center; - this.radius = radius; - } - - /** - * Returns center - * @return center - */ - public Vertex center() { - return center; - } - - /** - * Returns radius - * @return radius - */ - public double radius() { - return radius; - } - - /** - * Compute a bounding sphere for specified vertices - * using Jack Ritters algorithm from Graphics Gems. - * @param vertices collection of vertices - */ - public void compute(Collection<Vertex> vertices) { - BoundingBox box = new BoundingBox(vertices); - - Vertex xmin = box.xmin(); - Vertex xmax = box.xmax(); - Vertex ymin = box.ymin(); - Vertex ymax = box.ymax(); - Vertex zmin = box.zmin(); - Vertex zmax = box.zmax(); - - 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; - } - - center = v1.add(v2).scale(0.5); - radius = dia / 2; - - 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.1; - } - } - } - - /** * Moves the camera to a position where the entire model is visible. * @param aspect the acspect ratio of the view. --- 477,480 ---- *************** *** 700,706 **** if (!allVertices.isEmpty()) { ! BoundingSphere sphere = new BoundingSphere(allVertices); ! double radius = sphere.radius; ! Vertex modelCenter = sphere.center; //Setting up camera --- 498,504 ---- if (!allVertices.isEmpty()) { ! Command.BoundingSphere sphere = new Command.BoundingSphere(allVertices); ! double radius = sphere.radius(); ! Vertex modelCenter = sphere.center(); //Setting up camera Index: Command.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Command.java,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** Command.java 11 Dec 2007 15:14:13 -0000 1.52 --- Command.java 12 Dec 2007 09:38:34 -0000 1.53 *************** *** 1866,1868 **** --- 1866,2070 ---- } } + + /** + * Represents a bounding box + * + */ + public static class BoundingBox { + private Vertex xmin; + private Vertex xmax; + private Vertex ymin; + private Vertex ymax; + private Vertex zmin; + private Vertex zmax; + + /** + * Constructs bounding box for + * @param vertices Collection + */ + public BoundingBox(Collection<Vertex> vertices) { + compute(vertices); + } + + /** + * Compute boudning box + * @param vertices collection of vertices + */ + public void compute(Collection<Vertex> vertices) { + xmin = new Vertex(Double.POSITIVE_INFINITY, + Double.POSITIVE_INFINITY, + Double.POSITIVE_INFINITY); + xmax = new Vertex(Double.NEGATIVE_INFINITY, + Double.NEGATIVE_INFINITY, + Double.NEGATIVE_INFINITY); + ymin = xmin; + ymax = xmax; + zmin = xmin; + 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; + } + } + } + + /** + * + * @return vertex + */ + public Vertex xmin() { + return xmin; + } + + /** + * + * @return vertex + */ + public Vertex xmax() { + return xmax; + } + + /** + * + * @return vertex + */ + public Vertex ymin() { + return ymin; + } + + /** + * + * @return vertex + */ + public Vertex ymax() { + return ymax; + } + + /** + * + * @return vertex + */ + public Vertex zmin() { + return zmin; + } + + /** + * + * @return vertex + */ + public Vertex zmax() { + return zmax; + } + } + + /** + * Represents a bounding sphere + * + */ + public static class BoundingSphere { + private Vertex center; + private double radius; + + /** + * Constructs a bounding sphere for specified vertices + * @param vertices collection of vertices + */ + public BoundingSphere(Collection<Vertex> vertices) { + compute(vertices); + } + + /** + * Constructs a bounding sphere + * @param center center + * @param radius radius + */ + public BoundingSphere(Vertex center, double radius) { + this.center = center; + this.radius = radius; + } + + /** + * Returns center + * @return center + */ + public Vertex center() { + return center; + } + + /** + * Returns radius + * @return radius + */ + public double radius() { + return radius; + } + + /** + * Compute a bounding sphere for specified vertices + * using Jack Ritters algorithm from Graphics Gems. + * @param vertices collection of vertices + */ + public void compute(Collection<Vertex> vertices) { + BoundingBox box = new BoundingBox(vertices); + + Vertex xmin = box.xmin(); + Vertex xmax = box.xmax(); + Vertex ymin = box.ymin(); + Vertex ymax = box.ymax(); + Vertex zmin = box.zmin(); + Vertex zmax = box.zmax(); + + 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; + } + + center = v1.add(v2).scale(0.5); + radius = dia / 2; + + 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.1; + } + } + } } |