diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-03-05 17:06:39 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-03-05 17:06:39 +0300 |
commit | f4298de8aaafd36cb8da6f7051c24ca630589001 (patch) | |
tree | 8f5f0b2b6879bbb956ab4224ec51a7bf5b8d9e35 /source | |
parent | 19154014b8a87f1f63f5d75d6983adc5fa6dbc7f (diff) |
utility function object_camera_matrix, moved code from RE_SetCamera into this.
use for getting the render matrix of a camera (view plane, winmat, clipstart/end) without rendering.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_object.h | 5 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 109 | ||||
-rw-r--r-- | source/blender/editors/gpencil/drawgpencil.c | 2 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_paint.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_sequencer/sequencer_draw.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_sequencer/sequencer_edit.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_draw.c | 2 | ||||
-rw-r--r-- | source/blender/render/intern/source/initrender.c | 114 |
8 files changed, 122 insertions, 116 deletions
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index a6a641a3219..1362a191919 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -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 } diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 46c26524f47..2d7fc08aa74 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -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) { diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c index ed1835266d5..d01a7b7e96f 100644 --- a/source/blender/editors/gpencil/drawgpencil.c +++ b/source/blender/editors/gpencil/drawgpencil.c @@ -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 diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index 2e45c65568f..deb8e738ef7 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -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 diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index c1a023d0009..41e2fe2b124 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -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; } diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c index ce8d99da3a9..1cc2a935a32 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.c +++ b/source/blender/editors/space_sequencer/sequencer_edit.c @@ -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))) { diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 7fd46e7864d..ea81a8cafd9 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -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; diff --git a/source/blender/render/intern/source/initrender.c b/source/blender/render/intern/source/initrender.c index 0976cd70c19..5542a036d9a 100644 --- a/source/blender/render/intern/source/initrender.c +++ b/source/blender/render/intern/source/initrender.c @@ -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) |