there wasn't a good way to know if a RegionView3D was perspective or not (without having the View3D too and checking its camera values), added struct member 'is_persp', set with the view matrix.

This commit is contained in:
Campbell Barton 2011-05-18 17:52:26 +00:00
parent 0c41635f85
commit f4d8be977f
6 changed files with 29 additions and 38 deletions

@ -112,7 +112,6 @@ void viewray(struct ARegion *ar, struct View3D *v3d, float mval[2], float ray_st
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);
void view3d_get_object_project_mat(struct RegionView3D *v3d, struct Object *ob, float pmat[4][4]);
void view3d_project_float(struct ARegion *a, const float vec[3], float adr[2], float mat[4][4]);
void view3d_calc_camera_border(struct Scene *scene, struct ARegion *ar, struct RegionView3D *rv3d, struct View3D *v3d, struct rctf *viewborder_r, short do_shift);

@ -366,7 +366,7 @@ static void draw_textured_begin(Scene *scene, View3D *v3d, RegionView3D *rv3d, O
}
else {
/* draw with lights in the scene otherwise */
Gtexdraw.islit= GPU_scene_object_lights(scene, ob, v3d->lay, rv3d->viewmat, get_view3d_ortho(v3d, rv3d));
Gtexdraw.islit= GPU_scene_object_lights(scene, ob, v3d->lay, rv3d->viewmat, !rv3d->is_persp);
}
obcol[0]= CLAMPIS(ob->col[0]*255, 0, 255);

@ -383,7 +383,7 @@ static void viewops_data_create(bContext *C, wmOperator *op, wmEvent *event)
view3d_operator_needs_opengl(C); /* needed for zbuf drawing */
if((vod->use_dyn_ofs=view_autodist(CTX_data_scene(C), vod->ar, vod->v3d, event->mval, vod->dyn_ofs))) {
if (rv3d->persp==RV3D_PERSP || (rv3d->persp==RV3D_CAMOB && (vod->v3d->flag2 & V3D_LOCK_CAMERA))) {
if (rv3d->is_persp) {
float my_origin[3]; /* original G.vd->ofs */
float my_pivot[3]; /* view */
float dvec[3];

@ -507,7 +507,7 @@ void viewline(ARegion *ar, View3D *v3d, float mval[2], float ray_start[3], float
float vec[4];
int a;
if(!get_view3d_ortho(v3d, rv3d)) {
if(rv3d->is_persp) {
vec[0]= 2.0f * mval[0] / ar->winx - 1;
vec[1]= 2.0f * mval[1] / ar->winy - 1;
vec[2]= -1.0f;
@ -636,19 +636,24 @@ void window_to_3d_delta(ARegion *ar, float out[3], const int mx, const int my)
void window_to_3d_vector(ARegion *ar, float out[3], const int mx, const int my)
{
RegionView3D *rv3d= ar->regiondata;
float dx, dy;
float viewvec[3];
dx= (2.0f * mx / ar->winx) - 1.0f;
dy= (2.0f * my / ar->winy) - 1.0f;
if(rv3d->is_persp) {
float dx, dy;
float viewvec[3];
/* normalize here so vecs are proportional to eachother */
normalize_v3_v3(viewvec, rv3d->viewinv[2]);
dx= (2.0f * mx / ar->winx) - 1.0f;
dy= (2.0f * my / ar->winy) - 1.0f;
out[0]= (rv3d->persinv[0][0]*dx + rv3d->persinv[1][0]*dy) - viewvec[0];
out[1]= (rv3d->persinv[0][1]*dx + rv3d->persinv[1][1]*dy) - viewvec[1];
out[2]= (rv3d->persinv[0][2]*dx + rv3d->persinv[1][2]*dy) - viewvec[2];
/* normalize here so vecs are proportional to eachother */
normalize_v3_v3(viewvec, rv3d->viewinv[2]);
out[0]= (rv3d->persinv[0][0]*dx + rv3d->persinv[1][0]*dy) - viewvec[0];
out[1]= (rv3d->persinv[0][1]*dx + rv3d->persinv[1][1]*dy) - viewvec[1];
out[2]= (rv3d->persinv[0][2]*dx + rv3d->persinv[1][2]*dy) - viewvec[2];
}
else {
copy_v3_v3(out, rv3d->viewinv[2]);
}
normalize_v3(out);
}
@ -890,29 +895,6 @@ void project_float_noclip(ARegion *ar, const float vec[3], float adr[2])
}
}
int get_view3d_ortho(View3D *v3d, RegionView3D *rv3d)
{
Camera *cam;
if(rv3d->persp==RV3D_CAMOB) {
if(v3d->camera && v3d->camera->type==OB_CAMERA) {
cam= v3d->camera->data;
if(cam && cam->type==CAM_ORTHO)
return 1;
else
return 0;
}
else
return 0;
}
if(rv3d->persp==RV3D_ORTHO)
return 1;
return 0;
}
/* copies logic of get_view3d_viewplane(), keep in sync */
int get_view3d_cliprange(View3D *v3d, RegionView3D *rv3d, float *clipsta, float *clipend)
{
@ -1082,6 +1064,8 @@ void setwinmatrixview3d(ARegion *ar, View3D *v3d, rctf *rect) /* rect: for pick
int orth;
orth= get_view3d_viewplane(v3d, rv3d, ar->winx, ar->winy, &viewplane, &clipsta, &clipend, NULL);
rv3d->is_persp= !orth;
// printf("%d %d %f %f %f %f %f %f\n", winx, winy, viewplane.xmin, viewplane.ymin, viewplane.xmax, viewplane.ymax, clipsta, clipend);
x1= viewplane.xmin;
y1= viewplane.ymin;

@ -96,10 +96,13 @@ typedef struct RegionView3D {
float zfac; /* initgrabz() result */
float camdx, camdy; /* camera view offsets, 1.0 = viewplane moves entire width/height */
float pixsize; /* runtime only */
float ofs[3]; /* view center & orbit pivot, negative of worldspace location */
float ofs[3]; /* view center & orbit pivot, negative of worldspace location,
* also matches -viewinv[3][0:3] in ortho mode.*/
short camzoom;
short twdrawflag;
int pad;
char is_persp; /* check if persp/ortho view, since 'persp' cant be used for this since
* it can have cameras assigned as well. (only set in setwinmatrixview3d) */
char pad[3];
short rflag, viewlock;
short persp;

@ -1435,6 +1435,11 @@ static void rna_def_space_view3d(BlenderRNA *brna)
RNA_def_property_enum_items(prop, rv3d_persp_items);
RNA_def_property_ui_text(prop, "Perspective", "View Perspective");
RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL);
prop= RNA_def_property(srna, "is_perspective", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "is_persp", 1);
RNA_def_property_ui_text(prop, "Is Perspective", "");
RNA_def_property_flag(prop, PROP_EDITABLE);
prop= RNA_def_property(srna, "view_location", PROP_FLOAT, PROP_TRANSLATION);
#if 0