[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/view AbstractView.java,1.46,1.47
Status: Pre-Alpha
Brought to you by:
henryml
From: Nordholt <nor...@us...> - 2005-10-28 12:18:49
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32739 Modified Files: AbstractView.java Log Message: added method to determine surface orientation compared to the camera Index: AbstractView.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/AbstractView.java,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -d -r1.46 -r1.47 *** AbstractView.java 27 Oct 2005 15:05:10 -0000 1.46 --- AbstractView.java 28 Oct 2005 12:18:38 -0000 1.47 *************** *** 201,205 **** AbstractView.aspect = AbstractView.width / AbstractView.height; ! gl.glClearColor(0.7f, 0.7f, 0.7f, 0.0f); gl.glViewport(0, 0, (int)width, (int)height); --- 201,205 ---- AbstractView.aspect = AbstractView.width / AbstractView.height; ! gl.glClearColor(0.7f, 0.7f, 0.7f, 0.0f); gl.glViewport(0, 0, (int)width, (int)height); *************** *** 395,402 **** */ void labelSurface(Surface surface, boolean clickable) { - Vertex from = surface.center(); - Vertex n = surface.normal(); - n.scale(1 / n.length()); Transformation transformation = transformation(); Domain frontDomain = surface.getFrontDomain(); Domain backDomain = surface.getBackDomain(); --- 395,401 ---- */ void labelSurface(Surface surface, boolean clickable) { Transformation transformation = transformation(); + Vertex from = surface.center(); + Vertex front = transformation.project(from); Domain frontDomain = surface.getFrontDomain(); Domain backDomain = surface.getBackDomain(); *************** *** 419,433 **** int backWidth = glut.glutBitmapLength(GLUT.BITMAP_HELVETICA_18, backName); - Vertex front = transformation.project(from); Vertex frontTextAnchor; Vertex backTextAnchor; ! ! ! Vertex near = new Vertex("", front.getX(), front.getY(), 0.0); ! Vertex far = new Vertex("", front.getX(), front.getY(), 1.0); ! Edge ray = new Edge("", near, far); ! ray = transformation.unProject(ray); ! Vertex rayDir = ray.getTo().minus(ray.getFrom()); ! if (rayDir.dot(n) > 0) { frontTextAnchor = new Vertex("", front.getX() - (frontWidth / 2), front.getY() - 17, front.getZ()); --- 418,425 ---- int backWidth = glut.glutBitmapLength(GLUT.BITMAP_HELVETICA_18, backName); Vertex frontTextAnchor; Vertex backTextAnchor; ! ! if (!facingFront(surface)) { frontTextAnchor = new Vertex("", front.getX() - (frontWidth / 2), front.getY() - 17, front.getZ()); *************** *** 1213,1219 **** * @return The transformation */ ! public Transformation transformation() { ! return null; ! } /** --- 1205,1209 ---- * @return The transformation */ ! public abstract Transformation transformation(); /** *************** *** 1240,1242 **** --- 1230,1253 ---- return height; } + + /** + * Returns a boolean idicating wherther or not we are facing + * the front of the surface. + * @param surface the surface + * @return the boolean + */ + public boolean facingFront(Surface surface) { + Vertex normal = surface.normal(); + Transformation transformation = transformation(); + Vertex center = transformation.project(surface.center()); + Vertex from = new Vertex("", center.getX(), center.getY(), 0.0); + Vertex to = new Vertex("", center.getX(), center.getY(), 1.0); + Edge ray = new Edge("", from, to); + Vertex rayDir; + + ray = transformation.unProject(ray); + rayDir = ray.getTo().minus(ray.getFrom()); + normal.scale(1 / normal.length()); + return rayDir.dot(normal) < 0; + } } |