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:
authorHans Goudey <h.goudey@me.com>2022-02-02 00:42:04 +0300
committerHans Goudey <h.goudey@me.com>2022-02-02 00:42:04 +0300
commit03e580c98c5ef07ec864fb5823ad68acdc2d7551 (patch)
tree10d86749fa63afd09d5adc9828158f30b87feb59
parentff5e8e6d535374891e09bc0e6ceb7059a22bdd53 (diff)
Cleanup: Use C++ types
-rw-r--r--source/blender/blenkernel/intern/hair.cc37
1 files changed, 16 insertions, 21 deletions
diff --git a/source/blender/blenkernel/intern/hair.cc b/source/blender/blenkernel/intern/hair.cc
index 976e75822bc..5e8b81c03a4 100644
--- a/source/blender/blenkernel/intern/hair.cc
+++ b/source/blender/blenkernel/intern/hair.cc
@@ -31,7 +31,7 @@
#include "BLI_listbase.h"
#include "BLI_math_base.h"
#include "BLI_math_vec_types.hh"
-#include "BLI_rand.h"
+#include "BLI_rand.hh"
#include "BLI_string.h"
#include "BLI_utildefines.h"
@@ -54,6 +54,7 @@
#include "BLO_read_write.h"
using blender::float3;
+using blender::RandomNumberGenerator;
static const char *HAIR_ATTR_POSITION = "position";
static const char *HAIR_ATTR_RADIUS = "radius";
@@ -220,38 +221,32 @@ static void hair_random(Hair *hair)
CustomData_realloc(&hair->cdata, hair->totcurve);
BKE_hair_update_customdata_pointers(hair);
- RNG *rng = BLI_rng_new(0);
+ RandomNumberGenerator rng;
for (int i = 0; i < hair->totcurve; i++) {
HairCurve *curve = &hair->curves[i];
curve->firstpoint = i * numpoints;
curve->numpoints = numpoints;
- float theta = 2.0f * M_PI * BLI_rng_get_float(rng);
- float phi = saacosf(2.0f * BLI_rng_get_float(rng) - 1.0f);
+ const float theta = 2.0f * M_PI * rng.get_float();
+ const float phi = saacosf(2.0f * rng.get_float() - 1.0f);
- float no[3] = {sinf(theta) * sinf(phi), cosf(theta) * sinf(phi), cosf(phi)};
- normalize_v3(no);
+ float3 no = {std::sin(theta) * std::sin(phi), std::cos(theta) * std::sin(phi), std::cos(phi)};
+ blender::math::normalize(no);
- float co[3];
- copy_v3_v3(co, no);
-
- float(*curve_co)[3] = hair->co + curve->firstpoint;
- float *curve_radius = hair->radius + curve->firstpoint;
+ float(*curve_positions)[3] = hair->co + curve->firstpoint;
+ float *curve_radii = hair->radius + curve->firstpoint;
+ float3 co = no;
for (int key = 0; key < numpoints; key++) {
float t = key / (float)(numpoints - 1);
- copy_v3_v3(curve_co[key], co);
- curve_radius[key] = 0.02f * (1.0f - t);
-
- float offset[3] = {2.0f * BLI_rng_get_float(rng) - 1.0f,
- 2.0f * BLI_rng_get_float(rng) - 1.0f,
- 2.0f * BLI_rng_get_float(rng) - 1.0f};
- add_v3_v3(offset, no);
- madd_v3_v3fl(co, offset, 1.0f / numpoints);
+ copy_v3_v3(curve_positions[key], co);
+ curve_radii[key] = 0.02f * (1.0f - t);
+
+ float3 offset = float3(rng.get_float(), rng.get_float(), rng.get_float()) * 2.0f - 1.0f;
+
+ co += (offset + no) / numpoints;
}
}
-
- BLI_rng_free(rng);
}
void *BKE_hair_add(Main *bmain, const char *name)