Blender  V2.93
camera.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
24 #include <stddef.h>
25 #include <stdlib.h>
26 
27 /* Allow using deprecated functionality for .blend file I/O. */
28 #define DNA_DEPRECATED_ALLOW
29 
30 #include "DNA_ID.h"
31 #include "DNA_camera_types.h"
32 #include "DNA_defaults.h"
33 #include "DNA_light_types.h"
34 #include "DNA_object_types.h"
35 #include "DNA_scene_types.h"
36 #include "DNA_view3d_types.h"
37 
38 #include "BLI_listbase.h"
39 #include "BLI_math.h"
40 #include "BLI_rect.h"
41 #include "BLI_string.h"
42 #include "BLI_utildefines.h"
43 
44 #include "BKE_anim_data.h"
45 #include "BKE_camera.h"
46 #include "BKE_idtype.h"
47 #include "BKE_layer.h"
48 #include "BKE_lib_id.h"
49 #include "BKE_lib_query.h"
50 #include "BKE_main.h"
51 #include "BKE_object.h"
52 #include "BKE_scene.h"
53 #include "BKE_screen.h"
54 
55 #include "BLT_translation.h"
56 
57 #include "DEG_depsgraph_query.h"
58 
59 #include "MEM_guardedalloc.h"
60 
61 #include "BLO_read_write.h"
62 
63 /* -------------------------------------------------------------------- */
67 static void camera_init_data(ID *id)
68 {
69  Camera *cam = (Camera *)id;
71 
73 }
74 
85 static void camera_copy_data(Main *UNUSED(bmain),
86  ID *id_dst,
87  const ID *id_src,
88  const int UNUSED(flag))
89 {
90  Camera *cam_dst = (Camera *)id_dst;
91  const Camera *cam_src = (const Camera *)id_src;
92  BLI_duplicatelist(&cam_dst->bg_images, &cam_src->bg_images);
93 }
94 
95 static void camera_make_local(Main *bmain, ID *id, const int flags)
96 {
97  BKE_lib_id_make_local_generic(bmain, id, flags);
98 }
99 
101 static void camera_free_data(ID *id)
102 {
103  Camera *cam = (Camera *)id;
104  BLI_freelistN(&cam->bg_images);
105 }
106 
108 {
109  Camera *camera = (Camera *)id;
110 
112  LISTBASE_FOREACH (CameraBGImage *, bgpic, &camera->bg_images) {
113  if (bgpic->source == CAM_BGIMG_SOURCE_IMAGE) {
115  }
116  else if (bgpic->source == CAM_BGIMG_SOURCE_MOVIE) {
118  }
119  }
120 }
121 
122 static void camera_blend_write(BlendWriter *writer, ID *id, const void *id_address)
123 {
124  Camera *cam = (Camera *)id;
125  if (cam->id.us > 0 || BLO_write_is_undo(writer)) {
126  /* write LibData */
127  BLO_write_id_struct(writer, Camera, id_address, &cam->id);
128  BKE_id_blend_write(writer, &cam->id);
129 
130  if (cam->adt) {
131  BKE_animdata_blend_write(writer, cam->adt);
132  }
133 
134  LISTBASE_FOREACH (CameraBGImage *, bgpic, &cam->bg_images) {
135  BLO_write_struct(writer, CameraBGImage, bgpic);
136  }
137  }
138 }
139 
140 static void camera_blend_read_data(BlendDataReader *reader, ID *id)
141 {
142  Camera *ca = (Camera *)id;
143  BLO_read_data_address(reader, &ca->adt);
144  BKE_animdata_blend_read_data(reader, ca->adt);
145 
146  BLO_read_list(reader, &ca->bg_images);
147 
148  LISTBASE_FOREACH (CameraBGImage *, bgpic, &ca->bg_images) {
149  bgpic->iuser.ok = 1;
150  bgpic->iuser.scene = NULL;
151  }
152 }
153 
154 static void camera_blend_read_lib(BlendLibReader *reader, ID *id)
155 {
156  Camera *ca = (Camera *)id;
157  BLO_read_id_address(reader, ca->id.lib, &ca->ipo); /* deprecated, for versioning */
158 
159  BLO_read_id_address(reader, ca->id.lib, &ca->dof_ob); /* deprecated, for versioning */
160  BLO_read_id_address(reader, ca->id.lib, &ca->dof.focus_object);
161 
162  LISTBASE_FOREACH (CameraBGImage *, bgpic, &ca->bg_images) {
163  BLO_read_id_address(reader, ca->id.lib, &bgpic->ima);
164  BLO_read_id_address(reader, ca->id.lib, &bgpic->clip);
165  }
166 }
167 
168 static void camera_blend_read_expand(BlendExpander *expander, ID *id)
169 {
170  Camera *ca = (Camera *)id;
171  BLO_expand(expander, ca->ipo); // XXX deprecated - old animation system
172 
173  LISTBASE_FOREACH (CameraBGImage *, bgpic, &ca->bg_images) {
174  if (bgpic->source == CAM_BGIMG_SOURCE_IMAGE) {
175  BLO_expand(expander, bgpic->ima);
176  }
177  else if (bgpic->source == CAM_BGIMG_SOURCE_MOVIE) {
178  BLO_expand(expander, bgpic->ima);
179  }
180  }
181 }
182 
184  .id_code = ID_CA,
185  .id_filter = FILTER_ID_CA,
186  .main_listbase_index = INDEX_ID_CA,
187  .struct_size = sizeof(Camera),
188  .name = "Camera",
189  .name_plural = "cameras",
190  .translation_context = BLT_I18NCONTEXT_ID_CAMERA,
191  .flags = 0,
192 
194  .copy_data = camera_copy_data,
195  .free_data = camera_free_data,
196  .make_local = camera_make_local,
197  .foreach_id = camera_foreach_id,
198  .foreach_cache = NULL,
199  .owner_get = NULL,
200 
201  .blend_write = camera_blend_write,
202  .blend_read_data = camera_blend_read_data,
203  .blend_read_lib = camera_blend_read_lib,
204  .blend_read_expand = camera_blend_read_expand,
205 
206  .blend_read_undo_preserve = NULL,
207 
208  .lib_override_apply_post = NULL,
209 };
210 
213 /* -------------------------------------------------------------------- */
217 void *BKE_camera_add(Main *bmain, const char *name)
218 {
219  Camera *cam;
220 
221  cam = BKE_id_new(bmain, ID_CA, name);
222 
223  return cam;
224 }
225 
226 /* get the camera's dof value, takes the dof object into account */
228 {
229  Camera *cam = (Camera *)ob->data;
230  if (ob->type != OB_CAMERA) {
231  return 0.0f;
232  }
233  if (cam->dof.focus_object) {
234  float view_dir[3], dof_dir[3];
235  normalize_v3_v3(view_dir, ob->obmat[2]);
236  sub_v3_v3v3(dof_dir, ob->obmat[3], cam->dof.focus_object->obmat[3]);
237  return fabsf(dot_v3v3(view_dir, dof_dir));
238  }
239  return cam->dof.focus_distance;
240 }
241 
242 float BKE_camera_sensor_size(int sensor_fit, float sensor_x, float sensor_y)
243 {
244  /* sensor size used to fit to. for auto, sensor_x is both x and y. */
245  if (sensor_fit == CAMERA_SENSOR_FIT_VERT) {
246  return sensor_y;
247  }
248 
249  return sensor_x;
250 }
251 
252 int BKE_camera_sensor_fit(int sensor_fit, float sizex, float sizey)
253 {
254  if (sensor_fit == CAMERA_SENSOR_FIT_AUTO) {
255  if (sizex >= sizey) {
256  return CAMERA_SENSOR_FIT_HOR;
257  }
258 
259  return CAMERA_SENSOR_FIT_VERT;
260  }
261 
262  return sensor_fit;
263 }
264 
267 /* -------------------------------------------------------------------- */
272 {
273  memset(params, 0, sizeof(CameraParams));
274 
275  /* defaults */
276  params->sensor_x = DEFAULT_SENSOR_WIDTH;
277  params->sensor_y = DEFAULT_SENSOR_HEIGHT;
278  params->sensor_fit = CAMERA_SENSOR_FIT_AUTO;
279 
280  params->zoom = 1.0f;
281 
282  /* fallback for non camera objects */
283  params->clip_start = 0.1f;
284  params->clip_end = 100.0f;
285 }
286 
288 {
289  if (!cam_ob) {
290  return;
291  }
292 
293  if (cam_ob->type == OB_CAMERA) {
294  /* camera object */
295  Camera *cam = cam_ob->data;
296 
297  if (cam->type == CAM_ORTHO) {
298  params->is_ortho = true;
299  }
300  params->lens = cam->lens;
301  params->ortho_scale = cam->ortho_scale;
302 
303  params->shiftx = cam->shiftx;
304  params->shifty = cam->shifty;
305 
306  params->sensor_x = cam->sensor_x;
307  params->sensor_y = cam->sensor_y;
308  params->sensor_fit = cam->sensor_fit;
309 
310  params->clip_start = cam->clip_start;
311  params->clip_end = cam->clip_end;
312  }
313  else if (cam_ob->type == OB_LAMP) {
314  /* light object */
315  Light *la = cam_ob->data;
316  params->lens = 16.0f / tanf(la->spotsize * 0.5f);
317  if (params->lens == 0.0f) {
318  params->lens = 35.0f;
319  }
320  }
321  else {
322  params->lens = 35.0f;
323  }
324 }
325 
328  const View3D *v3d,
329  const RegionView3D *rv3d)
330 {
331  /* common */
332  params->lens = v3d->lens;
333  params->clip_start = v3d->clip_start;
334  params->clip_end = v3d->clip_end;
335 
336  if (rv3d->persp == RV3D_CAMOB) {
337  /* camera view */
338  const Object *ob_camera_eval = DEG_get_evaluated_object(depsgraph, v3d->camera);
339  BKE_camera_params_from_object(params, ob_camera_eval);
340 
342 
343  params->offsetx = 2.0f * rv3d->camdx * params->zoom;
344  params->offsety = 2.0f * rv3d->camdy * params->zoom;
345 
346  params->shiftx *= params->zoom;
347  params->shifty *= params->zoom;
348 
350  }
351  else if (rv3d->persp == RV3D_ORTHO) {
352  /* orthographic view */
353  float sensor_size = BKE_camera_sensor_size(
354  params->sensor_fit, params->sensor_x, params->sensor_y);
355  /* Halve, otherwise too extreme low zbuffer quality. */
356  params->clip_end *= 0.5f;
357  params->clip_start = -params->clip_end;
358 
359  params->is_ortho = true;
360  /* make sure any changes to this match ED_view3d_radius_to_dist_ortho() */
361  params->ortho_scale = rv3d->dist * sensor_size / v3d->lens;
363  }
364  else {
365  /* perspective view */
367  }
368 }
369 
371  CameraParams *params, int winx, int winy, float aspx, float aspy)
372 {
373  rctf viewplane;
374  float pixsize, viewfac, sensor_size, dx, dy;
375  int sensor_fit;
376 
377  params->ycor = aspy / aspx;
378 
379  if (params->is_ortho) {
380  /* orthographic camera */
381  /* scale == 1.0 means exact 1 to 1 mapping */
382  pixsize = params->ortho_scale;
383  }
384  else {
385  /* perspective camera */
386  sensor_size = BKE_camera_sensor_size(params->sensor_fit, params->sensor_x, params->sensor_y);
387  pixsize = (sensor_size * params->clip_start) / params->lens;
388  }
389 
390  /* determine sensor fit */
391  sensor_fit = BKE_camera_sensor_fit(params->sensor_fit, aspx * winx, aspy * winy);
392 
393  if (sensor_fit == CAMERA_SENSOR_FIT_HOR) {
394  viewfac = winx;
395  }
396  else {
397  viewfac = params->ycor * winy;
398  }
399 
400  pixsize /= viewfac;
401 
402  /* extra zoom factor */
403  pixsize *= params->zoom;
404 
405  /* compute view plane:
406  * fully centered, zbuffer fills in jittered between -.5 and +.5 */
407  viewplane.xmin = -0.5f * (float)winx;
408  viewplane.ymin = -0.5f * params->ycor * (float)winy;
409  viewplane.xmax = 0.5f * (float)winx;
410  viewplane.ymax = 0.5f * params->ycor * (float)winy;
411 
412  /* lens shift and offset */
413  dx = params->shiftx * viewfac + winx * params->offsetx;
414  dy = params->shifty * viewfac + winy * params->offsety;
415 
416  viewplane.xmin += dx;
417  viewplane.ymin += dy;
418  viewplane.xmax += dx;
419  viewplane.ymax += dy;
420 
421  /* the window matrix is used for clipping, and not changed during OSA steps */
422  /* using an offset of +0.5 here would give clip errors on edges */
423  viewplane.xmin *= pixsize;
424  viewplane.xmax *= pixsize;
425  viewplane.ymin *= pixsize;
426  viewplane.ymax *= pixsize;
427 
428  /* Used for rendering (offset by near-clip with perspective views), passed to RE_SetPixelSize.
429  * For viewport drawing 'RegionView3D.pixsize'. */
430  params->viewdx = pixsize;
431  params->viewdy = params->ycor * pixsize;
432  params->viewplane = viewplane;
433 }
434 
435 /* viewplane is assumed to be already computed */
437 {
438  rctf viewplane = params->viewplane;
439 
440  /* compute projection matrix */
441  if (params->is_ortho) {
442  orthographic_m4(params->winmat,
443  viewplane.xmin,
444  viewplane.xmax,
445  viewplane.ymin,
446  viewplane.ymax,
447  params->clip_start,
448  params->clip_end);
449  }
450  else {
451  perspective_m4(params->winmat,
452  viewplane.xmin,
453  viewplane.xmax,
454  viewplane.ymin,
455  viewplane.ymax,
456  params->clip_start,
457  params->clip_end);
458  }
459 }
460 
463 /* -------------------------------------------------------------------- */
468  const Camera *camera,
469  const float drawsize,
470  const bool do_clip,
471  const float scale[3],
472  float r_asp[2],
473  float r_shift[2],
474  float *r_drawsize,
475  float r_vec[4][3])
476 {
477  float facx, facy;
478  float depth;
479 
480  /* aspect correction */
481  if (scene) {
482  float aspx = (float)scene->r.xsch * scene->r.xasp;
483  float aspy = (float)scene->r.ysch * scene->r.yasp;
484  int sensor_fit = BKE_camera_sensor_fit(camera->sensor_fit, aspx, aspy);
485 
486  if (sensor_fit == CAMERA_SENSOR_FIT_HOR) {
487  r_asp[0] = 1.0;
488  r_asp[1] = aspy / aspx;
489  }
490  else {
491  r_asp[0] = aspx / aspy;
492  r_asp[1] = 1.0;
493  }
494  }
495  else {
496  r_asp[0] = 1.0f;
497  r_asp[1] = 1.0f;
498  }
499 
500  if (camera->type == CAM_ORTHO) {
501  facx = 0.5f * camera->ortho_scale * r_asp[0] * scale[0];
502  facy = 0.5f * camera->ortho_scale * r_asp[1] * scale[1];
503  r_shift[0] = camera->shiftx * camera->ortho_scale * scale[0];
504  r_shift[1] = camera->shifty * camera->ortho_scale * scale[1];
505  depth = -drawsize * scale[2];
506 
507  *r_drawsize = 0.5f * camera->ortho_scale;
508  }
509  else {
510  /* that way it's always visible - clip_start+0.1 */
511  float fac, scale_x, scale_y;
512  float half_sensor = 0.5f * ((camera->sensor_fit == CAMERA_SENSOR_FIT_VERT) ?
513  (camera->sensor_y) :
514  (camera->sensor_x));
515 
516  /* fixed size, variable depth (stays a reasonable size in the 3D view) */
517  *r_drawsize = (drawsize / 2.0f) / ((scale[0] + scale[1] + scale[2]) / 3.0f);
518  depth = *r_drawsize * camera->lens / (-half_sensor) * scale[2];
519  fac = *r_drawsize;
520  scale_x = scale[0];
521  scale_y = scale[1];
522 
523  facx = fac * r_asp[0] * scale_x;
524  facy = fac * r_asp[1] * scale_y;
525  r_shift[0] = camera->shiftx * fac * 2.0f * scale_x;
526  r_shift[1] = camera->shifty * fac * 2.0f * scale_y;
527  }
528 
529  r_vec[0][0] = r_shift[0] + facx;
530  r_vec[0][1] = r_shift[1] + facy;
531  r_vec[0][2] = depth;
532  r_vec[1][0] = r_shift[0] + facx;
533  r_vec[1][1] = r_shift[1] - facy;
534  r_vec[1][2] = depth;
535  r_vec[2][0] = r_shift[0] - facx;
536  r_vec[2][1] = r_shift[1] - facy;
537  r_vec[2][2] = depth;
538  r_vec[3][0] = r_shift[0] - facx;
539  r_vec[3][1] = r_shift[1] + facy;
540  r_vec[3][2] = depth;
541 
542  if (do_clip) {
543  /* Ensure the frame isn't behind the near clipping plane, T62814. */
544  float fac = (camera->clip_start + 0.1f) / -r_vec[0][2];
545  for (uint i = 0; i < 4; i++) {
546  if (camera->type == CAM_ORTHO) {
547  r_vec[i][2] *= fac;
548  }
549  else {
550  mul_v3_fl(r_vec[i], fac);
551  }
552  }
553  }
554 }
555 
556 void BKE_camera_view_frame(const Scene *scene, const Camera *camera, float r_vec[4][3])
557 {
558  float dummy_asp[2];
559  float dummy_shift[2];
560  float dummy_drawsize;
561  const float dummy_scale[3] = {1.0f, 1.0f, 1.0f};
562 
564  scene, camera, 1.0, false, dummy_scale, dummy_asp, dummy_shift, &dummy_drawsize, r_vec);
565 }
566 
569 /* -------------------------------------------------------------------- */
573 #define CAMERA_VIEWFRAME_NUM_PLANES 4
574 
575 typedef struct CameraViewFrameData {
576  float plane_tx[CAMERA_VIEWFRAME_NUM_PLANES][4]; /* 4 planes */
578  float dist_vals_sq[CAMERA_VIEWFRAME_NUM_PLANES]; /* distance squared (signed) */
579  unsigned int tot;
580 
581  /* Ortho camera only. */
582  bool is_ortho;
583  float camera_no[3];
584  float dist_to_cam;
585 
586  /* Not used by callbacks... */
587  float camera_rotmat[3][3];
589 
590 static void camera_to_frame_view_cb(const float co[3], void *user_data)
591 {
593 
594  for (uint i = 0; i < CAMERA_VIEWFRAME_NUM_PLANES; i++) {
595  const float nd = dist_signed_squared_to_plane_v3(co, data->plane_tx[i]);
596  CLAMP_MAX(data->dist_vals_sq[i], nd);
597  }
598 
599  if (data->is_ortho) {
600  const float d = dot_v3v3(data->camera_no, co);
601  CLAMP_MAX(data->dist_to_cam, d);
602  }
603 
604  data->tot++;
605 }
606 
608  const Object *ob,
611 {
612  float camera_rotmat_transposed_inversed[4][4];
613 
614  /* setup parameters */
617 
618  /* compute matrix, viewplane, .. */
619  if (scene) {
622  }
623  else {
624  BKE_camera_params_compute_viewplane(params, 1, 1, 1.0f, 1.0f);
625  }
627 
628  /* initialize callback data */
629  copy_m3_m4(data->camera_rotmat, (float(*)[4])ob->obmat);
630  normalize_m3(data->camera_rotmat);
631  /* To transform a plane which is in its homogeneous representation (4d vector),
632  * we need the inverse of the transpose of the transform matrix... */
633  copy_m4_m3(camera_rotmat_transposed_inversed, data->camera_rotmat);
634  transpose_m4(camera_rotmat_transposed_inversed);
635  invert_m4(camera_rotmat_transposed_inversed);
636 
637  /* Extract frustum planes from projection matrix. */
639  params->winmat,
640  /* left right top bottom near far */
641  data->plane_tx[2],
642  data->plane_tx[0],
643  data->plane_tx[3],
644  data->plane_tx[1],
645  NULL,
646  NULL);
647 
648  /* Rotate planes and get normals from them */
649  for (uint i = 0; i < CAMERA_VIEWFRAME_NUM_PLANES; i++) {
650  mul_m4_v4(camera_rotmat_transposed_inversed, data->plane_tx[i]);
651  normalize_v3_v3(data->normal_tx[i], data->plane_tx[i]);
652  }
653 
654  copy_v4_fl(data->dist_vals_sq, FLT_MAX);
655  data->tot = 0;
656  data->is_ortho = params->is_ortho;
657  if (params->is_ortho) {
658  /* we want (0, 0, -1) transformed by camera_rotmat, this is a quicker shortcut. */
659  negate_v3_v3(data->camera_no, data->camera_rotmat[2]);
660  data->dist_to_cam = FLT_MAX;
661  }
662 }
663 
666  float r_co[3],
667  float *r_scale)
668 {
669  float plane_tx[CAMERA_VIEWFRAME_NUM_PLANES][4];
670 
671  if (data->tot <= 1) {
672  return false;
673  }
674 
675  if (params->is_ortho) {
676  const float *cam_axis_x = data->camera_rotmat[0];
677  const float *cam_axis_y = data->camera_rotmat[1];
678  const float *cam_axis_z = data->camera_rotmat[2];
679  float dists[CAMERA_VIEWFRAME_NUM_PLANES];
680  float scale_diff;
681 
682  /* apply the dist-from-plane's to the transformed plane points */
683  for (int i = 0; i < CAMERA_VIEWFRAME_NUM_PLANES; i++) {
684  dists[i] = sqrtf_signed(data->dist_vals_sq[i]);
685  }
686 
687  if ((dists[0] + dists[2]) > (dists[1] + dists[3])) {
688  scale_diff = (dists[1] + dists[3]) *
689  (BLI_rctf_size_x(&params->viewplane) / BLI_rctf_size_y(&params->viewplane));
690  }
691  else {
692  scale_diff = (dists[0] + dists[2]) *
693  (BLI_rctf_size_y(&params->viewplane) / BLI_rctf_size_x(&params->viewplane));
694  }
695  *r_scale = params->ortho_scale - scale_diff;
696 
697  zero_v3(r_co);
698  madd_v3_v3fl(r_co, cam_axis_x, (dists[2] - dists[0]) * 0.5f + params->shiftx * scale_diff);
699  madd_v3_v3fl(r_co, cam_axis_y, (dists[1] - dists[3]) * 0.5f + params->shifty * scale_diff);
700  madd_v3_v3fl(r_co, cam_axis_z, -(data->dist_to_cam - 1.0f - params->clip_start));
701 
702  return true;
703  }
704 
705  float plane_isect_1[3], plane_isect_1_no[3], plane_isect_1_other[3];
706  float plane_isect_2[3], plane_isect_2_no[3], plane_isect_2_other[3];
707 
708  float plane_isect_pt_1[3], plane_isect_pt_2[3];
709 
710  /* apply the dist-from-plane's to the transformed plane points */
711  for (int i = 0; i < CAMERA_VIEWFRAME_NUM_PLANES; i++) {
712  float co[3];
713  mul_v3_v3fl(co, data->normal_tx[i], sqrtf_signed(data->dist_vals_sq[i]));
714  plane_from_point_normal_v3(plane_tx[i], co, data->normal_tx[i]);
715  }
716 
717  if ((!isect_plane_plane_v3(plane_tx[0], plane_tx[2], plane_isect_1, plane_isect_1_no)) ||
718  (!isect_plane_plane_v3(plane_tx[1], plane_tx[3], plane_isect_2, plane_isect_2_no))) {
719  return false;
720  }
721 
722  add_v3_v3v3(plane_isect_1_other, plane_isect_1, plane_isect_1_no);
723  add_v3_v3v3(plane_isect_2_other, plane_isect_2, plane_isect_2_no);
724 
725  if (isect_line_line_v3(plane_isect_1,
726  plane_isect_1_other,
727  plane_isect_2,
728  plane_isect_2_other,
729  plane_isect_pt_1,
730  plane_isect_pt_2) != 0) {
731  float cam_plane_no[3];
732  float plane_isect_delta[3];
733  float plane_isect_delta_len;
734 
735  float shift_fac = BKE_camera_sensor_size(
736  params->sensor_fit, params->sensor_x, params->sensor_y) /
737  params->lens;
738 
739  /* we want (0, 0, -1) transformed by camera_rotmat, this is a quicker shortcut. */
740  negate_v3_v3(cam_plane_no, data->camera_rotmat[2]);
741 
742  sub_v3_v3v3(plane_isect_delta, plane_isect_pt_2, plane_isect_pt_1);
743  plane_isect_delta_len = len_v3(plane_isect_delta);
744 
745  if (dot_v3v3(plane_isect_delta, cam_plane_no) > 0.0f) {
746  copy_v3_v3(r_co, plane_isect_pt_1);
747 
748  /* offset shift */
749  normalize_v3(plane_isect_1_no);
750  madd_v3_v3fl(r_co, plane_isect_1_no, params->shifty * plane_isect_delta_len * shift_fac);
751  }
752  else {
753  copy_v3_v3(r_co, plane_isect_pt_2);
754 
755  /* offset shift */
756  normalize_v3(plane_isect_2_no);
757  madd_v3_v3fl(r_co, plane_isect_2_no, params->shiftx * plane_isect_delta_len * shift_fac);
758  }
759 
760  return true;
761  }
762 
763  return false;
764 }
765 
766 /* don't move the camera, just yield the fit location */
767 /* r_scale only valid/useful for ortho cameras */
769  Depsgraph *depsgraph, const Scene *scene, Object *camera_ob, float r_co[3], float *r_scale)
770 {
772  CameraViewFrameData data_cb;
773 
774  /* just in case */
775  *r_scale = 1.0f;
776 
777  camera_frame_fit_data_init(scene, camera_ob, &params, &data_cb);
778 
779  /* run callback on all visible points */
781 
782  return camera_frame_fit_calc_from_data(&params, &data_cb, r_co, r_scale);
783 }
784 
786  const float (*cos)[3],
787  int num_cos,
788  Object *camera_ob,
789  float r_co[3],
790  float *r_scale)
791 {
792  Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
793  Object *camera_ob_eval = DEG_get_evaluated_object(depsgraph, camera_ob);
795  CameraViewFrameData data_cb;
796 
797  /* just in case */
798  *r_scale = 1.0f;
799 
800  camera_frame_fit_data_init(scene_eval, camera_ob_eval, &params, &data_cb);
801 
802  /* run callback on all given coordinates */
803  while (num_cos--) {
804  camera_to_frame_view_cb(cos[num_cos], &data_cb);
805  }
806 
807  return camera_frame_fit_calc_from_data(&params, &data_cb, r_co, r_scale);
808 }
809 
812 /* -------------------------------------------------------------------- */
816 static void camera_model_matrix(const Object *camera, float r_modelmat[4][4])
817 {
818  copy_m4_m4(r_modelmat, camera->obmat);
819 }
820 
821 static void camera_stereo3d_model_matrix(const Object *camera,
822  const bool is_left,
823  float r_modelmat[4][4])
824 {
825  Camera *data = (Camera *)camera->data;
826  float interocular_distance, convergence_distance;
827  short convergence_mode, pivot;
828  float sizemat[4][4];
829 
830  float fac = 1.0f;
831  float fac_signed;
832 
833  interocular_distance = data->stereo.interocular_distance;
834  convergence_distance = data->stereo.convergence_distance;
835  convergence_mode = data->stereo.convergence_mode;
836  pivot = data->stereo.pivot;
837 
838  if (((pivot == CAM_S3D_PIVOT_LEFT) && is_left) || ((pivot == CAM_S3D_PIVOT_RIGHT) && !is_left)) {
839  camera_model_matrix(camera, r_modelmat);
840  return;
841  }
842 
843  float size[3];
844  mat4_to_size(size, camera->obmat);
845  size_to_mat4(sizemat, size);
846 
847  if (pivot == CAM_S3D_PIVOT_CENTER) {
848  fac = 0.5f;
849  }
850 
851  fac_signed = is_left ? fac : -fac;
852 
853  /* rotation */
854  if (convergence_mode == CAM_S3D_TOE) {
855  float angle;
856  float angle_sin, angle_cos;
857  float toeinmat[4][4];
858  float rotmat[4][4];
859 
860  unit_m4(rotmat);
861 
862  if (pivot == CAM_S3D_PIVOT_CENTER) {
863  fac = -fac;
864  fac_signed = -fac_signed;
865  }
866 
867  angle = atanf((interocular_distance * 0.5f) / convergence_distance) / fac;
868 
869  angle_cos = cosf(angle * fac_signed);
870  angle_sin = sinf(angle * fac_signed);
871 
872  rotmat[0][0] = angle_cos;
873  rotmat[2][0] = -angle_sin;
874  rotmat[0][2] = angle_sin;
875  rotmat[2][2] = angle_cos;
876 
877  if (pivot == CAM_S3D_PIVOT_CENTER) {
878  /* set the rotation */
879  copy_m4_m4(toeinmat, rotmat);
880  /* set the translation */
881  toeinmat[3][0] = interocular_distance * fac_signed;
882 
883  /* transform */
884  normalize_m4_m4(r_modelmat, camera->obmat);
885  mul_m4_m4m4(r_modelmat, r_modelmat, toeinmat);
886 
887  /* scale back to the original size */
888  mul_m4_m4m4(r_modelmat, r_modelmat, sizemat);
889  }
890  else { /* CAM_S3D_PIVOT_LEFT, CAM_S3D_PIVOT_RIGHT */
891  /* rotate perpendicular to the interocular line */
892  normalize_m4_m4(r_modelmat, camera->obmat);
893  mul_m4_m4m4(r_modelmat, r_modelmat, rotmat);
894 
895  /* translate along the interocular line */
896  unit_m4(toeinmat);
897  toeinmat[3][0] = -interocular_distance * fac_signed;
898  mul_m4_m4m4(r_modelmat, r_modelmat, toeinmat);
899 
900  /* rotate to toe-in angle */
901  mul_m4_m4m4(r_modelmat, r_modelmat, rotmat);
902 
903  /* scale back to the original size */
904  mul_m4_m4m4(r_modelmat, r_modelmat, sizemat);
905  }
906  }
907  else {
908  normalize_m4_m4(r_modelmat, camera->obmat);
909 
910  /* translate - no rotation in CAM_S3D_OFFAXIS, CAM_S3D_PARALLEL */
911  translate_m4(r_modelmat, -interocular_distance * fac_signed, 0.0f, 0.0f);
912 
913  /* scale back to the original size */
914  mul_m4_m4m4(r_modelmat, r_modelmat, sizemat);
915  }
916 }
917 
918 /* the view matrix is used by the viewport drawing, it is basically the inverted model matrix */
920  const Object *camera,
921  const bool is_left,
922  float r_viewmat[4][4])
923 {
925  rd, camera, is_left ? STEREO_LEFT_NAME : STEREO_RIGHT_NAME, r_viewmat);
926  invert_m4(r_viewmat);
927 }
928 
929 /* left is the default */
930 static bool camera_is_left(const char *viewname)
931 {
932  if (viewname && viewname[0] != '\0') {
933  return !STREQ(viewname, STEREO_RIGHT_NAME);
934  }
935  return true;
936 }
937 
939  const Object *camera,
940  const char *viewname,
941  float r_modelmat[4][4])
942 {
943  BKE_camera_multiview_model_matrix_scaled(rd, camera, viewname, r_modelmat);
944  normalize_m4(r_modelmat);
945 }
946 
948  const Object *camera,
949  const char *viewname,
950  float r_modelmat[4][4])
951 {
952  const bool is_multiview = (rd && rd->scemode & R_MULTIVIEW) != 0;
953 
954  if (!is_multiview) {
955  camera_model_matrix(camera, r_modelmat);
956  }
957  else if (rd->views_format == SCE_VIEWS_FORMAT_MULTIVIEW) {
958  camera_model_matrix(camera, r_modelmat);
959  }
960  else { /* SCE_VIEWS_SETUP_BASIC */
961  const bool is_left = camera_is_left(viewname);
962  camera_stereo3d_model_matrix(camera, is_left, r_modelmat);
963  }
964 }
965 
967  const Object *camera,
968  const char *viewname,
969  float r_winmat[4][4])
970 {
972 
973  /* Setup parameters */
976  BKE_camera_multiview_params(rd, &params, camera, viewname);
977 
978  /* Compute matrix, viewplane, .. */
981 
982  copy_m4_m4(r_winmat, params.winmat);
983 }
984 
986 {
987  Camera *cam;
988  const bool is_multiview = (rd && rd->scemode & R_MULTIVIEW) != 0;
989 
990  if (!is_multiview) {
991  return false;
992  }
993 
994  if (camera->type != OB_CAMERA) {
995  return false;
996  }
997 
998  cam = camera->data;
999 
1001  ((cam->stereo.flag & CAM_S3D_SPHERICAL) != 0)) {
1002  return true;
1003  }
1004 
1005  return false;
1006 }
1007 
1008 static Object *camera_multiview_advanced(const Scene *scene, Object *camera, const char *suffix)
1009 {
1010  char name[MAX_NAME];
1011  const char *camera_name = camera->id.name + 2;
1012  const int len_name = strlen(camera_name);
1013  int len_suffix_max = -1;
1014 
1015  name[0] = '\0';
1016 
1017  /* we need to take the better match, thus the len_suffix_max test */
1018  LISTBASE_FOREACH (const SceneRenderView *, srv, &scene->r.views) {
1019  const int len_suffix = strlen(srv->suffix);
1020 
1021  if ((len_suffix < len_suffix_max) || (len_name < len_suffix)) {
1022  continue;
1023  }
1024 
1025  if (STREQ(camera_name + (len_name - len_suffix), srv->suffix)) {
1026  BLI_snprintf(name, sizeof(name), "%.*s%s", (len_name - len_suffix), camera_name, suffix);
1027  len_suffix_max = len_suffix;
1028  }
1029  }
1030 
1031  if (name[0] != '\0') {
1033  if (ob != NULL) {
1034  return ob;
1035  }
1036  }
1037 
1038  return camera;
1039 }
1040 
1041 /* returns the camera to be used for render */
1042 Object *BKE_camera_multiview_render(const Scene *scene, Object *camera, const char *viewname)
1043 {
1044  const bool is_multiview = (camera != NULL) && (scene->r.scemode & R_MULTIVIEW) != 0;
1045 
1046  if (!is_multiview) {
1047  return camera;
1048  }
1050  return camera;
1051  }
1052  /* SCE_VIEWS_FORMAT_MULTIVIEW */
1053  const char *suffix = BKE_scene_multiview_view_suffix_get(&scene->r, viewname);
1054  return camera_multiview_advanced(scene, camera, suffix);
1055 }
1056 
1057 static float camera_stereo3d_shift_x(const Object *camera, const char *viewname)
1058 {
1059  Camera *data = camera->data;
1060  float shift = data->shiftx;
1061  float interocular_distance, convergence_distance;
1062  short convergence_mode, pivot;
1063  bool is_left = true;
1064 
1065  float fac = 1.0f;
1066  float fac_signed;
1067 
1068  if (viewname && viewname[0]) {
1069  is_left = STREQ(viewname, STEREO_LEFT_NAME);
1070  }
1071 
1072  interocular_distance = data->stereo.interocular_distance;
1073  convergence_distance = data->stereo.convergence_distance;
1074  convergence_mode = data->stereo.convergence_mode;
1075  pivot = data->stereo.pivot;
1076 
1077  if (convergence_mode != CAM_S3D_OFFAXIS) {
1078  return shift;
1079  }
1080 
1081  if (((pivot == CAM_S3D_PIVOT_LEFT) && is_left) || ((pivot == CAM_S3D_PIVOT_RIGHT) && !is_left)) {
1082  return shift;
1083  }
1084 
1085  if (pivot == CAM_S3D_PIVOT_CENTER) {
1086  fac = 0.5f;
1087  }
1088 
1089  fac_signed = is_left ? fac : -fac;
1090  shift += ((interocular_distance / data->sensor_x) * (data->lens / convergence_distance)) *
1091  fac_signed;
1092 
1093  return shift;
1094 }
1095 
1097  const Object *camera,
1098  const char *viewname)
1099 {
1100  const bool is_multiview = (rd && rd->scemode & R_MULTIVIEW) != 0;
1101  Camera *data = camera->data;
1102 
1103  BLI_assert(camera->type == OB_CAMERA);
1104 
1105  if (!is_multiview) {
1106  return data->shiftx;
1107  }
1109  return data->shiftx;
1110  }
1111  /* SCE_VIEWS_SETUP_BASIC */
1112  return camera_stereo3d_shift_x(camera, viewname);
1113 }
1114 
1117  const Object *camera,
1118  const char *viewname)
1119 {
1120  if (camera->type == OB_CAMERA) {
1121  params->shiftx = BKE_camera_multiview_shift_x(rd, camera, viewname);
1122  }
1123 }
1124 
1127 /* -------------------------------------------------------------------- */
1132 {
1133  CameraBGImage *bgpic = MEM_callocN(sizeof(CameraBGImage), "Background Image");
1134 
1135  bgpic->scale = 1.0f;
1136  bgpic->alpha = 0.5f;
1137  bgpic->iuser.ok = 1;
1138  bgpic->iuser.flag |= IMA_ANIM_ALWAYS;
1139  bgpic->flag |= CAM_BGIMG_FLAG_EXPANDED;
1140 
1141  BLI_addtail(&cam->bg_images, bgpic);
1142 
1143  return bgpic;
1144 }
1145 
1147 {
1148  BLI_remlink(&cam->bg_images, bgpic);
1149 
1150  MEM_freeN(bgpic);
1151 }
1152 
1154 {
1155  CameraBGImage *bgpic = cam->bg_images.first;
1156 
1157  while (bgpic) {
1158  CameraBGImage *next_bgpic = bgpic->next;
1159 
1161 
1162  bgpic = next_bgpic;
1163  }
1164 }
1165 
typedef float(TangentPoint)[2]
void BKE_animdata_blend_read_data(struct BlendDataReader *reader, struct AnimData *adt)
Definition: anim_data.c:1574
void BKE_animdata_blend_write(struct BlendWriter *writer, struct AnimData *adt)
Definition: anim_data.c:1552
Camera data-block and utility functions.
#define CAMERA_PARAM_ZOOM_INIT_PERSP
Definition: BKE_camera.h:89
#define CAMERA_PARAM_ZOOM_INIT_CAMOB
Definition: BKE_camera.h:88
void BKE_lib_id_make_local_generic(struct Main *bmain, struct ID *id, const int flags)
Definition: lib_id.c:412
void BKE_id_blend_write(struct BlendWriter *writer, struct ID *id)
Definition: lib_id.c:2395
void * BKE_id_new(struct Main *bmain, const short type, const char *name)
Definition: lib_id.c:1177
#define BKE_LIB_FOREACHID_PROCESS(_data, _id_super, _cb_flag)
@ IDWALK_CB_USER
Definition: BKE_lib_query.h:87
@ IDWALK_CB_NOP
Definition: BKE_lib_query.h:47
General operations, lookup, etc. for blender objects.
void BKE_scene_foreach_display_point(struct Depsgraph *depsgraph, void(*func_cb)(const float[3], void *), void *user_data)
Definition: object.c:4209
struct Object * BKE_scene_object_find_by_name(const struct Scene *scene, const char *name)
const char * BKE_scene_multiview_view_suffix_get(const struct RenderData *rd, const char *viewname)
float BKE_screen_view3d_zoom_to_fac(float camzoom)
Definition: screen.c:1080
#define BLI_assert(a)
Definition: BLI_assert.h:58
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
void void void void void BLI_duplicatelist(struct ListBase *dst, const struct ListBase *src) ATTR_NONNULL(1
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:547
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:110
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:133
MINLINE float sqrtf_signed(float f)
void plane_from_point_normal_v3(float r_plane[4], const float plane_co[3], const float plane_no[3])
Definition: math_geom.c:243
int isect_line_line_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3], float r_i1[3], float r_i2[3])
Definition: math_geom.c:3103
bool isect_plane_plane_v3(const float plane_a[4], const float plane_b[4], float r_isect_co[3], float r_isect_no[3]) ATTR_WARN_UNUSED_RESULT
Definition: math_geom.c:2265
void perspective_m4(float mat[4][4], const float left, const float right, const float bottom, const float top, const float nearClip, const float farClip)
Definition: math_geom.c:4830
void planes_from_projmat(const float mat[4][4], float left[4], float right[4], float top[4], float bottom[4], float near[4], float far[4])
Definition: math_geom.c:4911
float dist_signed_squared_to_plane_v3(const float p[3], const float plane[4])
Definition: math_geom.c:433
void orthographic_m4(float mat[4][4], const float left, const float right, const float bottom, const float top, const float nearClip, const float farClip)
Definition: math_geom.c:4802
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:262
bool invert_m4(float R[4][4])
Definition: math_matrix.c:1187
void mul_m4_v4(const float M[4][4], float r[4])
Definition: math_matrix.c:866
void copy_m3_m4(float m1[3][3], const float m2[4][4])
Definition: math_matrix.c:105
void unit_m4(float m[4][4])
Definition: rct.c:1140
void copy_m4_m3(float m1[4][4], const float m2[3][3])
Definition: math_matrix.c:120
void translate_m4(float mat[4][4], float tx, float ty, float tz)
Definition: math_matrix.c:2325
void normalize_m3(float R[3][3]) ATTR_NONNULL()
Definition: math_matrix.c:1919
void size_to_mat4(float R[4][4], const float size[3])
Definition: math_matrix.c:2118
void normalize_m4_m4(float R[4][4], const float M[4][4]) ATTR_NONNULL()
Definition: math_matrix.c:1972
void copy_m4_m4(float m1[4][4], const float m2[4][4])
Definition: math_matrix.c:95
void mat4_to_size(float size[3], const float M[4][4])
Definition: math_matrix.c:2145
void transpose_m4(float R[4][4])
Definition: math_matrix.c:1358
void normalize_m4(float R[4][4]) ATTR_NONNULL()
Definition: math_matrix.c:1952
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
MINLINE float normalize_v3(float r[3])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void negate_v3_v3(float r[3], const float a[3])
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE float normalize_v3_v3(float r[3], const float a[3])
MINLINE void zero_v3(float r[3])
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void copy_v4_fl(float r[4], float f)
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition: BLI_rect.h:161
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition: BLI_rect.h:165
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
unsigned int uint
Definition: BLI_sys_types.h:83
#define CLAMP_MAX(a, c)
#define UNUSED(x)
#define ELEM(...)
#define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member)
#define MEMCPY_STRUCT_AFTER(struct_dst, struct_src, member)
#define STREQ(a, b)
#define BLO_read_data_address(reader, ptr_p)
#define BLO_write_id_struct(writer, struct_name, id_address, id)
#define BLO_write_struct(writer, struct_name, data_ptr)
void BLO_read_list(BlendDataReader *reader, struct ListBase *list)
Definition: readfile.c:5654
#define BLO_read_id_address(reader, lib, id_ptr_p)
#define BLO_expand(expander, id)
bool BLO_write_is_undo(BlendWriter *writer)
Definition: writefile.c:1412
#define BLT_I18NCONTEXT_ID_CAMERA
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
struct Object * DEG_get_evaluated_object(const struct Depsgraph *depsgraph, struct Object *object)
struct Scene * DEG_get_evaluated_scene(const struct Depsgraph *graph)
ID and Library types, which are fundamental for sdna.
#define FILTER_ID_CA
Definition: DNA_ID.h:708
@ INDEX_ID_CA
Definition: DNA_ID.h:835
@ ID_CA
Definition: DNA_ID_enums.h:68
#define DEFAULT_SENSOR_HEIGHT
struct Camera Camera
@ CAM_BGIMG_SOURCE_IMAGE
@ CAM_BGIMG_SOURCE_MOVIE
@ CAM_BGIMG_FLAG_EXPANDED
@ CAM_S3D_PIVOT_CENTER
@ CAM_S3D_PIVOT_RIGHT
@ CAM_S3D_PIVOT_LEFT
@ CAM_PERSP
@ CAM_PANO
@ CAM_ORTHO
#define DEFAULT_SENSOR_WIDTH
@ CAM_S3D_OFFAXIS
@ CAM_S3D_TOE
@ CAMERA_SENSOR_FIT_HOR
@ CAMERA_SENSOR_FIT_AUTO
@ CAMERA_SENSOR_FIT_VERT
@ CAM_S3D_SPHERICAL
#define DNA_struct_default_get(struct_name)
Definition: DNA_defaults.h:44
#define MAX_NAME
Definition: DNA_defs.h:62
#define IMA_ANIM_ALWAYS
Object is a sort of wrapper for general info.
@ OB_CAMERA
@ OB_LAMP
#define STEREO_LEFT_NAME
#define R_MULTIVIEW
@ SCE_VIEWS_FORMAT_STEREO_3D
@ SCE_VIEWS_FORMAT_MULTIVIEW
#define STEREO_RIGHT_NAME
#define RV3D_CAMOB
#define RV3D_ORTHO
Read Guarded memory(de)allocation.
static void init_data(ModifierData *md)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition: btVector3.h:356
static void camera_blend_read_expand(BlendExpander *expander, ID *id)
Definition: camera.c:168
static void camera_blend_read_data(BlendDataReader *reader, ID *id)
Definition: camera.c:140
static void camera_foreach_id(ID *id, LibraryForeachIDData *data)
Definition: camera.c:107
float BKE_camera_sensor_size(int sensor_fit, float sensor_x, float sensor_y)
Definition: camera.c:242
bool BKE_camera_view_frame_fit_to_coords(const Depsgraph *depsgraph, const float(*cos)[3], int num_cos, Object *camera_ob, float r_co[3], float *r_scale)
Definition: camera.c:785
void BKE_camera_multiview_model_matrix_scaled(const RenderData *rd, const Object *camera, const char *viewname, float r_modelmat[4][4])
Definition: camera.c:947
static void camera_blend_read_lib(BlendLibReader *reader, ID *id)
Definition: camera.c:154
IDTypeInfo IDType_ID_CA
Definition: camera.c:183
static bool camera_is_left(const char *viewname)
Definition: camera.c:930
static void camera_make_local(Main *bmain, ID *id, const int flags)
Definition: camera.c:95
void BKE_camera_multiview_params(const RenderData *rd, CameraParams *params, const Object *camera, const char *viewname)
Definition: camera.c:1115
#define CAMERA_VIEWFRAME_NUM_PLANES
Definition: camera.c:573
void BKE_camera_multiview_view_matrix(const RenderData *rd, const Object *camera, const bool is_left, float r_viewmat[4][4])
Definition: camera.c:919
static void camera_stereo3d_model_matrix(const Object *camera, const bool is_left, float r_modelmat[4][4])
Definition: camera.c:821
static void camera_model_matrix(const Object *camera, float r_modelmat[4][4])
Definition: camera.c:816
void BKE_camera_params_from_object(CameraParams *params, const Object *cam_ob)
Definition: camera.c:287
void BKE_camera_view_frame(const Scene *scene, const Camera *camera, float r_vec[4][3])
Definition: camera.c:556
static float camera_stereo3d_shift_x(const Object *camera, const char *viewname)
Definition: camera.c:1057
void * BKE_camera_add(Main *bmain, const char *name)
Definition: camera.c:217
static void camera_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, const int UNUSED(flag))
Definition: camera.c:85
int BKE_camera_sensor_fit(int sensor_fit, float sizex, float sizey)
Definition: camera.c:252
void BKE_camera_params_init(CameraParams *params)
Definition: camera.c:271
static void camera_to_frame_view_cb(const float co[3], void *user_data)
Definition: camera.c:590
void BKE_camera_view_frame_ex(const Scene *scene, const Camera *camera, const float drawsize, const bool do_clip, const float scale[3], float r_asp[2], float r_shift[2], float *r_drawsize, float r_vec[4][3])
Definition: camera.c:467
Object * BKE_camera_multiview_render(const Scene *scene, Object *camera, const char *viewname)
Definition: camera.c:1042
static bool camera_frame_fit_calc_from_data(CameraParams *params, CameraViewFrameData *data, float r_co[3], float *r_scale)
Definition: camera.c:664
static void camera_frame_fit_data_init(const Scene *scene, const Object *ob, CameraParams *params, CameraViewFrameData *data)
Definition: camera.c:607
static Object * camera_multiview_advanced(const Scene *scene, Object *camera, const char *suffix)
Definition: camera.c:1008
void BKE_camera_params_compute_viewplane(CameraParams *params, int winx, int winy, float aspx, float aspy)
Definition: camera.c:370
void BKE_camera_multiview_model_matrix(const RenderData *rd, const Object *camera, const char *viewname, float r_modelmat[4][4])
Definition: camera.c:938
void BKE_camera_multiview_window_matrix(const RenderData *rd, const Object *camera, const char *viewname, float r_winmat[4][4])
Definition: camera.c:966
void BKE_camera_background_image_remove(Camera *cam, CameraBGImage *bgpic)
Definition: camera.c:1146
void BKE_camera_background_image_clear(Camera *cam)
Definition: camera.c:1153
bool BKE_camera_view_frame_fit_to_scene(Depsgraph *depsgraph, const Scene *scene, Object *camera_ob, float r_co[3], float *r_scale)
Definition: camera.c:768
void BKE_camera_params_compute_matrix(CameraParams *params)
Definition: camera.c:436
static void camera_blend_write(BlendWriter *writer, ID *id, const void *id_address)
Definition: camera.c:122
bool BKE_camera_multiview_spherical_stereo(const RenderData *rd, const Object *camera)
Definition: camera.c:985
static void camera_free_data(ID *id)
Definition: camera.c:101
float BKE_camera_object_dof_distance(Object *ob)
Definition: camera.c:227
static void camera_init_data(ID *id)
Definition: camera.c:67
CameraBGImage * BKE_camera_background_image_new(Camera *cam)
Definition: camera.c:1131
struct CameraViewFrameData CameraViewFrameData
void BKE_camera_params_from_view3d(CameraParams *params, Depsgraph *depsgraph, const View3D *v3d, const RegionView3D *rv3d)
Definition: camera.c:326
float BKE_camera_multiview_shift_x(const RenderData *rd, const Object *camera, const char *viewname)
Definition: camera.c:1096
static float is_left(const float p0[2], const float p1[2], const float p2[2])
Definition: convexhull_2d.c:51
Scene scene
const Depsgraph * depsgraph
void * user_data
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
#define sinf(x)
#define cosf(x)
#define tanf(x)
#define atanf(x)
#define fabsf(x)
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:319
struct CameraBGImage * next
struct ImageUser iuser
struct Object * focus_object
float dist_vals_sq[CAMERA_VIEWFRAME_NUM_PLANES]
Definition: camera.c:578
float normal_tx[CAMERA_VIEWFRAME_NUM_PLANES][3]
Definition: camera.c:577
float camera_rotmat[3][3]
Definition: camera.c:587
float camera_no[3]
Definition: camera.c:583
float plane_tx[CAMERA_VIEWFRAME_NUM_PLANES][4]
Definition: camera.c:576
unsigned int tot
Definition: camera.c:579
float clip_end
char sensor_fit
float sensor_y
struct ListBase bg_images
float shiftx
struct CameraStereoSettings stereo
struct AnimData * adt
float sensor_x
float clip_start
float shifty
struct CameraDOFSettings dof
float ortho_scale
short id_code
Definition: BKE_idtype.h:120
Definition: DNA_ID.h:273
struct Library * lib
Definition: DNA_ID.h:277
int us
Definition: DNA_ID.h:293
char name[66]
Definition: DNA_ID.h:283
float spotsize
void * first
Definition: DNA_listBase.h:47
Definition: BKE_main.h:116
float obmat[4][4]
void * data
ListBase views
short views_format
struct RenderData r
float clip_end
struct Object * camera
float clip_start
float xmax
Definition: DNA_vec_types.h:85
float xmin
Definition: DNA_vec_types.h:85
float ymax
Definition: DNA_vec_types.h:86
float ymin
Definition: DNA_vec_types.h:86