utility function object_camera_matrix, moved code from RE_SetCamera into this.
authorCampbell Barton <ideasman42@gmail.com>
Fri, 5 Mar 2010 14:06:39 +0000 (14:06 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 5 Mar 2010 14:06:39 +0000 (14:06 +0000)
use for getting the render matrix of a camera (view plane, winmat, clipstart/end) without rendering.

source/blender/blenkernel/BKE_object.h
source/blender/blenkernel/intern/object.c
source/blender/editors/gpencil/drawgpencil.c
source/blender/editors/gpencil/gpencil_paint.c
source/blender/editors/space_sequencer/sequencer_draw.c
source/blender/editors/space_sequencer/sequencer_edit.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/render/intern/source/initrender.c

index a6a641a32197850857eb98263d3329e2e9f637b6..1362a19191983e61ea153bb2a7ee61c2e21071d0 100644 (file)
@@ -45,6 +45,7 @@ struct SoftBody;
 struct BulletSoftBody;
 struct Group;
 struct bAction;
+struct RenderData;
 
 void clear_workob(struct Object *workob);
 void what_does_parent(struct Scene *scene, struct Object *ob, struct Object *workob);
@@ -128,6 +129,10 @@ int object_insert_ptcache(struct Object *ob);
 // void object_delete_ptcache(struct Object *ob, int index);
 struct KeyBlock *object_insert_shape_key(struct Scene *scene, struct Object *ob, char *name, int from_mix);
 
+void object_camera_matrix(
+               struct RenderData *rd, struct Object *camera, int winx, int winy, short field_second,
+               float winmat[][4], struct rctf *viewplane, float *clipsta, float *clipend, float *lens, float *ycor,
+               float *viewdx, float *viewdy);
 
 #ifdef __cplusplus
 }
index 46c26524f47f7e6f2416fc661b4d002258270438..2d7fc08aa743914b705e72df2474948ac4322f68 100644 (file)
@@ -2715,6 +2715,115 @@ int object_insert_ptcache(Object *ob)
        return i;
 }
 
+/* 'lens' may be set for envmap only */
+void object_camera_matrix(
+               RenderData *rd, Object *camera, int winx, int winy, short field_second,
+               float winmat[][4], rctf *viewplane, float *clipsta, float *clipend, float *lens, float *ycor,
+               float *viewdx, float *viewdy
+) {
+       Camera *cam=NULL;
+       float pixsize;
+       float shiftx=0.0, shifty=0.0, winside, viewfac;
+
+       /* question mark */
+       (*ycor)= rd->yasp / rd->xasp;
+       if(rd->mode & R_FIELDS)
+               (*ycor) *= 2.0f;
+
+       if(camera->type==OB_CAMERA) {
+               cam= camera->data;
+
+               if(cam->type==CAM_ORTHO) rd->mode |= R_ORTHO;
+               if(cam->flag & CAM_PANORAMA) rd->mode |= R_PANORAMA;
+
+               /* solve this too... all time depending stuff is in convertblender.c?
+                * Need to update the camera early because it's used for projection matrices
+                * and other stuff BEFORE the animation update loop is done
+                * */
+#if 0 // XXX old animation system
+               if(cam->ipo) {
+                       calc_ipo(cam->ipo, frame_to_float(re->scene, re->r.cfra));
+                       execute_ipo(&cam->id, cam->ipo);
+               }
+#endif // XXX old animation system
+               shiftx=cam->shiftx;
+               shifty=cam->shifty;
+               (*lens)= cam->lens;
+               (*clipsta)= cam->clipsta;
+               (*clipend)= cam->clipend;
+       }
+       else if(camera->type==OB_LAMP) {
+               Lamp *la= camera->data;
+               float fac= cos( M_PI*la->spotsize/360.0 );
+               float phi= acos(fac);
+
+               (*lens)= 16.0*fac/sin(phi);
+               if((*lens)==0.0f)
+                       (*lens)= 35.0;
+               (*clipsta)= la->clipsta;
+               (*clipend)= la->clipend;
+       }
+       else {  /* envmap exception... */;
+               if((*lens)==0.0f)
+                       (*lens)= 16.0;
+
+               if((*clipsta)==0.0f || (*clipend)==0.0f) {
+                       (*clipsta)= 0.1f;
+                       (*clipend)= 1000.0f;
+               }
+       }
+
+       /* ortho only with camera available */
+       if(cam && rd->mode & R_ORTHO) {
+               if(rd->xasp*winx >= rd->yasp*winy) {
+                       viewfac= winx;
+               }
+               else {
+                       viewfac= (*ycor) * winy;
+               }
+               /* ortho_scale == 1.0 means exact 1 to 1 mapping */
+               pixsize= cam->ortho_scale/viewfac;
+       }
+       else {
+               if(rd->xasp*winx >= rd->yasp*winy)      viewfac= (winx*(*lens))/32.0;
+               else                                                            viewfac= (*ycor) * (winy*(*lens))/32.0;
+               pixsize= (*clipsta) / viewfac;
+       }
+
+       /* viewplane fully centered, zbuffer fills in jittered between -.5 and +.5 */
+       winside= MAX2(winx, winy);
+       viewplane->xmin= -0.5f*(float)winx + shiftx*winside;
+       viewplane->ymin= -0.5f*(*ycor)*(float)winy + shifty*winside;
+       viewplane->xmax=  0.5f*(float)winx + shiftx*winside;
+       viewplane->ymax=  0.5f*(*ycor)*(float)winy + shifty*winside;
+
+       if(field_second) {
+               if(rd->mode & R_ODDFIELD) {
+                       viewplane->ymin-= .5 * (*ycor);
+                       viewplane->ymax-= .5 * (*ycor);
+               }
+               else {
+                       viewplane->ymin+= .5* (*ycor);
+                       viewplane->ymax+= .5* (*ycor);
+               }
+       }
+       /* the window matrix is used for clipping, and not changed during OSA steps */
+       /* using an offset of +0.5 here would give clip errors on edges */
+       viewplane->xmin= pixsize*(viewplane->xmin);
+       viewplane->xmax= pixsize*(viewplane->xmax);
+       viewplane->ymin= pixsize*(viewplane->ymin);
+       viewplane->ymax= pixsize*(viewplane->ymax);
+
+       (*viewdx)= pixsize;
+       (*viewdy)= (*ycor) * pixsize;
+
+       if(rd->mode & R_ORTHO)
+               orthographic_m4(winmat, viewplane->xmin, viewplane->xmax, viewplane->ymin, viewplane->ymax, *clipsta, *clipend);
+       else
+               perspective_m4(winmat, viewplane->xmin, viewplane->xmax, viewplane->ymin, viewplane->ymax, *clipsta, *clipend);
+
+}
+
 #if 0
 static int pc_findindex(ListBase *listbase, int index)
 {
index ed1835266d542e0e685fc0b1d75d5fd1deff4611..d01a7b7e96f84cf89eb6c567722116112761aafa 100644 (file)
@@ -684,7 +684,7 @@ void draw_gpencil_2dimage (bContext *C, ImBuf *ibuf)
                        zoom= (float)(SEQ_ZOOM_FAC(sseq->zoom));
                        if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
                                /* XXX sequencer zoom should store it? */
-                               zoomx = zoom; //  * ((float)G.scene->r.xasp / (float)G.scene->r.yasp);
+                               zoomx = zoom; //  * (G.scene->r.xasp / G.scene->r.yasp);
                                zoomy = zoom;
                        } 
                        else
index 2e45c65568fdda17312853884c7bf072dc27c7f7..deb8e738ef76361963c11185b08b8975b1bd5edc 100644 (file)
@@ -1077,7 +1077,7 @@ static void gp_paint_initstroke (tGPsdata *p, short paintmode)
                                /* calculate zoom factor */
                                zoom= (float)(SEQ_ZOOM_FAC(sseq->zoom));
                                if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
-                                       zoomx = zoom * ((float)p->scene->r.xasp / (float)p->scene->r.yasp);
+                                       zoomx = zoom * (p->scene->r.xasp / p->scene->r.yasp);
                                        zoomy = zoom;
                                } 
                                else
index c1a023d0009829ddac8e84604ce6861a772afbc9..41e2fe2b1249eaef58bb28a851488995d2605902 100644 (file)
@@ -678,7 +678,7 @@ void draw_image_seq(const bContext* C, Scene *scene, ARegion *ar, SpaceSeq *sseq
        recty = viewrecty + 0.5f;
 
        if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
-               viewrectx *= (float)scene->r.xasp / (float)scene->r.yasp;
+               viewrectx *= scene->r.xasp / scene->r.yasp;
                viewrectx /= proxy_size / 100.0;
                viewrecty /= proxy_size / 100.0;
        }
index ce8d99da3a93c4a1d6daf6db240bb84f818b3868..1cc2a935a3251059769ce657bc9e757559975c13 100644 (file)
@@ -2237,7 +2237,7 @@ static int sequencer_view_all_preview_exec(bContext *C, wmOperator *op)
        imgheight= (scene->r.size*scene->r.ysch)/100;
 
        /* Apply aspect, dosnt need to be that accurate */
-       imgwidth= (int)(imgwidth * ((float)scene->r.xasp / (float)scene->r.yasp));
+       imgwidth= (int)(imgwidth * (scene->r.xasp / scene->r.yasp));
 
        if (((imgwidth >= width) || (imgheight >= height)) &&
                ((width > 0) && (height > 0))) {
index 7fd46e7864d78b53b776a7f3f1b933c998aea2cf..ea81a8cafd96534e7f067c582939c5fcd5a9f18e 100644 (file)
@@ -854,7 +854,7 @@ static void draw_selected_name(Scene *scene, Object *ob, View3D *v3d)
 static void view3d_get_viewborder_size(Scene *scene, ARegion *ar, float size_r[2])
 {
        float winmax= MAX2(ar->winx, ar->winy);
-       float aspect= (float) (scene->r.xsch*scene->r.xasp)/(scene->r.ysch*scene->r.yasp);
+       float aspect= (scene->r.xsch*scene->r.xasp) / (scene->r.ysch*scene->r.yasp);
        
        if(aspect>1.0) {
                size_r[0]= winmax;
index 0976cd70c1949bffcea9ea1de9da42acb0420182..5542a036d9afd5fbccb29478ead6cccf67f6a05a 100644 (file)
@@ -447,117 +447,9 @@ void make_sample_tables(Render *re)
 /* per render, there's one persistant viewplane. Parts will set their own viewplanes */
 void RE_SetCamera(Render *re, Object *camera)
 {
-       Camera *cam=NULL;
-       rctf viewplane;
-       float pixsize, clipsta, clipend;
-       float lens, shiftx=0.0, shifty=0.0, winside, viewfac;
-       
-       /* question mark */
-       re->ycor= ( (float)re->r.yasp)/( (float)re->r.xasp);
-       if(re->r.mode & R_FIELDS)
-               re->ycor *= 2.0f;
-       
-       if(camera->type==OB_CAMERA) {
-               cam= camera->data;
-               
-               if(cam->type==CAM_ORTHO) re->r.mode |= R_ORTHO;
-               if(cam->flag & CAM_PANORAMA) re->r.mode |= R_PANORAMA;
-               
-               /* solve this too... all time depending stuff is in convertblender.c?
-                * Need to update the camera early because it's used for projection matrices
-                * and other stuff BEFORE the animation update loop is done 
-                * */
-#if 0 // XXX old animation system
-               if(cam->ipo) {
-                       calc_ipo(cam->ipo, frame_to_float(re->scene, re->r.cfra));
-                       execute_ipo(&cam->id, cam->ipo);
-               }
-#endif // XXX old animation system
-               lens= cam->lens;
-               shiftx=cam->shiftx;
-               shifty=cam->shifty;
-
-               clipsta= cam->clipsta;
-               clipend= cam->clipend;
-       }
-       else if(camera->type==OB_LAMP) {
-               Lamp *la= camera->data;
-               float fac= cos( M_PI*la->spotsize/360.0 );
-               float phi= acos(fac);
-               
-               lens= 16.0*fac/sin(phi);
-               if(lens==0.0f)
-                       lens= 35.0;
-               clipsta= la->clipsta;
-               clipend= la->clipend;
-       }
-       else {  /* envmap exception... */
-               lens= re->lens;
-               if(lens==0.0f)
-                       lens= 16.0;
-               
-               clipsta= re->clipsta;
-               clipend= re->clipend;
-               if(clipsta==0.0f || clipend==0.0f) {
-                       clipsta= 0.1f;
-                       clipend= 1000.0f;
-               }
-       }
-
-       /* ortho only with camera available */
-       if(cam && (re->r.mode & R_ORTHO)) {
-               if( (re->r.xasp*re->winx) >= (re->r.yasp*re->winy) ) {
-                       viewfac= re->winx;
-               }
-               else {
-                       viewfac= re->ycor*re->winy;
-               }
-               /* ortho_scale == 1.0 means exact 1 to 1 mapping */
-               pixsize= cam->ortho_scale/viewfac;
-       }
-       else {
-               if( (re->r.xasp*re->winx) >= (re->r.yasp*re->winy) ) {
-                       viewfac= (re->winx*lens)/32.0;
-               }
-               else {
-                       viewfac= re->ycor*(re->winy*lens)/32.0;
-               }
-               
-               pixsize= clipsta/viewfac;
-       }
-       
-       /* viewplane fully centered, zbuffer fills in jittered between -.5 and +.5 */
-       winside= MAX2(re->winx, re->winy);
-       viewplane.xmin= -0.5f*(float)re->winx + shiftx*winside; 
-       viewplane.ymin= -0.5f*re->ycor*(float)re->winy + shifty*winside;
-       viewplane.xmax=  0.5f*(float)re->winx + shiftx*winside; 
-       viewplane.ymax=  0.5f*re->ycor*(float)re->winy + shifty*winside; 
-
-       if(re->flag & R_SEC_FIELD) {
-               if(re->r.mode & R_ODDFIELD) {
-                       viewplane.ymin-= .5*re->ycor;
-                       viewplane.ymax-= .5*re->ycor;
-               }
-               else {
-                       viewplane.ymin+= .5*re->ycor;
-                       viewplane.ymax+= .5*re->ycor;
-               }
-       }
-       /* the window matrix is used for clipping, and not changed during OSA steps */
-       /* using an offset of +0.5 here would give clip errors on edges */
-       viewplane.xmin= pixsize*(viewplane.xmin);
-       viewplane.xmax= pixsize*(viewplane.xmax);
-       viewplane.ymin= pixsize*(viewplane.ymin);
-       viewplane.ymax= pixsize*(viewplane.ymax);
-       
-       re->viewdx= pixsize;
-       re->viewdy= re->ycor*pixsize;
-
-       if(re->r.mode & R_ORTHO)
-               RE_SetOrtho(re, &viewplane, clipsta, clipend);
-       else 
-               RE_SetWindow(re, &viewplane, clipsta, clipend);
-
+       object_camera_matrix(&re->r, camera, re->winx, re->winy, re->flag & R_SEC_FIELD,
+                       re->winmat, &re->viewplane, &re->clipsta, &re->clipend,
+                       &re->lens, &re->ycor, &re->viewdx, &re->viewdy);
 }
 
 void RE_SetPixelSize(Render *re, float pixsize)