Cycles Standalone: The camera now gets properly updated, when changing window size...
authorThomas Dinges <blender@dingto.org>
Fri, 14 Feb 2014 17:40:31 +0000 (18:40 +0100)
committerThomas Dinges <blender@dingto.org>
Fri, 14 Feb 2014 17:40:31 +0000 (18:40 +0100)
intern/cycles/app/cycles_standalone.cpp
intern/cycles/app/cycles_xml.cpp
intern/cycles/render/camera.cpp
intern/cycles/render/camera.h

index 230833802b0fbf9138fe161da5fdacb9a8306930..3ec92a2aa00b4c3f75ae6563e10cd153fb7da1e5 100644 (file)
@@ -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
index 14fe43115d53fe33ece2b212a1bcf2afba87bbc6..f30e399350a3d376afa72e685cff36c6fac6175b 100644 (file)
@@ -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;
index edf7f7fb09d061010ed49efa4afa2e61c1e44141..d2e2a220861fecafc6199b1d574d9274ef05884b 100644 (file)
@@ -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)
index 4e8f3d721115db0790ea0ba2861722d71be955d8..c28670bc55f14c8e6a98c0a6f85e49bc55858b8d 100644 (file)
@@ -102,6 +102,8 @@ public:
        /* functions */
        Camera();
        ~Camera();
+       
+       void compute_auto_viewplane();
 
        void update();