[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27277] trunk/blender/source/blender: utility function object_camera_matrix, moved code from RE_SetCamera into this.

Campbell Barton ideasman42 at gmail.com
Fri Mar 5 15:06:41 CET 2010


Revision: 27277
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27277
Author:   campbellbarton
Date:     2010-03-05 15:06:39 +0100 (Fri, 05 Mar 2010)

Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_object.h
    trunk/blender/source/blender/blenkernel/intern/object.c
    trunk/blender/source/blender/editors/gpencil/drawgpencil.c
    trunk/blender/source/blender/editors/gpencil/gpencil_paint.c
    trunk/blender/source/blender/editors/space_sequencer/sequencer_draw.c
    trunk/blender/source/blender/editors/space_sequencer/sequencer_edit.c
    trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
    trunk/blender/source/blender/render/intern/source/initrender.c

Modified: trunk/blender/source/blender/blenkernel/BKE_object.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_object.h	2010-03-05 13:00:48 UTC (rev 27276)
+++ trunk/blender/source/blender/blenkernel/BKE_object.h	2010-03-05 14:06:39 UTC (rev 27277)
@@ -45,6 +45,7 @@
 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 @@
 // 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
 }

Modified: trunk/blender/source/blender/blenkernel/intern/object.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/object.c	2010-03-05 13:00:48 UTC (rev 27276)
+++ trunk/blender/source/blender/blenkernel/intern/object.c	2010-03-05 14:06:39 UTC (rev 27277)
@@ -2715,6 +2715,115 @@
 	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)
 {

Modified: trunk/blender/source/blender/editors/gpencil/drawgpencil.c
===================================================================
--- trunk/blender/source/blender/editors/gpencil/drawgpencil.c	2010-03-05 13:00:48 UTC (rev 27276)
+++ trunk/blender/source/blender/editors/gpencil/drawgpencil.c	2010-03-05 14:06:39 UTC (rev 27277)
@@ -684,7 +684,7 @@
 			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

Modified: trunk/blender/source/blender/editors/gpencil/gpencil_paint.c
===================================================================
--- trunk/blender/source/blender/editors/gpencil/gpencil_paint.c	2010-03-05 13:00:48 UTC (rev 27276)
+++ trunk/blender/source/blender/editors/gpencil/gpencil_paint.c	2010-03-05 14:06:39 UTC (rev 27277)
@@ -1077,7 +1077,7 @@
 				/* 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

Modified: trunk/blender/source/blender/editors/space_sequencer/sequencer_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_sequencer/sequencer_draw.c	2010-03-05 13:00:48 UTC (rev 27276)
+++ trunk/blender/source/blender/editors/space_sequencer/sequencer_draw.c	2010-03-05 14:06:39 UTC (rev 27277)
@@ -678,7 +678,7 @@
 	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;
 	}

Modified: trunk/blender/source/blender/editors/space_sequencer/sequencer_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_sequencer/sequencer_edit.c	2010-03-05 13:00:48 UTC (rev 27276)
+++ trunk/blender/source/blender/editors/space_sequencer/sequencer_edit.c	2010-03-05 14:06:39 UTC (rev 27277)
@@ -2237,7 +2237,7 @@
 	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))) {

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_draw.c	2010-03-05 13:00:48 UTC (rev 27276)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_draw.c	2010-03-05 14:06:39 UTC (rev 27277)
@@ -854,7 +854,7 @@
 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;

Modified: trunk/blender/source/blender/render/intern/source/initrender.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/initrender.c	2010-03-05 13:00:48 UTC (rev 27276)
+++ trunk/blender/source/blender/render/intern/source/initrender.c	2010-03-05 14:06:39 UTC (rev 27277)
@@ -447,117 +447,9 @@
 /* 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) ) {

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list