diff options
author | Chien Yang <[email protected]> | 2007-12-12 22:49:10 +0000 |
---|---|---|
committer | Chien Yang <[email protected]> | 2007-12-12 22:49:10 +0000 |
commit | 7c8d3429aeadce2cae63d69250001827e29a0153 (patch) | |
tree | 5419041a47ded71deb5db598acc6b387be0666b6 /src | |
parent | 3ec8b06226426acddcd5917c9abcbd4361f17262 (diff) |
Issue number: 544
Obtained from: mcneillk
Submitted by: mcneillk
Reviewed by: jada
1) Integated suggested enhancement.
2) Formated code in modified methods to improve code readability.
git-svn-id: https://svn.java.net/svn/j3d-core~svn/trunk@879 ba19aa83-45c5-6ac9-afd3-db810772062c
Diffstat (limited to 'src')
4 files changed, 182 insertions, 135 deletions
diff --git a/src/classes/share/javax/media/j3d/GroupRetained.java b/src/classes/share/javax/media/j3d/GroupRetained.java index c6451a1..dbb6a04 100644 --- a/src/classes/share/javax/media/j3d/GroupRetained.java +++ b/src/classes/share/javax/media/j3d/GroupRetained.java @@ -138,10 +138,15 @@ class GroupRetained extends NodeRetained implements BHLeafInterface { GroupRetained() { this.nodeType = NodeRetained.GROUP; - localBounds = new BoundingSphere(); - ((BoundingSphere)localBounds).setRadius( -1.0 ); + // issue 544 + if (VirtualUniverse.mc.useBoxForGroupBounds) { + localBounds = new BoundingBox((Bounds) null); + } else { + localBounds = new BoundingSphere(); + ((BoundingSphere) localBounds).setRadius(-1.0); + } } - + /** * Sets the collision bounds of a node. * @param bounds the bounding object for the node @@ -2184,8 +2189,6 @@ class GroupRetained extends NodeRetained implements BHLeafInterface { */ void doSetLive(SetLiveState s) { int i, nchildren; - - BoundingSphere boundingSphere = new BoundingSphere(); NodeRetained child; super.doSetLive(s); locale = s.locale; @@ -2458,12 +2461,18 @@ class GroupRetained extends NodeRetained implements BHLeafInterface { } if (boundsAutoCompute) { - cachedBounds = new BoundingSphere(); - ((BoundingSphere)cachedBounds).setRadius(-1); - for (int i=children.size()-1; i>=0; i--) { - NodeRetained child = (NodeRetained)children.get(i); - if(child != null) + // issue 544 + if (VirtualUniverse.mc.useBoxForGroupBounds) { + cachedBounds = new BoundingBox((Bounds) null); + } else { + cachedBounds = new BoundingSphere(); + ((BoundingSphere) cachedBounds).setRadius(-1); + } + for (int i = children.size() - 1; i >= 0; i--) { + NodeRetained child = (NodeRetained) children.get(i); + if (child != null) { child.computeCombineBounds(cachedBounds); + } } bounds.combine(cachedBounds); } else { @@ -2488,19 +2497,24 @@ class GroupRetained extends NodeRetained implements BHLeafInterface { if (validCachedBounds) { return (Bounds) cachedBounds.clone(); } - - BoundingSphere boundingSphere = new BoundingSphere(); - boundingSphere.setRadius(-1.0); - - for (int i=children.size()-1; i>=0; i--) { - NodeRetained child = (NodeRetained)children.get(i); - if(child != null) - child.computeCombineBounds((Bounds) boundingSphere); - } - - return (Bounds) boundingSphere; - } - return super.getBounds(); + // issue 544 + Bounds boundingObject = null; + if (VirtualUniverse.mc.useBoxForGroupBounds) { + boundingObject = new BoundingBox((Bounds) null); + } else { + boundingObject = new BoundingSphere(); + ((BoundingSphere) boundingObject).setRadius(-1.0); + } + for (int i = children.size() - 1; i >= 0; i--) { + NodeRetained child = (NodeRetained) children.get(i); + if (child != null) { + child.computeCombineBounds((Bounds) boundingObject); + } + } + + return (Bounds) boundingObject; + } + return super.getBounds(); } /** diff --git a/src/classes/share/javax/media/j3d/MasterControl.java b/src/classes/share/javax/media/j3d/MasterControl.java index 2b57a77..cdc39f3 100644 --- a/src/classes/share/javax/media/j3d/MasterControl.java +++ b/src/classes/share/javax/media/j3d/MasterControl.java @@ -480,7 +480,10 @@ class MasterControl { // Issue 480: Cache the bounds of nodes so that getBounds does not // recompute the boounds of the entire graph per call boolean cacheAutoComputedBounds = false; - + + // issue 544 + boolean useBoxForGroupBounds = false; + /** * Constructs a new MasterControl object. Note that there is * exatly one MasterControl object, created statically by @@ -670,11 +673,17 @@ class MasterControl { } // Issue 480 : Cache bounds returned by getBounds() - cacheAutoComputedBounds = - getBooleanProperty("j3d.cacheAutoComputeBounds", - cacheAutoComputedBounds, - "Cache AutoCompute Bounds, accelerates getBounds()"); - + cacheAutoComputedBounds = + getBooleanProperty("j3d.cacheAutoComputeBounds", + cacheAutoComputedBounds, + "Cache AutoCompute Bounds, accelerates getBounds()"); + + // Issue 544 + useBoxForGroupBounds = + getBooleanProperty("j3d.useBoxForGroupBounds", + useBoxForGroupBounds, + "Use of BoundingBox for group geometric bounds"); + // Initialize the native J3D library if (!Pipeline.getPipeline().initializeJ3D(disableXinerama)) { throw new RuntimeException(J3dI18N.getString("MasterControl0")); diff --git a/src/classes/share/javax/media/j3d/SwitchRetained.java b/src/classes/share/javax/media/j3d/SwitchRetained.java index 2a37bf7..5461dad 100644 --- a/src/classes/share/javax/media/j3d/SwitchRetained.java +++ b/src/classes/share/javax/media/j3d/SwitchRetained.java @@ -611,121 +611,140 @@ class SwitchRetained extends GroupRetained implements TargetsInterface } - void computeCombineBounds(Bounds bounds) { - int i; - NodeRetained child; - - if(boundsAutoCompute) { - if (!VirtualUniverse.mc.cacheAutoComputedBounds) { - if(whichChild == Switch.CHILD_ALL) { - for(i=0; i<children.size(); i++) { - child = (NodeRetained)children.get(i); - if(child != null) - child.computeCombineBounds(bounds); - } - } else if(whichChild == Switch.CHILD_MASK) { - for(i=0; i<children.size(); i++) { - if(childMask.get(i)) { - child = (NodeRetained)children.get(i); - if(child != null) + void computeCombineBounds(Bounds bounds) { + int i; + NodeRetained child; + + if (boundsAutoCompute) { + if (!VirtualUniverse.mc.cacheAutoComputedBounds) { + if (whichChild == Switch.CHILD_ALL) { + for (i = 0; i < children.size(); i++) { + child = (NodeRetained) children.get(i); + if (child != null) { child.computeCombineBounds(bounds); + } + } + } else if (whichChild == Switch.CHILD_MASK) { + for (i = 0; i < children.size(); i++) { + if (childMask.get(i)) { + child = (NodeRetained) children.get(i); + if (child != null) { + child.computeCombineBounds(bounds); + } + } + } + } else if (whichChild != Switch.CHILD_NONE) { + if (whichChild < children.size()) { + child = (NodeRetained) children.get(whichChild); + if (child != null) { + child.computeCombineBounds(bounds); + } } } - } else if(whichChild != Switch.CHILD_NONE) { - if (whichChild < children.size()) { - child = (NodeRetained)children.get(whichChild); - if(child != null) - child.computeCombineBounds(bounds); - } - } - } else { - // Issue 514 : NPE in Wonderland : triggered in cached bounds computation - if (!validCachedBounds) { - validCachedBounds = true; - cachedBounds = new BoundingSphere(); - ((BoundingSphere)cachedBounds).setRadius(-1); - if(whichChild == Switch.CHILD_ALL) { - for(i=0; i<children.size(); i++) { - child = (NodeRetained)children.get(i); - if(child != null) - child.computeCombineBounds(cachedBounds); + } else { + // Issue 514 : NPE in Wonderland : triggered in cached bounds computation + if (!validCachedBounds) { + validCachedBounds = true; + + // Issue 544 + if (VirtualUniverse.mc.useBoxForGroupBounds) { + cachedBounds = new BoundingBox((Bounds) null); + } else { + cachedBounds = new BoundingSphere(); + ((BoundingSphere) cachedBounds).setRadius(-1); } - } else if(whichChild == Switch.CHILD_MASK) { - for(i=0; i<children.size(); i++) { - if(childMask.get(i)) { - child = (NodeRetained)children.get(i); - if(child != null) + if (whichChild == Switch.CHILD_ALL) { + for (i = 0; i < children.size(); i++) { + child = (NodeRetained) children.get(i); + if (child != null) { child.computeCombineBounds(cachedBounds); + } + } + } else if (whichChild == Switch.CHILD_MASK) { + for (i = 0; i < children.size(); i++) { + if (childMask.get(i)) { + child = (NodeRetained) children.get(i); + if (child != null) { + child.computeCombineBounds(cachedBounds); + } + } + } + } else if (whichChild != Switch.CHILD_NONE) { + if (whichChild < children.size()) { + child = (NodeRetained) children.get(whichChild); + if (child != null) { + child.computeCombineBounds(cachedBounds); + } } - } - } else if(whichChild != Switch.CHILD_NONE) { - if (whichChild < children.size()) { - child = (NodeRetained)children.get(whichChild); - if(child != null) - child.computeCombineBounds(cachedBounds); } } + bounds.combine(cachedBounds); + } + } else { + // Should this be lock too ? ( MT safe ? ) + synchronized (localBounds) { + bounds.combine(localBounds); } - bounds.combine(cachedBounds); - } - } else { - // Should this be lock too ? ( MT safe ? ) - synchronized(localBounds) { - bounds.combine(localBounds); } } - } /** * Gets the bounding object of a node. * @return the node's bounding object */ - Bounds getBounds() { - - int i; - NodeRetained child; - - if(boundsAutoCompute) { - // Issue 514 : NPE in Wonderland : triggered in cached bounds computation - if (validCachedBounds) { - return (Bounds) cachedBounds.clone(); + Bounds getBounds() { + + int i; + NodeRetained child; + + if (boundsAutoCompute) { + // Issue 514 : NPE in Wonderland : triggered in cached bounds computation + if (validCachedBounds) { + return (Bounds) cachedBounds.clone(); + } + + // issue 544 + Bounds boundingObject = null; + if (VirtualUniverse.mc.useBoxForGroupBounds) { + boundingObject = new BoundingBox((Bounds) null); + } else { + boundingObject = new BoundingSphere(); + ((BoundingSphere) boundingObject).setRadius(-1.0); + } + + if (whichChild == Switch.CHILD_ALL) { + for (i = 0; i < children.size(); i++) { + child = (NodeRetained) children.get(i); + if (child != null) { + child.computeCombineBounds((Bounds) boundingObject); + } + } + } else if (whichChild == Switch.CHILD_MASK) { + for (i = 0; i < children.size(); i++) { + if (childMask.get(i)) { + child = (NodeRetained) children.get(i); + if (child != null) { + child.computeCombineBounds((Bounds) boundingObject); + } + } + } + } else if (whichChild != Switch.CHILD_NONE && + whichChild >= 0 && + whichChild < children.size()) { + + child = (NodeRetained) children.get(whichChild); + if (child != null) { + child.computeCombineBounds((Bounds) boundingObject); + } + } + + return (Bounds) boundingObject; + } else { + return super.getBounds(); } - - BoundingSphere boundingSphere = new BoundingSphere(); - boundingSphere.setRadius(-1.0); - - if(whichChild == Switch.CHILD_ALL) { - for(i=0; i<children.size(); i++) { - child = (NodeRetained)children.get(i); - if(child != null) - child.computeCombineBounds((Bounds) boundingSphere); - } - } - else if(whichChild == Switch.CHILD_MASK) { - for(i=0; i<children.size(); i++) { - if(childMask.get(i)) { - child = (NodeRetained)children.get(i); - if(child != null) - child.computeCombineBounds((Bounds) boundingSphere); - } - } - } - else if(whichChild != Switch.CHILD_NONE && - whichChild >= 0 && - whichChild < children.size()) { - - child = (NodeRetained)children.get(whichChild); - if(child != null) - child.computeCombineBounds((Bounds) boundingSphere); - } - - return (Bounds) boundingSphere; - } - else - return super.getBounds(); - } - + } + /* void compile(CompileState compState) { diff --git a/src/classes/share/javax/media/j3d/TransformGroupRetained.java b/src/classes/share/javax/media/j3d/TransformGroupRetained.java index d5a4e70..2fa65ee 100644 --- a/src/classes/share/javax/media/j3d/TransformGroupRetained.java +++ b/src/classes/share/javax/media/j3d/TransformGroupRetained.java @@ -4,7 +4,7 @@ * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Use is subject to license terms. - * + * * $Revision$ * $Date$ * $State$ @@ -783,24 +783,29 @@ class TransformGroupRetained extends GroupRetained implements TargetsInterface } NodeRetained child; - BoundingSphere boundingSphere = new BoundingSphere(); - boundingSphere.setRadius(-1.0); - + //issue 544 + Bounds boundingObject = null; + if (VirtualUniverse.mc.useBoxForGroupBounds) { + boundingObject = new BoundingBox((Bounds) null); + } else { + boundingObject = new BoundingSphere(); + ((BoundingSphere) boundingObject).setRadius(-1.0); + } if(boundsAutoCompute) { for (int i=children.size()-1; i>=0; i--) { child = (NodeRetained)children.get(i); if(child != null) - child.computeCombineBounds(boundingSphere); + child.computeCombineBounds(boundingObject); } if (VirtualUniverse.mc.cacheAutoComputedBounds) { - cachedBounds = (Bounds) boundingSphere.clone(); + cachedBounds = (Bounds) boundingObject.clone(); } } else { // Should this be lock too ? ( MT safe ? ) synchronized(localBounds) { - boundingSphere.set(localBounds); + boundingObject.set(localBounds); } } @@ -808,9 +813,9 @@ class TransformGroupRetained extends GroupRetained implements TargetsInterface // Thoughts : // Make a temp copy with lock : transform.getWithLock(trans);, but this will cause gc ... synchronized(transform) { - boundingSphere.transform(transform); + boundingObject.transform(transform); } - bounds.combine(boundingSphere); + bounds.combine(boundingObject); } |