[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30776] trunk/blender/source/blender/ editors/space_view3d: patch [#22901] pixel- and aspectratio corrected camera representation in 3dview

Campbell Barton ideasman42 at gmail.com
Mon Jul 26 23:35:25 CEST 2010


Revision: 30776
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30776
Author:   campbellbarton
Date:     2010-07-26 23:35:24 +0200 (Mon, 26 Jul 2010)

Log Message:
-----------
patch [#22901] pixel- and aspectratio corrected camera representation in 3dview
from Ralf H?\195?\182lzemer (cheleb) with my own edits to make the selected camera more clear in the camera view, this also works around the problem where you cant see the camera to select it with passepartout close to 1.0.

--- snip ---
Attached patch changes the camera representation to draw pixel- and aspectratio corrected in 3dview. It does also fix
a little issue where the camera name would jump when the title save would be (de)activated in the camera view.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_view3d/drawobject.c
    trunk/blender/source/blender/editors/space_view3d/view3d_draw.c

Modified: trunk/blender/source/blender/editors/space_view3d/drawobject.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/drawobject.c	2010-07-26 21:10:39 UTC (rev 30775)
+++ trunk/blender/source/blender/editors/space_view3d/drawobject.c	2010-07-26 21:35:24 UTC (rev 30776)
@@ -1248,17 +1248,28 @@
 	/* a standing up pyramid with (0,0,0) as top */
 	Camera *cam;
 	World *wrld;
-	float nobmat[4][4], vec[8][4], fac, facx, facy, depth;
+	float nobmat[4][4], vec[8][4], fac, facx, facy, depth, aspx, aspy, caspx, caspy;
 	int i;
 
 	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(rv3d->persp>=2 && cam->type==CAM_ORTHO && ob==v3d->camera) {
-		facx= 0.5*cam->ortho_scale*1.28;
-		facy= 0.5*cam->ortho_scale*1.024;
+		facx= 0.5*cam->ortho_scale*caspx;
+		facy= 0.5*cam->ortho_scale*caspy;
 		depth= -cam->clipsta-0.1;
 	}
 	else {
@@ -1266,8 +1277,8 @@
 		if(rv3d->persp>=2 && ob==v3d->camera) fac= cam->clipsta+0.1; /* that way it's always visible */
 		
 		depth= - fac*cam->lens/16.0;
-		facx= fac*1.28;
-		facy= fac*1.024;
+		facx= fac*caspx;
+		facy= fac*caspy;
 	}
 	
 	vec[0][0]= 0.0; vec[0][1]= 0.0; vec[0][2]= 0.001;	/* GLBUG: for picking at iris Entry (well thats old!) */
@@ -1308,16 +1319,16 @@
 		else if (i==1 && (ob == v3d->camera)) glBegin(GL_TRIANGLES);
 		else break;
 		
-		vec[0][0]= -0.7*cam->drawsize;
-		vec[0][1]= 1.1*cam->drawsize;
+		vec[0][0]= -0.7*cam->drawsize*caspx;
+		vec[0][1]= 1.1*cam->drawsize*caspy;
 		glVertex3fv(vec[0]);
 		
 		vec[0][0]= 0.0; 
-		vec[0][1]= 1.8*cam->drawsize;
+		vec[0][1]= 1.8*cam->drawsize*caspy;
 		glVertex3fv(vec[0]);
 		
-		vec[0][0]= 0.7*cam->drawsize; 
-		vec[0][1]= 1.1*cam->drawsize;
+		vec[0][0]= 0.7*cam->drawsize*caspx; 
+		vec[0][1]= 1.1*cam->drawsize*caspy;
 		glVertex3fv(vec[0]);
 	
 		glEnd();
@@ -6138,7 +6149,7 @@
 
 		/* draw extra: after normal draw because of makeDispList */
 		if(dtx && (G.f & G_RENDER_OGL)==0) {
-        
+
 			if(dtx & OB_AXIS) {
 				drawaxes(rv3d, rv3d->viewmatob, 1.0f, flag, OB_ARROWS);
 			}

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_draw.c	2010-07-26 21:10:39 UTC (rev 30775)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_draw.c	2010-07-26 21:35:24 UTC (rev 30776)
@@ -971,6 +971,7 @@
 	extern void gl_round_box(int mode, float minx, float miny, float maxx, float maxy, float rad);          // interface_panel.c
 	float fac, a;
 	float x1, x2, y1, y2;
+	float x1i, x2i, y1i, y2i;
 	float x3, y3, x4, y4;
 	rctf viewborder;
 	Camera *ca= NULL;
@@ -982,11 +983,18 @@
 		ca = v3d->camera->data;
 	
 	calc_viewborder(scene, ar, rv3d, v3d, &viewborder);
+	/* the offsets */
 	x1= viewborder.xmin;
 	y1= viewborder.ymin;
 	x2= viewborder.xmax;
 	y2= viewborder.ymax;
 	
+	/* apply offsets so the real 3D camera shows through */
+	x1i= (int)(x1 - 1.0f);
+	y1i= (int)(y1 - 1.0f);
+	x2i= (int)(x2 + 1.0f);
+	y2i= (int)(y2 + 1.0f);
+	
 	/* passepartout, specified in camera edit buttons */
 	if (ca && (ca->flag & CAM_SHOWPASSEPARTOUT) && ca->passepartalpha > 0.000001) {
 		if (ca->passepartalpha == 1.0) {
@@ -996,29 +1004,29 @@
 			glEnable(GL_BLEND);
 			glColor4f(0, 0, 0, ca->passepartalpha);
 		}
-		if (x1 > 0.0)
-			glRectf(0.0, (float)ar->winy, x1, 0.0);
-		if (x2 < (float)ar->winx)
-			glRectf(x2, (float)ar->winy, (float)ar->winx, 0.0);
-		if (y2 < (float)ar->winy)
-			glRectf(x1, (float)ar->winy, x2, y2);
-		if (y2 > 0.0) 
-			glRectf(x1, y1, x2, 0.0);
+		if (x1i > 0.0)
+			glRectf(0.0, (float)ar->winy, x1i, 0.0);
+		if (x2i < (float)ar->winx)
+			glRectf(x2i, (float)ar->winy, (float)ar->winx, 0.0);
+		if (y2i < (float)ar->winy)
+			glRectf(x1i, (float)ar->winy, x2i, y2i);
+		if (y2i > 0.0) 
+			glRectf(x1i, y1i, x2i, 0.0);
 		
 		glDisable(GL_BLEND);
 	}
-	
+
 	/* edge */
-	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); 
-	
+	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);	
+
 	setlinestyle(0);
 	UI_ThemeColor(TH_BACK);
-	glRectf(x1, y1, x2, y2);
+	glRectf(x1i, y1i, x2i, y2i);
 	
 	setlinestyle(3);
 	UI_ThemeColor(TH_WIRE);
-	glRectf(x1, y1, x2, y2);
-	
+	glRectf(x1i, y1i, x2i, y2i);
+
 	/* border */
 	if(scene->r.mode & R_BORDER) {
 		
@@ -1031,7 +1039,7 @@
 		cpack(0x4040FF);
 		glRectf(x3,  y3,  x4,  y4); 
 	}
-	
+    
 	/* safety border */
 	if (ca && (ca->flag & CAM_SHOWTITLESAFE)) {
 		fac= 0.1;
@@ -1049,14 +1057,14 @@
 		uiSetRoundBox(15);
 		gl_round_box(GL_LINE_LOOP, x1, y1, x2, y2, 12.0);
 	}
-	
+
 	setlinestyle(0);
 	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-	
+
 	/* camera name - draw in highlighted text color */
 	if (ca && (ca->flag & CAM_SHOWNAME)) {
 		UI_ThemeColor(TH_TEXT_HI);
-		BLF_draw_default(x1, y1-15, 0.0f, v3d->camera->id.name+2);
+		BLF_draw_default(x1i, y1i-15, 0.0f, v3d->camera->id.name+2);
 		UI_ThemeColor(TH_WIRE);
 	}
 }





More information about the Bf-blender-cvs mailing list