- allow RegionView3D.view_matrix to be set.
- RegionView3D.view_rotation was inverted.
- add C function view3d_settings_from_mat()
note, intentionally removed NULL checks, double checked this is ok with callers.
This commit is contained in:
Campbell Barton
2011-04-25 03:02:26 +00:00
parent 262eec84cd
commit bdbf0abe60
4 changed files with 48 additions and 20 deletions

View File

@@ -183,5 +183,11 @@ int ED_view3d_lock(struct RegionView3D *rv3d);
unsigned int ED_view3d_datamask(struct Scene *scene, struct View3D *v3d);
unsigned int ED_viewedit_datamask(struct bScreen *screen);
/* assigning view matrix */
void view3d_settings_from_mat(float mat[][4], float *ofs, float *quat, float *dist);
void view3d_settings_from_ob(struct Object *ob, float *ofs, float *quat, float *dist, float *lens);
int view3d_is_ortho(struct View3D *v3d, struct RegionView3D *rv3d);
#endif /* ED_VIEW3D_H */

View File

@@ -147,10 +147,6 @@ void VIEW3D_OT_select_circle(struct wmOperatorType *ot);
void VIEW3D_OT_select_border(struct wmOperatorType *ot);
void VIEW3D_OT_select_lasso(struct wmOperatorType *ot);
/* view3d_view.c */
void view3d_settings_from_ob(struct Object *ob, float *ofs, float *quat, float *dist, float *lens);
int view3d_is_ortho(View3D *v3d, RegionView3D *rv3d);
void VIEW3D_OT_smoothview(struct wmOperatorType *ot);
void VIEW3D_OT_setcameratoview(struct wmOperatorType *ot);
void VIEW3D_OT_object_as_camera(struct wmOperatorType *ot);

View File

@@ -106,9 +106,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)
{
if (!ob) return;
{
if(ob->type==OB_LAMP ) {
Lamp *la = ob->data;
if (lens) {
@@ -137,39 +135,42 @@ static void object_lens_clip_settings(Object *ob, float *lens, float *clipsta, f
*
* The dist is not modified for this function, if NULL its assimed zero
* */
void view3d_settings_from_ob(Object *ob, float *ofs, float *quat, float *dist, float *lens)
void view3d_settings_from_mat(float mat[][4], float *ofs, float *quat, float *dist)
{
if (!ob) return;
/* Offset */
if (ofs)
negate_v3_v3(ofs, ob->obmat[3]);
negate_v3_v3(ofs, mat[3]);
/* Quat */
if (quat) {
float imat[4][4];
invert_m4_m4(imat, ob->obmat);
invert_m4_m4(imat, mat);
mat4_to_quat(quat, imat);
}
if (dist) {
float tquat[4];
float nmat[3][3];
float vec[3];
vec[0]= 0.0f;
vec[1]= 0.0f;
vec[2]= -(*dist);
mat4_to_quat(tquat, ob->obmat);
mul_qt_v3(tquat, vec);
copy_m3_m4(nmat, mat);
normalize_m3(nmat);
mul_m3_v3(nmat, vec);;
sub_v3_v3(ofs, vec);
}
}
/* Lens */
if (lens)
void view3d_settings_from_ob(Object *ob, float *ofs, float *quat, float *dist, float *lens)
{
view3d_settings_from_mat(ob->obmat, ofs, quat, dist);
if (lens) {
object_lens_clip_settings(ob, lens, NULL, NULL);
}
}

View File

@@ -384,6 +384,25 @@ static void rna_RegionView3D_view_location_set(PointerRNA *ptr, const float *val
negate_v3_v3(rv3d->ofs, values);
}
static void rna_RegionView3D_view_rotation_get(PointerRNA *ptr, float *values)
{
RegionView3D *rv3d= (RegionView3D *)(ptr->data);
invert_qt_qt(values, rv3d->viewquat);
}
static void rna_RegionView3D_view_rotation_set(PointerRNA *ptr, const float *values)
{
RegionView3D *rv3d= (RegionView3D *)(ptr->data);
invert_qt_qt(rv3d->viewquat, values);
}
static void rna_RegionView3D_view_matrix_set(PointerRNA *ptr, const float *values)
{
RegionView3D *rv3d= (RegionView3D *)(ptr->data);
negate_v3_v3(rv3d->ofs, values);
view3d_settings_from_mat((float (*)[4])values, rv3d->ofs, rv3d->viewquat, &rv3d->dist);
}
/* Space Image Editor */
static PointerRNA rna_SpaceImageEditor_uvedit_get(PointerRNA *ptr)
@@ -1361,9 +1380,10 @@ static void rna_def_space_view3d(BlenderRNA *brna)
prop= RNA_def_property(srna, "view_matrix", PROP_FLOAT, PROP_MATRIX);
RNA_def_property_float_sdna(prop, NULL, "viewmat");
RNA_def_property_clear_flag(prop, PROP_EDITABLE); // XXX: for now, it's too risky for users to do this
RNA_def_property_multi_array(prop, 2, matrix_dimsize);
RNA_def_property_float_funcs(prop, NULL, "rna_RegionView3D_view_matrix_set", NULL);
RNA_def_property_ui_text(prop, "View Matrix", "Current view matrix of the 3D region");
RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL);
prop= RNA_def_property(srna, "view_perspective", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "persp");
@@ -1382,8 +1402,13 @@ static void rna_def_space_view3d(BlenderRNA *brna)
RNA_def_property_ui_range(prop, -10000.0, 10000.0, 10, 4);
RNA_def_property_update(prop, NC_WINDOW, NULL);
prop= RNA_def_property(srna, "view_rotation", PROP_FLOAT, PROP_QUATERNION);
prop= RNA_def_property(srna, "view_rotation", PROP_FLOAT, PROP_QUATERNION); // cant use because its inverted
#if 0
RNA_def_property_float_sdna(prop, NULL, "viewquat");
#else
RNA_def_property_array(prop, 4);
RNA_def_property_float_funcs(prop, "rna_RegionView3D_view_rotation_get", "rna_RegionView3D_view_rotation_set", NULL);
#endif
RNA_def_property_ui_text(prop, "View Rotation", "Rotation in quaternions (keep normalized)");
RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL);