From 7c8d3429aeadce2cae63d69250001827e29a0153 Mon Sep 17 00:00:00 2001 From: Chien Yang Date: Wed, 12 Dec 2007 22:49:10 +0000 Subject: 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 --- .../share/javax/media/j3d/GroupRetained.java | 60 +++--- .../share/javax/media/j3d/MasterControl.java | 21 +- .../share/javax/media/j3d/SwitchRetained.java | 213 +++++++++++---------- .../javax/media/j3d/TransformGroupRetained.java | 23 ++- 4 files changed, 182 insertions(+), 135 deletions(-) (limited to 'src') 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= 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= 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); } -- cgit v1.2.3