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:
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2013-01-27 03:49:13 +0400
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2013-01-27 03:49:13 +0400
commit556912792ad3c37c294256a558c96b39f264e7b5 (patch)
tree9b6ee8cf1ad92ee89c04f27a89be11599c5b40c0 /source/blender/blenlib
parent9251d628db0abe599d927d79170025d8545c8ace (diff)
parentc84383301c5a2582e95259a7e4468a23a3566401 (diff)
Merged changes in the trunk up to revision 54110.
Conflicts resolved: source/blender/blenfont/SConscript source/blender/blenkernel/intern/subsurf_ccg.c source/blender/makesdna/intern/makesdna.c source/blender/makesrna/intern/rna_scene.c
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_array.h126
-rw-r--r--source/blender/blenlib/BLI_math_base.h5
-rw-r--r--source/blender/blenlib/BLI_math_color.h6
-rw-r--r--source/blender/blenlib/BLI_math_matrix.h2
-rw-r--r--source/blender/blenlib/BLI_math_rotation.h3
-rw-r--r--source/blender/blenlib/BLI_math_vector.h5
-rw-r--r--source/blender/blenlib/BLI_mempool.h5
-rw-r--r--source/blender/blenlib/CMakeLists.txt1
-rw-r--r--source/blender/blenlib/intern/BLI_array.c97
-rw-r--r--source/blender/blenlib/intern/BLI_mempool.c38
-rw-r--r--source/blender/blenlib/intern/math_color_inline.c14
-rw-r--r--source/blender/blenlib/intern/math_matrix.c41
-rw-r--r--source/blender/blenlib/intern/math_rotation.c157
-rw-r--r--source/blender/blenlib/intern/math_vector.c39
-rw-r--r--source/blender/blenlib/intern/noise.c24
-rw-r--r--source/blender/blenlib/intern/threads.c6
16 files changed, 452 insertions, 117 deletions
diff --git a/source/blender/blenlib/BLI_array.h b/source/blender/blenlib/BLI_array.h
index 7c8816cb58a..0ba0f138c28 100644
--- a/source/blender/blenlib/BLI_array.h
+++ b/source/blender/blenlib/BLI_array.h
@@ -25,53 +25,19 @@
* ***** END GPL LICENSE BLOCK *****
*/
+#ifndef __BLI_ARRAY_H__
+#define __BLI_ARRAY_H__
+
/** \file BLI_array.h
* \ingroup bli
- * \brief A macro array library.
- *
- * this library needs to be changed to not use macros quite so heavily,
- * and to be more of a complete array API. The way arrays are
- * exposed to client code as normal C arrays is very useful though, imho.
- * it does require some use of macros, however.
- *
- * anyway, it's used a bit too heavily to simply rewrite as a
- * more "correct" solution without macros entirely. I originally wrote this
- * to be very easy to use, without the normal pain of most array libraries.
- * This was especially helpful when it came to the massive refactors necessary
- * for bmesh, and really helped to speed the process up. - joeedh
- *
- * little array macro library. example of usage:
- *
- * int *arr = NULL;
- * BLI_array_declare(arr);
- * int i;
- *
- * for (i = 0; i < 10; i++) {
- * BLI_array_grow_one(arr);
- * arr[i] = something;
- * }
- * BLI_array_free(arr);
- *
- * arrays are buffered, using double-buffering (so on each reallocation,
- * the array size is doubled). supposedly this should give good Big Oh
- * behavior, though it may not be the best in practice.
+ * \brief A (mainly) macro array library.
*/
-#define BLI_array_declare(arr) \
- int _##arr##_count = 0; \
- void *_##arr##_tmp; \
- void *_##arr##_static = NULL
-
-/* this will use stack space, up to maxstatic array elements, before
- * switching to dynamic heap allocation */
-#define BLI_array_staticdeclare(arr, maxstatic) \
- int _##arr##_count = 0; \
- void *_##arr##_tmp; \
- char _##arr##_static[maxstatic * sizeof(arr)]
-
+/* -------------------------------------------------------------------- */
+/* internal defines */
/* this returns the entire size of the array, including any buffering. */
-#define BLI_array_totalsize_dyn(arr) ( \
+#define _bli_array_totalsize_dynamic(arr) ( \
((arr) == NULL) ? \
0 : \
MEM_allocN_len(arr) / sizeof(*arr) \
@@ -80,55 +46,61 @@
#define _bli_array_totalsize_static(arr) \
(sizeof(_##arr##_static) / sizeof(*arr))
-#define BLI_array_totalsize(arr) ( \
+#define _bli_array_totalsize(arr) ( \
(size_t) \
(((void *)(arr) == (void *)_##arr##_static && (void *)(arr) != NULL) ? \
_bli_array_totalsize_static(arr) : \
- BLI_array_totalsize_dyn(arr)) \
+ _bli_array_totalsize_dynamic(arr)) \
)
+/* BLI_array.c
+ *
+ * Doing the realloc in a macro isn't so simple,
+ * so use a function the macros can use.
+ */
+void _bli_array_grow_func(void **arr_p, const void *arr_static,
+ const int sizeof_arr_p, const int arr_count, const int num,
+ const char *alloc_str);
+
+
+/* -------------------------------------------------------------------- */
+/* public defines */
+
+#define BLI_array_declare(arr) \
+ int _##arr##_count = 0; \
+ void *_##arr##_static = NULL
+
+/* this will use stack space, up to maxstatic array elements, before
+ * switching to dynamic heap allocation */
+#define BLI_array_staticdeclare(arr, maxstatic) \
+ int _##arr##_count = 0; \
+ char _##arr##_static[maxstatic * sizeof(arr)]
/* this returns the logical size of the array, not including buffering. */
#define BLI_array_count(arr) _##arr##_count
-/* Grow the array by a fixed number of items. zeroes the new elements.
+/* Grow the array by a fixed number of items.
*
* Allow for a large 'num' value when the new size is more then double
* to allocate the exact sized array. */
-
-/* grow an array by a specified number of items */
-#define BLI_array_grow_items(arr, num) ( \
+#define BLI_array_grow_items(arr, num) (( \
(((void *)(arr) == NULL) && \
((void *)(_##arr##_static) != NULL) && \
- /* dont add _##arr##_count below because it must be zero */ \
+ /* don't add _##arr##_count below because it must be zero */ \
(_bli_array_totalsize_static(arr) >= _##arr##_count + num)) ? \
/* we have an empty array and a static var big enough */ \
- ((arr = (void *)_##arr##_static), (_##arr##_count += (num))) \
+ (arr = (void *)_##arr##_static) \
: \
/* use existing static array or allocate */ \
- (LIKELY(BLI_array_totalsize(arr) >= _##arr##_count + num) ? \
- (_##arr##_count += num) : /* UNLIKELY --> realloc */ \
- ( \
- (void) (_##arr##_tmp = MEM_callocN( \
- sizeof(*arr) * (num < _##arr##_count ? \
- (_##arr##_count * 2 + 2) : \
- (_##arr##_count + num)), \
- #arr " " __FILE__ ":" STRINGIFY(__LINE__) \
- ) \
- ), \
- (void) (arr && memcpy(_##arr##_tmp, \
- arr, \
- sizeof(*arr) * _##arr##_count) \
- ), \
- (void) (arr && ((void *)(arr) != (void *)_##arr##_static ? \
- (MEM_freeN(arr), arr) : \
- arr) \
- ), \
- (void) (arr = _##arr##_tmp \
- ), \
- (_##arr##_count += num) \
- )) \
-)
+ (LIKELY(_bli_array_totalsize(arr) >= _##arr##_count + num) ? \
+ (void)0 /* do nothing */ : \
+ _bli_array_grow_func((void **)&(arr), _##arr##_static, \
+ sizeof(*arr), _##arr##_count, num, \
+ "BLI_array." #arr), \
+ (void)0) /* msvc2008 needs this */ \
+ ), \
+ /* increment the array count, all conditions above are accounted for. */ \
+ (_##arr##_count += num))
/* returns length of array */
#define BLI_array_grow_one(arr) BLI_array_grow_items(arr, 1)
@@ -167,20 +139,23 @@
/* resets the logical size of an array to zero, but doesn't
* free the memory. */
#define BLI_array_empty(arr) \
- _##arr##_count = 0; (void)0
+ { _##arr##_count = 0; } (void)0
/* set the count of the array, doesn't actually increase the allocated array
* size. don't use this unless you know what you're doing. */
#define BLI_array_length_set(arr, count) \
- _##arr##_count = (count); (void)0
+ { _##arr##_count = (count); }(void)0
/* only to prevent unused warnings */
#define BLI_array_fake_user(arr) \
(void)_##arr##_count, \
- (void)_##arr##_tmp, \
(void)_##arr##_static
+/* -------------------------------------------------------------------- */
+/* other useful defines
+ * (unrelated to the main array macros) */
+
/* not part of the 'API' but handy funcs,
* same purpose as BLI_array_staticdeclare()
* but use when the max size is known ahead of time */
@@ -224,3 +199,4 @@
const int _##arr##_count = (realsize)
#endif
+#endif /* __BLI_ARRAY_H__ */
diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h
index 69d6478e0e2..94063c9a40a 100644
--- a/source/blender/blenlib/BLI_math_base.h
+++ b/source/blender/blenlib/BLI_math_base.h
@@ -80,6 +80,9 @@
#define MAXFLOAT ((float)3.40282347e+38)
#endif
+/* do not redefine functions from C99 or POSIX.1-2001 */
+#if !(defined(_ISOC99_SOURCE) || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L))
+
#ifndef sqrtf
#define sqrtf(a) ((float)sqrt(a))
#endif
@@ -129,6 +132,8 @@
#define hypotf(a, b) ((float)hypot(a, b))
#endif
+#endif /* C99 or POSIX.1-2001 */
+
#ifdef WIN32
# ifndef FREE_WINDOWS
# define isnan(n) _isnan(n)
diff --git a/source/blender/blenlib/BLI_math_color.h b/source/blender/blenlib/BLI_math_color.h
index 3831ec3cbb4..145427ea529 100644
--- a/source/blender/blenlib/BLI_math_color.h
+++ b/source/blender/blenlib/BLI_math_color.h
@@ -102,8 +102,10 @@ void BLI_init_srgb_conversion(void);
/**************** Alpha Transformations *****************/
-MINLINE void premul_to_straight_v4(float straight[4], const float premul[4]);
-MINLINE void straight_to_premul_v4(float straight[4], const float premul[4]);
+MINLINE void premul_to_straight_v4_v4(float straight[4], const float premul[4]);
+MINLINE void premul_to_straight_v4(float color[4]);
+MINLINE void straight_to_premul_v4_v4(float straight[4], const float premul[4]);
+MINLINE void straight_to_premul_v4(float color[4]);
MINLINE void straight_uchar_to_premul_float(float result[4], const unsigned char color[4]);
MINLINE void premul_float_to_straight_uchar(unsigned char *result, const float color[4]);
diff --git a/source/blender/blenlib/BLI_math_matrix.h b/source/blender/blenlib/BLI_math_matrix.h
index c12ec62ca1b..415c503146c 100644
--- a/source/blender/blenlib/BLI_math_matrix.h
+++ b/source/blender/blenlib/BLI_math_matrix.h
@@ -173,6 +173,8 @@ void rotate_m4(float mat[4][4], const char axis, const float angle);
void mat3_to_rot_size(float rot[3][3], float size[3], float mat3[3][3]);
void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], float wmat[4][4]);
+void mat4_to_loc_quat(float loc[3], float quat[4], float wmat[4][4]);
+void mat4_decompose(float loc[3], float quat[4], float size[3], float wmat[4][4]);
void loc_eul_size_to_mat4(float R[4][4],
const float loc[3], const float eul[3], const float size[3]);
diff --git a/source/blender/blenlib/BLI_math_rotation.h b/source/blender/blenlib/BLI_math_rotation.h
index 652925fbe49..e349a05ac23 100644
--- a/source/blender/blenlib/BLI_math_rotation.h
+++ b/source/blender/blenlib/BLI_math_rotation.h
@@ -186,6 +186,9 @@ float fov_to_focallength(float fov, float sensor);
float angle_wrap_rad(float angle);
float angle_wrap_deg(float angle);
+int mat3_from_axis_conversion(int from_forward, int from_up, int to_forward, int to_up,
+ float r_mat[3][3]);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h
index f4572afec84..42a6b90f738 100644
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@ -171,6 +171,10 @@ void mid_v3_v3v3(float r[3], const float a[3], const float b[3]);
void mid_v2_v2v2(float r[2], const float a[2], const float b[2]);
void mid_v3_v3v3v3(float v[3], const float v1[3], const float v2[3], const float v3[3]);
+void flip_v4_v4v4(float v[4], const float v1[4], const float v2[4]);
+void flip_v3_v3v3(float v[3], const float v1[3], const float v2[3]);
+void flip_v2_v2v2(float v[2], const float v1[2], const float v2[2]);
+
/********************************* Comparison ********************************/
MINLINE int is_zero_v3(const float a[3]);
@@ -251,6 +255,7 @@ void sub_vn_vn(float *array_tar, const float *array_src, const int size);
void sub_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, const int size);
void msub_vn_vn(float *array_tar, const float *array_src, const float f, const int size);
void msub_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, const float f, const int size);
+void interp_vn_vn(float *array_tar, const float *array_src, const float t, const int size);
void fill_vn_i(int *array_tar, const int size, const int val);
void fill_vn_ushort(unsigned short *array_tar, const int size, const unsigned short val);
void fill_vn_fl(float *array_tar, const int size, const float val);
diff --git a/source/blender/blenlib/BLI_mempool.h b/source/blender/blenlib/BLI_mempool.h
index 8fd2166e6f8..20ea89f3abf 100644
--- a/source/blender/blenlib/BLI_mempool.h
+++ b/source/blender/blenlib/BLI_mempool.h
@@ -86,6 +86,11 @@ __attribute__((warn_unused_result))
__attribute__((nonnull(1)))
#endif
;
+void BLI_mempool_as_array(BLI_mempool *pool, void **data)
+#ifdef __GNUC__
+__attribute__((nonnull(1)))
+#endif
+;
/** iteration stuff. note: this may easy to produce bugs with **/
/* private structure */
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index f438e6bdec3..82ff09b5999 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -38,6 +38,7 @@ set(INC_SYS
set(SRC
intern/BLI_args.c
+ intern/BLI_array.c
intern/BLI_dynstr.c
intern/BLI_ghash.c
intern/BLI_heap.c
diff --git a/source/blender/blenlib/intern/BLI_array.c b/source/blender/blenlib/intern/BLI_array.c
new file mode 100644
index 00000000000..5823b7db3f1
--- /dev/null
+++ b/source/blender/blenlib/intern/BLI_array.c
@@ -0,0 +1,97 @@
+/*
+ * ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2008 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Joseph Eagar,
+ * Campbell Barton
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenlib/intern/BLI_array.c
+ * \ingroup bli
+ * \brief A (mainly) macro array library.
+ *
+ * This library needs to be changed to not use macros quite so heavily,
+ * and to be more of a complete array API. The way arrays are
+ * exposed to client code as normal C arrays is very useful though, imho.
+ * it does require some use of macros, however.
+ *
+ * anyway, it's used a bit too heavily to simply rewrite as a
+ * more "correct" solution without macros entirely. I originally wrote this
+ * to be very easy to use, without the normal pain of most array libraries.
+ * This was especially helpful when it came to the massive refactors necessary
+ * for bmesh, and really helped to speed the process up. - joeedh
+ *
+ * little array macro library. example of usage:
+ *
+ * int *arr = NULL;
+ * BLI_array_declare(arr);
+ * int i;
+ *
+ * for (i = 0; i < 10; i++) {
+ * BLI_array_grow_one(arr);
+ * arr[i] = something;
+ * }
+ * BLI_array_free(arr);
+ *
+ * arrays are buffered, using double-buffering (so on each reallocation,
+ * the array size is doubled). supposedly this should give good Big Oh
+ * behavior, though it may not be the best in practice.
+ */
+
+#include <string.h>
+
+#include "BLI_array.h"
+
+#include "MEM_guardedalloc.h"
+
+/**
+ * This function is only to be called via macros.
+ *
+ * \note The caller must adjust \a arr_count
+ */
+void _bli_array_grow_func(void **arr_p, const void *arr_static,
+ const int sizeof_arr_p, const int arr_count, const int num,
+ const char *alloc_str)
+{
+ void *arr = *arr_p;
+ void *arr_tmp;
+
+ arr_tmp = MEM_mallocN(sizeof_arr_p *
+ ((num < arr_count) ?
+ (arr_count * 2 + 2) : (arr_count + num)), alloc_str);
+
+ if (arr) {
+ memcpy(arr_tmp, arr, sizeof_arr_p * arr_count);
+
+ if (arr != arr_static) {
+ MEM_freeN(arr);
+ }
+ }
+
+ *arr_p = arr_tmp;
+
+ /* caller must do */
+#if 0
+ arr_count += num;
+#endif
+}
diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c
index d98e63d88dd..0d6b8a44a1e 100644
--- a/source/blender/blenlib/intern/BLI_mempool.c
+++ b/source/blender/blenlib/intern/BLI_mempool.c
@@ -27,9 +27,7 @@
/** \file blender/blenlib/intern/BLI_mempool.c
* \ingroup bli
- */
-
-/*
+ *
* Simple, fast memory allocator for allocating many elements of the same size.
*/
@@ -295,33 +293,41 @@ int BLI_mempool_count(BLI_mempool *pool)
void *BLI_mempool_findelem(BLI_mempool *pool, int index)
{
- if (!(pool->flag & BLI_MEMPOOL_ALLOW_ITER)) {
- fprintf(stderr, "%s: Error! you can't iterate over this mempool!\n", __func__);
- return NULL;
- }
- else if ((index >= 0) && (index < pool->totused)) {
+ BLI_assert(pool->flag & BLI_MEMPOOL_ALLOW_ITER);
+
+ if ((index >= 0) && (index < pool->totused)) {
/* we could have some faster mem chunk stepping code inline */
BLI_mempool_iter iter;
void *elem;
BLI_mempool_iternew(pool, &iter);
for (elem = BLI_mempool_iterstep(&iter); index-- != 0; elem = BLI_mempool_iterstep(&iter)) {
/* do nothing */
- };
+ }
return elem;
}
return NULL;
}
-void BLI_mempool_iternew(BLI_mempool *pool, BLI_mempool_iter *iter)
+/**
+ * \param data array of pointers at least the size of 'pool->totused'
+ */
+void BLI_mempool_as_array(BLI_mempool *pool, void **data)
{
- if (!(pool->flag & BLI_MEMPOOL_ALLOW_ITER)) {
- fprintf(stderr, "%s: Error! you can't iterate over this mempool!\n", __func__);
- iter->curchunk = NULL;
- iter->curindex = 0;
-
- return;
+ BLI_mempool_iter iter;
+ void *elem;
+ void **p = data;
+ BLI_assert(pool->flag & BLI_MEMPOOL_ALLOW_ITER);
+ BLI_mempool_iternew(pool, &iter);
+ for (elem = BLI_mempool_iterstep(&iter); elem; elem = BLI_mempool_iterstep(&iter)) {
+ *p++ = elem;
}
+ BLI_assert((p - data) == pool->totused);
+}
+
+void BLI_mempool_iternew(BLI_mempool *pool, BLI_mempool_iter *iter)
+{
+ BLI_assert(pool->flag & BLI_MEMPOOL_ALLOW_ITER);
iter->pool = pool;
iter->curchunk = pool->chunks.first;
diff --git a/source/blender/blenlib/intern/math_color_inline.c b/source/blender/blenlib/intern/math_color_inline.c
index b8eeca50db6..c24da9fcf80 100644
--- a/source/blender/blenlib/intern/math_color_inline.c
+++ b/source/blender/blenlib/intern/math_color_inline.c
@@ -270,7 +270,7 @@ MINLINE int compare_rgb_uchar(const unsigned char col_a[3], const unsigned char
/**************** Alpha Transformations *****************/
-MINLINE void premul_to_straight_v4(float straight[4], const float premul[4])
+MINLINE void premul_to_straight_v4_v4(float straight[4], const float premul[4])
{
if (premul[3] == 0.0f || premul[3] == 1.0f) {
straight[0] = premul[0];
@@ -287,7 +287,12 @@ MINLINE void premul_to_straight_v4(float straight[4], const float premul[4])
}
}
-MINLINE void straight_to_premul_v4(float premul[4], const float straight[4])
+MINLINE void premul_to_straight_v4(float color[4])
+{
+ premul_to_straight_v4_v4(color, color);
+}
+
+MINLINE void straight_to_premul_v4_v4(float premul[4], const float straight[4])
{
float alpha = straight[3];
premul[0] = straight[0] * alpha;
@@ -296,6 +301,11 @@ MINLINE void straight_to_premul_v4(float premul[4], const float straight[4])
premul[3] = straight[3];
}
+MINLINE void straight_to_premul_v4(float color[4])
+{
+ straight_to_premul_v4_v4(color, color);
+}
+
MINLINE void straight_uchar_to_premul_float(float result[4], const unsigned char color[4])
{
float alpha = color[3] / 255.0f;
diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c
index 02fc5b07d6d..8f9ea917b8c 100644
--- a/source/blender/blenlib/intern/math_matrix.c
+++ b/source/blender/blenlib/intern/math_matrix.c
@@ -980,14 +980,8 @@ void normalize_m4(float mat[4][4])
void normalize_m4_m4(float rmat[4][4], float mat[4][4])
{
- float len;
-
- len = normalize_v3_v3(rmat[0], mat[0]);
- if (len != 0.0f) rmat[0][3] = mat[0][3] / len;
- len = normalize_v3_v3(rmat[1], mat[1]);
- if (len != 0.0f) rmat[1][3] = mat[1][3] / len;
- len = normalize_v3_v3(rmat[2], mat[2]);
- if (len != 0.0f) rmat[2][3] = mat[2][3] / len;
+ copy_m4_m4(rmat, mat);
+ normalize_m4(rmat);
}
void adjoint_m2_m2(float m1[2][2], float m[2][2])
@@ -1212,6 +1206,33 @@ void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], float wm
copy_v3_v3(loc, wmat[3]);
}
+void mat4_to_loc_quat(float loc[3], float quat[4], float wmat[4][4])
+{
+ float mat3[3][3];
+ float mat3_n[3][3]; /* normalized mat3 */
+
+ copy_m3_m4(mat3, wmat);
+ normalize_m3_m3(mat3_n, mat3);
+
+ /* so scale doesn't interfere with rotation [#24291] */
+ /* note: this is a workaround for negative matrix not working for rotation conversion, FIXME */
+ if (is_negative_m3(mat3)) {
+ negate_v3(mat3_n[0]);
+ negate_v3(mat3_n[1]);
+ negate_v3(mat3_n[2]);
+ }
+
+ mat3_to_quat(quat, mat3_n);
+ copy_v3_v3(loc, wmat[3]);
+}
+
+void mat4_decompose(float loc[3], float quat[4], float size[3], float wmat[4][4])
+{
+ float rot[3][3];
+ mat4_to_loc_rot_size(loc, rot, size, wmat);
+ mat3_to_quat(quat, rot);
+}
+
void scale_m3_fl(float m[3][3], float scale)
{
m[0][0] = m[1][1] = m[2][2] = scale;
@@ -1245,8 +1266,8 @@ void rotate_m4(float mat[4][4], const char axis, const float angle)
assert(axis >= 'X' && axis <= 'Z');
- cosine = (float)cos(angle);
- sine = (float)sin(angle);
+ cosine = cosf(angle);
+ sine = sinf(angle);
switch (axis) {
case 'X':
for (col = 0; col < 4; col++)
diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c
index 71f146e8131..b38b5a2de10 100644
--- a/source/blender/blenlib/intern/math_rotation.c
+++ b/source/blender/blenlib/intern/math_rotation.c
@@ -589,10 +589,10 @@ void interp_qt_qtqt(float result[4], const float quat1[4], const float quat2[4],
}
if ((1.0f - cosom) > 0.0001f) {
- omega = (float)acos(cosom);
- sinom = (float)sin(omega);
- sc1 = (float)sin((1 - t) * omega) / sinom;
- sc2 = (float)sin(t * omega) / sinom;
+ omega = acosf(cosom);
+ sinom = sinf(omega);
+ sc1 = sinf((1.0f - t) * omega) / sinom;
+ sc2 = sinf(t * omega) / sinom;
}
else {
sc1 = 1.0f - t;
@@ -1737,3 +1737,152 @@ float angle_wrap_deg(float angle)
{
return mod_inline(angle + 180.0f, 360.0f) - 180.0f;
}
+
+/* axis conversion */
+static float _axis_convert_matrix[23][3][3] = {
+ {{-1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}},
+ {{-1.0, 0.0, 0.0}, {0.0, 0.0, -1.0}, {0.0, -1.0, 0.0}},
+ {{-1.0, 0.0, 0.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}},
+ {{-1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, -1.0}},
+ {{0.0, -1.0, 0.0}, {-1.0, 0.0, 0.0}, {0.0, 0.0, -1.0}},
+ {{0.0, 0.0, 1.0}, {-1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}},
+ {{0.0, 0.0, -1.0}, {-1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}},
+ {{0.0, 1.0, 0.0}, {-1.0, 0.0, 0.0}, {0.0, 0.0, 1.0}},
+ {{0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}, {-1.0, 0.0, 0.0}},
+ {{0.0, 0.0, -1.0}, {0.0, -1.0, 0.0}, {-1.0, 0.0, 0.0}},
+ {{0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}, {-1.0, 0.0, 0.0}},
+ {{0.0, 1.0, 0.0}, {0.0, 0.0, -1.0}, {-1.0, 0.0, 0.0}},
+ {{0.0, -1.0, 0.0}, {0.0, 0.0, -1.0}, {1.0, 0.0, 0.0}},
+ {{0.0, 0.0, 1.0}, {0.0, -1.0, 0.0}, {1.0, 0.0, 0.0}},
+ {{0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}},
+ {{0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}, {1.0, 0.0, 0.0}},
+ {{0.0, -1.0, 0.0}, {1.0, 0.0, 0.0}, {0.0, 0.0, 1.0}},
+ {{0.0, 0.0, -1.0}, {1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}},
+ {{0.0, 0.0, 1.0}, {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}},
+ {{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {0.0, 0.0, -1.0}},
+ {{1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, -1.0}},
+ {{1.0, 0.0, 0.0}, {0.0, 0.0, 1.0}, {0.0, -1.0, 0.0}},
+ {{1.0, 0.0, 0.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}},
+};
+
+static int _axis_convert_lut[23][24] = {
+ {0x8C8, 0x4D0, 0x2E0, 0xAE8, 0x701, 0x511, 0x119, 0xB29, 0x682, 0x88A,
+ 0x09A, 0x2A2, 0x80B, 0x413, 0x223, 0xA2B, 0x644, 0x454, 0x05C, 0xA6C,
+ 0x745, 0x94D, 0x15D, 0x365},
+ {0xAC8, 0x8D0, 0x4E0, 0x2E8, 0x741, 0x951, 0x159, 0x369, 0x702, 0xB0A,
+ 0x11A, 0x522, 0xA0B, 0x813, 0x423, 0x22B, 0x684, 0x894, 0x09C, 0x2AC,
+ 0x645, 0xA4D, 0x05D, 0x465},
+ {0x4C8, 0x2D0, 0xAE0, 0x8E8, 0x681, 0x291, 0x099, 0x8A9, 0x642, 0x44A,
+ 0x05A, 0xA62, 0x40B, 0x213, 0xA23, 0x82B, 0x744, 0x354, 0x15C, 0x96C,
+ 0x705, 0x50D, 0x11D, 0xB25},
+ {0x2C8, 0xAD0, 0x8E0, 0x4E8, 0x641, 0xA51, 0x059, 0x469, 0x742, 0x34A,
+ 0x15A, 0x962, 0x20B, 0xA13, 0x823, 0x42B, 0x704, 0xB14, 0x11C, 0x52C,
+ 0x685, 0x28D, 0x09D, 0x8A5},
+ {0x708, 0xB10, 0x120, 0x528, 0x8C1, 0xAD1, 0x2D9, 0x4E9, 0x942, 0x74A,
+ 0x35A, 0x162, 0x64B, 0xA53, 0x063, 0x46B, 0x804, 0xA14, 0x21C, 0x42C,
+ 0x885, 0x68D, 0x29D, 0x0A5},
+ {0xB08, 0x110, 0x520, 0x728, 0x941, 0x151, 0x359, 0x769, 0x802, 0xA0A,
+ 0x21A, 0x422, 0xA4B, 0x053, 0x463, 0x66B, 0x884, 0x094, 0x29C, 0x6AC,
+ 0x8C5, 0xACD, 0x2DD, 0x4E5},
+ {0x508, 0x710, 0xB20, 0x128, 0x881, 0x691, 0x299, 0x0A9, 0x8C2, 0x4CA,
+ 0x2DA, 0xAE2, 0x44B, 0x653, 0xA63, 0x06B, 0x944, 0x754, 0x35C, 0x16C,
+ 0x805, 0x40D, 0x21D, 0xA25},
+ {0x108, 0x510, 0x720, 0xB28, 0x801, 0x411, 0x219, 0xA29, 0x882, 0x08A,
+ 0x29A, 0x6A2, 0x04B, 0x453, 0x663, 0xA6B, 0x8C4, 0x4D4, 0x2DC, 0xAEC,
+ 0x945, 0x14D, 0x35D, 0x765},
+ {0x748, 0x350, 0x160, 0x968, 0xAC1, 0x2D1, 0x4D9, 0x8E9, 0xA42, 0x64A,
+ 0x45A, 0x062, 0x68B, 0x293, 0x0A3, 0x8AB, 0xA04, 0x214, 0x41C, 0x82C,
+ 0xB05, 0x70D, 0x51D, 0x125},
+ {0x948, 0x750, 0x360, 0x168, 0xB01, 0x711, 0x519, 0x129, 0xAC2, 0x8CA,
+ 0x4DA, 0x2E2, 0x88B, 0x693, 0x2A3, 0x0AB, 0xA44, 0x654, 0x45C, 0x06C,
+ 0xA05, 0x80D, 0x41D, 0x225},
+ {0x348, 0x150, 0x960, 0x768, 0xA41, 0x051, 0x459, 0x669, 0xA02, 0x20A,
+ 0x41A, 0x822, 0x28B, 0x093, 0x8A3, 0x6AB, 0xB04, 0x114, 0x51C, 0x72C,
+ 0xAC5, 0x2CD, 0x4DD, 0x8E5},
+ {0x148, 0x950, 0x760, 0x368, 0xA01, 0x811, 0x419, 0x229, 0xB02, 0x10A,
+ 0x51A, 0x722, 0x08B, 0x893, 0x6A3, 0x2AB, 0xAC4, 0x8D4, 0x4DC, 0x2EC,
+ 0xA45, 0x04D, 0x45D, 0x665},
+ {0x688, 0x890, 0x0A0, 0x2A8, 0x4C1, 0x8D1, 0xAD9, 0x2E9, 0x502, 0x70A,
+ 0xB1A, 0x122, 0x74B, 0x953, 0x163, 0x36B, 0x404, 0x814, 0xA1C, 0x22C,
+ 0x445, 0x64D, 0xA5D, 0x065},
+ {0x888, 0x090, 0x2A0, 0x6A8, 0x501, 0x111, 0xB19, 0x729, 0x402, 0x80A,
+ 0xA1A, 0x222, 0x94B, 0x153, 0x363, 0x76B, 0x444, 0x054, 0xA5C, 0x66C,
+ 0x4C5, 0x8CD, 0xADD, 0x2E5},
+ {0x288, 0x690, 0x8A0, 0x0A8, 0x441, 0x651, 0xA59, 0x069, 0x4C2, 0x2CA,
+ 0xADA, 0x8E2, 0x34B, 0x753, 0x963, 0x16B, 0x504, 0x714, 0xB1C, 0x12C,
+ 0x405, 0x20D, 0xA1D, 0x825},
+ {0x088, 0x290, 0x6A0, 0x8A8, 0x401, 0x211, 0xA19, 0x829, 0x442, 0x04A,
+ 0xA5A, 0x662, 0x14B, 0x353, 0x763, 0x96B, 0x4C4, 0x2D4, 0xADC, 0x8EC,
+ 0x505, 0x10D, 0xB1D, 0x725},
+ {0x648, 0x450, 0x060, 0xA68, 0x2C1, 0x4D1, 0x8D9, 0xAE9, 0x282, 0x68A,
+ 0x89A, 0x0A2, 0x70B, 0x513, 0x123, 0xB2B, 0x204, 0x414, 0x81C, 0xA2C,
+ 0x345, 0x74D, 0x95D, 0x165},
+ {0xA48, 0x650, 0x460, 0x068, 0x341, 0x751, 0x959, 0x169, 0x2C2, 0xACA,
+ 0x8DA, 0x4E2, 0xB0B, 0x713, 0x523, 0x12B, 0x284, 0x694, 0x89C, 0x0AC,
+ 0x205, 0xA0D, 0x81D, 0x425},
+ {0x448, 0x050, 0xA60, 0x668, 0x281, 0x091, 0x899, 0x6A9, 0x202, 0x40A,
+ 0x81A, 0xA22, 0x50B, 0x113, 0xB23, 0x72B, 0x344, 0x154, 0x95C, 0x76C,
+ 0x2C5, 0x4CD, 0x8DD, 0xAE5},
+ {0x048, 0xA50, 0x660, 0x468, 0x201, 0xA11, 0x819, 0x429, 0x342, 0x14A,
+ 0x95A, 0x762, 0x10B, 0xB13, 0x723, 0x52B, 0x2C4, 0xAD4, 0x8DC, 0x4EC,
+ 0x285, 0x08D, 0x89D, 0x6A5},
+ {0x808, 0xA10, 0x220, 0x428, 0x101, 0xB11, 0x719, 0x529, 0x142, 0x94A,
+ 0x75A, 0x362, 0x8CB, 0xAD3, 0x2E3, 0x4EB, 0x044, 0xA54, 0x65C, 0x46C,
+ 0x085, 0x88D, 0x69D, 0x2A5},
+ {0xA08, 0x210, 0x420, 0x828, 0x141, 0x351, 0x759, 0x969, 0x042, 0xA4A,
+ 0x65A, 0x462, 0xACB, 0x2D3, 0x4E3, 0x8EB, 0x084, 0x294, 0x69C, 0x8AC,
+ 0x105, 0xB0D, 0x71D, 0x525},
+ {0x408, 0x810, 0xA20, 0x228, 0x081, 0x891, 0x699, 0x2A9, 0x102, 0x50A,
+ 0x71A, 0xB22, 0x4CB, 0x8D3, 0xAE3, 0x2EB, 0x144, 0x954, 0x75C, 0x36C,
+ 0x045, 0x44D, 0x65D, 0xA65},
+ };
+
+// _axis_convert_num = {'X': 0, 'Y': 1, 'Z': 2, '-X': 3, '-Y': 4, '-Z': 5}
+
+MINLINE int _axis_signed(const int axis)
+{
+ return (axis < 3) ? axis : axis - 3;
+}
+
+/*
+ * Each argument us an axis in ['X', 'Y', 'Z', '-X', '-Y', '-Z']
+ * where the first 2 are a source and the second 2 are the target.
+ */
+int mat3_from_axis_conversion(int from_forward, int from_up, int to_forward, int to_up,
+ float r_mat[3][3])
+{
+ // from functools import reduce
+ int value;
+ int i;
+
+ if (from_forward == to_forward && from_up == to_up) {
+ unit_m3(r_mat);
+ return false;
+ }
+
+ if ((_axis_signed(from_forward) == _axis_signed(from_up)) ||
+ (_axis_signed(to_forward) == _axis_signed(to_up)))
+ {
+ /* we could assert here! */
+ unit_m3(r_mat);
+ return false;
+ }
+
+ value = ((from_forward << (0 * 3)) |
+ (from_up << (1 * 3)) |
+ (to_forward << (2 * 3)) |
+ (to_up << (3 * 3)));
+
+ for (i = 0; i < (sizeof(_axis_convert_matrix) / sizeof(*_axis_convert_matrix)); i++) {
+ int j;
+ for (j = 0; j < sizeof(*_axis_convert_lut) / sizeof(*_axis_convert_lut[0]); j++) {
+ if (_axis_convert_lut[i][j] == value) {
+ copy_m3_m3(r_mat, _axis_convert_matrix[i]);
+ return true;
+ }
+ }
+
+ }
+// BLI_assert(0);
+ return false;
+}
diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c
index 812e2b3e63d..490ed2a99fb 100644
--- a/source/blender/blenlib/intern/math_vector.c
+++ b/source/blender/blenlib/intern/math_vector.c
@@ -122,6 +122,32 @@ void mid_v3_v3v3v3(float v[3], const float v1[3], const float v2[3], const float
v[2] = (v1[2] + v2[2] + v3[2]) / 3.0f;
}
+/**
+ * Equivalent to:
+ * interp_v3_v3v3(v, v1, v2, -1.0f);
+ */
+
+void flip_v4_v4v4(float v[4], const float v1[4], const float v2[4])
+{
+ v[0] = v1[0] + (v1[0] - v2[0]);
+ v[1] = v1[1] + (v1[1] - v2[1]);
+ v[2] = v1[2] + (v1[2] - v2[2]);
+ v[3] = v1[3] + (v1[3] - v2[3]);
+}
+
+void flip_v3_v3v3(float v[3], const float v1[3], const float v2[3])
+{
+ v[0] = v1[0] + (v1[0] - v2[0]);
+ v[1] = v1[1] + (v1[1] - v2[1]);
+ v[2] = v1[2] + (v1[2] - v2[2]);
+}
+
+void flip_v2_v2v2(float v[2], const float v1[2], const float v2[2])
+{
+ v[0] = v1[0] + (v1[0] - v2[0]);
+ v[1] = v1[1] + (v1[1] - v2[1]);
+}
+
/********************************** Angles ***********************************/
/* Return the angle in radians between vecs 1-2 and 2-3 in radians
@@ -685,6 +711,19 @@ void msub_vn_vnvn(float *array_tar, const float *array_src_a, const float *array
}
}
+void interp_vn_vn(float *array_tar, const float *array_src, const float t, const int size)
+{
+ const float s = 1.0f - t;
+ float *tar = array_tar + (size - 1);
+ const float *src = array_src + (size - 1);
+ int i = size;
+ while (i--) {
+ *(tar) = (s * *(tar)) + (t * *(src));
+ tar--;
+ src--;
+ }
+}
+
void fill_vn_i(int *array_tar, const int size, const int val)
{
int *tar = array_tar + (size - 1);
diff --git a/source/blender/blenlib/intern/noise.c b/source/blender/blenlib/intern/noise.c
index f37e1e03f39..c159f707b98 100644
--- a/source/blender/blenlib/intern/noise.c
+++ b/source/blender/blenlib/intern/noise.c
@@ -1460,7 +1460,8 @@ float BLI_gNoise(float noisesize, float x, float y, float z, int hard, int noise
noisefunc = cellNoiseU;
break;
case 0:
- default: {
+ default:
+ {
noisefunc = orgBlenderNoise;
/* add one to make return value same as BLI_hnoise */
x += 1;
@@ -1592,7 +1593,8 @@ float mg_fBm(float x, float y, float z, float H, float lacunarity, float octaves
noisefunc = cellNoise;
break;
case 0:
- default: {
+ default:
+ {
noisefunc = orgBlenderNoiseS;
}
}
@@ -1662,7 +1664,8 @@ float mg_MultiFractal(float x, float y, float z, float H, float lacunarity, floa
noisefunc = cellNoise;
break;
case 0:
- default: {
+ default:
+ {
noisefunc = orgBlenderNoiseS;
}
}
@@ -1728,7 +1731,8 @@ float mg_HeteroTerrain(float x, float y, float z, float H, float lacunarity, flo
noisefunc = cellNoise;
break;
case 0:
- default: {
+ default:
+ {
noisefunc = orgBlenderNoiseS;
}
}
@@ -1801,7 +1805,8 @@ float mg_HybridMultiFractal(float x, float y, float z, float H, float lacunarity
noisefunc = cellNoise;
break;
case 0:
- default: {
+ default:
+ {
noisefunc = orgBlenderNoiseS;
}
}
@@ -1876,7 +1881,8 @@ float mg_RidgedMultiFractal(float x, float y, float z, float H, float lacunarity
noisefunc = cellNoise;
break;
case 0:
- default: {
+ default:
+ {
noisefunc = orgBlenderNoiseS;
}
}
@@ -1941,7 +1947,8 @@ float mg_VLNoise(float x, float y, float z, float distortion, int nbas1, int nba
noisefunc1 = cellNoise;
break;
case 0:
- default: {
+ default:
+ {
noisefunc1 = orgBlenderNoiseS;
}
}
@@ -1975,7 +1982,8 @@ float mg_VLNoise(float x, float y, float z, float distortion, int nbas1, int nba
noisefunc2 = cellNoise;
break;
case 0:
- default: {
+ default:
+ {
noisefunc2 = orgBlenderNoiseS;
}
}
diff --git a/source/blender/blenlib/intern/threads.c b/source/blender/blenlib/intern/threads.c
index 146e1d531f1..686484ef1db 100644
--- a/source/blender/blenlib/intern/threads.c
+++ b/source/blender/blenlib/intern/threads.c
@@ -729,6 +729,9 @@ void BLI_thread_queue_wait_finish(ThreadQueue *queue)
void BLI_begin_threaded_malloc(void)
{
+ /* Used for debug only */
+ /* BLI_assert(thread_levels >= 0); */
+
if (thread_levels == 0) {
MEM_set_lock_callback(BLI_lock_malloc_thread, BLI_unlock_malloc_thread);
}
@@ -737,6 +740,9 @@ void BLI_begin_threaded_malloc(void)
void BLI_end_threaded_malloc(void)
{
+ /* Used for debug only */
+ /* BLI_assert(thread_levels >= 0); */
+
thread_levels--;
if (thread_levels == 0)
MEM_set_lock_callback(NULL, NULL);