Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-09-29 11:59:33 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-09-29 11:59:33 +0400
commit4b325a938e716787bc51b5cb89e704aac1bd012a (patch)
tree7e9494be70af9b80349dea07e96ae43047f9dd87 /source/blender/blenkernel
parent9701a58fecb7f8a690dacb44c248969c653dbc4b (diff)
make drawobject.c's code for getting the camera view frame into its own function. (no functional changes)
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_object.h5
-rw-r--r--source/blender/blenkernel/intern/object.c76
2 files changed, 81 insertions, 0 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)
{