diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-09-29 11:59:33 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-09-29 11:59:33 +0400 |
commit | 4b325a938e716787bc51b5cb89e704aac1bd012a (patch) | |
tree | 7e9494be70af9b80349dea07e96ae43047f9dd87 | |
parent | 9701a58fecb7f8a690dacb44c248969c653dbc4b (diff) |
make drawobject.c's code for getting the camera view frame into its own function. (no functional changes)
-rw-r--r-- | source/blender/blenkernel/BKE_object.h | 5 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 76 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/drawobject.c | 102 |
3 files changed, 111 insertions, 72 deletions
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index 7e39461a032..1dd4feeab2e 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -146,6 +146,11 @@ void object_camera_matrix( float winmat[][4], struct rctf *viewplane, float *clipsta, float *clipend, float *lens, float *ycor, float *viewdx, float *viewdy); +void camera_view_frame_ex(struct Scene *scene, struct Camera *camera, float drawsize, const short do_clip, const float scale[3], + float r_asp[2], float r_shift[2], float *r_drawsize, float r_vec[4][3]); + +void camera_frame(struct Scene *scene, struct Camera *camera, float r_vec[4][3]); + void object_relink(struct Object *ob); #ifdef __cplusplus diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index eae317b97fc..c9bad579507 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -3057,6 +3057,82 @@ void object_camera_matrix( } +void camera_view_frame_ex(Scene *scene, Camera *camera, float drawsize, const short do_clip, const float scale[3], + float r_asp[2], float r_shift[2], float *r_drawsize, float r_vec[4][3]) +{ + float aspx, aspy; + float facx, facy; + float depth; + + /* aspect correcton */ + if (scene) { + aspx= (float) scene->r.xsch*scene->r.xasp; + aspy= (float) scene->r.ysch*scene->r.yasp; + + if(aspx < aspy) { + r_asp[0]= aspx / aspy; + r_asp[1]= 1.0; + } + else { + r_asp[0]= 1.0; + r_asp[1]= aspy / aspx; + } + } + else { + aspx= 1.0f; + aspy= 1.0f; + r_asp[0]= 1.0f; + r_asp[1]= 1.0f; + } + + if(camera->type==CAM_ORTHO) { + facx= 0.5f * camera->ortho_scale * r_asp[0] * scale[0]; + facy= 0.5f * camera->ortho_scale * r_asp[1] * scale[1]; + r_shift[0]= camera->shiftx * camera->ortho_scale * scale[0]; + r_shift[1]= camera->shifty * camera->ortho_scale * scale[1]; + depth= do_clip ? -((camera->clipsta * scale[2]) + 0.1f) : - drawsize * camera->ortho_scale * scale[2]; + + *r_drawsize= 0.5f * camera->ortho_scale; + } + else { + /* that way it's always visible - clipsta+0.1 */ + float fac; + *r_drawsize= drawsize / ((scale[0] + scale[1] + scale[2]) / 3.0f); + + if(do_clip) { + /* fixed depth, variable size (avoids exceeding clipping range) */ + depth = -(camera->clipsta + 0.1f); + fac = depth / (camera->lens/-16.0f * scale[2]); + } + else { + /* fixed size, variable depth (stays a reasonable size in the 3D view) */ + depth= *r_drawsize * camera->lens/-16.0f * scale[2]; + fac= *r_drawsize; + } + + facx= fac * r_asp[0] * scale[0]; + facy= fac * r_asp[1] * scale[1]; + r_shift[0]= camera->shiftx*fac*2 * scale[0]; + r_shift[1]= camera->shifty*fac*2 * scale[1]; + } + + r_vec[0][0]= r_shift[0] + facx; r_vec[0][1]= r_shift[1] + facy; r_vec[0][2]= depth; + r_vec[1][0]= r_shift[0] + facx; r_vec[1][1]= r_shift[1] - facy; r_vec[1][2]= depth; + r_vec[2][0]= r_shift[0] - facx; r_vec[2][1]= r_shift[1] - facy; r_vec[2][2]= depth; + r_vec[3][0]= r_shift[0] - facx; r_vec[3][1]= r_shift[1] + facy; r_vec[3][2]= depth; +} + +void camera_frame(Scene *scene, Camera *camera, float r_vec[4][3]) +{ + float dummy_asp[2]; + float dummy_shift[2]; + float dummy_drawsize; + const float dummy_scale[3]= {1.0f, 1.0f, 1.0f}; + + camera_view_frame_ex(scene, camera, FALSE, 1.0, dummy_scale, + dummy_asp, dummy_shift, &dummy_drawsize, r_vec); +} + #if 0 static int pc_findindex(ListBase *listbase, int index) { diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 63a1d7f7b4f..35c3e909d84 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -1370,15 +1370,12 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob { /* a standing up pyramid with (0,0,0) as top */ Camera *cam; - float vec[8][4], facx, facy, depth, aspx, aspy, caspx, caspy, shx, shy; + float tvec[3]; + float vec[4][3], asp[2], shift[2], scale[3]; int i; float drawsize; const short is_view= (rv3d->persp==RV3D_CAMOB && ob==v3d->camera); - const float scax= 1.0f / len_v3(ob->obmat[0]); - const float scay= 1.0f / len_v3(ob->obmat[1]); - const float scaz= 1.0f / len_v3(ob->obmat[2]); - #ifdef VIEW3D_CAMERA_BORDER_HACK if(is_view && !(G.f & G_PICKSEL)) { glGetFloatv(GL_CURRENT_COLOR, view3d_camera_border_hack_col); @@ -1388,82 +1385,43 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob #endif cam= ob->data; - aspx= (float) scene->r.xsch*scene->r.xasp; - aspy= (float) scene->r.ysch*scene->r.yasp; - if(aspx < aspy) { - caspx= aspx / aspy; - caspy= 1.0; - } - else { - caspx= 1.0; - caspy= aspy / aspx; - } - - glDisable(GL_LIGHTING); - glDisable(GL_CULL_FACE); - - if(cam->type==CAM_ORTHO) { - facx= 0.5f * cam->ortho_scale * caspx * scax; - facy= 0.5f * cam->ortho_scale * caspy * scay; - shx= cam->shiftx * cam->ortho_scale * scax; - shy= cam->shifty * cam->ortho_scale * scay; - depth= is_view ? -((cam->clipsta * scaz) + 0.1f) : - cam->drawsize * cam->ortho_scale * scaz; - - drawsize= 0.5f * cam->ortho_scale; - } - else { - /* that way it's always visible - clipsta+0.1 */ - float fac; - drawsize= cam->drawsize / ((scax + scay + scaz) / 3.0f); + scale[0]= 1.0f / len_v3(ob->obmat[0]); + scale[1]= 1.0f / len_v3(ob->obmat[1]); + scale[2]= 1.0f / len_v3(ob->obmat[2]); - if(is_view) { - /* fixed depth, variable size (avoids exceeding clipping range) */ - depth = -(cam->clipsta + 0.1f); - fac = depth / (cam->lens/-16.0f * scaz); - } - else { - /* fixed size, variable depth (stays a reasonable size in the 3D view) */ - depth= drawsize * cam->lens/-16.0f * scaz; - fac= drawsize; - } + camera_view_frame_ex(scene, cam, cam->drawsize, is_view, scale, + asp, shift, &drawsize, vec); - facx= fac * caspx * scax; - facy= fac * caspy * scay; - shx= cam->shiftx*fac*2 * scax; - shy= cam->shifty*fac*2 * scay; - } - - vec[0][0]= 0.0; vec[0][1]= 0.0; vec[0][2]= 0.0; - vec[1][0]= shx + facx; vec[1][1]= shy + facy; vec[1][2]= depth; - vec[2][0]= shx + facx; vec[2][1]= shy - facy; vec[2][2]= depth; - vec[3][0]= shx - facx; vec[3][1]= shy - facy; vec[3][2]= depth; - vec[4][0]= shx - facx; vec[4][1]= shy + facy; vec[4][2]= depth; + glDisable(GL_LIGHTING); + glDisable(GL_CULL_FACE); /* camera frame */ glBegin(GL_LINE_LOOP); - glVertex3fv(vec[1]); - glVertex3fv(vec[2]); - glVertex3fv(vec[3]); - glVertex3fv(vec[4]); + glVertex3fv(vec[0]); + glVertex3fv(vec[1]); + glVertex3fv(vec[2]); + glVertex3fv(vec[3]); glEnd(); if(is_view) return; + zero_v3(tvec); + /* center point to camera frame */ glBegin(GL_LINE_STRIP); - glVertex3fv(vec[2]); - glVertex3fv(vec[0]); - glVertex3fv(vec[1]); - glVertex3fv(vec[4]); - glVertex3fv(vec[0]); - glVertex3fv(vec[3]); + glVertex3fv(vec[1]); + glVertex3fv(tvec); + glVertex3fv(vec[0]); + glVertex3fv(vec[3]); + glVertex3fv(tvec); + glVertex3fv(vec[2]); glEnd(); /* arrow on top */ - vec[0][2]= depth; + tvec[2]= vec[1][2]; /* copy the depth */ /* draw an outline arrow for inactive cameras and filled @@ -1474,16 +1432,16 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob else if (i==1 && (ob == v3d->camera)) glBegin(GL_TRIANGLES); else break; - vec[0][0]= shx + ((-0.7f * drawsize) * scax); - vec[0][1]= shy + ((drawsize * (caspy + 0.1f)) * scay); - glVertex3fv(vec[0]); /* left */ + tvec[0]= shift[0] + ((-0.7f * drawsize) * scale[0]); + tvec[1]= shift[1] + ((drawsize * (asp[1] + 0.1f)) * scale[1]); + glVertex3fv(tvec); /* left */ - vec[0][0]= shx + ((0.7f * drawsize) * scax); - glVertex3fv(vec[0]); /* right */ + tvec[0]= shift[0] + ((0.7f * drawsize) * scale[0]); + glVertex3fv(tvec); /* right */ - vec[0][0]= shx; - vec[0][1]= shy + ((1.1f * drawsize * (caspy + 0.7f)) * scay); - glVertex3fv(vec[0]); /* top */ + tvec[0]= shift[0]; + tvec[1]= shift[1] + ((1.1f * drawsize * (asp[1] + 0.7f)) * scale[1]); + glVertex3fv(tvec); /* top */ glEnd(); } |