Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2015-01-03 14:05:16 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2015-01-03 14:05:23 +0300
commit780bb88a7a5b30eaf8a62b999a30ac7bb4153ebf (patch)
tree621e1c05f686c3c522c31b0061202671fdc32139 /source/blender/blenlib
parent16ed20ff3cc68589a5fe48075d2b80692d3c90ea (diff)
Refactor 'fit in camera view' code, and expose it to RNA.
This changes BKE's fitting code to use `BKE_camera_params_compute_viewplane` instead of `BKE_camera_view_frame`. This allows that code to work with orthographic projection too. Also, two funcs were added to rna's Object, to resp. get the projection matrix of that object (mostly useful for cameras and lamps objects), and return position this object should be to see all (to fit) a given set of points. Reviewers: campbellbarton Reviewed By: campbellbarton Differential Revision: https://developer.blender.org/D961
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_math_geom.h3
-rw-r--r--source/blender/blenlib/intern/math_geom.c53
2 files changed, 56 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index 95ab3185d1f..ee99f860a97 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -265,6 +265,9 @@ void orthographic_m4(float mat[4][4], const float left, const float right,
void window_translate_m4(float winmat[4][4], float perspmat[4][4],
const float x, const float y);
+void planes_from_projmat(float mat[4][4], float left[4], float right[4], float top[4], float bottom[4],
+ float front[4], float back[4]);
+
int box_clip_bounds_m4(float boundbox[2][3],
const float bounds[4], float winmat[4][4]);
void box_minmax_bounds_m4(float min[3], float max[3],
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index a360148182d..59d9cf85dec 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -3104,6 +3104,59 @@ void window_translate_m4(float winmat[4][4], float perspmat[4][4], const float x
}
}
+/**
+ * Frustum planes extraction from a projection matrix (homogeneous 4d vector representations of planes).
+ *
+ * plane parameters can be NULL if you do not need them.
+ */
+void planes_from_projmat(float mat[4][4], float left[4], float right[4], float top[4], float bottom[4],
+ float near[4], float far[4])
+{
+ /* References:
+ *
+ * https://fgiesen.wordpress.com/2012/08/31/frustum-planes-from-the-projection-matrix/
+ * http://www8.cs.umu.se/kurser/5DV051/HT12/lab/plane_extraction.pdf
+ */
+
+ int i;
+
+ if (left) {
+ for (i = 4; i--; ) {
+ left[i] = mat[i][3] + mat[i][0];
+ }
+ }
+
+ if (right) {
+ for (i = 4; i--; ) {
+ right[i] = mat[i][3] - mat[i][0];
+ }
+ }
+
+ if (bottom) {
+ for (i = 4; i--; ) {
+ bottom[i] = mat[i][3] + mat[i][1];
+ }
+ }
+
+ if (top) {
+ for (i = 4; i--; ) {
+ top[i] = mat[i][3] - mat[i][1];
+ }
+ }
+
+ if (near) {
+ for (i = 4; i--; ) {
+ near[i] = mat[i][3] + mat[i][2];
+ }
+ }
+
+ if (far) {
+ for (i = 4; i--; ) {
+ far[i] = mat[i][3] - mat[i][2];
+ }
+ }
+}
+
static void i_multmatrix(float icand[4][4], float Vm[4][4])
{
int row, col;