diff options
-rw-r--r-- | source/blender/editors/include/ED_view3d.h | 7 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 62 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_view.c | 82 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_space.c | 2 |
4 files changed, 73 insertions, 80 deletions
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index 673a1ab265e..8ed1488c599 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -109,6 +109,7 @@ void viewvector(struct RegionView3D *rv3d, float coord[3], float vec[3]); void viewline(struct ARegion *ar, struct View3D *v3d, float mval[2], float ray_start[3], float ray_end[3]); void viewray(struct ARegion *ar, struct View3D *v3d, float mval[2], float ray_start[3], float ray_normal[3]); +void get_object_clip_range(struct Object *ob, float *lens, float *clipsta, float *clipend); int get_view3d_cliprange(struct View3D *v3d, struct RegionView3D *rv3d, float *clipsta, float *clipend); int get_view3d_viewplane(struct View3D *v3d, struct RegionView3D *rv3d, int winxi, int winyi, struct rctf *viewplane, float *clipsta, float *clipend, float *pixsize); int get_view3d_ortho(struct View3D *v3d, struct RegionView3D *rv3d); @@ -187,10 +188,10 @@ unsigned int ED_viewedit_datamask(struct bScreen *screen); /* assigning view matrix */ -void view3d_apply_mat4(float mat[][4], float *ofs, float *quat, float *dist); +void ED_view3d_from_m4(float mat[][4], float ofs[3], float quat[4], float *dist); -void view3d_apply_ob(struct Object *ob, float *ofs, float *quat, float *dist, float *lens); -void view3d_to_ob(struct RegionView3D *rv3d, struct Object *ob); +void ED_view3d_from_object(struct Object *ob, float ofs[3], float quat[4], float *dist, float *lens); +void ED_view3d_to_object(struct Object *ob, const float ofs[3], const float quat[4], const float dist); int view3d_is_ortho(struct View3D *v3d, struct RegionView3D *rv3d); diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 53d2bed996e..26eed2b8a57 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -40,6 +40,7 @@ #include "DNA_object_types.h" #include "DNA_scene_types.h" #include "DNA_camera_types.h" +#include "DNA_lamp_types.h" #include "MEM_guardedalloc.h" @@ -790,7 +791,7 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, wmEvent *event) View3D *v3d = vod->sa->spacedata.first; if(v3d->camera) { - view3d_apply_ob(v3d->camera, rv3d->ofs, rv3d->viewquat, &rv3d->dist, NULL); + ED_view3d_from_object(v3d->camera, rv3d->ofs, rv3d->viewquat, &rv3d->dist, NULL); } if(rv3d->persp==RV3D_CAMOB) { @@ -3448,3 +3449,62 @@ void view3d_persp_mat4(RegionView3D *rv3d, float mat[][4]) mul_v3_v3fl(dvec, mat[2], -rv3d->dist); sub_v3_v3v3(mat[3], dvec, rv3d->ofs); } + + +/* Gets the view trasnformation from a camera +* currently dosnt take camzoom into account +* +* The dist is not modified for this function, if NULL its assimed zero +* */ +void ED_view3d_from_m4(float mat[][4], float ofs[3], float quat[4], float *dist) +{ + /* Offset */ + if (ofs) + negate_v3_v3(ofs, mat[3]); + + /* Quat */ + if (quat) { + float imat[4][4]; + invert_m4_m4(imat, mat); + mat4_to_quat(quat, imat); + } + + if (dist) { + float nmat[3][3]; + float vec[3]; + + vec[0]= 0.0f; + vec[1]= 0.0f; + vec[2]= -(*dist); + + copy_m3_m4(nmat, mat); + normalize_m3(nmat); + + mul_m3_v3(nmat, vec);; + sub_v3_v3(ofs, vec); + } +} + + +/* object -> view */ +void ED_view3d_from_object(Object *ob, float ofs[3], float quat[4], float *dist, float *lens) +{ + ED_view3d_from_m4(ob->obmat, ofs, quat, dist); + + if (lens) { + get_object_clip_range(ob, lens, NULL, NULL); + } +} + +/* view -> object */ +void ED_view3d_to_object(Object *ob, const float ofs[3], const float quat[4], const float dist) +{ + float mat4[4][4]; + float dvec[3]= {0.0f, 0.0f, dist}; + float iviewquat[4]= {-quat[0], quat[1], quat[2], quat[3]}; + + quat_to_mat4(mat4, iviewquat); + mul_mat3_m4_v3(mat4, dvec); + sub_v3_v3v3(mat4[3], dvec, ofs); + object_apply_mat4(ob, mat4, TRUE, TRUE); +} diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index a58720034bd..5c54c32236b 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -32,9 +32,9 @@ #include "DNA_camera_types.h" -#include "DNA_lamp_types.h" #include "DNA_scene_types.h" #include "DNA_object_types.h" +#include "DNA_lamp_types.h" #include "MEM_guardedalloc.h" @@ -105,7 +105,7 @@ float *give_cursor(Scene *scene, View3D *v3d) /* Gets the lens and clipping values from a camera of lamp type object */ -static void object_lens_clip_settings(Object *ob, float *lens, float *clipsta, float *clipend) +void get_object_clip_range(Object *ob, float *lens, float *clipsta, float *clipend) { if(ob->type==OB_LAMP ) { Lamp *la = ob->data; @@ -129,51 +129,6 @@ static void object_lens_clip_settings(Object *ob, float *lens, float *clipsta, f } } - -/* Gets the view trasnformation from a camera -* currently dosnt take camzoom into account -* -* The dist is not modified for this function, if NULL its assimed zero -* */ -void view3d_apply_mat4(float mat[][4], float *ofs, float *quat, float *dist) -{ - /* Offset */ - if (ofs) - negate_v3_v3(ofs, mat[3]); - - /* Quat */ - if (quat) { - float imat[4][4]; - invert_m4_m4(imat, mat); - mat4_to_quat(quat, imat); - } - - if (dist) { - float nmat[3][3]; - float vec[3]; - - vec[0]= 0.0f; - vec[1]= 0.0f; - vec[2]= -(*dist); - - copy_m3_m4(nmat, mat); - normalize_m3(nmat); - - mul_m3_v3(nmat, vec);; - sub_v3_v3(ofs, vec); - } -} - -void view3d_apply_ob(Object *ob, float *ofs, float *quat, float *dist, float *lens) -{ - view3d_apply_mat4(ob->obmat, ofs, quat, dist); - - if (lens) { - object_lens_clip_settings(ob, lens, NULL, NULL); - } -} - - /* ****************** smooth view operator ****************** */ /* This operator is one of the 'timer refresh' ones like animation playback */ @@ -214,7 +169,7 @@ void smooth_view(bContext *C, View3D *v3d, ARegion *ar, Object *oldcamera, Objec if(lens) sms.new_lens= *lens; if (camera) { - view3d_apply_ob(camera, sms.new_ofs, sms.new_quat, &sms.new_dist, &sms.new_lens); + ED_view3d_from_object(camera, sms.new_ofs, sms.new_quat, &sms.new_dist, &sms.new_lens); sms.to_camera= 1; /* restore view3d values in end */ } @@ -239,7 +194,7 @@ void smooth_view(bContext *C, View3D *v3d, ARegion *ar, Object *oldcamera, Objec /* original values */ if (oldcamera) { sms.orig_dist= rv3d->dist; // below function does weird stuff with it... - view3d_apply_ob(oldcamera, sms.orig_ofs, sms.orig_quat, &sms.orig_dist, &sms.orig_lens); + ED_view3d_from_object(oldcamera, sms.orig_ofs, sms.orig_quat, &sms.orig_dist, &sms.orig_lens); } else { copy_v3_v3(sms.orig_ofs, rv3d->ofs); @@ -396,29 +351,6 @@ void VIEW3D_OT_smoothview(wmOperatorType *ot) /* ****************** change view operators ****************** */ -void view3d_to_ob(RegionView3D *rv3d, Object *ob) -{ - float mat3[3][3]; - float iviewquat[4]; - float dvec[3]= {0.0f, 0.0f, rv3d->dist}; - - invert_qt_qt(iviewquat, rv3d->viewquat); - normalize_qt(iviewquat); - mul_qt_v3(iviewquat, dvec); - - sub_v3_v3v3(ob->loc, dvec, rv3d->ofs); - rv3d->viewquat[0]= -rv3d->viewquat[0]; - - // quat_to_eul( ob->rot,rv3d->viewquat); // in 2.4x for xyz eulers only - quat_to_mat3(mat3, rv3d->viewquat); - object_mat3_to_rot(ob, mat3, 0); - - rv3d->viewquat[0]= -rv3d->viewquat[0]; - - ob->recalc= OB_RECALC_OB; -} - - static int view3d_setcameratoview_exec(bContext *C, wmOperator *UNUSED(op)) { View3D *v3d = CTX_wm_view3d(C); @@ -430,7 +362,7 @@ static int view3d_setcameratoview_exec(bContext *C, wmOperator *UNUSED(op)) rv3d->lpersp= rv3d->persp; } - view3d_to_ob(rv3d, v3d->camera); + ED_view3d_to_object(v3d->camera, rv3d->ofs, rv3d->viewquat, rv3d->dist); DAG_id_tag_update(&v3d->camera->id, OB_RECALC_OB); rv3d->persp = RV3D_CAMOB; @@ -1192,7 +1124,7 @@ static void obmat_to_viewmat(View3D *v3d, RegionView3D *rv3d, Object *ob, short rv3d->persp=RV3D_PERSP; rv3d->dist= 0.0; - view3d_apply_ob(v3d->camera, rv3d->ofs, NULL, NULL, &v3d->lens); + ED_view3d_from_object(v3d->camera, rv3d->ofs, NULL, NULL, &v3d->lens); smooth_view(NULL, NULL, NULL, NULL, NULL, orig_ofs, new_quat, &orig_dist, &orig_lens); // XXX rv3d->persp=RV3D_CAMOB; /* just to be polite, not needed */ @@ -1932,7 +1864,7 @@ void view3d_align_axis_to_vector(View3D *v3d, RegionView3D *rv3d, int axisidx, f copy_v3_v3(orig_ofs, rv3d->ofs); rv3d->persp= RV3D_PERSP; rv3d->dist= 0.0; - view3d_apply_ob(v3d->camera, rv3d->ofs, NULL, NULL, &v3d->lens); + ED_view3d_from_object(v3d->camera, rv3d->ofs, NULL, NULL, &v3d->lens); smooth_view(NULL, NULL, NULL, NULL, NULL, orig_ofs, new_quat, &orig_dist, &orig_lens); // XXX } else { if (rv3d->persp==RV3D_CAMOB) rv3d->persp= RV3D_PERSP; /* switch out of camera mode */ diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index 5281e152d54..c92c0d971e8 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -426,7 +426,7 @@ static void rna_RegionView3D_view_matrix_set(PointerRNA *ptr, const float *value { RegionView3D *rv3d= (RegionView3D *)(ptr->data); negate_v3_v3(rv3d->ofs, values); - view3d_apply_mat4((float (*)[4])values, rv3d->ofs, rv3d->viewquat, &rv3d->dist); + ED_view3d_from_m4((float (*)[4])values, rv3d->ofs, rv3d->viewquat, &rv3d->dist); } /* Space Image Editor */ |