33 const float co_test[3],
78 float priority = 0.0f,
len = 0.0f;
88 for (cur = effectors->
first; cur; cur = cur->
next) {
93 if (gabr->
ob == eob) {
120 else if (temp > priority) {
137 if (eff ==
NULL && gabr->
ob) {
139 temp_eff.
ob = gabr->
ob;
208 KDTreeNearest_3d *ptn =
NULL;
212 float vec[3] = {0.0f, 0.0f, 0.0f}, loc[3] = {0.0f, 0.0f, 0.0f};
213 float co1[3], vel1[3], co2[3], vel2[3];
214 float len,
t, inp, t_min = 2.0f;
215 int n, neighbors = 0, nearest = 0;
241 col.current = coll->
ob;
244 if (
col.md &&
col.md->bvhtree) {
256 if (hit.
index >= 0) {
257 t = hit.
dist /
col.original_ray_length;
282 neighbors = BLI_kdtree_3d_range_search_with_len_squared_cb(bbd->
sim->
psys->
tree,
290 for (n = 1; n < neighbors; n++) {
306 if (
t > 0.0f &&
t < t_min) {
315 if (len < 2.0f * val->personal_space * pa->
size) {
337 neighbors = BLI_kdtree_3d_range_search_with_len_squared_cb(epsys->
tree,
346 for (n = 0; n < neighbors; n++) {
362 if (
t > 0.0f &&
t < t_min) {
371 if (len < 2.0f * val->personal_space * pa->
size) {
389 if (ptn && nearest == 0) {
400 KDTreeNearest_3d *ptn =
NULL;
403 float vec[3] = {0.0f, 0.0f, 0.0f};
404 int neighbors = BLI_kdtree_3d_range_search(
408 if (neighbors > 1 && ptn[1].dist != 0.0f) {
423 neighbors = BLI_kdtree_3d_range_search(
426 if (neighbors > 0 && ptn[0].dist <
len) {
445 KDTreeNearest_3d ptn[11];
446 float vec[3] = {0.0f, 0.0f, 0.0f}, loc[3] = {0.0f, 0.0f, 0.0f};
447 int neighbors = BLI_kdtree_3d_find_nearest_n_with_len_squared_cb(
458 for (n = 1; n < neighbors; n++) {
463 mul_v3_fl(loc, 1.0f / ((
float)neighbors - 1.0f));
464 mul_v3_fl(vec, 1.0f / ((
float)neighbors - 1.0f));
483 float vec[3] = {0.0f, 0.0f, 0.0f}, loc[3] = {0.0f, 0.0f, 0.0f};
504 if (len < 2.0f * val->personal_space * pa->
size) {
514 if (
t > 0.0f &&
t < 3.0f) {
522 if (len < 2.0f * val->personal_space * pa->
size) {
550 float vec2[3],
t, t_min = 3.0f;
564 if (len < 2.0f * val->personal_space * pa->
size) {
574 if (
t > 0.0f &&
t < t_min) {
582 if (len < 2.0f * val->personal_space * pa->
size) {
624 float vec[3] = {0.0f, 0.0f, 0.0f};
626 if (asbr->
wander > 0.0f) {
675 KDTreeNearest_3d *ptn =
NULL;
681 float closest_enemy[3] = {0.0f, 0.0f, 0.0f};
682 float closest_dist = fbr->
distance + 1.0f;
683 float f_strength = 0.0f, e_strength = 0.0f;
689 int neighbors = BLI_kdtree_3d_range_search(
691 for (n = 0; n < neighbors; n++) {
710 for (n = 0; n < neighbors; n++) {
711 bpa = epars[ptn[n].index].
boid;
716 closest_dist = ptn[n].dist;
717 enemy_pa = epars + ptn[n].index;
731 if (e_strength > 0.0f) {
735 if (closest_dist <= bbd->part->boids->range + pa->
size + enemy_pa->
size) {
746 bpa = enemy_pa->
boid;
760 e_strength / f_strength) {
762 if (closest_dist < fbr->flee_distance * fbr->
distance) {
847 const float zvec[3] = {0.0f, 0.0f, 2000.0f};
851 float radius = 0.0f,
t, ray_dir[3];
869 col.current = coll->
ob;
871 col.fac1 =
col.fac2 = 0.0f;
873 if (
col.md &&
col.md->bvhtree) {
885 if (hit.
index >= 0) {
886 t = hit.
dist /
col.original_ray_length;
902 col.current = coll->
ob;
905 if (
col.md &&
col.md->bvhtree) {
917 if (hit.
index >= 0) {
918 t = hit.
dist /
col.original_ray_length;
927 ground_nor[0] = ground_nor[1] = 0.0f;
928 ground_nor[2] = 1.0f;
955 for (rule =
state->rules.first; rule; rule = rule->
next) {
959 if (flbr->
ob && flbr->
cfra != cfra) {
975 float nor[3], vel[3];
1042 static int boid_condition_is_true(BoidCondition *cond)
1066 BoidCondition *cond =
state->conditions.first;
1067 for (; cond; cond = cond->next) {
1068 if (boid_condition_is_true(cond)) {
1069 pa->
boid->state_id = cond->state_id;
1086 switch (
state->ruleset_type) {
1088 for (rule =
state->rules.first; rule; rule = rule->
next) {
1105 float wanted_co[3] = {0.0f, 0.0f, 0.0f}, wanted_speed = 0.0f;
1107 for (rule =
state->rules.first; rule; rule = rule->
next) {
1119 wanted_speed /= (
float)n;
1131 float mul = 1.0f +
state->rule_fuzziness;
1134 float cvel[3], dir[3];
1152 float cvel[3], dir[3];
1153 float z_v, ground_v, cur_v;
1166 if (
dot_v2v2(cvel, dir) > 0.95f /
mul || len <= state->rule_fuzziness) {
1174 len =
sasqrt((ground_v - cur_v) * (ground_v - cur_v) + z_v * z_v);
1176 if (len < val.jump_speed * mul || bbd->part->boids->options &
BOID_ALLOW_FLIGHT) {
1210 float acc[3] = {0.0f, 0.0f, 0.0f}, tan_acc[3], nor_acc[3];
1211 float dvec[3], bvec[3];
1212 float new_dir[3], new_speed;
1213 float old_dir[3], old_speed;
1214 float wanted_dir[3];
1215 float q[4], mat[3][3];
1216 float ground_co[3] = {0.0f, 0.0f, 0.0f}, ground_nor[3] = {0.0f, 0.0f, 1.0f};
1217 float force[3] = {0.0f, 0.0f, 0.0f};
1226 pa_mass *= pa->
size;
1242 float landing_level = 2.0f;
1243 float level = landing_level + 1.0f;
1266 else if (level < landing_level) {
1268 bbd->
wanted_co[2] *= (level - 1.0f) / landing_level;
1277 if (new_speed == 0.0f) {
1281 float old_dir2[2], wanted_dir2[2],
nor[3],
angle;
1289 if (
dot_v2v2(old_dir2, wanted_dir2) < -0.99f) {
1328 if (level >= landing_level) {
1329 float len2 =
dot_v2v2(new_vel, new_vel);
1333 root =
sasqrt(new_speed * new_speed - len2);
1335 new_vel[2] = new_vel[2] < 0.0f ? -root : root;
1424 boid_climb(boids, pa, ground_co, ground_nor);
1459 boid_climb(boids, pa, ground_co, ground_nor);
1478 boid_climb(boids, pa, ground_co, ground_nor);
1504 boid_climb(boids, pa, ground_co, ground_nor);
1630 boids->
pitch = 1.0f;
1636 boids->
range = 1.0f;
1649 strcpy(
state->name,
"State");
1652 state->rule_fuzziness = 0.5;
1653 state->volume = 1.0f;
1654 state->channels |= ~0;
typedef float(TangentPoint)[2]
float effector_falloff(struct EffectorCache *eff, struct EffectorData *efd, struct EffectedPoint *point, struct EffectorWeights *weights)
void BKE_effectors_apply(struct ListBase *effectors, struct ListBase *colliders, struct EffectorWeights *weights, struct EffectedPoint *point, float *force, float *wind_force, float *impulse)
bool get_effector_data(struct EffectorCache *eff, struct EffectorData *efd, struct EffectedPoint *point, int real_velocity)
bool closest_point_on_surface(struct SurfaceModifierData *surmd, const float co[3], float surface_co[3], float surface_nor[3], float surface_vel[3])
void pd_point_from_particle(struct ParticleSimulationData *sim, struct ParticleData *pa, struct ParticleKey *state, struct EffectedPoint *point)
struct ModifierData * BKE_modifiers_findby_type(const struct Object *ob, ModifierType type)
struct ParticleSystem * psys_get_target_system(struct Object *ob, struct ParticleTarget *pt)
void copy_particle_key(struct ParticleKey *to, struct ParticleKey *from, int time)
void BKE_psys_collision_neartest_cb(void *userdata, int index, const struct BVHTreeRay *ray, struct BVHTreeRayHit *hit)
int psys_uses_gravity(struct ParticleSimulationData *sim)
BLI_INLINE float psys_frand(ParticleSystem *psys, unsigned int seed)
#define BVH_RAYCAST_DEFAULT
int BLI_bvhtree_ray_cast_ex(BVHTree *tree, const float co[3], const float dir[3], float radius, BVHTreeRayHit *hit, BVHTree_RayCastCallback callback, void *userdata, int flag)
A KD-tree for nearest neighbor search.
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)
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE float saacos(float fac)
MINLINE float min_ff(float a, float b)
MINLINE float sasqrt(float fac)
void axis_angle_to_quat(float r[4], const float axis[3], float angle)
void mul_qt_v3(const float q[4], float r[3])
void mat3_to_quat_is_ok(float q[4], const float mat[3][3])
void copy_qt_qt(float q[4], const float a[4])
MINLINE float len_squared_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
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_v3(float r[3], const float a[3])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void mul_v2_fl(float r[2], float f)
MINLINE void copy_v2_v2(float r[2], const float a[2])
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])
void project_v3_v3v3(float out[3], const float p[3], const float v_proj[3])
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void negate_v3(float r[3])
MINLINE float normalize_v3_v3(float r[3], const float a[3])
MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE float dot_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
MINLINE float len_v2(const float a[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void zero_v3(float r[3])
MINLINE float normalize_v2(float r[2])
MINLINE void add_v3_v3(float r[3], const float a[3])
MINLINE bool compare_len_v3v3(const float a[3], const float b[3], float limit) ATTR_WARN_UNUSED_RESULT
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
float BLI_rng_get_float(struct RNG *rng) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
#define BRULE_ACOLL_WITH_BOIDS
#define BOIDSTATE_CURRENT
#define BOID_ALLOW_FLIGHT
#define BRULE_ACOLL_WITH_DEFLECTORS
#define BRULE_LEADER_IN_LINE
@ eBoidRulesetType_Average
@ eBoidRulesetType_Random
#define BRULE_GOAL_AVOID_PREDICT
@ eBoidRuleType_FollowLeader
@ eBoidRuleType_AvoidCollision
@ eBoidRuleType_AverageSpeed
#define PFIELD_SHAPE_SURFACE
#define PTARGET_MODE_FRIEND
#define PTARGET_MODE_ENEMY
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
Read Guarded memory(de)allocation.
ATTR_WARN_UNUSED_RESULT const BMVert * v
void boid_free_settings(BoidSettings *boids)
static bool rule_flock(BoidRule *UNUSED(rule), BoidBrainData *bbd, BoidValues *UNUSED(val), ParticleData *pa)
BoidState * boid_duplicate_state(BoidSettings *boids, BoidState *state)
BoidState * boid_get_current_state(BoidSettings *boids)
static bool boid_rule_applies(ParticleData *pa, BoidSettings *UNUSED(boids), BoidRule *rule)
BoidState * boid_new_state(BoidSettings *boids)
static bool rule_average_speed(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, ParticleData *pa)
static Object * boid_find_ground(BoidBrainData *bbd, ParticleData *pa, float ground_co[3], float ground_nor[3])
struct BoidValues BoidValues
BoidRule * boid_new_rule(int type)
static bool rule_follow_leader(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, ParticleData *pa)
static void boid_climb(BoidSettings *boids, ParticleData *pa, float *surface_co, float *surface_nor)
static bool apply_boid_rule(BoidBrainData *bbd, BoidRule *rule, BoidValues *val, ParticleData *pa, float fuzziness)
void boid_body(BoidBrainData *bbd, ParticleData *pa)
static bool rule_goal_avoid(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, ParticleData *pa)
void boids_precalc_rules(ParticleSettings *part, float cfra)
static bool rule_avoid_collision(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, ParticleData *pa)
static bool rule_fight(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, ParticleData *pa)
static float boid_goal_signed_dist(float *boid_co, float *goal_co, float *goal_nor)
bool(* boid_rule_cb)(BoidRule *rule, BoidBrainData *data, BoidValues *val, ParticleData *pa)
BoidSettings * boid_copy_settings(const BoidSettings *boids)
static float len_squared_v3v3_with_normal_bias(const float co_search[3], const float co_test[3], const void *user_data)
void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa)
static bool rule_separate(BoidRule *UNUSED(rule), BoidBrainData *bbd, BoidValues *val, ParticleData *pa)
static boid_rule_cb boid_rules[]
static BoidState * get_boid_state(BoidSettings *boids, ParticleData *pa)
static bool rule_none(BoidRule *UNUSED(rule), BoidBrainData *UNUSED(data), BoidValues *UNUSED(val), ParticleData *UNUSED(pa))
static void set_boid_values(BoidValues *val, BoidSettings *boids, ParticleData *pa)
void boid_default_settings(BoidSettings *boids)
void jump(const btVector3 &v=btVector3(0, 0, 0))
static void mul(btAlignedObjectArray< T > &items, const Q &value)
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
struct @211::@212 surface
IconTextureDrawCall normal
void(* MEM_freeN)(void *vmemh)
void *(* MEM_dupallocN)(const void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
T length(const vec_base< T, Size > &a)
const EnumPropertyItem rna_enum_boidrule_type_items[]
struct ParticleSettings * part
struct ParticleSimulationData * sim
float land_personal_space
struct CollisionModifierData * collmd
struct ColliderCache * next
struct EffectorCache * next
struct Depsgraph * depsgraph
struct BoidSettings * boids
struct EffectorWeights * effector_weights
struct Depsgraph * depsgraph
struct ParticleSystem * psys
struct ListBase * colliders
struct ListBase * effectors
struct ParticleTarget * next
struct PhysicsSettings physics_settings