[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [40682] trunk/blender/source/blender: make drawobject.c' s code for getting the camera view frame into its own function.

Campbell Barton ideasman42 at gmail.com
Thu Sep 29 09:59:37 CEST 2011


Revision: 40682
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40682
Author:   campbellbarton
Date:     2011-09-29 07:59:33 +0000 (Thu, 29 Sep 2011)
Log Message:
-----------
make drawobject.c's code for getting the camera view frame into its own function. (no functional changes)

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_object.h
    trunk/blender/source/blender/blenkernel/intern/object.c
    trunk/blender/source/blender/editors/space_view3d/drawobject.c

Modified: trunk/blender/source/blender/blenkernel/BKE_object.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_object.h	2011-09-29 06:34:58 UTC (rev 40681)
+++ trunk/blender/source/blender/blenkernel/BKE_object.h	2011-09-29 07:59:33 UTC (rev 40682)
@@ -146,6 +146,11 @@
 		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

Modified: trunk/blender/source/blender/blenkernel/intern/object.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/object.c	2011-09-29 06:34:58 UTC (rev 40681)
+++ trunk/blender/source/blender/blenkernel/intern/object.c	2011-09-29 07:59:33 UTC (rev 40682)
@@ -3057,6 +3057,82 @@
 
 }
 
+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)
 {

Modified: trunk/blender/source/blender/editors/space_view3d/drawobject.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/drawobject.c	2011-09-29 06:34:58 UTC (rev 40681)
+++ trunk/blender/source/blender/editors/space_view3d/drawobject.c	2011-09-29 07:59:33 UTC (rev 40682)
@@ -1370,15 +1370,12 @@
 {
 	/* 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 @@
 #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;
-	}
-	
+	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]);
+
+	camera_view_frame_ex(scene, cam, cam->drawsize, is_view, scale,
+	                     asp, shift, &drawsize, vec);
+
 	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);
 
-		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;
-		}
-
-		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;
-
 	/* 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 @@
 		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();
 	}




More information about the Bf-blender-cvs mailing list