From 2b018673509fe7a38a6332fae00bd605335bd286 Mon Sep 17 00:00:00 2001 From: Matt Ebb Date: Thu, 15 Apr 2010 04:56:44 +0000 Subject: Fix [#22029] Camera in degree mode doesn't update Removed the camera->angle from DNA, now it just uses RNA to handle the conversions. Really need to convert this to physical units at some point... :/ --- source/blender/blenkernel/BKE_object.h | 3 +++ source/blender/blenkernel/intern/object.c | 12 ++++++++++- source/blender/blenlib/intern/uvproject.c | 2 +- source/blender/blenloader/intern/readfile.c | 4 ---- source/blender/makesdna/DNA_camera_types.h | 4 +++- source/blender/makesrna/intern/rna_camera.c | 31 ++++++++++------------------- 6 files changed, 29 insertions(+), 27 deletions(-) diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index 065d747a959..9930ad175a7 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -77,6 +77,9 @@ void *add_camera(char *name); struct Camera *copy_camera(struct Camera *cam); void make_local_camera(struct Camera *cam); float dof_camera(struct Object *ob); +float camera_get_angle(struct Camera *cam); +void camera_set_angle(struct Camera *cam, float angle); + void *add_lamp(char *name); struct Lamp *copy_lamp(struct Lamp *la); void make_local_lamp(struct Lamp *la); diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index ef630a18ab4..f05239057b9 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -679,7 +679,6 @@ void *add_camera(char *name) cam= alloc_libblock(&G.main->camera, ID_CA, name); cam->lens= 35.0f; - cam->angle= 49.14f; cam->clipsta= 0.1f; cam->clipend= 100.0f; cam->drawsize= 0.5f; @@ -774,6 +773,17 @@ float dof_camera(Object *ob) return cam->YF_dofdist; } +/* angle in radians */ +float camera_get_angle(Camera *cam) +{ + return 2.f * atan(16.0f/cam->lens); +} + +void camera_set_angle(Camera *cam, float angle) +{ + cam->lens = 16.0f / tan(angle * 0.5f); +} + void *add_lamp(char *name) { Lamp *la; diff --git a/source/blender/blenlib/intern/uvproject.c b/source/blender/blenlib/intern/uvproject.c index 0e7c36886ce..51e2269326a 100644 --- a/source/blender/blenlib/intern/uvproject.c +++ b/source/blender/blenlib/intern/uvproject.c @@ -135,7 +135,7 @@ UvCameraInfo *project_camera_info(Object *ob, float (*rotmat)[4], float winx, fl uci.do_pano = (camera->flag & CAM_PANORAMA); uci.do_persp = (camera->type==CAM_PERSP); - uci.camangle= DEG2RAD(camera->angle)/2.0f; + uci.camangle= DEG2RAD(camera_get_angle(camera))/2.0f; uci.camsize= uci.do_persp ? uci.camsize= tanf(uci.camangle) : camera->ortho_scale; if (invert_m4_m4(uci.caminv, ob->obmat)) { diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 12ae08089da..2039681b1f2 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -8437,10 +8437,6 @@ static void do_versions(FileData *fd, Library *lib, Main *main) Object *ob= main->object.first; Camera *cam = main->camera.first; Material *ma; - - for(; cam; cam= cam->id.next) { - cam->angle= 360.0f * (float)atan(16.0f/cam->lens) / (float)M_PI; - } for(ma=main->mat.first; ma; ma= ma->id.next) { if(ma->sss_scale==0.0f) { diff --git a/source/blender/makesdna/DNA_camera_types.h b/source/blender/makesdna/DNA_camera_types.h index a15f9a4eb4c..3b16a16c2b5 100644 --- a/source/blender/makesdna/DNA_camera_types.h +++ b/source/blender/makesdna/DNA_camera_types.h @@ -46,11 +46,13 @@ typedef struct Camera { struct AnimData *adt; /* animation data (must be immediately after id for utilities to use it) */ short type, flag; - float passepartalpha, angle; + float passepartalpha; float clipsta, clipend; float lens, ortho_scale, drawsize; float shiftx, shifty; + float pad; + /* yafray: dof params */ /* qdn: yafray var 'YF_dofdist' now enabled for defocus composit node as well. The name was not changed so that no other files need to be modified */ diff --git a/source/blender/makesrna/intern/rna_camera.c b/source/blender/makesrna/intern/rna_camera.c index c4dc461ad38..5ffac4e270e 100644 --- a/source/blender/makesrna/intern/rna_camera.c +++ b/source/blender/makesrna/intern/rna_camera.c @@ -36,29 +36,20 @@ #ifdef RNA_RUNTIME -static void rna_Camera_angle_update(Main *bmain, Scene *scene, PointerRNA *ptr) -{ - Camera *cam= (Camera*)ptr->id.data; - cam->lens = 16.0f / tan(M_PI*cam->angle/360.0f); -} - -static void rna_Camera_lens_update(Main *bmain, Scene *scene, PointerRNA *ptr) -{ - Camera *cam= (Camera*)ptr->id.data; - cam->angle= 360.0f * atan(16.0f/cam->lens) / M_PI; -} +#include "BKE_object.h" /* only for rad/deg conversion! can remove later */ static float rna_Camera_angle_get(PointerRNA *ptr) { Camera *cam= ptr->id.data; - return cam->angle * (M_PI / 180.0); + + return camera_get_angle(cam); } static void rna_Camera_angle_set(PointerRNA *ptr, float value) { Camera *cam= ptr->id.data; - cam->angle= value * (180.0 / M_PI); + camera_set_angle(cam, value); } #else @@ -93,12 +84,6 @@ void RNA_def_camera(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Passepartout Alpha", "Opacity (alpha) of the darkened overlay in Camera view"); RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL); - prop= RNA_def_property(srna, "angle", PROP_FLOAT, PROP_ANGLE); - RNA_def_property_range(prop, M_PI * (0.367/180.0), M_PI * (172.847/180.0)); - RNA_def_property_ui_text(prop, "Angle", "Perspective Camera lens field of view in degrees"); - RNA_def_property_float_funcs(prop, "rna_Camera_angle_get", "rna_Camera_angle_set", NULL); /* only for deg/rad conversion */ - RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_angle_update"); - prop= RNA_def_property(srna, "clip_start", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "clipsta"); RNA_def_property_range(prop, 0.0f, FLT_MAX); @@ -115,7 +100,13 @@ void RNA_def_camera(BlenderRNA *brna) RNA_def_property_float_sdna(prop, NULL, "lens"); RNA_def_property_range(prop, 1.0f, 5000.0f); RNA_def_property_ui_text(prop, "Lens", "Perspective Camera lens value in millimeters"); - RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_lens_update"); + RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL); + + prop= RNA_def_property(srna, "angle", PROP_FLOAT, PROP_ANGLE); + RNA_def_property_range(prop, M_PI * (0.367/180.0), M_PI * (172.847/180.0)); + RNA_def_property_ui_text(prop, "Angle", "Perspective Camera lens field of view in degrees"); + RNA_def_property_float_funcs(prop, "rna_Camera_angle_get", "rna_Camera_angle_set", NULL); /* only for deg/rad conversion */ + RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL); prop= RNA_def_property(srna, "ortho_scale", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "ortho_scale"); -- cgit v1.2.3