Browse Source

Camera frustum is valid on first frame

Marko Pintera 11 years ago
parent
commit
6ed941be49

+ 3 - 0
BansheeCore/Include/BsCameraProxy.h

@@ -13,9 +13,12 @@ namespace BansheeEngine
 	class BS_CORE_EXPORT CameraProxy
 	{
 	public:
+		void calcWorldFrustum();
+
 		Viewport viewport;
 		Matrix4 viewMatrix;
 		Matrix4 projMatrix;
+		Matrix4 worldMatrix;
 		INT32 priority;
 		UINT64 layer;
 		bool ignoreSceneRenderables;

+ 15 - 0
BansheeCore/Source/BsCameraProxy.cpp

@@ -1 +1,16 @@
 #include "BsCameraProxy.h"
+
+namespace BansheeEngine
+{
+	void CameraProxy::calcWorldFrustum()
+	{
+		const Vector<Plane>& frustumPlanes = frustum.getPlanes();
+		Vector<Plane> worldPlanes;
+		for (auto& plane : frustumPlanes)
+		{
+			worldPlanes.push_back(worldMatrix.multiply3x4(plane));
+		}
+
+		worldFrustum = ConvexVolume(worldPlanes);
+	}
+}

+ 1 - 0
BansheeEngine/Source/BsCamera.cpp

@@ -480,6 +480,7 @@ namespace BansheeEngine
 		proxy->priority = mPriority;
 		proxy->projMatrix = getProjectionMatrix();
 		proxy->viewMatrix = getViewMatrix();
+		proxy->worldMatrix = SO()->getWorldTfrm();
 		proxy->viewport = mViewport->clone();
 		proxy->frustum = getFrustum();
 		proxy->ignoreSceneRenderables = mIgnoreSceneRenderables;

+ 4 - 9
BansheeRenderer/Source/BsBansheeRenderer.cpp

@@ -149,6 +149,8 @@ namespace BansheeEngine
 
 			std::sort(begin(cameras), end(cameras), cameraComparer);
 		}
+
+		proxy->calcWorldFrustum();
 	}
 
 	void BansheeRenderer::removeCameraProxy(CameraProxyPtr proxy)
@@ -174,15 +176,8 @@ namespace BansheeEngine
 	{
 		proxy->viewMatrix = viewMatrix;
 		proxy->worldPosition = worldPosition;
-
-		const Vector<Plane>& frustumPlanes = proxy->frustum.getPlanes();
-		Vector<Plane> worldPlanes;
-		for (auto& plane : frustumPlanes)
-		{
-			worldPlanes.push_back(worldMatrix.multiply3x4(plane));
-		}
-
-		proxy->worldFrustum = ConvexVolume(worldPlanes);
+		proxy->worldMatrix = worldMatrix;
+		proxy->calcWorldFrustum();
 	}
 
 	void BansheeRenderer::renderableRemoved(const HRenderable& renderable)