Quellcode durchsuchen

Rewrote and fixed frustum culling, added Vector4 class, added AABB calculation to entities, made local bounding box protected and added accessors, fixed bounding box generation across the board, moved some mesh related settings from Entity to SceneMesh, fixed world-space particles, added visibility calculation toggles to Scenes

Ivan Safrin vor 12 Jahren
Ursprung
Commit
4cb18f7521

+ 2 - 0
Core/Contents/CMakeLists.txt

@@ -70,6 +70,7 @@ SET(polycore_SRCS
     Source/PolyTweenManager.cpp
     Source/PolyVector2.cpp
     Source/PolyVector3.cpp
+    Source/PolyVector4.cpp
     Source/PolyVertex.cpp
     Source/tinystr.cpp
     Source/tinyxml.cpp
@@ -157,6 +158,7 @@ SET(polycore_HDRS
     Include/PolyTweenManager.h
     Include/PolyVector2.h
     Include/PolyVector3.h
+    Include/PolyVector4.h
     Include/PolyVertex.h
     Include/tinystr.h
     Include/tinyxml.h

+ 5 - 10
Core/Contents/Include/PolyCamera.h

@@ -25,6 +25,7 @@
 #include "PolyGlobals.h"
 #include "PolyEntity.h"
 #include "PolyVector2.h"
+#include "PolyVector4.h"
 
 namespace Polycode {
 
@@ -73,15 +74,9 @@ namespace Polycode {
 			* @return Returns true if the sphere is within the camera's frustum, or false if it isn't.
 			* @see canSee()
 			*/								
-			bool isSphereInFrustum(Vector3 pos, Number fRadius);
-		
-			/**
-			* Checks if the camera can see an entity based on its bounding radius.
-			* @param entity Entity to check.
-			* @return Returns true if the entity's bounding radius is within the camera's frustum, or false if it isn't.
-			* @see isSphereInFrustum()
-			*/					
-			bool canSee(Entity *entity);
+			bool isSphereInFrustum(const Vector3 &pos, Number fRadius);
+        
+            bool isAABBInFrustum(const AABB &aabb);
 			
 			/**
 			* Toggles orthographic projection mode for camera.
@@ -238,7 +233,7 @@ namespace Polycode {
 
 			Number leftFrustum,rightFrustum,topFrustum,bottomFrustum;
 
-			Number frustumPlanes[6][4];
+			Vector4 frustumPlanes[6];
 
 			Scene *parentScene;
 

+ 33 - 41
Core/Contents/Include/PolyEntity.h

@@ -47,6 +47,12 @@ namespace Polycode {
 		String propName;
 		String propValue;		
 	};
+    
+    class _PolyExport AABB {
+        public:
+            Vector3 min;
+            Vector3 max;
+    };
 
 	class _PolyExport Rotation {
 		public:
@@ -519,34 +525,11 @@ namespace Polycode {
 			*/
 			//@{			
 	
-			/**
-			* Recalculates the bounding box of the entity based on its size.
-			*/
-			void recalculateBBox();
-			
-			/**
-			* Returns the bounding box radius.
-			* @return The bounding box radius.
-			*/			
-			Number getBBoxRadius() const;
-			
-			/**
-			* Returns the entity's bounding box radius compounded from its children's bounding box radii.
-			* @return The compound bounding box radius.
-			*/						
-			Number getCompoundBBoxRadius() const;
-			
 			
 			void setAnchorPoint(const Vector3 &anchorPoint);
 			void setAnchorPoint(Number x, Number y, Number z);			
 			Vector3 getAnchorPoint() const;
 			
-			/**
-			* Sets the bounding box radius.
-			* @param rad New bounding box radius.
-			*/
-			void setBBoxRadius(Number rad);		
-			
 			virtual MouseEventResult onMouseDown(const Ray &ray, int mouseButton, int timestamp);
 			virtual MouseEventResult onMouseUp(const Ray &ray, int mouseButton, int timestamp);
 			virtual MouseEventResult onMouseMove(const Ray &ray, int timestamp);
@@ -582,17 +565,7 @@ namespace Polycode {
 			* matrix when billboardMode is enabled
 			*/
 			bool billboardIgnoreScale;
-			
-			/**
-			* Normally, translucent textures do not affect the depth buffer, but if this flag is set to true, this entity's alpha channel is written to the depth buffer at a preset threshold. This flag is set to false by default.
-			*/			
-			bool alphaTest;
-			
-			/**
-			* If this flag is set to false, backface culling is disabled when rendering this entity, rendering both sides of each face. Set to true by default.
-			*/
-			bool backfaceCulled;	
-		
+
 
 
 			/**
@@ -681,8 +654,7 @@ namespace Polycode {
 			void setRenderer(Renderer *renderer);
 			
 			virtual bool customHitDetection(const Ray &ray) { return true; }			
-			
-			Vector3 bBox;			
+					
 			bool ignoreParentMatrix;
 						
 			bool enableScissor;	
@@ -705,6 +677,8 @@ namespace Polycode {
 			void clearTags();
 			void addTag(String tag); 
 
+			//@}
+        
 			/**
 			* If set to true, will cast shadows (Defaults to true).
 			*/
@@ -725,10 +699,29 @@ namespace Polycode {
 			bool mouseOver;
         
             static int defaultBlendingMode;
-			
-			//@}		
+        
+            void recalculateAABBAllChildren();
+            void recalculateAABB();
+        
+            /*
+             Return axis-aligned bounding box in world space.
+             */
+            AABB getWorldAABB();
+        
+            Vector3 getLocalBoundingBox();
+            void setLocalBoundingBox(const Vector3 box);
+            void setLocalBoundingBox(Number x, Number y, Number z);
+            void setLocalBoundingBoxX(Number x);
+            void setLocalBoundingBoxY(Number y);
+            void setLocalBoundingBoxZ(Number z);
+        
+            bool rendererVis;
+
 		protected:
 		
+            AABB aabb;
+            Vector3 bBox;
+        
 			int lastClickTicks;
 			Number yAdjust;
 			std::vector<String> *tags;
@@ -738,8 +731,6 @@ namespace Polycode {
 			std::vector<Entity*> children;
 
 			Vector3 anchorPoint;
-			
-			Number bBoxRadius;		
 		
 			Vector3 position;
 			Vector3 scale;		
@@ -749,7 +740,8 @@ namespace Polycode {
 			
 			bool lockMatrix;
 			bool matrixDirty;
-			Matrix4 transformMatrix;		
+        
+			Matrix4 transformMatrix;
 			Entity *parentEntity;
 		
 			Renderer *renderer;

+ 8 - 2
Core/Contents/Include/PolyScene.h

@@ -191,12 +191,18 @@ namespace Polycode {
         bool remapMouse;
         
         bool constrainPickingToViewport;
-		
+        
+        void doVisibilityChecking(bool val);
+        bool doesVisibilityChecking();
+		      
 	protected:
 		
 		void initScene(int sceneType, bool virtualScene);
-
+        void setEntityVisibility(Entity *entity, Camera *camera);
+        void setEntityVisibilityBool(Entity *entity, bool val);
+        
 		bool hasLightmaps;
+        bool _doVisibilityChecking;
 		
 		Renderer *renderer;
 		std::vector <SceneLight*> lights;		

+ 12 - 0
Core/Contents/Include/PolySceneMesh.h

@@ -185,6 +185,18 @@ namespace Polycode {
         
             virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly) const;
             virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const;
+        
+            
+            /**
+             * Normally, translucent textures do not affect the depth buffer, but if this flag is set to true, this entity's alpha channel is written to the depth buffer at a preset threshold. This flag is set to false by default.
+             */
+            bool alphaTest;
+            
+            /**
+             * If this flag is set to false, backface culling is disabled when rendering this entity, rendering both sides of each face. Set to true by default.
+             */
+            bool backfaceCulled;	
+        
 			
 		protected:
 		

+ 168 - 0
Core/Contents/Include/PolyVector4.h

@@ -0,0 +1,168 @@
+/*
+ Copyright (C) 2011 by Ivan Safrin
+ 
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+ 
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+ */
+
+#pragma once
+#include "PolyGlobals.h"
+#include <math.h>
+
+//#ifdef _WINDOWS
+	#include <assert.h>
+//#endif 
+
+namespace Polycode {
+
+	/**
+	* 4D Vector class.
+	*/
+	class _PolyExport Vector4 : public PolyBase {
+		public:
+		
+			/**
+			* Create from x,y,z coordinates.
+			* @param x X coordinate.
+			* @param y Y coordinate.			
+			* @param z Z coordinate.						
+			* @param w W coordinate.
+			*/					
+			Vector4(Number x,Number y,Number z, Number w);
+
+			/**
+			* Create from single value for all coordinates
+			* @param val Value for all coordinates
+			*/					
+			Vector4(Number val);
+			
+			/**
+			* Default constructor.
+			*/ 
+			Vector4();
+			virtual ~Vector4();
+
+			/**
+			* Sets the vector from x,y,z coordinates.
+			* @param x X coordinate.
+			* @param y Y coordinate.			
+			* @param z Z coordinate.
+            * @param w W coordinate
+			*/
+			void set(Number x, Number y, Number z, Number w);
+
+			inline Vector4 operator - ( const Vector4& v2 ) const {
+				return Vector4(x - v2.x, y - v2.y, z - v2.z, w - v2.w);
+			}
+
+			
+			// ----------------------------------------------------------------------------------------------------------------
+			/** @name Operators
+			*  Available vector operators.
+			*/
+			//@{
+			
+
+			inline Vector4 operator * (const Number val) const {
+				return Vector4(x * val, y * val, z * val, w * val);
+			}
+
+			inline Vector4 operator * (const Vector4 &v2) const {
+				return Vector4(x * v2.x, y * v2.y, z * v2.z, w * v2.w);
+			}
+
+
+			inline Vector4 operator / (const Number val) const {
+				assert( val != 0.0 );
+				return operator*(1/val);
+			}
+
+			inline Vector4& operator = ( const Vector4& v2)  {
+				x = v2.x;
+				y = v2.y;
+				z = v2.z;
+				w = v2.w;
+				return *this;
+			}
+
+			inline Vector4& operator += ( const Vector4& v2)  {
+				x += v2.x;
+				y += v2.y;
+				z += v2.z;
+				w += v2.w;
+				return *this;
+			}
+
+			inline Vector4& operator -= ( const Vector4& v2)  {
+				x -= v2.x;
+				y -= v2.y;
+				z -= v2.z;
+				w -= v2.w;
+				return *this;
+			}
+	
+			inline Vector4 operator + ( const Vector4& v2 ) const {
+				return Vector4(x + v2.x, y + v2.y, z + v2.z, w + v2.w);
+			}
+        
+            inline Vector4 operator - () {
+                return Vector4(-x, -y, -z, -w);
+            }
+
+			inline bool operator == ( const Vector4& v2)  {
+				return (v2.x == x && v2.y == y && v2.z == z && v2.w == w);
+			}		
+
+			inline bool operator != ( const Vector4& v2)  {
+				return (v2.x != x || v2.y != y || v2.z != z || v2.w != w);
+			}				
+		
+			//@}
+			// ----------------------------------------------------------------------------------------------------------------
+			
+			
+			/**
+			* Returns the dot product with another vector.
+			* @return Dor product with the vector.
+			*/			
+			inline Number dot(const Vector4 &u) const {
+				return x * u.x + y * u.y + z * u.z + w * u.w;
+			}
+
+			/**
+			* X coordinate.
+			*/
+			Number x;
+			
+			/**
+			* Y coordinate.
+			*/			
+			Number y;
+			
+			/**
+			* Z coordinate.
+			*/			
+			Number z;			
+
+            /**
+             * W coordinate.
+             */
+            Number w;
+
+	};
+}

+ 2 - 0
Core/Contents/Include/Polycode.h

@@ -41,7 +41,9 @@
 #include "PolyCoreInput.h"
 #include "PolyInputKeys.h"
 #include "PolyInputEvent.h"
+#include "PolyVector2.h"
 #include "PolyVector3.h"
+#include "PolyVector4.h"
 #include "PolyBezierCurve.h"
 #include "PolyQuaternionCurve.h"
 #include "PolyRectangle.h"

+ 105 - 93
Core/Contents/Source/PolyCamera.cpp

@@ -70,21 +70,39 @@ void Camera::setFOV(Number fov) {
 	this->fov = fov;
 }
 
-bool Camera::isSphereInFrustum(Vector3 pos, Number fRadius) {
+bool Camera::isSphereInFrustum(const Vector3 &pos, Number fRadius) {
 	if(!frustumCulling)
 		return true;
     for( int i = 0; i < 6; ++i )
     {
-        if( frustumPlanes[i][0] * pos.x +
-            frustumPlanes[i][1] * pos.y +
-            frustumPlanes[i][2] * pos.z +
-            frustumPlanes[i][3] <= -fRadius )
+        if( frustumPlanes[i].x * pos.x +
+            frustumPlanes[i].y * pos.y +
+            frustumPlanes[i].z * pos.z +
+            frustumPlanes[i].w <= -fRadius )
             return false;
     }
 
     return true;
 }
 
+
+bool Camera::isAABBInFrustum(const AABB &aabb) {
+    for( int i=0; i < 6; i++) {
+        int out = 0;
+        out += (frustumPlanes[i].dot(Vector4(aabb.min.x, aabb.min.y, aabb.min.z, 1.0)) < 0.0) ? 1 : 0;
+        out += (frustumPlanes[i].dot(Vector4(aabb.max.x, aabb.min.y, aabb.min.z, 1.0)) < 0.0) ? 1 : 0;
+        out += (frustumPlanes[i].dot(Vector4(aabb.min.x, aabb.max.y, aabb.min.z, 1.0)) < 0.0) ? 1 : 0;
+        out += (frustumPlanes[i].dot(Vector4(aabb.max.x, aabb.max.y, aabb.min.z, 1.0)) < 0.0) ? 1 : 0;
+        out += (frustumPlanes[i].dot(Vector4(aabb.min.x, aabb.min.y, aabb.max.z, 1.0)) < 0.0) ? 1 : 0;
+        out += (frustumPlanes[i].dot(Vector4(aabb.max.x, aabb.min.y, aabb.max.z, 1.0)) < 0.0) ? 1 : 0;
+        out += (frustumPlanes[i].dot(Vector4(aabb.min.x, aabb.max.y, aabb.max.z, 1.0)) < 0.0) ? 1 : 0;
+        out += (frustumPlanes[i].dot(Vector4(aabb.max.x, aabb.max.y, aabb.max.z, 1.0)) < 0.0) ? 1 : 0;
+        if( out==8 ) return false;
+    }
+    
+    return true;
+}
+
 void Camera::setOrthoSize(Number orthoSizeX, Number orthoSizeY) {
 	this->orthoSizeX = orthoSizeX;
 	this->orthoSizeY = orthoSizeY;
@@ -121,12 +139,10 @@ Number Camera::getOrthoSizeY() {
 
 void Camera::buildFrustumPlanes() {
 
-	Matrix4 p; 
 	Matrix4 mv;
 	Matrix4 mvp;
 	Number t;
 
-	p = renderer->getProjectionMatrix();
     mv = renderer->getModelviewMatrix();
 
     //
@@ -134,134 +150,134 @@ void Camera::buildFrustumPlanes() {
     // a combined model-view-projection matrix.
     //
 
-    mvp.ml[ 0] = mv.ml[ 0] * p.ml[ 0] + mv.ml[ 1] * p.ml[ 4] + mv.ml[ 2] * p.ml[ 8] + mv.ml[ 3] * p.ml[12];
+    mvp.ml[ 0] = mv.ml[ 0] * projectionMatrix.ml[ 0] + mv.ml[ 1] * projectionMatrix.ml[ 4] + mv.ml[ 2] * projectionMatrix.ml[ 8] + mv.ml[ 3] * projectionMatrix.ml[12];
 
-    mvp.ml[ 1] = mv.ml[ 0] * p.ml[ 1] + mv.ml[ 1] * p.ml[ 5] + mv.ml[ 2] * p.ml[ 9] + mv.ml[ 3] * p.ml[13];
-    mvp.ml[ 2] = mv.ml[ 0] * p.ml[ 2] + mv.ml[ 1] * p.ml[ 6] + mv.ml[ 2] * p.ml[10] + mv.ml[ 3] * p.ml[14];
-    mvp.ml[ 3] = mv.ml[ 0] * p.ml[ 3] + mv.ml[ 1] * p.ml[ 7] + mv.ml[ 2] * p.ml[11] + mv.ml[ 3] * p.ml[15];
+    mvp.ml[ 1] = mv.ml[ 0] * projectionMatrix.ml[ 1] + mv.ml[ 1] * projectionMatrix.ml[ 5] + mv.ml[ 2] * projectionMatrix.ml[ 9] + mv.ml[ 3] * projectionMatrix.ml[13];
+    mvp.ml[ 2] = mv.ml[ 0] * projectionMatrix.ml[ 2] + mv.ml[ 1] * projectionMatrix.ml[ 6] + mv.ml[ 2] * projectionMatrix.ml[10] + mv.ml[ 3] * projectionMatrix.ml[14];
+    mvp.ml[ 3] = mv.ml[ 0] * projectionMatrix.ml[ 3] + mv.ml[ 1] * projectionMatrix.ml[ 7] + mv.ml[ 2] * projectionMatrix.ml[11] + mv.ml[ 3] * projectionMatrix.ml[15];
 
-    mvp.ml[ 4] = mv.ml[ 4] * p.ml[ 0] + mv.ml[ 5] * p.ml[ 4] + mv.ml[ 6] * p.ml[ 8] + mv.ml[ 7] * p.ml[12];
-    mvp.ml[ 5] = mv.ml[ 4] * p.ml[ 1] + mv.ml[ 5] * p.ml[ 5] + mv.ml[ 6] * p.ml[ 9] + mv.ml[ 7] * p.ml[13];
-    mvp.ml[ 6] = mv.ml[ 4] * p.ml[ 2] + mv.ml[ 5] * p.ml[ 6] + mv.ml[ 6] * p.ml[10] + mv.ml[ 7] * p.ml[14];
-    mvp.ml[ 7] = mv.ml[ 4] * p.ml[ 3] + mv.ml[ 5] * p.ml[ 7] + mv.ml[ 6] * p.ml[11] + mv.ml[ 7] * p.ml[15];
+    mvp.ml[ 4] = mv.ml[ 4] * projectionMatrix.ml[ 0] + mv.ml[ 5] * projectionMatrix.ml[ 4] + mv.ml[ 6] * projectionMatrix.ml[ 8] + mv.ml[ 7] * projectionMatrix.ml[12];
+    mvp.ml[ 5] = mv.ml[ 4] * projectionMatrix.ml[ 1] + mv.ml[ 5] * projectionMatrix.ml[ 5] + mv.ml[ 6] * projectionMatrix.ml[ 9] + mv.ml[ 7] * projectionMatrix.ml[13];
+    mvp.ml[ 6] = mv.ml[ 4] * projectionMatrix.ml[ 2] + mv.ml[ 5] * projectionMatrix.ml[ 6] + mv.ml[ 6] * projectionMatrix.ml[10] + mv.ml[ 7] * projectionMatrix.ml[14];
+    mvp.ml[ 7] = mv.ml[ 4] * projectionMatrix.ml[ 3] + mv.ml[ 5] * projectionMatrix.ml[ 7] + mv.ml[ 6] * projectionMatrix.ml[11] + mv.ml[ 7] * projectionMatrix.ml[15];
 
-    mvp.ml[ 8] = mv.ml[ 8] * p.ml[ 0] + mv.ml[ 9] * p.ml[ 4] + mv.ml[10] * p.ml[ 8] + mv.ml[11] * p.ml[12];
-    mvp.ml[ 9] = mv.ml[ 8] * p.ml[ 1] + mv.ml[ 9] * p.ml[ 5] + mv.ml[10] * p.ml[ 9] + mv.ml[11] * p.ml[13];
-    mvp.ml[10] = mv.ml[ 8] * p.ml[ 2] + mv.ml[ 9] * p.ml[ 6] + mv.ml[10] * p.ml[10] + mv.ml[11] * p.ml[14];
-    mvp.ml[11] = mv.ml[ 8] * p.ml[ 3] + mv.ml[ 9] * p.ml[ 7] + mv.ml[10] * p.ml[11] + mv.ml[11] * p.ml[15];
+    mvp.ml[ 8] = mv.ml[ 8] * projectionMatrix.ml[ 0] + mv.ml[ 9] * projectionMatrix.ml[ 4] + mv.ml[10] * projectionMatrix.ml[ 8] + mv.ml[11] * projectionMatrix.ml[12];
+    mvp.ml[ 9] = mv.ml[ 8] * projectionMatrix.ml[ 1] + mv.ml[ 9] * projectionMatrix.ml[ 5] + mv.ml[10] * projectionMatrix.ml[ 9] + mv.ml[11] * projectionMatrix.ml[13];
+    mvp.ml[10] = mv.ml[ 8] * projectionMatrix.ml[ 2] + mv.ml[ 9] * projectionMatrix.ml[ 6] + mv.ml[10] * projectionMatrix.ml[10] + mv.ml[11] * projectionMatrix.ml[14];
+    mvp.ml[11] = mv.ml[ 8] * projectionMatrix.ml[ 3] + mv.ml[ 9] * projectionMatrix.ml[ 7] + mv.ml[10] * projectionMatrix.ml[11] + mv.ml[11] * projectionMatrix.ml[15];
 
-    mvp.ml[12] = mv.ml[12] * p.ml[ 0] + mv.ml[13] * p.ml[ 4] + mv.ml[14] * p.ml[ 8] + mv.ml[15] * p.ml[12];
-    mvp.ml[13] = mv.ml[12] * p.ml[ 1] + mv.ml[13] * p.ml[ 5] + mv.ml[14] * p.ml[ 9] + mv.ml[15] * p.ml[13];
-    mvp.ml[14] = mv.ml[12] * p.ml[ 2] + mv.ml[13] * p.ml[ 6] + mv.ml[14] * p.ml[10] + mv.ml[15] * p.ml[14];
-    mvp.ml[15] = mv.ml[12] * p.ml[ 3] + mv.ml[13] * p.ml[ 7] + mv.ml[14] * p.ml[11] + mv.ml[15] * p.ml[15];
+    mvp.ml[12] = mv.ml[12] * projectionMatrix.ml[ 0] + mv.ml[13] * projectionMatrix.ml[ 4] + mv.ml[14] * projectionMatrix.ml[ 8] + mv.ml[15] * projectionMatrix.ml[12];
+    mvp.ml[13] = mv.ml[12] * projectionMatrix.ml[ 1] + mv.ml[13] * projectionMatrix.ml[ 5] + mv.ml[14] * projectionMatrix.ml[ 9] + mv.ml[15] * projectionMatrix.ml[13];
+    mvp.ml[14] = mv.ml[12] * projectionMatrix.ml[ 2] + mv.ml[13] * projectionMatrix.ml[ 6] + mv.ml[14] * projectionMatrix.ml[10] + mv.ml[15] * projectionMatrix.ml[14];
+    mvp.ml[15] = mv.ml[12] * projectionMatrix.ml[ 3] + mv.ml[13] * projectionMatrix.ml[ 7] + mv.ml[14] * projectionMatrix.ml[11] + mv.ml[15] * projectionMatrix.ml[15];
 
     //
     // Extract the frustum's right clipping plane and normalize it.
     //
 
-    frustumPlanes[0][0] = mvp.ml[ 3] - mvp.ml[ 0];
-    frustumPlanes[0][1] = mvp.ml[ 7] - mvp.ml[ 4];
-    frustumPlanes[0][2] = mvp.ml[11] - mvp.ml[ 8];
-    frustumPlanes[0][3] = mvp.ml[15] - mvp.ml[12];
+    frustumPlanes[0].x = mvp.ml[ 3] - mvp.ml[ 0];
+    frustumPlanes[0].y = mvp.ml[ 7] - mvp.ml[ 4];
+    frustumPlanes[0].z = mvp.ml[11] - mvp.ml[ 8];
+    frustumPlanes[0].w = mvp.ml[15] - mvp.ml[12];
 
-    t = (Number) sqrt( frustumPlanes[0][0] * frustumPlanes[0][0] + 
-                      frustumPlanes[0][1] * frustumPlanes[0][1] + 
-                      frustumPlanes[0][2] * frustumPlanes[0][2] );
+    t = (Number) sqrt( frustumPlanes[0].x * frustumPlanes[0].x + 
+                      frustumPlanes[0].y * frustumPlanes[0].y + 
+                      frustumPlanes[0].z * frustumPlanes[0].z );
 
-    frustumPlanes[0][0] /= t;
-    frustumPlanes[0][1] /= t;
-    frustumPlanes[0][2] /= t;
-    frustumPlanes[0][3] /= t;
+    frustumPlanes[0].x /= t;
+    frustumPlanes[0].y /= t;
+    frustumPlanes[0].z /= t;
+    frustumPlanes[0].w /= t;
 
     //
     // Extract the frustum's left clipping plane and normalize it.
     //
 
-    frustumPlanes[1][0] = mvp.ml[ 3] + mvp.ml[ 0];
-    frustumPlanes[1][1] = mvp.ml[ 7] + mvp.ml[ 4];
-    frustumPlanes[1][2] = mvp.ml[11] + mvp.ml[ 8];
-    frustumPlanes[1][3] = mvp.ml[15] + mvp.ml[12];
+    frustumPlanes[1].x = mvp.ml[ 3] + mvp.ml[ 0];
+    frustumPlanes[1].y = mvp.ml[ 7] + mvp.ml[ 4];
+    frustumPlanes[1].z = mvp.ml[11] + mvp.ml[ 8];
+    frustumPlanes[1].w = mvp.ml[15] + mvp.ml[12];
 
-    t = (Number) sqrt( frustumPlanes[1][0] * frustumPlanes[1][0] + 
-                      frustumPlanes[1][1] * frustumPlanes[1][1] + 
-                      frustumPlanes[1][2] * frustumPlanes[1][2] );
+    t = (Number) sqrt( frustumPlanes[1].x * frustumPlanes[1].x + 
+                      frustumPlanes[1].y * frustumPlanes[1].y + 
+                      frustumPlanes[1].z * frustumPlanes[1].z );
 
-    frustumPlanes[1][0] /= t;
-    frustumPlanes[1][1] /= t;
-    frustumPlanes[1][2] /= t;
-    frustumPlanes[1][3] /= t;
+    frustumPlanes[1].x /= t;
+    frustumPlanes[1].y /= t;
+    frustumPlanes[1].z /= t;
+    frustumPlanes[1].w /= t;
 
     //
     // Extract the frustum's bottom clipping plane and normalize it.
     //
 
-    frustumPlanes[2][0] = mvp.ml[ 3] + mvp.ml[ 1];
-    frustumPlanes[2][1] = mvp.ml[ 7] + mvp.ml[ 5];
-    frustumPlanes[2][2] = mvp.ml[11] + mvp.ml[ 9];
-    frustumPlanes[2][3] = mvp.ml[15] + mvp.ml[13];
+    frustumPlanes[2].x = mvp.ml[ 3] + mvp.ml[ 1];
+    frustumPlanes[2].y = mvp.ml[ 7] + mvp.ml[ 5];
+    frustumPlanes[2].z = mvp.ml[11] + mvp.ml[ 9];
+    frustumPlanes[2].w = mvp.ml[15] + mvp.ml[13];
 
-    t = (Number) sqrt( frustumPlanes[2][0] * frustumPlanes[2][0] + 
-                      frustumPlanes[2][1] * frustumPlanes[2][1] + 
-                      frustumPlanes[2][2] * frustumPlanes[2][2] );
+    t = (Number) sqrt( frustumPlanes[2].x * frustumPlanes[2].x + 
+                      frustumPlanes[2].y * frustumPlanes[2].y + 
+                      frustumPlanes[2].z * frustumPlanes[2].z );
 
-    frustumPlanes[2][0] /= t;
-    frustumPlanes[2][1] /= t;
-    frustumPlanes[2][2] /= t;
-    frustumPlanes[2][3] /= t;
+    frustumPlanes[2].x /= t;
+    frustumPlanes[2].y /= t;
+    frustumPlanes[2].z /= t;
+    frustumPlanes[2].w /= t;
 
     //
     // Extract the frustum's top clipping plane and normalize it.
     //
 
-    frustumPlanes[3][0] = mvp.ml[ 3] - mvp.ml[ 1];
-    frustumPlanes[3][1] = mvp.ml[ 7] - mvp.ml[ 5];
-    frustumPlanes[3][2] = mvp.ml[11] - mvp.ml[ 9];
-    frustumPlanes[3][3] = mvp.ml[15] - mvp.ml[13];
+    frustumPlanes[3].x = mvp.ml[ 3] - mvp.ml[ 1];
+    frustumPlanes[3].y = mvp.ml[ 7] - mvp.ml[ 5];
+    frustumPlanes[3].z = mvp.ml[11] - mvp.ml[ 9];
+    frustumPlanes[3].w = mvp.ml[15] - mvp.ml[13];
 
-    t = (Number) sqrt( frustumPlanes[3][0] * frustumPlanes[3][0] + 
-                      frustumPlanes[3][1] * frustumPlanes[3][1] + 
-                      frustumPlanes[3][2] * frustumPlanes[3][2] );
+    t = (Number) sqrt( frustumPlanes[3].x * frustumPlanes[3].x + 
+                      frustumPlanes[3].y * frustumPlanes[3].y + 
+                      frustumPlanes[3].z * frustumPlanes[3].z );
 
-    frustumPlanes[3][0] /= t;
-    frustumPlanes[3][1] /= t;
-    frustumPlanes[3][2] /= t;
-    frustumPlanes[3][3] /= t;
+    frustumPlanes[3].x /= t;
+    frustumPlanes[3].y /= t;
+    frustumPlanes[3].z /= t;
+    frustumPlanes[3].w /= t;
 
     //
     // Extract the frustum's far clipping plane and normalize it.
     //
 
-    frustumPlanes[4][0] = mvp.ml[ 3] - mvp.ml[ 2];
-    frustumPlanes[4][1] = mvp.ml[ 7] - mvp.ml[ 6];
-    frustumPlanes[4][2] = mvp.ml[11] - mvp.ml[10];
-    frustumPlanes[4][3] = mvp.ml[15] - mvp.ml[14];
+    frustumPlanes[4].x = mvp.ml[ 3] - mvp.ml[ 2];
+    frustumPlanes[4].y = mvp.ml[ 7] - mvp.ml[ 6];
+    frustumPlanes[4].z = mvp.ml[11] - mvp.ml[10];
+    frustumPlanes[4].w = mvp.ml[15] - mvp.ml[14];
 
-    t = (Number) sqrt( frustumPlanes[4][0] * frustumPlanes[4][0] +  
-                      frustumPlanes[4][1] * frustumPlanes[4][1] + 
-                      frustumPlanes[4][2] * frustumPlanes[4][2] );
+    t = (Number) sqrt( frustumPlanes[4].x * frustumPlanes[4].x +  
+                      frustumPlanes[4].y * frustumPlanes[4].y + 
+                      frustumPlanes[4].z * frustumPlanes[4].z );
 
-    frustumPlanes[4][0] /= t;
-    frustumPlanes[4][1] /= t;
-    frustumPlanes[4][2] /= t;
-    frustumPlanes[4][3] /= t;
+    frustumPlanes[4].x /= t;
+    frustumPlanes[4].y /= t;
+    frustumPlanes[4].z /= t;
+    frustumPlanes[4].w /= t;
 
     //
     // Extract the frustum's near clipping plane and normalize it.
     //
 
-    frustumPlanes[5][0] = mvp.ml[ 3] + mvp.ml[ 2];
-    frustumPlanes[5][1] = mvp.ml[ 7] + mvp.ml[ 6];
-    frustumPlanes[5][2] = mvp.ml[11] + mvp.ml[10];
-    frustumPlanes[5][3] = mvp.ml[15] + mvp.ml[14];
+    frustumPlanes[5].x = mvp.ml[ 3] + mvp.ml[ 2];
+    frustumPlanes[5].y = mvp.ml[ 7] + mvp.ml[ 6];
+    frustumPlanes[5].z = mvp.ml[11] + mvp.ml[10];
+    frustumPlanes[5].w = mvp.ml[15] + mvp.ml[14];
 
-    t = (Number) sqrt( frustumPlanes[5][0] * frustumPlanes[5][0] + 
-                      frustumPlanes[5][1] * frustumPlanes[5][1] + 
-                      frustumPlanes[5][2] * frustumPlanes[5][2] );
+    t = (Number) sqrt( frustumPlanes[5].x * frustumPlanes[5].x + 
+                      frustumPlanes[5].y * frustumPlanes[5].y + 
+                      frustumPlanes[5].z * frustumPlanes[5].z );
 
-    frustumPlanes[5][0] /= t;
-    frustumPlanes[5][1] /= t;
-    frustumPlanes[5][2] /= t;
-    frustumPlanes[5][3] /= t;
+    frustumPlanes[5].x /= t;
+    frustumPlanes[5].y /= t;
+    frustumPlanes[5].z /= t;
+    frustumPlanes[5].w /= t;
 
 }
 
@@ -288,10 +304,6 @@ Scene *Camera::getParentScene() const {
     return parentScene;
 }
 
-bool Camera::canSee(Entity *entity) {
-	return isSphereInFrustum(entity->getPosition(), entity->getBBoxRadius());
-}
-
 void Camera::setParentScene(Scene *parentScene) {
 	this->parentScene = parentScene;
 }

+ 109 - 46
Core/Contents/Source/PolyEntity.cpp

@@ -53,18 +53,15 @@ void Entity::initEntity() {
 	enabled = true;
 	depthTest = true;
 	visible = true;
-	bBoxRadius = 0;
 	color.setColor(1.0f,1.0f,1.0f,1.0f);
 	parentEntity = NULL;
 	matrixDirty = true;
 	billboardMode = false;
 	billboardRoll = false;
 	billboardIgnoreScale = false;
-	backfaceCulled = true;
 	depthOnly = false;
 	depthWrite = true;
 	ignoreParentMatrix = false;
-	alphaTest = false;
 	blendingMode = Entity::defaultBlendingMode;
 	lockMatrix = false;
 	colorAffectsChildren = true;
@@ -80,6 +77,7 @@ void Entity::initEntity() {
 	mouseOver = false;
 	yAdjust = 1.0;
 	lastClickTicks = 0.0;
+    rendererVis = true;
 }
 
 Entity *Entity::getEntityById(String id, bool recursive) const {
@@ -113,8 +111,6 @@ void Entity::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) co
 	clone->custEntityType = custEntityType;
 	clone->billboardMode = billboardMode;	
 	clone->billboardRoll = billboardRoll;
-	clone->alphaTest = alphaTest;
-	clone->backfaceCulled = backfaceCulled;
 	clone->depthWrite = depthWrite;
 	clone->depthTest = depthTest;
 	clone->blendingMode = blendingMode;
@@ -319,40 +315,10 @@ void Entity::setColor(Number r, Number g, Number b, Number a) {
 	color.setColor(r,g,b,a);
 }
 
-void Entity::recalculateBBox() {
-	
-}
-
 void Entity::setBlendingMode(int newBlendingMode) {
 	blendingMode = newBlendingMode;
 }
 
-Number Entity::getBBoxRadius() const {
-	Number compRad;
-	Number biggest = bBoxRadius;
-	for(int i=0;i<children.size();i++) {
-		compRad = children[i]->getCompoundBBoxRadius();
-		if(compRad > biggest)
-			biggest = compRad;
-	}	
-	return biggest;
-}
-
-Number Entity::getCompoundBBoxRadius() const {
-	Number compRad;
-	Number biggest = bBoxRadius + position.distance(Vector3(0,0,0));
-	for(int i=0;i<children.size();i++) {
-		compRad = children[i]->getCompoundBBoxRadius();
-		if(compRad > biggest)
-			biggest = compRad;
-	}	
-	return biggest;
-}
-
-void Entity::setBBoxRadius(Number rad) {
-	bBoxRadius = rad;
-}
-
 Entity::~Entity() {
 	if(ownsChildren) {
 		for(int i=0; i < children.size(); i++) {	
@@ -371,6 +337,7 @@ void Entity::setInverseY(bool val) {
 	for(int i=0; i < children.size(); i++) {
 		children[i]->setInverseY(val);
 	}
+    matrixDirty = true;
 }
 
 bool Entity::getInverseY() {
@@ -425,9 +392,11 @@ void Entity::doUpdates() {
 
 void Entity::updateEntityMatrix() {
 
-	if(matrixDirty)
+	if(matrixDirty) {
 		rebuildTransformMatrix();
-	
+        recalculateAABBAllChildren();
+	}
+    
 	for(int i=0; i < children.size(); i++) {
 		children[i]->updateEntityMatrix();
 	}
@@ -525,16 +494,13 @@ void Entity::transformAndRender() {
 		renderer->enableDepthTest(false);
 	else
 		renderer->enableDepthTest(true);
-		 
-	renderer->enableAlphaTest(alphaTest);
 	
     renderer->pushVertexColor();
 	renderer->multiplyVertexColor(color);
 	
 	renderer->setBlendingMode(blendingMode);
-	renderer->enableBackfaceCulling(backfaceCulled);
 	   
-	if(visible) {
+	if(visible && rendererVis) {
 		renderer->pushMatrix();		
 		renderer->translate3D(-anchorPoint.x * bBox.x * 0.5, -anchorPoint.y * bBox.y * 0.5 * yAdjust, -anchorPoint.z * bBox.z * 0.5);
 		Render();
@@ -580,6 +546,102 @@ void Entity::dirtyMatrix(bool val) {
 	matrixDirty = val;
 }
 
+void Entity::recalculateAABBAllChildren() {
+    recalculateAABB();
+    for(int i=0; i< children.size(); i++) {
+        children[i]->recalculateAABBAllChildren();
+    }
+}
+
+void Entity::recalculateAABB() {
+
+    aabb.min = Vector3();
+    aabb.max = Vector3();
+    
+    Vector3 bBoxCoords[8] = {
+        Vector3(-bBox.x * 0.5, -bBox.y * 0.5, bBox.z * 0.5),
+        Vector3(bBox.x * 0.5, -bBox.y * 0.5, bBox.z * 0.5),
+        Vector3(-bBox.x * 0.5, -bBox.y * 0.5, -bBox.z * 0.5),
+        Vector3(bBox.x * 0.5, -bBox.y * 0.5, -bBox.z * 0.5),
+        Vector3(-bBox.x * 0.5, bBox.y * 0.5, bBox.z * 0.5),
+        Vector3(bBox.x * 0.5, bBox.y * 0.5, bBox.z * 0.5),
+        Vector3(-bBox.x * 0.5, bBox.y * 0.5, -bBox.z * 0.5),
+        Vector3(bBox.x * 0.5, bBox.y * 0.5, -bBox.z * 0.5)
+    };
+    
+    Matrix4 fullMatrix = getAnchorAdjustedMatrix();
+    if(ignoreParentMatrix) {
+        fullMatrix = transformMatrix;
+    }
+    
+    for(int i=0; i < 8; i++) {
+        bBoxCoords[i] = fullMatrix * bBoxCoords[i];
+        if(i ==0 ) {
+            aabb.min = bBoxCoords[i];
+            aabb.max = bBoxCoords[i];
+        } else {
+            if(bBoxCoords[i].x < aabb.min.x) {
+                aabb.min.x = bBoxCoords[i].x;
+            }
+            if(bBoxCoords[i].y < aabb.min.y) {
+                aabb.min.y = bBoxCoords[i].y;
+            }
+            if(bBoxCoords[i].z < aabb.min.z) {
+                aabb.min.z = bBoxCoords[i].z;
+            }
+            
+            if(bBoxCoords[i].x > aabb.max.x) {
+                aabb.max.x = bBoxCoords[i].x;
+            }
+            if(bBoxCoords[i].y > aabb.max.y) {
+                aabb.max.y = bBoxCoords[i].y;
+            }
+            if(bBoxCoords[i].z > aabb.max.z) {
+                aabb.max.z = bBoxCoords[i].z;
+            }
+        }
+    }
+        
+}
+
+AABB Entity::getWorldAABB() {
+    return aabb;
+}
+
+Vector3 Entity::getLocalBoundingBox() {
+    return bBox;
+}
+
+void Entity::setLocalBoundingBox(const Vector3 box) {
+    bBox = box;
+    recalculateAABB();
+    matrixDirty = true;
+}
+
+void Entity::setLocalBoundingBox(Number x, Number y, Number z) {
+    bBox.set(x, y, z);
+    recalculateAABB();
+    matrixDirty = true;
+}
+
+void Entity::setLocalBoundingBoxX(Number x) {
+    bBox.x = x;
+    recalculateAABB();
+    matrixDirty = true;
+}
+
+void Entity::setLocalBoundingBoxY(Number y) {
+    bBox.y = y;
+    recalculateAABB();
+    matrixDirty = true;
+}
+
+void Entity::setLocalBoundingBoxZ(Number z) {
+    bBox.z = z;
+    recalculateAABB();
+    matrixDirty = true;
+}
+
 void Entity::setRotationQuat(Number w, Number x, Number y, Number z) {
 	rotationQuat.w = w;
 	rotationQuat.x = x;
@@ -723,15 +785,15 @@ void Entity::setParentEntity(Entity *entity) {
 }
 
 void Entity::setWidth(Number width) {
-	bBox.x = width;
+	setLocalBoundingBoxX(width);
 }
 
 void Entity::setHeight(Number height) {
-	bBox.y = height;
+	setLocalBoundingBoxY(height);
 }
 
 void Entity::setDepth(Number depth) {
-	bBox.z = depth;
+	setLocalBoundingBoxZ(depth);
 }
 
 Number Entity::getWidth() const {
@@ -746,7 +808,6 @@ Number Entity::getDepth() const {
 	return bBox.z;
 }
 
-
 Number Entity::getPitch() const {
 	return rotation.x;
 }
@@ -906,11 +967,13 @@ void Entity::addTag(String tag) {
 }
 
 void Entity::setAnchorPoint(const Vector3 &anchorPoint) {
-	this->anchorPoint = anchorPoint;	
+	this->anchorPoint = anchorPoint;
+    matrixDirty = true;
 }
 
 void Entity::setAnchorPoint(Number x, Number y, Number z) {
 	anchorPoint.set(x,y,z);
+    matrixDirty = true;
 }
 
 Vector3 Entity::getAnchorPoint() const {

+ 24 - 3
Core/Contents/Source/PolyParticleEmitter.cpp

@@ -28,7 +28,7 @@
 
 using namespace Polycode;
 
-SceneParticleEmitter::SceneParticleEmitter(unsigned int particleCount, Number lifetime, Number speed) : SceneMesh(Mesh::POINT_MESH), particleCount(particleCount), particleSpeed(speed), lifetime(lifetime), directionVector(0.0, 1.0, 0.0), cyclesLeftOver(0.0), useFloorPlane(false), floorPlaneOffset(-1.0), floorDamping(0.5), particlesInWorldSpace(false), perlinEnabled(false), perlinValue(1.0,1.0,1.0), particleType(SceneParticleEmitter::PARTICLE_TYPE_POINT), particleSize(0.1), particleRotationSpeed(0.0, 0.0, 0.0), useColorCurves(false), useScaleCurve(false), loopParticles(true){
+SceneParticleEmitter::SceneParticleEmitter(unsigned int particleCount, Number lifetime, Number speed) : SceneMesh(Mesh::POINT_MESH), particleCount(particleCount), particleSpeed(speed), lifetime(lifetime), directionVector(0.0, 1.0, 0.0), cyclesLeftOver(0.0), useFloorPlane(false), floorPlaneOffset(-1.0), floorDamping(0.5), particlesInWorldSpace(false), perlinEnabled(false), perlinValue(1.0,1.0,1.0), particleType(SceneParticleEmitter::PARTICLE_TYPE_QUAD), particleSize(0.1), particleRotationSpeed(0.0, 0.0, 0.0), useColorCurves(false), useScaleCurve(false), loopParticles(true){
     
     core = CoreServices::getInstance()->getCore();
 	timeStep = core->getRefreshIntervalMs() / 1000.0f;
@@ -162,12 +162,12 @@ void SceneParticleEmitter::enableParticleSystem(bool val) {
 
 void SceneParticleEmitter::rebuildParticles() {
     mesh->clearMesh();
+    Matrix4 inverseMatrix = systemTrasnformMatrix.Inverse();
     
     switch(particleType) {
         case PARTICLE_TYPE_POINT:
         {
             mesh->setMeshType(Mesh::POINT_MESH);
-            Matrix4 inverseMatrix = systemTrasnformMatrix.Inverse();
             for(int i=0; i < particles.size(); i++) {
                 if(particles[i].lifetime > lifetime || particles[i].lifetime < 0.0) {
                     continue;
@@ -183,7 +183,6 @@ void SceneParticleEmitter::rebuildParticles() {
         case PARTICLE_TYPE_QUAD:
         {
             mesh->setMeshType(Mesh::QUAD_MESH);
-            Matrix4 inverseMatrix = systemTrasnformMatrix.Inverse();
             Matrix4 cameraMatrix = renderer->getCameraMatrix();
             Quaternion q;
             
@@ -337,7 +336,11 @@ void SceneParticleEmitter::setPerlinValue(const Vector3 &perlinValue) {
 }
 
 void SceneParticleEmitter::updateParticles() {
+    
+    Matrix4 inverseMatrix = systemTrasnformMatrix.Inverse();
+    
     Number normLife;
+    Vector3 newBBox;
     
     for(int i=0; i < particles.size(); i++) {
         particles[i].lifetime += timeStep;
@@ -371,6 +374,7 @@ void SceneParticleEmitter::updateParticles() {
         
         particles[i].velocity += gravity * timeStep;
         particles[i].position += particles[i].velocity * timeStep * particleSpeed;
+        
         if(perlinEnabled) {
             
             particles[i].position += Vector3(motionPerlin->Get((particles[i].lifetime/lifetime), particles[i].perlinPos.x) * perlinValue.x * timeStep, motionPerlin->Get((particles[i].lifetime/lifetime), particles[i].perlinPos.y) * perlinValue.y * timeStep , motionPerlin->Get((particles[i].lifetime/lifetime), particles[i].perlinPos.z) * perlinValue.z * timeStep);
@@ -382,7 +386,24 @@ void SceneParticleEmitter::updateParticles() {
                 particles[i].velocity.y *= -1.0 * floorDamping;
             }
         }
+        
+        Vector3 bBoxTest = particles[i].position;
+        if(particlesInWorldSpace) {
+            bBoxTest = inverseMatrix * bBoxTest;
+        }
+        
+        if(fabs(bBoxTest.x) > newBBox.x) {
+            newBBox.x = fabs(bBoxTest.x);
+        }
+        if(fabs(bBoxTest.y) > newBBox.y) {
+            newBBox.y = fabs(bBoxTest.y);
+        }
+        if(fabs(bBoxTest.z) > newBBox.z) {
+            newBBox.z = fabs(bBoxTest.z);
+        }
     }
+    
+    setLocalBoundingBox((newBBox + Vector3(particleSize, particleSize, particleSize))* 2.0);
 }
 
 void SceneParticleEmitter::Render() {

+ 50 - 14
Core/Contents/Source/PolyScene.cpp

@@ -64,6 +64,7 @@ void Scene::initScene(int sceneType, bool virtualScene) {
 	useClearColor = false;
 	ownsChildren = false;
     remapMouse = false;
+    _doVisibilityChecking = true;
     constrainPickingToViewport = true;
 	renderer = CoreServices::getInstance()->getRenderer();
 	rootEntity.setRenderer(renderer);
@@ -71,6 +72,7 @@ void Scene::initScene(int sceneType, bool virtualScene) {
 	
     setSceneType(sceneType);
 	
+    core->addEventListener(this, Core::EVENT_CORE_RESIZE);
 	core->getInput()->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
 	core->getInput()->addEventListener(this, InputEvent::EVENT_MOUSEUP);
 	core->getInput()->addEventListener(this, InputEvent::EVENT_MOUSEMOVE);
@@ -96,6 +98,7 @@ void Scene::setSceneType(int newType) {
             defaultCamera->setOrthoSizeMode(Camera::ORTHO_SIZE_VIEWPORT);
 			defaultCamera->topLeftOrtho = true;
 			rootEntity.setInverseY(true);
+            rootEntity.setPositionY(-CoreServices::getInstance()->getCore()->getYRes());            
             break;
 		case SCENE_3D:
 			defaultCamera->setClippingPlanes(1.0, 1000.0);
@@ -129,9 +132,7 @@ bool Scene::isEnabled() {
 }
 
 void Scene::Update() {
-	if(sceneType == SCENE_2D_TOPLEFT) {
-		rootEntity.setPositionY(-CoreServices::getInstance()->getCore()->getYRes());
-	}
+    rootEntity.updateEntityMatrix();
 	rootEntity.doUpdates();
 }
 
@@ -176,6 +177,35 @@ Camera *Scene::getDefaultCamera() {
 	return defaultCamera;
 }
 
+void Scene::doVisibilityChecking(bool val) {
+    _doVisibilityChecking = val;
+    if(!_doVisibilityChecking) {
+        setEntityVisibilityBool(&rootEntity, true);
+    }
+}
+
+bool Scene::doesVisibilityChecking() {
+    return _doVisibilityChecking;
+}
+
+void Scene::setEntityVisibilityBool(Entity *entity, bool val) {
+    entity->rendererVis = val;
+    for(int i=0; i < entity->getNumChildren(); i++) {
+        setEntityVisibilityBool(entity->getChildAtIndex(i), val);
+    }
+}
+
+void Scene::setEntityVisibility(Entity *entity, Camera *camera) {
+    if(camera->frustumCulling) {
+        entity->rendererVis = camera->isAABBInFrustum(entity->getWorldAABB());
+    } else {
+        entity->rendererVis = true;
+    }
+    for(int i=0; i < entity->getNumChildren(); i++) {
+        setEntityVisibility(entity->getChildAtIndex(i), camera);
+    }
+}
+
 void Scene::Render(Camera *targetCamera) {	
 	if(!targetCamera && !activeCamera)
 		return;
@@ -244,17 +274,18 @@ void Scene::Render(Camera *targetCamera) {
 	}	
 		
 	targetCamera->doCameraTransform();
-	targetCamera->buildFrustumPlanes();
-	
-	CoreServices::getInstance()->getRenderer()->enableFog(fogEnabled);	
+    
+	CoreServices::getInstance()->getRenderer()->enableFog(fogEnabled);
 	if(fogEnabled) {
 		CoreServices::getInstance()->getRenderer()->setFogProperties(fogMode, fogColor, fogDensity, fogStartDepth, fogEndDepth);
 	} else {
 		CoreServices::getInstance()->getRenderer()->setFogProperties(fogMode, fogColor, 0.0, fogStartDepth, fogEndDepth);	
 	}
 	
-	
-	rootEntity.updateEntityMatrix();
+    if(_doVisibilityChecking) {
+        targetCamera->buildFrustumPlanes();
+        setEntityVisibility(&rootEntity, targetCamera);
+    }
 	rootEntity.transformAndRender();		
 }
 
@@ -264,14 +295,15 @@ void Scene::RenderDepthOnly(Camera *targetCamera) {
 	CoreServices::getInstance()->getRenderer()->cullFrontFaces(true);
 
 	targetCamera->rebuildTransformMatrix();	
-	targetCamera->doCameraTransform();	
-	targetCamera->buildFrustumPlanes();
+	targetCamera->doCameraTransform();
 	
 	CoreServices::getInstance()->getRenderer()->setTexture(NULL);
 	CoreServices::getInstance()->getRenderer()->enableShaders(false);
-	
-	
-	rootEntity.updateEntityMatrix();
+		
+    if(_doVisibilityChecking) {
+        targetCamera->buildFrustumPlanes();
+        setEntityVisibility(&rootEntity, targetCamera);
+    }
 	rootEntity.transformAndRender();	
 	
 	CoreServices::getInstance()->getRenderer()->enableShaders(true);
@@ -324,7 +356,11 @@ Ray Scene::projectRayFromCameraAndViewportCoordinate(Camera *camera, Vector2 coo
 
 
 void Scene::handleEvent(Event *event) {
-	if(event->getDispatcher() == core->getInput() && rootEntity.processInputEvents) {
+    if(event->getDispatcher() == core) {
+        if(sceneType == SCENE_2D_TOPLEFT) {
+            rootEntity.setPositionY(-CoreServices::getInstance()->getCore()->getYRes());
+        }
+    } else if(event->getDispatcher() == core->getInput() && rootEntity.processInputEvents) {
 		InputEvent *inputEvent = (InputEvent*) event;
 
         if(constrainPickingToViewport) {

+ 6 - 4
Core/Contents/Source/PolySceneEntityInstance.cpp

@@ -439,10 +439,12 @@ Entity *SceneEntityInstance::loadObjectEntryIntoEntity(ObjectEntry *entry, Entit
 	
 	entity->ownsChildren = true;
 
-	entry->readNumber("bbX", &entity->bBox.x);
-	entry->readNumber("bbY", &entity->bBox.y);
-	entry->readNumber("bbZ", &entity->bBox.z);
-
+    Vector3 bBox;
+	entry->readNumber("bbX", &bBox.x);
+	entry->readNumber("bbY", &bBox.y);
+	entry->readNumber("bbZ", &bBox.z);
+    entity->setLocalBoundingBox(bBox);
+    
 	entity->color.r = (*entry)["cR"]->NumberVal;
 	entity->color.g = (*entry)["cG"]->NumberVal;
 	entity->color.b = (*entry)["cB"]->NumberVal;

+ 2 - 6
Core/Contents/Source/PolySceneLabel.cpp

@@ -115,15 +115,11 @@ void SceneLabel::updateFromLabel() {
 
 	setPrimitiveOptions(type, label->getWidth()*labelScale/CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX(),label->getHeight()*labelScale/CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX());
 	
-	bBox.x = label->getWidth()*labelScale / CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX();
-	bBox.y = label->getHeight()*labelScale/ CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX();
-	bBox.z = 0.001;
-	
+    setLocalBoundingBox(label->getWidth()*labelScale / CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX(), label->getHeight()*labelScale/ CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX(), 0.001);
+    
 	if(useVertexBuffer)
 		CoreServices::getInstance()->getRenderer()->createVertexBufferForMesh(mesh);
 	
-	// TODO: resize it here	
-	bBoxRadius = label->getWidth()*labelScale/CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX();
 }
 
 void SceneLabel::Render() {

+ 1 - 2
Core/Contents/Source/PolySceneLight.cpp

@@ -45,8 +45,7 @@ SceneLight::SceneLight(int type, Scene *parentScene, Number intensity, Number co
 	this->depthWrite = false;
 	lightMesh = new Mesh(Mesh::QUAD_MESH);
 	lightMesh->createBox(0.1,0.1,0.1);
-	bBoxRadius = lightMesh->getRadius();
-	bBox = lightMesh->calculateBBox();
+	setLocalBoundingBox(lightMesh->calculateBBox());
 	shadowMapFOV = 60.0f;
 	zBufferTexture = NULL;
 	spotCamera = NULL;

+ 15 - 8
Core/Contents/Source/PolySceneMesh.cpp

@@ -55,12 +55,13 @@ SceneMesh::SceneMesh(const String& fileName) : Entity(), texture(NULL), material
 	overlayWireframe = false;
 	useGeometryHitDetection = false;
     forceMaterial = false;
+    backfaceCulled = true;
+	alphaTest = false;
 }
 
 SceneMesh::SceneMesh(Mesh *mesh) : Entity(), texture(NULL), material(NULL), skeleton(NULL), localShaderOptions(NULL) {
 	this->mesh = mesh;
-	bBoxRadius = mesh->getRadius();
-	bBox = mesh->calculateBBox();
+	setLocalBoundingBox(mesh->calculateBBox());
 	useVertexBuffer = false;
 	lineSmooth = false;
 	ownsMesh = true;
@@ -71,12 +72,13 @@ SceneMesh::SceneMesh(Mesh *mesh) : Entity(), texture(NULL), material(NULL), skel
 	overlayWireframe = false;	
 	useGeometryHitDetection = false;
     forceMaterial = false;
+    backfaceCulled = true;
+	alphaTest = false;
 }
 
 SceneMesh::SceneMesh(int meshType) : texture(NULL), material(NULL), skeleton(NULL), localShaderOptions(NULL) {
 	mesh = new Mesh(meshType);
-	bBoxRadius = mesh->getRadius();
-	bBox = mesh->calculateBBox();
+	setLocalBoundingBox(mesh->calculateBBox());
 	useVertexBuffer = false;	
 	lineSmooth = false;
 	ownsMesh = true;
@@ -85,12 +87,13 @@ SceneMesh::SceneMesh(int meshType) : texture(NULL), material(NULL), skeleton(NUL
 	overlayWireframe = false;
 	useGeometryHitDetection = false;
     forceMaterial = false;
+    backfaceCulled = true;
+	alphaTest = false;
 }
 
 void SceneMesh::setMesh(Mesh *mesh) {
 	this->mesh = mesh;
-	bBoxRadius = mesh->getRadius();
-	bBox = mesh->calculateBBox();
+	setLocalBoundingBox(mesh->calculateBBox());
 	useVertexBuffer = false;	
 }
 
@@ -117,6 +120,8 @@ void SceneMesh::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly)
     _clone->pointSize = pointSize;
     _clone->pointSmooth = pointSmooth;
     _clone->ownsMesh = ownsMesh;
+	_clone->alphaTest = alphaTest;
+	_clone->backfaceCulled = backfaceCulled;
     _clone->ownsSkeleton = ownsSkeleton;
     _clone->overlayWireframe = overlayWireframe;
     _clone->wireFrameColor = wireFrameColor;
@@ -143,8 +148,7 @@ void SceneMesh::setFilename(String fileName) {
 
 void SceneMesh::loadFromFile(String fileName) {
 	mesh = new Mesh(fileName);
-	bBoxRadius = mesh->getRadius();
-	bBox = mesh->calculateBBox();
+	setLocalBoundingBox(mesh->calculateBBox());
     this->fileName = fileName;
 }
 
@@ -343,6 +347,9 @@ void SceneMesh::Render() {
 	
 	Renderer *renderer = CoreServices::getInstance()->getRenderer();
 	
+    renderer->enableAlphaTest(alphaTest);
+	renderer->enableBackfaceCulling(backfaceCulled);
+    
 	renderer->setLineSize(lineWidth);
 	renderer->setLineSmooth(lineSmooth);
 	renderer->setPointSize(pointSize);

+ 14 - 34
Core/Contents/Source/PolyScenePrimitive.cpp

@@ -66,63 +66,43 @@ void ScenePrimitive::recreatePrimitive() {
 	switch(type) {
 		case TYPE_PLANE:
 			mesh->createPlane(v1,v2);
-			bBox.x = v1;
-			bBox.y = 0.001;
-			bBox.z = v2;
+            setLocalBoundingBox(v1, 0.001, v2);
 		break;
 		case TYPE_VPLANE:
 			mesh->createVPlane(v1,v2);
-			bBox.x = v1;
-			bBox.y = v2;
-			bBox.z = 0.001;
-		break;		
+            setLocalBoundingBox(v1, v2, 0.001);
+		break;
 		case TYPE_BOX:
 			mesh->createBox(v1,v2,v3);
-			bBox.x = v1;
-			bBox.y = v2;
-			bBox.z = v3;			
+            setLocalBoundingBox(v1, v2, v3);
 		break;
 		case TYPE_SPHERE:
 			mesh->createSphere(v1,v2,v3);
-			bBox.x = v1*2;
-			bBox.y = v1*2;
-			bBox.z = v1*2;						
+            setLocalBoundingBox(v1*2, v1*2, v1*2);
 		break;
 		case TYPE_CYLINDER:
 			mesh->createCylinder(v1,v2,v3);
-			bBox.x = v2*2;
-			bBox.y = v1;
-			bBox.z = v2*2;						
+            setLocalBoundingBox(v2*2, v1, v2*2);
 		break;
 		case TYPE_UNCAPPED_CYLINDER:
 			mesh->createCylinder(v1,v2,v3, false);
-			bBox.x = v2*2;
-			bBox.y = v1;
-			bBox.z = v2*2;						
-		break;						
+            setLocalBoundingBox(v2*2, v1, v2*2);
+		break;
 		case TYPE_CONE:
 			mesh->createCone(v1,v2,v3);
-			bBox.x = v2*2;
-			bBox.y = v1;
-			bBox.z = v2*2;						
-		break;				
+            setLocalBoundingBox(v2*2, v1, v2*2);
+		break;
 		case TYPE_TORUS:
 			mesh->createTorus(v1,v2,v3,v4);
-			bBox.x = (v1*2) + (v2*2);
-			bBox.y = v2 * 2;
-			bBox.z = (v1*2) + (v2*2);
-		break;						
+            setLocalBoundingBox((v1*2) + (v2*2), v2 * 2, (v1*2) + (v2*2));
+		break;
 		case TYPE_CIRCLE:
 			mesh->createCircle(v1, v2, v3);
-			bBox.x = v1;
-			bBox.y = v2;
-			bBox.z = 0.001;
+            setLocalBoundingBox(v1, v2, 0.001);
 		break;
 		case TYPE_LINE_CIRCLE:
 			mesh->createLineCircle(v1, v2, v3);
-			bBox.x = v1;
-			bBox.y = v2;
-			bBox.z = 0.001;
+            setLocalBoundingBox(v1, v2, 0.001);
         break;
 	}
 }

+ 47 - 0
Core/Contents/Source/PolyVector4.cpp

@@ -0,0 +1,47 @@
+/*
+ Copyright (C) 2011 by Ivan Safrin
+ 
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+ 
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+
+#include "PolyVector4.h"
+
+using namespace Polycode;
+
+Vector4::Vector4() : x(0),y(0),z(0), w(0){
+}
+
+void Vector4::set(Number x, Number y, Number z, Number w) {
+	this->x = x;
+	this->y = y;
+	this->z = z;
+	this->w = w;
+}
+
+Vector4::Vector4(Number x,Number y,Number z, Number w) {
+	set(x, y, z, w);
+}
+
+Vector4::Vector4(Number val) {
+	set(val,val,val,val);
+}
+
+Vector4::~Vector4() {
+
+}

+ 0 - 1
IDE/Contents/Include/PolycodeMeshEditor.h

@@ -59,7 +59,6 @@ class PolycodeMeshEditor : public PolycodeEditor {
 		UIComboBox *materialDropDown;
 		UIRect *headerBg;
 		
-		UIHSlider *lightsSlider;
 		TrackballCamera *trackballCamera;
 
 };

+ 2 - 0
IDE/Contents/Source/EditorGrid.cpp

@@ -200,6 +200,8 @@ void EditorGrid::rebuildGrid() {
     zLine->setStart(Vector3(0.0, 0.0, gridSize * gridLen * 0.5));
     zLine->setEnd(Vector3(0.0, 0.0, gridSize * gridLen * -0.5));
     
+    grid->setLocalBoundingBox(gridSize * gridLen, 0.0, gridSize * gridLen);
+    
     grid->cacheToVertexBuffer(true);
 }
 

+ 7 - 7
IDE/Contents/Source/PolycodeEntityEditor.cpp

@@ -218,7 +218,7 @@ CameraPreviewWindow::CameraPreviewWindow() : UIElement() {
     scene = NULL;
     renderTexture = NULL;
     
-    bBox = bgRect->bBox;
+    setLocalBoundingBox(bgRect->getLocalBoundingBox());
     pinned = false;
     cameraSelected = false;
     
@@ -322,13 +322,13 @@ EntityEditorMainView::EntityEditorMainView(PolycodeEditor *editor) {
     // setup custom lights for disabled lighting
     customLight1 = new SceneLight(SceneLight::POINT_LIGHT, mainScene,999999, customFalloff, customFalloff, customFalloff);
     customLight1->editorOnly = true;
-    customLight1->setPosition(9999, 9999, 9999);
+    customLight1->setPosition(-9999, 9999, 9999);
     mainScene->addLight(customLight1);
     customLight1->enabled = false;
 
     customLight2 = new SceneLight(SceneLight::POINT_LIGHT, mainScene,999999, customFalloff, customFalloff, customFalloff);
     customLight2->editorOnly = true;
-    customLight2->setPosition(-9999, -9999, -9999);
+    customLight2->setPosition(8999, -8999, -8999);
     mainScene->addLight(customLight2);
     customLight2->enabled = false;
     
@@ -846,7 +846,7 @@ void EntityEditorMainView::addEntityFromMenu(String command) {
     
     if(command == "add_particles") {
         SceneParticleEmitter  *newEmitter = new SceneParticleEmitter(30, 3.0, 0.2);
-        newEmitter->bBox = Vector3(0.5, 0.5, 0.5);
+        newEmitter->setLocalBoundingBox(0.5, 0.5, 0.5);
         
         newEmitter->setParticleType(SceneParticleEmitter::PARTICLE_TYPE_QUAD);
         
@@ -1800,9 +1800,9 @@ void PolycodeEntityEditor::saveEntityToObjectEntry(Entity *entity, ObjectEntry *
     entry->addChild("pY", entity->getPosition().y);
     entry->addChild("pZ", entity->getPosition().z);
     
-    entry->addChild("bbX", entity->bBox.x);
-    entry->addChild("bbY", entity->bBox.y);
-    entry->addChild("bbZ", entity->bBox.z);
+    entry->addChild("bbX", entity->getLocalBoundingBox().x);
+    entry->addChild("bbY", entity->getLocalBoundingBox().y);
+    entry->addChild("bbZ", entity->getLocalBoundingBox().z);
     
     ObjectEntry *children = NULL;
     

+ 4 - 0
IDE/Contents/Source/PolycodeIDEApp.cpp

@@ -102,6 +102,10 @@ PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() {
 			
 	
 	Scene *screen = new Scene(Scene::SCENE_2D_TOPLEFT);
+    
+    screen->doVisibilityChecking(false);
+    screen->getDefaultCamera()->frustumCulling = false;
+    
     globalScene = screen;
     
 	screen->rootEntity.processInputEvents = true;

+ 8 - 26
IDE/Contents/Source/PolycodeMeshEditor.cpp

@@ -34,13 +34,15 @@ PolycodeMeshEditor::PolycodeMeshEditor() : PolycodeEditor(true){
 	
 //	previewScene->ambientColor.setColor(0.0, 0.0, 0.0, 1.0);
 				
-	mainLight = new SceneLight(SceneLight::POINT_LIGHT, previewScene, 1590.0);
-	mainLight->setPosition(-10,10,10);
+    Number customFalloff = 0.006;
+	mainLight = new SceneLight(SceneLight::POINT_LIGHT, previewScene, 999999, customFalloff, customFalloff, customFalloff);
 	previewScene->addLight(mainLight);
 
-	secondLight = new SceneLight(SceneLight::POINT_LIGHT, previewScene, 1590.0);
-	secondLight->setPosition(10,-10,10);
+	secondLight = new SceneLight(SceneLight::POINT_LIGHT, previewScene, 999999, customFalloff, customFalloff, customFalloff);
 	previewScene->addLight(secondLight);
+    
+	mainLight->setPosition(9999, 9999, 9999);
+	secondLight->setPosition(-9999, -9999, -9999);
 
 	headerBg = new UIRect(10,10);
 	addChild(headerBg);
@@ -62,17 +64,6 @@ PolycodeMeshEditor::PolycodeMeshEditor() : PolycodeEditor(true){
 	addChild(materialDropDown);
 	materialDropDown->setPosition(100, 3);
 
-	label = new UILabel("LIGHTS", 18, "section", Label::ANTIALIAS_FULL);
-	label->color.setColorHexFromString(CoreServices::getInstance()->getConfig()->getStringValue("Polycode", "uiHeaderFontColor"));
-	addChild(label);
-	label->setPosition(320, 3);
-
-	lightsSlider = new UIHSlider(0.0, 5000, 200);
-	addChild(lightsSlider);
-	lightsSlider->setSliderValue(1000.0);
-	lightsSlider->setPosition(380, 8);	
-	lightsSlider->addEventListener(this, UIEvent::CHANGE_EVENT);
-	
 	reloadMaterials();
 
 	previewBase = new Entity();
@@ -110,10 +101,7 @@ void PolycodeMeshEditor::reloadMaterials() {
 
 void PolycodeMeshEditor::handleEvent(Event *event) {
 	
-	if(event->getDispatcher() == lightsSlider) {
-		mainLight->setIntensity(lightsSlider->getSliderValue());
-		secondLight->setIntensity(lightsSlider->getSliderValue());		
-	} else if(event->getDispatcher() == materialDropDown) {
+    if(event->getDispatcher() == materialDropDown) {
 		if(previewMesh) {
 			previewMesh->setMaterial((Material*)materialDropDown->getSelectedItem()->data);
 		}
@@ -123,7 +111,6 @@ void PolycodeMeshEditor::handleEvent(Event *event) {
 }
 
 PolycodeMeshEditor::~PolycodeMeshEditor() {
-    printf("CALLED IT!\n");
     CoreServices::getInstance()->getResourceManager()->getGlobalPool()->removeAllHandlersForListener(this);
 }
 
@@ -135,13 +122,8 @@ bool PolycodeMeshEditor::openFile(OSFileEntry filePath) {
 
 	previewMesh->alphaTest = true;
 	CoreServices::getInstance()->getRenderer()->alphaTestValue = 0.9;
-	
-	Number radius = previewMesh->getBBoxRadius();
 				
-	mainLight->setPosition(-(radius*3),(radius*3),(radius*3));
-	secondLight->setPosition((radius*3),-(radius*3),(radius*3));
-	
-	trackballCamera->setCameraDistance(radius*3);
+	trackballCamera->setCameraDistance(previewMesh->getLocalBoundingBox().x);
 	return true;
 }
 

+ 1 - 6
IDE/Contents/Source/PolycodeProps.cpp

@@ -1347,12 +1347,7 @@ void SceneEntityInstanceProp::set(String fileName) {
 		previewInstance->setPosition(2, 1);
 		
 		lastData = currentData;
-		currentData = fileName;
-		
-		Number radius = previewInstance->getCompoundBBoxRadius();
-		if(radius > 48) {
-			previewInstance->setScale(48.0/(radius*2.0), 48.0/(radius*2.0));		
-		}
+		currentData = fileName;		
 		
 		propContents->addChild(previewInstance);	
 	}

+ 3 - 3
IDE/Contents/Source/TransformGizmo.cpp

@@ -296,7 +296,7 @@ TransformGizmo::TransformGizmo(Scene *targetScene, Camera *targetCamera) : Entit
     viewportRotateGrip->visible = false;
 
 	xTransformGrip = new Entity();
-	xTransformGrip->bBox.set(1.3, 0.1, 0.1);
+	xTransformGrip->setLocalBoundingBox(1.3, 0.1, 0.1);
     xTransformGrip->depthTest = false;
     xTransformGrip->setColor(1.0, 0.0, 0.0, 1.0);
 	addChild(xTransformGrip);
@@ -305,14 +305,14 @@ TransformGizmo::TransformGizmo(Scene *targetScene, Camera *targetCamera) : Entit
 	xTransformGrip->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
 
 	yTransformGrip = new Entity();
-	yTransformGrip->bBox.set(0.1, 1.3, 0.1);
+	yTransformGrip->setLocalBoundingBox(0.1, 1.3, 0.1);
 	addChild(yTransformGrip);
 	yTransformGrip->setAnchorPoint(Vector3(0.0, -1.0, 0.0));
 	yTransformGrip->processInputEvents = true;
 	yTransformGrip->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
 
 	zTransformGrip = new Entity();
-	zTransformGrip->bBox.set(0.1, 0.1, 1.3);
+	zTransformGrip->setLocalBoundingBox(0.1, 0.1, 1.3);
 	addChild(zTransformGrip);
 	zTransformGrip->setAnchorPoint(Vector3(0.0, 0.0, -1.0));
 	zTransformGrip->processInputEvents = true;

+ 1 - 1
Modules/Contents/3DPhysics/Source/PolyCollisionSceneEntity.cpp

@@ -88,7 +88,7 @@ btCollisionShape *CollisionEntity::createCollisionShape(Entity *entity, int type
 	btCollisionShape *collisionShape = NULL;	
 	
     Vector3 scale = entity->getCompoundScale();
-    Vector3 bBox = entity->bBox;// * scale;
+    Vector3 bBox = entity->getLocalBoundingBox();// * scale;
 	
     Number largestSize = bBox.x;
     if(bBox.y > largestSize) {

+ 1 - 1
Modules/Contents/UI/Include/PolyUIComboBox.h

@@ -74,7 +74,7 @@ namespace Polycode {
 			std::vector<UIComboBoxItem*> items;
 			int selectedIndex;
 			
-			SceneLabel *selectedLabel;
+			UILabel *selectedLabel;
 			Number comboHeight;
 			Number comboWidth;
 			Number dropDownX;

+ 1 - 1
Modules/Contents/UI/Source/PolyUIComboBox.cpp

@@ -77,7 +77,7 @@ UIComboBox::UIComboBox(UIGlobalMenu *globalMenu, Number comboWidth) : UIElement(
 	addChild(bgBox);
 	addChild(dropDownImage);
 	
-	selectedLabel = new SceneLabel("<None>", fontSize, fontName);
+	selectedLabel = new UILabel("<None>", fontSize, fontName);
     selectedLabel->setBlendingMode(Renderer::BLEND_MODE_NORMAL);
 	selectedLabel->setPosition(paddingX, paddingY);
 	addChild(selectedLabel);

+ 2 - 2
Modules/Contents/UI/Source/PolyUIElement.cpp

@@ -41,12 +41,12 @@ UILabel::UILabel(const String& text, int size, const String& fontName, int amode
 	
 	color.setColorHexFromString(conf->getStringValue("Polycode", "uiDefaultFontColor"));
 	addChild(label);
-	bBox = label->bBox;
+	setLocalBoundingBox(label->getLocalBoundingBox());
 }
 
 void UILabel::setText(const String& text) {
 	label->setText(text);
-	bBox = label->bBox;	
+    setLocalBoundingBox(label->getLocalBoundingBox());
 }
 
 String UILabel::getText() {

+ 1 - 1
Modules/Contents/UI/Source/PolyUIIconSelector.cpp

@@ -102,7 +102,7 @@ void UIIconSelector::resetSize() {
     setWidth((paddingX*2)+innerSize);
     setHeight((paddingY*2)+selectorSize);
     
-    bgRect->resizeBox(bBox.x, bBox.y);
+    bgRect->resizeBox(getWidth(), getHeight());
 }
 
 UIIconSelector::~UIIconSelector() {