From e280c27adfde6807ddc2d9363101fec92ac3e9b7 Mon Sep 17 00:00:00 2001 From: "mul..va" Date: Thu, 31 Mar 2011 08:45:49 +0000 Subject: [PATCH] URL: http://jmonkeyengine.org/groups/contribution-depot-jme3/forum/topic/checking-gui-culling/ Check Culling of Gui Node on Screen Space Now Gui node can have Bucket.Dynamic git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7145 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- engine/src/core/com/jme3/renderer/Camera.java | 20 +++++++++++++++++++ engine/src/core/com/jme3/scene/Spatial.java | 15 +++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/engine/src/core/com/jme3/renderer/Camera.java b/engine/src/core/com/jme3/renderer/Camera.java index 46be4da15..01048b7a6 100644 --- a/engine/src/core/com/jme3/renderer/Camera.java +++ b/engine/src/core/com/jme3/renderer/Camera.java @@ -31,6 +31,7 @@ */ package com.jme3.renderer; +import com.jme3.bounding.BoundingBox; import com.jme3.bounding.BoundingVolume; import com.jme3.export.JmeExporter; import com.jme3.export.JmeImporter; @@ -205,6 +206,7 @@ public class Camera implements Savable, Cloneable { protected Matrix4f viewMatrix = new Matrix4f(); protected Matrix4f projectionMatrix = new Matrix4f(); protected Matrix4f viewProjectionMatrix = new Matrix4f(); + private BoundingBox guiBounding = new BoundingBox(); /** * Constructor instantiates a new Camera object. All @@ -962,6 +964,10 @@ public class Camera implements Savable, Cloneable { return rVal; } + + public boolean containsGui(BoundingVolume bound) { + return guiBounding.intersects(bound); + } /** * @return the view matrix of the camera. @@ -1042,6 +1048,20 @@ public class Camera implements Savable, Cloneable { */ public void onViewPortChange() { viewportChanged = true; + setGuiBounding(); + } + + private void setGuiBounding() { + float sx = width*viewPortLeft; + float ex = width*viewPortRight; + float sy = height*viewPortBottom; + float ey = height*viewPortTop; + float xExtent = (ex-sx)/2; + float yExtent = (ey-sy)/2; + guiBounding.setCenter(new Vector3f(sx+xExtent, sy+yExtent, 0)); + guiBounding.setXExtent(xExtent); + guiBounding.setYExtent(yExtent); + guiBounding.setZExtent(Float.MAX_VALUE); } /** diff --git a/engine/src/core/com/jme3/scene/Spatial.java b/engine/src/core/com/jme3/scene/Spatial.java index af4cd4493..f2330b633 100644 --- a/engine/src/core/com/jme3/scene/Spatial.java +++ b/engine/src/core/com/jme3/scene/Spatial.java @@ -51,6 +51,7 @@ import com.jme3.renderer.Camera; import com.jme3.renderer.RenderManager; import com.jme3.renderer.ViewPort; import com.jme3.renderer.queue.RenderQueue; +import com.jme3.renderer.queue.RenderQueue.Bucket; import com.jme3.renderer.queue.RenderQueue.ShadowMode; import com.jme3.scene.control.Control; import com.jme3.util.TempVars; @@ -247,11 +248,15 @@ public abstract class Spatial implements Savable, Cloneable, Collidable { : Camera.FrustumIntersect.Intersects); if (frustrumIntersects == Camera.FrustumIntersect.Intersects) { - int state = cam.getPlaneState(); - - frustrumIntersects = cam.contains(getWorldBound()); - - cam.setPlaneState(state); + if (getQueueBucket() == Bucket.Gui) { + return cam.containsGui(getWorldBound()); + } else { + int state = cam.getPlaneState(); + + frustrumIntersects = cam.contains(getWorldBound()); + + cam.setPlaneState(state); + } } return frustrumIntersects != Camera.FrustumIntersect.Outside;