[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41561] trunk/blender/source/blender: Code refactoring: split camera functions from object.c into new camera.c.

Brecht Van Lommel brechtvanlommel at pandora.be
Sat Nov 5 14:00:39 CET 2011


Revision: 41561
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41561
Author:   blendix
Date:     2011-11-05 13:00:39 +0000 (Sat, 05 Nov 2011)
Log Message:
-----------
Code refactoring: split camera functions from object.c into new camera.c.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_object.h
    trunk/blender/source/blender/blenkernel/CMakeLists.txt
    trunk/blender/source/blender/blenkernel/intern/library.c
    trunk/blender/source/blender/blenkernel/intern/object.c
    trunk/blender/source/blender/collada/DocumentImporter.cpp
    trunk/blender/source/blender/editors/object/object_add.c
    trunk/blender/source/blender/editors/object/object_relations.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
    trunk/blender/source/blender/editors/space_view3d/drawobject.c
    trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
    trunk/blender/source/blender/makesrna/intern/rna_camera_api.c
    trunk/blender/source/blender/makesrna/intern/rna_main_api.c
    trunk/blender/source/blender/nodes/composite/node_composite_util.h
    trunk/blender/source/blender/render/intern/source/initrender.c
    trunk/blender/source/blender/render/intern/source/pipeline.c

Added Paths:
-----------
    trunk/blender/source/blender/blenkernel/BKE_camera.h
    trunk/blender/source/blender/blenkernel/intern/camera.c

Copied: trunk/blender/source/blender/blenkernel/BKE_camera.h (from rev 41560, trunk/blender/source/blender/blenkernel/BKE_object.h)
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_camera.h	                        (rev 0)
+++ trunk/blender/source/blender/blenkernel/BKE_camera.h	2011-11-05 13:00:39 UTC (rev 41561)
@@ -0,0 +1,71 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef BKE_CAMERA_H
+#define BKE_CAMERA_H
+
+/** \file BKE_camera.h
+ *  \ingroup bke
+ *  \brief Camera datablock and utility functions.
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct Camera;
+struct Object;
+struct RenderData;
+struct Scene;
+struct rctf;
+
+void *add_camera(const char *name);
+struct Camera *copy_camera(struct Camera *cam);
+void make_local_camera(struct Camera *cam);
+void free_camera(struct Camera *ca);
+
+float dof_camera(struct Object *ob);
+
+void object_camera_mode(struct RenderData *rd, struct Object *camera);
+void object_camera_intrinsics(struct Object *camera, struct Camera **cam_r, short *is_ortho, float *shiftx, float *shifty,
+			float *clipsta, float *clipend, float *lens, float *sensor_x, float *sensor_y, short *sensor_fit);
+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 *sensor_x, float *sensor_y, short *sensor_fit, 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_view_frame(struct Scene *scene, struct Camera *camera, float r_vec[4][3]);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+

Modified: trunk/blender/source/blender/blenkernel/BKE_object.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_object.h	2011-11-05 12:28:25 UTC (rev 41560)
+++ trunk/blender/source/blender/blenkernel/BKE_object.h	2011-11-05 13:00:39 UTC (rev 41561)
@@ -74,16 +74,11 @@
 
 void unlink_object(struct Object *ob);
 int exist_object(struct Object *obtest);
-void *add_camera(const char *name);
-struct Camera *copy_camera(struct Camera *cam);
-void make_local_camera(struct Camera *cam);
-float dof_camera(struct Object *ob);
 	
 void *add_lamp(const char *name);
 struct Lamp *copy_lamp(struct Lamp *la);
 struct Lamp *localize_lamp(struct Lamp *la);
 void make_local_lamp(struct Lamp *la);
-void free_camera(struct Camera *ca);
 void free_lamp(struct Lamp *la);
 
 struct Object *add_only_object(int type, const char *name);
@@ -138,20 +133,6 @@
 
 int object_is_modified(struct Scene *scene, struct Object *ob);
 
-void object_camera_mode(struct RenderData *rd, struct Object *camera);
-void object_camera_intrinsics(struct Object *camera, struct Camera **cam_r, short *is_ortho, float *shiftx, float *shifty,
-			float *clipsta, float *clipend, float *lens, float *sensor_x, float *sensor_y, short *sensor_fit);
-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 *sensor_x, float *sensor_y, short *sensor_fit, 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_view_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/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/blenkernel/CMakeLists.txt	2011-11-05 12:28:25 UTC (rev 41560)
+++ trunk/blender/source/blender/blenkernel/CMakeLists.txt	2011-11-05 13:00:39 UTC (rev 41561)
@@ -76,6 +76,7 @@
 	intern/brush.c
 	intern/bullet.c
 	intern/bvhutils.c
+	intern/camera.c
 	intern/cdderivedmesh.c
 	intern/cloth.c
 	intern/collision.c
@@ -160,6 +161,7 @@
 	BKE_brush.h
 	BKE_bullet.h
 	BKE_bvhutils.h
+	BKE_camera.h
 	BKE_cdderivedmesh.h
 	BKE_cloth.h
 	BKE_collision.h

Copied: trunk/blender/source/blender/blenkernel/intern/camera.c (from rev 41560, trunk/blender/source/blender/blenkernel/intern/object.c)
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/camera.c	                        (rev 0)
+++ trunk/blender/source/blender/blenkernel/intern/camera.c	2011-11-05 13:00:39 UTC (rev 41561)
@@ -0,0 +1,394 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenkernel/intern/camera.c
+ *  \ingroup bke
+ */
+
+#include "DNA_camera_types.h"
+#include "DNA_lamp_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
+
+#include "BKE_animsys.h"
+#include "BKE_camera.h"
+#include "BKE_global.h"
+#include "BKE_library.h"
+#include "BKE_main.h"
+
+void *add_camera(const char *name)
+{
+	Camera *cam;
+	
+	cam=  alloc_libblock(&G.main->camera, ID_CA, name);
+
+	cam->lens= 35.0f;
+	cam->sensor_x= 32.0f;
+	cam->sensor_y= 18.0f;
+	cam->clipsta= 0.1f;
+	cam->clipend= 100.0f;
+	cam->drawsize= 0.5f;
+	cam->ortho_scale= 6.0;
+	cam->flag |= CAM_SHOWPASSEPARTOUT;
+	cam->passepartalpha = 0.5f;
+	
+	return cam;
+}
+
+Camera *copy_camera(Camera *cam)
+{
+	Camera *camn;
+	
+	camn= copy_libblock(cam);
+	
+	return camn;
+}
+
+void make_local_camera(Camera *cam)
+{
+	Main *bmain= G.main;
+	Object *ob;
+	int is_local= FALSE, is_lib= FALSE;
+
+	/* - only lib users: do nothing
+	 * - only local users: set flag
+	 * - mixed: make copy
+	 */
+	
+	if(cam->id.lib==NULL) return;
+	if(cam->id.us==1) {
+		id_clear_lib_data(bmain, &cam->id);
+		return;
+	}
+	
+	for(ob= bmain->object.first; ob && ELEM(0, is_lib, is_local); ob= ob->id.next) {
+		if(ob->data==cam) {
+			if(ob->id.lib) is_lib= TRUE;
+			else is_local= TRUE;
+		}
+	}
+	
+	if(is_local && is_lib == FALSE) {
+		id_clear_lib_data(bmain, &cam->id);
+	}
+	else if(is_local && is_lib) {
+		Camera *camn= copy_camera(cam);
+
+		camn->id.us= 0;
+
+		/* Remap paths of new ID using old library as base. */
+		BKE_id_lib_local_paths(bmain, &camn->id);
+
+		for(ob= bmain->object.first; ob; ob= ob->id.next) {
+			if(ob->data == cam) {
+				if(ob->id.lib==NULL) {
+					ob->data= camn;
+					camn->id.us++;
+					cam->id.us--;
+				}
+			}
+		}
+	}
+}
+
+/* get the camera's dof value, takes the dof object into account */
+float dof_camera(Object *ob)
+{
+	Camera *cam = (Camera *)ob->data; 
+	if (ob->type != OB_CAMERA)
+		return 0.0f;
+	if (cam->dof_ob) {	
+		/* too simple, better to return the distance on the view axis only
+		 * return len_v3v3(ob->obmat[3], cam->dof_ob->obmat[3]); */
+		float mat[4][4], imat[4][4], obmat[4][4];
+		
+		copy_m4_m4(obmat, ob->obmat);
+		normalize_m4(obmat);
+		invert_m4_m4(imat, obmat);
+		mul_m4_m4m4(mat, cam->dof_ob->obmat, imat);
+		return (float)fabs(mat[3][2]);
+	}
+	return cam->YF_dofdist;
+}
+
+void free_camera(Camera *ca)
+{
+	BKE_free_animdata((ID *)ca);
+}
+
+void object_camera_mode(RenderData *rd, Object *camera)
+{
+	rd->mode &= ~(R_ORTHO|R_PANORAMA);
+	if(camera && camera->type==OB_CAMERA) {
+		Camera *cam= camera->data;
+		if(cam->type == CAM_ORTHO) rd->mode |= R_ORTHO;
+		if(cam->flag & CAM_PANORAMA) rd->mode |= R_PANORAMA;
+	}
+}
+
+void object_camera_intrinsics(Object *camera, Camera **cam_r, short *is_ortho, float *shiftx, float *shifty,
+			float *clipsta, float *clipend, float *lens, float *sensor_x, float *sensor_y, short *sensor_fit)
+{
+	Camera *cam= NULL;
+
+	(*shiftx)= 0.0f;
+	(*shifty)= 0.0f;
+
+	(*sensor_x)= DEFAULT_SENSOR_WIDTH;
+	(*sensor_y)= DEFAULT_SENSOR_HEIGHT;
+	(*sensor_fit)= CAMERA_SENSOR_FIT_AUTO;
+
+	if(camera->type==OB_CAMERA) {
+		cam= camera->data;
+
+		if(cam->type == CAM_ORTHO) {
+			*is_ortho= TRUE;
+		}
+
+		/* 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);
+		}

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list