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

This commit is contained in:
Thomas Dinges 2014-02-14 18:40:31 +01:00
parent 2bf591762a
commit 8cc925a216
4 changed files with 43 additions and 21 deletions

@ -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,9 +226,17 @@ 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)
{
@ -365,7 +383,7 @@ static void options_parse(int argc, const char **argv)
options.session_params.start_resolution = 64;
/* load scene */
scene_init(options.width, options.height);
scene_init();
}
CCL_NAMESPACE_END

@ -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;

@ -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)

@ -103,6 +103,8 @@ public:
Camera();
~Camera();
void compute_auto_viewplane();
void update();
void device_update(Device *device, DeviceScene *dscene, Scene *scene);