Explorar o código

Added a way to switch cameras in a scene

Ivan Safrin %!s(int64=14) %!d(string=hai) anos
pai
achega
5f7eea2457

+ 16 - 0
Bindings/Contents/LUA/API/Polycode/Scene.lua

@@ -97,6 +97,22 @@ function Scene:getDefaultCamera()
 	end
 	end
 end
 end
 
 
+function Scene:getActiveCamera()
+	local retVal =  Polycore.Scene_getActiveCamera(self.__ptr)
+	if retVal == nil then return nil end
+	if Polycore.__ptr_lookup[retVal] ~= nil then
+		return Polycore.__ptr_lookup[retVal]
+	else
+		Polycore.__ptr_lookup[retVal] = Camera("__skip_ptr__")
+		Polycore.__ptr_lookup[retVal].__ptr = retVal
+		return Polycore.__ptr_lookup[retVal]
+	end
+end
+
+function Scene:setActiveCamera(camera)
+	local retVal = Polycore.Scene_setActiveCamera(self.__ptr, camera.__ptr)
+end
+
 function Scene:enableLighting(enable)
 function Scene:enableLighting(enable)
 	local retVal = Polycore.Scene_enableLighting(self.__ptr, enable)
 	local retVal = Polycore.Scene_enableLighting(self.__ptr, enable)
 end
 end

+ 21 - 0
Bindings/Contents/LUA/Include/PolycodeLUAWrappers.h

@@ -7096,6 +7096,27 @@ static int Polycore_Scene_getDefaultCamera(lua_State *L) {
 	return 1;
 	return 1;
 }
 }
 
 
+static int Polycore_Scene_getActiveCamera(lua_State *L) {
+	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
+	Scene *inst = (Scene*)lua_topointer(L, 1);
+	void *ptrRetVal = (void*)inst->getActiveCamera();
+	if(ptrRetVal == NULL) {
+		lua_pushnil(L);
+	} else {
+		lua_pushlightuserdata(L, ptrRetVal);
+	}
+	return 1;
+}
+
+static int Polycore_Scene_setActiveCamera(lua_State *L) {
+	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
+	Scene *inst = (Scene*)lua_topointer(L, 1);
+	luaL_checktype(L, 2, LUA_TLIGHTUSERDATA);
+	Camera* camera = (Camera*)lua_topointer(L, 2);
+	inst->setActiveCamera(camera);
+	return 0;
+}
+
 static int Polycore_Scene_enableLighting(lua_State *L) {
 static int Polycore_Scene_enableLighting(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	Scene *inst = (Scene*)lua_topointer(L, 1);
 	Scene *inst = (Scene*)lua_topointer(L, 1);

+ 2 - 0
Bindings/Contents/LUA/Source/PolycodeLUA.cpp

@@ -748,6 +748,8 @@ int luaopen_Polycode(lua_State *L) {
 		{"Scene_addEntity", Polycore_Scene_addEntity},
 		{"Scene_addEntity", Polycore_Scene_addEntity},
 		{"Scene_removeEntity", Polycore_Scene_removeEntity},
 		{"Scene_removeEntity", Polycore_Scene_removeEntity},
 		{"Scene_getDefaultCamera", Polycore_Scene_getDefaultCamera},
 		{"Scene_getDefaultCamera", Polycore_Scene_getDefaultCamera},
+		{"Scene_getActiveCamera", Polycore_Scene_getActiveCamera},
+		{"Scene_setActiveCamera", Polycore_Scene_setActiveCamera},
 		{"Scene_enableLighting", Polycore_Scene_enableLighting},
 		{"Scene_enableLighting", Polycore_Scene_enableLighting},
 		{"Scene_enableFog", Polycore_Scene_enableFog},
 		{"Scene_enableFog", Polycore_Scene_enableFog},
 		{"Scene_setFogProperties", Polycore_Scene_setFogProperties},
 		{"Scene_setFogProperties", Polycore_Scene_setFogProperties},

+ 13 - 0
Core/Contents/Include/PolyScene.h

@@ -73,6 +73,18 @@ namespace Polycode {
 		*/				
 		*/				
 		Camera *getDefaultCamera();
 		Camera *getDefaultCamera();
 		
 		
+		/**
+		* Returns the scene's active camera.
+		* @return The scene's active camera.
+		*/						
+		Camera *getActiveCamera();
+		
+		/**
+		* Sets the scene's active camera.
+		* @param camera New camera to set as the active camera.
+		*/
+		void setActiveCamera(Camera *camera);
+		
 		/**
 		/**
 		* Enables and disables lighting in the scene.
 		* Enables and disables lighting in the scene.
 		* @param enable If false, disables lighting in the scene, if true, enables it.		
 		* @param enable If false, disables lighting in the scene, if true, enables it.		
@@ -193,6 +205,7 @@ namespace Polycode {
 		bool isSceneVirtual;
 		bool isSceneVirtual;
 		
 		
 		Camera *defaultCamera;
 		Camera *defaultCamera;
+		Camera *activeCamera;
 		std::vector <SceneEntity*> entities;
 		std::vector <SceneEntity*> entities;
 		
 		
 		bool lightingEnabled;
 		bool lightingEnabled;

+ 2 - 2
Core/Contents/Include/PolyScenePrimitive.h

@@ -70,8 +70,8 @@ namespace Polycode {
 
 
 			/**
 			/**
 			* A cylinder.
 			* A cylinder.
-			* v1 - Cylinder radius
-			* v2 - Cylinder length			
+			* v1 - Cylinder length			
+			* v2 - Cylinder radius
 			* v3 - Number of segments.
 			* v3 - Number of segments.
 			*/			
 			*/			
 			static const int TYPE_CYLINDER = 3;
 			static const int TYPE_CYLINDER = 3;

+ 10 - 2
Core/Contents/Source/PolyScene.cpp

@@ -39,6 +39,7 @@ using namespace Polycode;
 
 
 Scene::Scene() : EventDispatcher() {
 Scene::Scene() : EventDispatcher() {
 	defaultCamera = new Camera(this);
 	defaultCamera = new Camera(this);
+	activeCamera = defaultCamera;
 	CoreServices::getInstance()->getSceneManager()->addScene(this);
 	CoreServices::getInstance()->getSceneManager()->addScene(this);
 	fogEnabled = false;
 	fogEnabled = false;
 	lightingEnabled = false;
 	lightingEnabled = false;
@@ -53,6 +54,7 @@ Scene::Scene() : EventDispatcher() {
 
 
 Scene::Scene(bool virtualScene) {
 Scene::Scene(bool virtualScene) {
 	defaultCamera = new Camera(this);
 	defaultCamera = new Camera(this);
+	activeCamera = defaultCamera;	
 	fogEnabled = false;
 	fogEnabled = false;
 	lightingEnabled = false;
 	lightingEnabled = false;
 	enabled = true;
 	enabled = true;
@@ -63,7 +65,13 @@ Scene::Scene(bool virtualScene) {
 	useClearColor = false;	
 	useClearColor = false;	
 }
 }
 
 
+void Scene::setActiveCamera(Camera *camera) {
+	activeCamera = camera;
+}
 
 
+Camera *Scene::getActiveCamera() {
+	return activeCamera;
+}
 
 
 void Scene::setVirtual(bool val) {
 void Scene::setVirtual(bool val) {
 	isSceneVirtual = val;
 	isSceneVirtual = val;
@@ -145,11 +153,11 @@ Camera *Scene::getDefaultCamera() {
 
 
 void Scene::Render(Camera *targetCamera) {
 void Scene::Render(Camera *targetCamera) {
 	
 	
-	if(!targetCamera && !defaultCamera)
+	if(!targetCamera && !activeCamera)
 		return;
 		return;
 	
 	
 	if(!targetCamera)
 	if(!targetCamera)
-		targetCamera = defaultCamera;
+		targetCamera = activeCamera;
 	
 	
 	// prepare lights...
 	// prepare lights...
 	for(int i=0; i<entities.size();i++) {
 	for(int i=0; i<entities.size();i++) {

+ 2 - 2
Core/Contents/Source/PolySceneManager.cpp

@@ -88,8 +88,8 @@ void SceneManager::Update() {
 			CoreServices::getInstance()->getRenderer()->loadIdentity();
 			CoreServices::getInstance()->getRenderer()->loadIdentity();
 			Scene *scene = scenes[i];
 			Scene *scene = scenes[i];
 			scene->Update();
 			scene->Update();
-			if(scene->getDefaultCamera()->hasFilterShader()) {
-				scene->getDefaultCamera()->drawFilter();
+			if(scene->getActiveCamera()->hasFilterShader()) {
+				scene->getActiveCamera()->drawFilter();
 			} else {
 			} else {
 				scene->Render();
 				scene->Render();
 			}
 			}