50 const Vector3 &normal,
51 const node_t &surface_point,
52 const std::vector<int> &neighbour_node_ids,
55 auto sign = [](
float x){
return (
x >= 0) ? 1 : -1; };
63 int face_indicator = weight *
sign(distance);
66 if (neighbour_node_ids.size() > weight) {
67 for (
auto id : neighbour_node_ids) {
68 const auto neighbour_distance = normal.dotProduct(
nodes[
id].AbsPosition - surface_point.
AbsPosition);
69 face_indicator +=
sign(neighbour_distance);
74 return (face_indicator < 0);
91 const auto distance = local.
distance;
92 return (coord.alpha >= 0) && (coord.beta >= 0) && (coord.gamma >= 0) && (std::abs(distance) <= margin);
99 const float alpha,
const float beta,
const float gamma,
100 const Vector3 &normal,
106 const float tr_mass = na.
mass * alpha + nb.
mass * beta + no.
mass * gamma;
107 const float mass = remote ? hitnode.
mass : (hitnode.
mass * tr_mass) / (hitnode.
mass + tr_mass);
109 auto forcevec =
primitiveCollision(&hitnode, velocity, mass, normal, dt, &submesh_ground_model, penetration_depth);
111 hitnode.
Forces += forcevec;
112 na.
Forces -= forcevec * alpha;
113 nb.
Forces -= forcevec * beta;
114 no.
Forces -= forcevec * gamma;
119 const int free_collcab,
int collcabs[],
int cabs[],
121 const float collrange,
124 for (
int i=0; i<free_collcab; i++)
126 if (inter_collcabrate[i].rate > 0)
129 inter_collcabrate[i].
rate--;
132 inter_collcabrate[i].
rate = std::min(inter_collcabrate[i].distance, 12);
135 int tmpv = collcabs[i]*3;
136 const auto no = &
nodes[cabs[tmpv]];
137 const auto na = &
nodes[cabs[tmpv+1]];
138 const auto nb = &
nodes[cabs[tmpv+2]];
140 interPointCD.
query(no->AbsPosition
142 , nb->AbsPosition, collrange);
147 const Triangle triangle(na->AbsPosition, nb->AbsPosition, no->AbsPosition);
164 const auto local_point = transform(hitnode.
AbsPosition);
170 inter_collcabrate[i].
rate = 0;
172 const auto coord = local_point.barycentric;
173 auto distance = local_point.distance;
174 auto normal = triangle.
normal();
183 distance = -distance;
186 const auto penetration_depth = collrange - distance;
188 const bool remote = (hit_actor->
ar_state == ActorState::NETWORKED_OK);
191 coord.beta, coord.gamma, normal, dt, remote, submesh_ground_model);
195 na->nd_has_mesh_contact =
true;
196 nb->nd_has_mesh_contact =
true;
197 no->nd_has_mesh_contact =
true;
204 inter_collcabrate[i].
rate++;
211 const int free_collcab,
int collcabs[],
int cabs[],
213 const float collrange,
216 for (
int i=0; i<free_collcab; i++)
218 if (intra_collcabrate[i].rate > 0)
221 intra_collcabrate[i].
rate--;
224 if (intra_collcabrate[i].distance > 0)
226 intra_collcabrate[i].
rate = std::min(intra_collcabrate[i].distance, 12);
230 int tmpv = collcabs[i]*3;
231 const auto no = &
nodes[cabs[tmpv]];
232 const auto na = &
nodes[cabs[tmpv+1]];
233 const auto nb = &
nodes[cabs[tmpv+2]];
235 intraPointCD.
query(no->AbsPosition
237 , nb->AbsPosition, collrange);
239 bool collision =
false;
244 const Triangle triangle(na->AbsPosition, nb->AbsPosition, no->AbsPosition);
254 if (no == &hitnode || na == &hitnode || nb == &hitnode)
continue;
257 const auto local_point = transform(hitnode.
AbsPosition);
265 const auto coord = local_point.barycentric;
266 auto distance = local_point.distance;
267 auto normal = triangle.
normal();
274 distance = -distance;
277 const auto penetration_depth = collrange - distance;
280 coord.beta, coord.gamma, normal, dt,
false, submesh_ground_model);
287 intra_collcabrate[i].
rate = -20000;
291 intra_collcabrate[i].
rate++;