fix view3d_persp_mat4, which gave incorrect translation, rename to ED_view3d_to_m4. added doxygen docs.

This commit is contained in:
Campbell Barton 2011-05-23 02:23:03 +00:00
parent bf65ed9447
commit 0d26333eb5
4 changed files with 53 additions and 38 deletions

@ -147,6 +147,43 @@ void ED_view3d_win_to_ray(struct ARegion *ar, struct View3D *v3d, const float mv
*/ */
void ED_view3d_global_to_vector(struct RegionView3D *rv3d, const float coord[3], float vec[3]); void ED_view3d_global_to_vector(struct RegionView3D *rv3d, const float coord[3], float vec[3]);
/**
* Calculate the view transformation matrix from RegionView3D input.
* The resulting matrix is equivilent to RegionView3D.viewinv
* @param mat The view 4x4 transformation matrix to calculate.
* @param ofs The view offset, normally from RegionView3D.ofs.
* @param quat The view rotation, quaternion normally from RegionView3D.viewquat.
* @param dist The view distance from ofs, normally from RegionView3D.dist.
*/
void ED_view3d_to_m4(float mat[][4], const float ofs[3], const float quat[4], const float dist);
/**
* Set the view transformation from a 4x4 matrix.
* @param mat The view 4x4 transformation matrix to assign.
* @param ofs The view offset, normally from RegionView3D.ofs.
* @param quat The view rotation, quaternion normally from RegionView3D.viewquat.
* @param dist The view distance from ofs, normally from RegionView3D.dist.
*/
void ED_view3d_from_m4(float mat[][4], float ofs[3], float quat[4], float *dist);
/**
* Set the RegionView3D members from an objects transformation and optionally lens.
* @param ob The object to set the view to.
* @param ofs The view offset to be set, normally from RegionView3D.ofs.
* @param quat The view rotation to be set, quaternion normally from RegionView3D.viewquat.
* @param dist The view distance from ofs to be set, normally from RegionView3D.dist.
*/
void ED_view3d_from_object(struct Object *ob, float ofs[3], float quat[4], float *dist, float *lens);
/**
* Set the object transformation from RegionView3D members.
* @param ob The object which has the transformation assigned.
* @param ofs The view offset, normally from RegionView3D.ofs.
* @param quat The view rotation, quaternion normally from RegionView3D.viewquat.
* @param dist The view distance from ofs, normally from RegionView3D.dist.
*/
void ED_view3d_to_object(struct Object *ob, const float ofs[3], const float quat[4], const float dist);
#if 0 /* UNUSED */ #if 0 /* UNUSED */
void view3d_unproject(struct bglMats *mats, float out[3], const short x, const short y, const float z); void view3d_unproject(struct bglMats *mats, float out[3], const short x, const short y, const float z);
#endif #endif
@ -246,13 +283,6 @@ int ED_view3d_lock(struct RegionView3D *rv3d);
unsigned int ED_view3d_datamask(struct Scene *scene, struct View3D *v3d); unsigned int ED_view3d_datamask(struct Scene *scene, struct View3D *v3d);
unsigned int ED_viewedit_datamask(struct bScreen *screen); unsigned int ED_viewedit_datamask(struct bScreen *screen);
/* assigning view matrix */
void ED_view3d_from_m4(float mat[][4], float ofs[3], float quat[4], float *dist);
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);
/* camera lock functions */ /* camera lock functions */
/* copy the camera to the view before starting a view transformation */ /* copy the camera to the view before starting a view transformation */
void ED_view3d_camera_lock_init(struct View3D *v3d, struct RegionView3D *rv3d); void ED_view3d_camera_lock_init(struct View3D *v3d, struct RegionView3D *rv3d);

@ -3523,25 +3523,6 @@ void viewmoveNDOF(Scene *scene, ARegion *ar, View3D *v3d, int UNUSED(mode))
} }
#endif // if 0, unused NDof code #endif // if 0, unused NDof code
/* give a 4x4 matrix from a perspective view, only needs viewquat, ofs and dist
* basically the same as...
* rv3d->persp= RV3D_PERSP
* setviewmatrixview3d(scene, v3d, rv3d);
* setcameratoview3d(v3d, rv3d, v3d->camera);
* ...but less of a hassle
* */
void view3d_persp_mat4(RegionView3D *rv3d, float mat[][4])
{
float qt[4], dvec[3];
copy_qt_qt(qt, rv3d->viewquat);
qt[0]= -qt[0];
quat_to_mat4(mat, qt);
mat[3][2] -= rv3d->dist;
translate_m4(mat, rv3d->ofs[0], rv3d->ofs[1], rv3d->ofs[2]);
mul_v3_v3fl(dvec, mat[2], -rv3d->dist);
sub_v3_v3v3(mat[3], dvec, rv3d->ofs);
}
/* Gets the view trasnformation from a camera /* Gets the view trasnformation from a camera
* currently dosnt take camzoom into account * currently dosnt take camzoom into account
@ -3577,6 +3558,16 @@ void ED_view3d_from_m4(float mat[][4], float ofs[3], float quat[4], float *dist)
} }
} }
void ED_view3d_to_m4(float mat[][4], const float ofs[3], const float quat[4], const float dist)
{
float iviewquat[4]= {-quat[0], quat[1], quat[2], quat[3]};
float dvec[3]= {0.0f, 0.0f, dist};
quat_to_mat4(mat, iviewquat);
mul_mat3_m4_v3(mat, dvec);
sub_v3_v3v3(mat[3], dvec, ofs);
}
/* object -> view */ /* object -> view */
void ED_view3d_from_object(Object *ob, float ofs[3], float quat[4], float *dist, float *lens) void ED_view3d_from_object(Object *ob, float ofs[3], float quat[4], float *dist, float *lens)
@ -3591,12 +3582,7 @@ void ED_view3d_from_object(Object *ob, float ofs[3], float quat[4], float *dist,
/* view -> object */ /* view -> object */
void ED_view3d_to_object(Object *ob, const float ofs[3], const float quat[4], const float dist) void ED_view3d_to_object(Object *ob, const float ofs[3], const float quat[4], const float dist)
{ {
float mat4[4][4]; float mat[4][4];
float dvec[3]= {0.0f, 0.0f, dist}; ED_view3d_to_m4(mat, ofs, quat, dist);
float iviewquat[4]= {-quat[0], quat[1], quat[2], quat[3]}; object_apply_mat4(ob, mat, TRUE, TRUE);
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);
} }

@ -568,7 +568,7 @@ static int flyApply(bContext *C, FlyInfo *fly)
apply_rotation= 1; /* if the user presses shift they can look about without movinf the direction there looking*/ apply_rotation= 1; /* if the user presses shift they can look about without movinf the direction there looking*/
if(fly->root_parent) if(fly->root_parent)
view3d_persp_mat4(rv3d, prev_view_mat); ED_view3d_to_m4(prev_view_mat, fly->rv3d->ofs, fly->rv3d->viewquat, fly->rv3d->dist);
/* the dist defines a vector that is infront of the offset /* the dist defines a vector that is infront of the offset
to rotate the view about. to rotate the view about.
@ -797,7 +797,7 @@ static int flyApply(bContext *C, FlyInfo *fly)
float parent_mat[4][4]; float parent_mat[4][4];
invert_m4_m4(prev_view_imat, prev_view_mat); invert_m4_m4(prev_view_imat, prev_view_mat);
view3d_persp_mat4(rv3d, view_mat); ED_view3d_to_m4(view_mat, rv3d->ofs, rv3d->viewquat, rv3d->dist);
mul_m4_m4m4(diff_mat, prev_view_imat, view_mat); mul_m4_m4m4(diff_mat, prev_view_imat, view_mat);
mul_m4_m4m4(parent_mat, fly->root_parent->obmat, diff_mat); mul_m4_m4m4(parent_mat, fly->root_parent->obmat, diff_mat);
object_apply_mat4(fly->root_parent, parent_mat, TRUE, FALSE); object_apply_mat4(fly->root_parent, parent_mat, TRUE, FALSE);
@ -817,7 +817,7 @@ static int flyApply(bContext *C, FlyInfo *fly)
} }
else { else {
float view_mat[4][4]; float view_mat[4][4];
view3d_persp_mat4(rv3d, view_mat); ED_view3d_to_m4(view_mat, rv3d->ofs, rv3d->viewquat, rv3d->dist);
object_apply_mat4(v3d->camera, view_mat, TRUE, FALSE); object_apply_mat4(v3d->camera, view_mat, TRUE, FALSE);
id_key= &v3d->camera->id; id_key= &v3d->camera->id;
} }

@ -91,7 +91,6 @@ void VIEW3D_OT_zoom_border(struct wmOperatorType *ot);
void VIEW3D_OT_drawtype(struct wmOperatorType *ot); void VIEW3D_OT_drawtype(struct wmOperatorType *ot);
void view3d_boxview_copy(ScrArea *sa, ARegion *ar); void view3d_boxview_copy(ScrArea *sa, ARegion *ar);
void view3d_persp_mat4(struct RegionView3D *rv3d, float mat[][4]);
/* view3d_fly.c */ /* view3d_fly.c */
void view3d_keymap(struct wmKeyConfig *keyconf); void view3d_keymap(struct wmKeyConfig *keyconf);