Revision: 36752
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36752
Author:   campbellbarton
Date:     2011-05-18 17:52:26 +0000 (Wed, 18 May 2011)
Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/include/ED_view3d.h
    trunk/blender/source/blender/editors/space_view3d/drawmesh.c
    trunk/blender/source/blender/editors/space_view3d/view3d_edit.c
    trunk/blender/source/blender/editors/space_view3d/view3d_view.c
    trunk/blender/source/blender/makesdna/DNA_view3d_types.h
    trunk/blender/source/blender/makesrna/intern/rna_space.c

Modified: trunk/blender/source/blender/editors/include/ED_view3d.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_view3d.h    2011-05-18 
15:57:20 UTC (rev 36751)
+++ trunk/blender/source/blender/editors/include/ED_view3d.h    2011-05-18 
17:52:26 UTC (rev 36752)
@@ -112,7 +112,6 @@
 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);

Modified: trunk/blender/source/blender/editors/space_view3d/drawmesh.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/drawmesh.c        
2011-05-18 15:57:20 UTC (rev 36751)
+++ trunk/blender/source/blender/editors/space_view3d/drawmesh.c        
2011-05-18 17:52:26 UTC (rev 36752)
@@ -366,7 +366,7 @@
        }
        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);

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_edit.c     
2011-05-18 15:57:20 UTC (rev 36751)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_edit.c     
2011-05-18 17:52:26 UTC (rev 36752)
@@ -383,7 +383,7 @@
                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];

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_view.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_view.c     
2011-05-18 15:57:20 UTC (rev 36751)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_view.c     
2011-05-18 17:52:26 UTC (rev 36752)
@@ -507,7 +507,7 @@
        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_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 @@
        }
 }
 
-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 @@
        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;

Modified: trunk/blender/source/blender/makesdna/DNA_view3d_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_view3d_types.h    2011-05-18 
15:57:20 UTC (rev 36751)
+++ trunk/blender/source/blender/makesdna/DNA_view3d_types.h    2011-05-18 
17:52:26 UTC (rev 36752)
@@ -96,10 +96,13 @@
        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;

Modified: trunk/blender/source/blender/makesrna/intern/rna_space.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_space.c    2011-05-18 
15:57:20 UTC (rev 36751)
+++ trunk/blender/source/blender/makesrna/intern/rna_space.c    2011-05-18 
17:52:26 UTC (rev 36752)
@@ -1435,6 +1435,11 @@
        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

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to