[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Camera.java, 1.16, 1.17
Status: Pre-Alpha
Brought to you by:
henryml
|
From: Nordholt <nor...@us...> - 2006-06-16 10:00:56
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv599 Modified Files: Camera.java Log Message: changed viewentiremodel implementation to take the aspect into account and to find a better center point. Still does not work quite as I would like it though Index: Camera.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Camera.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Camera.java 6 Jun 2006 09:22:31 -0000 1.16 --- Camera.java 16 Jun 2006 09:45:17 -0000 1.17 *************** *** 10,13 **** --- 10,14 ---- import java.util.Collection; import java.util.Iterator; + import java.util.HashSet; import java.util.List; import java.util.Set; *************** *** 395,425 **** /** * Moves the camera to a position where the entire model is visible. */ ! public void viewEntireModel() { Set allVertices = Project.getInstance().world().collect(); if (!allVertices.isEmpty()) { ! Vertex modelCenter = Project.getInstance().world().center(); Iterator it = allVertices.iterator(); - double maxDistance = 0; while (it.hasNext()) { Vertex v = (Vertex) it.next(); ! double distance = v.minus(modelCenter).length(); ! if (distance > maxDistance) { ! maxDistance = distance; } } ! double cameraDistance = ! maxDistance / Math.tan(Math.toRadians((this.getFocalwidth() / 2))); ! Vertex cameraPos = new Vertex(camera[0] - center[0], ! camera[1] - center[1], ! camera[2] - center[2]); ! cameraPos.scale(cameraDistance / cameraPos.length()); ! cameraPos = cameraPos.add(modelCenter); ! setCenter(new double[] {modelCenter.getX(), ! modelCenter.getY(), ! modelCenter.getZ()}); ! setCamera(new double[] {cameraPos.getX(), ! cameraPos.getY(), ! cameraPos.getZ()}); } } --- 396,454 ---- /** * Moves the camera to a position where the entire model is visible. + * @param aspect the acspect ratio of the view. */ ! public void viewEntireModel(double aspect) { Set allVertices = Project.getInstance().world().collect(); if (!allVertices.isEmpty()) { ! //Computing center and radius of the minimal covering sphere ! Set notTested = new HashSet(allVertices); ! double radius = 0; ! Vertex p1 = null; ! Vertex p2 = null; Iterator it = allVertices.iterator(); while (it.hasNext()) { Vertex v = (Vertex) it.next(); ! notTested.remove(v); ! Iterator testIt = notTested.iterator(); ! while (testIt.hasNext()) { ! Vertex u = (Vertex)testIt.next(); ! if ((v.minus(u).length() / 2.0) > radius) { ! p1 = v; ! p2 = u; ! radius = v.minus(u).length() / 2.0; ! } } } ! if (p1 != null && p2 != null) { ! Vertex modelCenter = p1.minus(p2); ! modelCenter.scale(1.0 / 2.0); ! modelCenter = modelCenter.add(p2); ! ! //Setting up camera ! double halfFocal; ! if (aspect < 1.0) { ! halfFocal = (this.getFocalwidth() * aspect) / 2.0; ! log.info("doing"); ! } else { ! halfFocal = (this.getFocalwidth() / 2.0); ! } ! ! double halfFocalVerTan = Math.tan(Math.toRadians(halfFocal)); ! double halfFocalHorTan = halfFocalVerTan / aspect; ! ! double width = Math.min(halfFocalHorTan, halfFocalVerTan); ! double cameraDistance = radius / width; ! Vertex cameraPos = new Vertex(camera[0] - center[0], ! camera[1] - center[1], ! camera[2] - center[2]); ! cameraPos.scale(cameraDistance / cameraPos.length()); ! cameraPos = cameraPos.add(modelCenter); ! setCenter(new double[] {modelCenter.getX(), ! modelCenter.getY(), ! modelCenter.getZ()}); ! setCamera(new double[] {cameraPos.getX(), ! cameraPos.getY(), ! cameraPos.getZ()}); ! } } } |