mirror of
https://github.com/godotengine/godot.git
synced 2026-01-06 10:11:57 +03:00
Add functions to apply impulse and force to SoftBody on GodotPhysics and JoltPhysics
This commit is contained in:
@@ -737,6 +737,34 @@ void GodotPhysicsServer3D::body_apply_force(RID p_body, const Vector3 &p_force,
|
||||
body->wakeup();
|
||||
}
|
||||
|
||||
void GodotPhysicsServer3D::soft_body_apply_point_impulse(RID p_body, int p_point_index, const Vector3 &p_impulse) {
|
||||
GodotSoftBody3D *soft_body = soft_body_owner.get_or_null(p_body);
|
||||
ERR_FAIL_NULL(soft_body);
|
||||
|
||||
soft_body->apply_node_impulse(p_point_index, p_impulse);
|
||||
}
|
||||
|
||||
void GodotPhysicsServer3D::soft_body_apply_point_force(RID p_body, int p_point_index, const Vector3 &p_force) {
|
||||
GodotSoftBody3D *soft_body = soft_body_owner.get_or_null(p_body);
|
||||
ERR_FAIL_NULL(soft_body);
|
||||
|
||||
soft_body->apply_node_force(p_point_index, p_force);
|
||||
}
|
||||
|
||||
void GodotPhysicsServer3D::soft_body_apply_central_impulse(RID p_body, const Vector3 &p_impulse) {
|
||||
GodotSoftBody3D *soft_body = soft_body_owner.get_or_null(p_body);
|
||||
ERR_FAIL_NULL(soft_body);
|
||||
|
||||
soft_body->apply_central_impulse(p_impulse);
|
||||
}
|
||||
|
||||
void GodotPhysicsServer3D::soft_body_apply_central_force(RID p_body, const Vector3 &p_force) {
|
||||
GodotSoftBody3D *soft_body = soft_body_owner.get_or_null(p_body);
|
||||
ERR_FAIL_NULL(soft_body);
|
||||
|
||||
soft_body->apply_central_force(p_force);
|
||||
}
|
||||
|
||||
void GodotPhysicsServer3D::body_apply_torque(RID p_body, const Vector3 &p_torque) {
|
||||
GodotBody3D *body = body_owner.get_or_null(p_body);
|
||||
ERR_FAIL_NULL(body);
|
||||
|
||||
@@ -212,6 +212,11 @@ public:
|
||||
virtual void body_apply_impulse(RID p_body, const Vector3 &p_impulse, const Vector3 &p_position = Vector3()) override;
|
||||
virtual void body_apply_torque_impulse(RID p_body, const Vector3 &p_impulse) override;
|
||||
|
||||
virtual void soft_body_apply_point_impulse(RID p_body, int p_point_index, const Vector3 &p_impulse) override;
|
||||
virtual void soft_body_apply_point_force(RID p_body, int p_point_index, const Vector3 &p_force) override;
|
||||
virtual void soft_body_apply_central_impulse(RID p_body, const Vector3 &p_impulse) override;
|
||||
virtual void soft_body_apply_central_force(RID p_body, const Vector3 &p_force) override;
|
||||
|
||||
virtual void body_apply_central_force(RID p_body, const Vector3 &p_force) override;
|
||||
virtual void body_apply_force(RID p_body, const Vector3 &p_force, const Vector3 &p_position = Vector3()) override;
|
||||
virtual void body_apply_torque(RID p_body, const Vector3 &p_torque) override;
|
||||
|
||||
@@ -446,6 +446,30 @@ void GodotSoftBody3D::apply_node_impulse(uint32_t p_node_index, const Vector3 &p
|
||||
node.v += p_impulse * node.im;
|
||||
}
|
||||
|
||||
void GodotSoftBody3D::apply_node_force(uint32_t p_node_index, const Vector3 &p_force) {
|
||||
ERR_FAIL_UNSIGNED_INDEX(p_node_index, nodes.size());
|
||||
Node &node = nodes[p_node_index];
|
||||
node.f += p_force;
|
||||
}
|
||||
|
||||
void GodotSoftBody3D::apply_central_impulse(const Vector3 &p_impulse) {
|
||||
const Vector3 impulse = p_impulse / nodes.size();
|
||||
for (Node &node : nodes) {
|
||||
if (node.im > 0) {
|
||||
node.v += impulse * node.im;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GodotSoftBody3D::apply_central_force(const Vector3 &p_force) {
|
||||
const Vector3 force = p_force / nodes.size();
|
||||
for (Node &node : nodes) {
|
||||
if (node.im > 0) {
|
||||
node.f += force;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GodotSoftBody3D::apply_node_bias_impulse(uint32_t p_node_index, const Vector3 &p_impulse) {
|
||||
ERR_FAIL_UNSIGNED_INDEX(p_node_index, nodes.size());
|
||||
Node &node = nodes[p_node_index];
|
||||
|
||||
@@ -172,6 +172,9 @@ public:
|
||||
Vector3 get_node_velocity(uint32_t p_node_index) const;
|
||||
Vector3 get_node_biased_velocity(uint32_t p_node_index) const;
|
||||
void apply_node_impulse(uint32_t p_node_index, const Vector3 &p_impulse);
|
||||
void apply_node_force(uint32_t p_node_index, const Vector3 &p_force);
|
||||
void apply_central_impulse(const Vector3 &p_impulse);
|
||||
void apply_central_force(const Vector3 &p_force);
|
||||
void apply_node_bias_impulse(uint32_t p_node_index, const Vector3 &p_impulse);
|
||||
|
||||
uint32_t get_face_count() const;
|
||||
|
||||
Reference in New Issue
Block a user