[Bf-blender-cvs] [8cc925a] master: Cycles Standalone: The camera now gets properly updated, when changing window size or using --width --height overwrites.

Thomas Dinges noreply at git.blender.org
Fri Feb 14 18:40:57 CET 2014


Commit: 8cc925a21664698fd88bdd58db93ae5bd922cec3
Author: Thomas Dinges
Date:   Fri Feb 14 18:40:31 2014 +0100
https://developer.blender.org/rB8cc925a21664698fd88bdd58db93ae5bd922cec3

Cycles Standalone: The camera now gets properly updated, when changing window size or using --width --height overwrites.

===================================================================

M	intern/cycles/app/cycles_standalone.cpp
M	intern/cycles/app/cycles_xml.cpp
M	intern/cycles/render/camera.cpp
M	intern/cycles/render/camera.h

===================================================================

diff --git a/intern/cycles/app/cycles_standalone.cpp b/intern/cycles/app/cycles_standalone.cpp
index 2308338..3ec92a2 100644
--- a/intern/cycles/app/cycles_standalone.cpp
+++ b/intern/cycles/app/cycles_standalone.cpp
@@ -114,15 +114,25 @@ static void session_init()
 	options.scene = NULL;
 }
 
-static void scene_init(int width, int height)
+static void scene_init()
 {
 	options.scene = new Scene(options.scene_params, options.session_params.device);
+
+	/* Read XML */
 	xml_read_file(options.scene, options.filepath.c_str());
 
-	if (width == 0 || height == 0) {
+	/* Camera width/height override? */
+	if (!(options.width == 0 || options.height == 0)) {
+		options.scene->camera->width = options.width;
+		options.scene->camera->height = options.height;
+	}
+	else {
 		options.width = options.scene->camera->width;
 		options.height = options.scene->camera->height;
 	}
+
+	/* Calculate Viewplane */
+	options.scene->camera->compute_auto_viewplane();
 }
 
 static void session_exit()
@@ -216,8 +226,16 @@ static void resize(int width, int height)
 	options.width = width;
 	options.height = height;
 
-	if(options.session)
+	if(options.session) {
+		/* Update camera */
+		options.session->scene->camera->width = width;
+		options.session->scene->camera->height = height;
+		options.session->scene->camera->compute_auto_viewplane();
+		options.session->scene->camera->need_update = true;
+		options.session->scene->camera->need_device_update = true;
+
 		options.session->reset(session_buffer_params(), options.session_params.samples);
+	}
 }
 
 static void keyboard(unsigned char key)
@@ -360,12 +378,12 @@ static void options_parse(int argc, const char **argv)
 		fprintf(stderr, "No file path specified\n");
 		exit(EXIT_FAILURE);
 	}
-	
+
 	/* For smoother Viewport */
 	options.session_params.start_resolution = 64;
 
 	/* load scene */
-	scene_init(options.width, options.height);
+	scene_init();
 }
 
 CCL_NAMESPACE_END
diff --git a/intern/cycles/app/cycles_xml.cpp b/intern/cycles/app/cycles_xml.cpp
index 14fe431..f30e399 100644
--- a/intern/cycles/app/cycles_xml.cpp
+++ b/intern/cycles/app/cycles_xml.cpp
@@ -289,21 +289,6 @@ static void xml_read_camera(const XMLReadState& state, pugi::xml_node node)
 	xml_read_int(&cam->width, node, "width");
 	xml_read_int(&cam->height, node, "height");
 
-	float aspect = (float)cam->width/(float)cam->height;
-
-	if(cam->width >= cam->height) {
-		cam->viewplane.left = -aspect;
-		cam->viewplane.right = aspect;
-		cam->viewplane.bottom = -1.0f;
-		cam->viewplane.top = 1.0f;
-	}
-	else {
-		cam->viewplane.left = -1.0f;
-		cam->viewplane.right = 1.0f;
-		cam->viewplane.bottom = -1.0f/aspect;
-		cam->viewplane.top = 1.0f/aspect;
-	}
-
 	if(xml_read_float(&cam->fov, node, "fov"))
 		cam->fov *= M_PI/180.0f;
 
@@ -333,7 +318,6 @@ static void xml_read_camera(const XMLReadState& state, pugi::xml_node node)
 	xml_read_float(&cam->sensorwidth, node, "sensorwidth");
 	xml_read_float(&cam->sensorheight, node, "sensorheight");
 
-
 	cam->matrix = state.tfm;
 
 	cam->need_update = true;
diff --git a/intern/cycles/render/camera.cpp b/intern/cycles/render/camera.cpp
index edf7f7f..d2e2a22 100644
--- a/intern/cycles/render/camera.cpp
+++ b/intern/cycles/render/camera.cpp
@@ -78,6 +78,24 @@ Camera::~Camera()
 {
 }
 
+void Camera::compute_auto_viewplane()
+{
+	float aspect = (float)width/(float)height;
+
+	if(width >= height) {
+		viewplane.left = -aspect;
+		viewplane.right = aspect;
+		viewplane.bottom = -1.0f;
+		viewplane.top = 1.0f;
+	}
+	else {
+		viewplane.left = -1.0f;
+		viewplane.right = 1.0f;
+		viewplane.bottom = -1.0f/aspect;
+		viewplane.top = 1.0f/aspect;
+	}
+}
+
 void Camera::update()
 {
 	if(!need_update)
diff --git a/intern/cycles/render/camera.h b/intern/cycles/render/camera.h
index 4e8f3d7..c28670b 100644
--- a/intern/cycles/render/camera.h
+++ b/intern/cycles/render/camera.h
@@ -102,6 +102,8 @@ public:
 	/* functions */
 	Camera();
 	~Camera();
+	
+	void compute_auto_viewplane();
 
 	void update();




More information about the Bf-blender-cvs mailing list