mirror of
https://github.com/godotengine/godot.git
synced 2024-11-21 03:18:37 +08:00
Refactor physics force and impulse code
This commit is contained in:
parent
030a26206f
commit
ba27deef06
@ -18,9 +18,9 @@
|
||||
<method name="apply_impulse">
|
||||
<return type="void">
|
||||
</return>
|
||||
<argument index="0" name="position" type="Vector3">
|
||||
<argument index="0" name="impulse" type="Vector3">
|
||||
</argument>
|
||||
<argument index="1" name="impulse" type="Vector3">
|
||||
<argument index="1" name="position" type="Vector3" default="Vector3( 0, 0, 0 )">
|
||||
</argument>
|
||||
<description>
|
||||
</description>
|
||||
|
@ -22,9 +22,9 @@
|
||||
<method name="add_force">
|
||||
<return type="void">
|
||||
</return>
|
||||
<argument index="0" name="offset" type="Vector2">
|
||||
<argument index="0" name="force" type="Vector2">
|
||||
</argument>
|
||||
<argument index="1" name="force" type="Vector2">
|
||||
<argument index="1" name="position" type="Vector2" default="Vector2( 0, 0 )">
|
||||
</argument>
|
||||
<description>
|
||||
Adds a positioned force to the body. Both the force and the offset from the body origin are in global coordinates.
|
||||
@ -51,9 +51,9 @@
|
||||
<method name="apply_impulse">
|
||||
<return type="void">
|
||||
</return>
|
||||
<argument index="0" name="offset" type="Vector2">
|
||||
<argument index="0" name="impulse" type="Vector2">
|
||||
</argument>
|
||||
<argument index="1" name="impulse" type="Vector2">
|
||||
<argument index="1" name="position" type="Vector2" default="Vector2( 0, 0 )">
|
||||
</argument>
|
||||
<description>
|
||||
Applies a positioned impulse to the body. An impulse is time-independent! Applying an impulse every frame would result in a framerate-dependent force. For this reason, it should only be used when simulating one-time impacts (use the "_force" functions otherwise). The offset uses the rotation of the global coordinate system, but is centered at the object's origin.
|
||||
|
@ -12,7 +12,7 @@
|
||||
<method name="add_central_force">
|
||||
<return type="void">
|
||||
</return>
|
||||
<argument index="0" name="force" type="Vector3">
|
||||
<argument index="0" name="force" type="Vector3" default="Vector3( 0, 0, 0 )">
|
||||
</argument>
|
||||
<description>
|
||||
Adds a constant directional force without affecting rotation.
|
||||
@ -24,7 +24,7 @@
|
||||
</return>
|
||||
<argument index="0" name="force" type="Vector3">
|
||||
</argument>
|
||||
<argument index="1" name="position" type="Vector3">
|
||||
<argument index="1" name="position" type="Vector3" default="Vector3( 0, 0, 0 )">
|
||||
</argument>
|
||||
<description>
|
||||
Adds a positioned force to the body. Both the force and the offset from the body origin are in global coordinates.
|
||||
@ -42,7 +42,7 @@
|
||||
<method name="apply_central_impulse">
|
||||
<return type="void">
|
||||
</return>
|
||||
<argument index="0" name="j" type="Vector3">
|
||||
<argument index="0" name="impulse" type="Vector3" default="Vector3( 0, 0, 0 )">
|
||||
</argument>
|
||||
<description>
|
||||
Applies a single directional impulse without affecting rotation.
|
||||
@ -52,9 +52,9 @@
|
||||
<method name="apply_impulse">
|
||||
<return type="void">
|
||||
</return>
|
||||
<argument index="0" name="position" type="Vector3">
|
||||
<argument index="0" name="impulse" type="Vector3">
|
||||
</argument>
|
||||
<argument index="1" name="j" type="Vector3">
|
||||
<argument index="1" name="position" type="Vector3" default="Vector3( 0, 0, 0 )">
|
||||
</argument>
|
||||
<description>
|
||||
Applies a positioned impulse to the body. An impulse is time-independent! Applying an impulse every frame would result in a framerate-dependent force. For this reason it should only be used when simulating one-time impacts. The position uses the rotation of the global coordinate system, but is centered at the object's origin.
|
||||
@ -63,7 +63,7 @@
|
||||
<method name="apply_torque_impulse">
|
||||
<return type="void">
|
||||
</return>
|
||||
<argument index="0" name="j" type="Vector3">
|
||||
<argument index="0" name="impulse" type="Vector3">
|
||||
</argument>
|
||||
<description>
|
||||
Apply a torque impulse (which will be affected by the body mass and shape). This will rotate the body around the vector [code]j[/code] passed as parameter.
|
||||
|
@ -331,9 +331,9 @@
|
||||
</return>
|
||||
<argument index="0" name="body" type="RID">
|
||||
</argument>
|
||||
<argument index="1" name="offset" type="Vector2">
|
||||
<argument index="1" name="force" type="Vector2">
|
||||
</argument>
|
||||
<argument index="2" name="force" type="Vector2">
|
||||
<argument index="2" name="position" type="Vector2" default="Vector2( 0, 0 )">
|
||||
</argument>
|
||||
<description>
|
||||
Adds a positioned force to the applied force and torque. As with [method body_apply_impulse], both the force and the offset from the body origin are in global coordinates. A force differs from an impulse in that, while the two are forces, the impulse clears itself after being applied.
|
||||
@ -379,9 +379,9 @@
|
||||
</return>
|
||||
<argument index="0" name="body" type="RID">
|
||||
</argument>
|
||||
<argument index="1" name="position" type="Vector2">
|
||||
<argument index="1" name="impulse" type="Vector2">
|
||||
</argument>
|
||||
<argument index="2" name="impulse" type="Vector2">
|
||||
<argument index="2" name="position" type="Vector2" default="Vector2( 0, 0 )">
|
||||
</argument>
|
||||
<description>
|
||||
Adds a positioned impulse to the applied force and torque. Both the force and the offset from the body origin are in global coordinates.
|
||||
|
@ -334,7 +334,7 @@
|
||||
</argument>
|
||||
<argument index="1" name="force" type="Vector3">
|
||||
</argument>
|
||||
<argument index="2" name="position" type="Vector3">
|
||||
<argument index="2" name="position" type="Vector3" default="Vector3( 0, 0, 0 )">
|
||||
</argument>
|
||||
<description>
|
||||
</description>
|
||||
@ -379,9 +379,9 @@
|
||||
</return>
|
||||
<argument index="0" name="body" type="RID">
|
||||
</argument>
|
||||
<argument index="1" name="position" type="Vector3">
|
||||
<argument index="1" name="impulse" type="Vector3">
|
||||
</argument>
|
||||
<argument index="2" name="impulse" type="Vector3">
|
||||
<argument index="2" name="position" type="Vector3" default="Vector3( 0, 0, 0 )">
|
||||
</argument>
|
||||
<description>
|
||||
Gives the body a push at a [code]position[/code] in the direction of the [code]impulse[/code].
|
||||
|
@ -34,9 +34,9 @@
|
||||
<method name="add_force">
|
||||
<return type="void">
|
||||
</return>
|
||||
<argument index="0" name="offset" type="Vector2">
|
||||
<argument index="0" name="force" type="Vector2">
|
||||
</argument>
|
||||
<argument index="1" name="force" type="Vector2">
|
||||
<argument index="1" name="position" type="Vector2" default="Vector2( 0, 0 )">
|
||||
</argument>
|
||||
<description>
|
||||
Adds a positioned force to the body. Both the force and the offset from the body origin are in global coordinates.
|
||||
@ -54,7 +54,7 @@
|
||||
<method name="apply_central_impulse">
|
||||
<return type="void">
|
||||
</return>
|
||||
<argument index="0" name="impulse" type="Vector2">
|
||||
<argument index="0" name="impulse" type="Vector2" default="Vector2( 0, 0 )">
|
||||
</argument>
|
||||
<description>
|
||||
Applies a directional impulse without affecting rotation.
|
||||
@ -63,9 +63,9 @@
|
||||
<method name="apply_impulse">
|
||||
<return type="void">
|
||||
</return>
|
||||
<argument index="0" name="offset" type="Vector2">
|
||||
<argument index="0" name="impulse" type="Vector2">
|
||||
</argument>
|
||||
<argument index="1" name="impulse" type="Vector2">
|
||||
<argument index="1" name="position" type="Vector2" default="Vector2( 0, 0 )">
|
||||
</argument>
|
||||
<description>
|
||||
Applies a positioned impulse to the body. An impulse is time-independent! Applying an impulse every frame would result in a framerate-dependent force. For this reason it should only be used when simulating one-time impacts (use the "_force" functions otherwise). The position uses the rotation of the global coordinate system, but is centered at the object's origin.
|
||||
|
@ -37,7 +37,7 @@
|
||||
</return>
|
||||
<argument index="0" name="force" type="Vector3">
|
||||
</argument>
|
||||
<argument index="1" name="position" type="Vector3">
|
||||
<argument index="1" name="position" type="Vector3" default="Vector3( 0, 0, 0 )">
|
||||
</argument>
|
||||
<description>
|
||||
Adds a constant directional force (i.e. acceleration).
|
||||
@ -66,9 +66,9 @@
|
||||
<method name="apply_impulse">
|
||||
<return type="void">
|
||||
</return>
|
||||
<argument index="0" name="position" type="Vector3">
|
||||
<argument index="0" name="impulse" type="Vector3">
|
||||
</argument>
|
||||
<argument index="1" name="impulse" type="Vector3">
|
||||
<argument index="1" name="position" type="Vector3" default="Vector3( 0, 0, 0 )">
|
||||
</argument>
|
||||
<description>
|
||||
Applies a positioned impulse to the body. An impulse is time independent! Applying an impulse every frame would result in a framerate-dependent force. For this reason it should only be used when simulating one-time impacts. The position uses the rotation of the global coordinate system, but is centered at the object's origin.
|
||||
|
@ -707,11 +707,11 @@ void BulletPhysicsServer3D::body_add_central_force(RID p_body, const Vector3 &p_
|
||||
body->apply_central_force(p_force);
|
||||
}
|
||||
|
||||
void BulletPhysicsServer3D::body_add_force(RID p_body, const Vector3 &p_force, const Vector3 &p_pos) {
|
||||
void BulletPhysicsServer3D::body_add_force(RID p_body, const Vector3 &p_force, const Vector3 &p_position) {
|
||||
RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
|
||||
ERR_FAIL_COND(!body);
|
||||
|
||||
body->apply_force(p_force, p_pos);
|
||||
body->apply_force(p_force, p_position);
|
||||
}
|
||||
|
||||
void BulletPhysicsServer3D::body_add_torque(RID p_body, const Vector3 &p_torque) {
|
||||
@ -728,11 +728,11 @@ void BulletPhysicsServer3D::body_apply_central_impulse(RID p_body, const Vector3
|
||||
body->apply_central_impulse(p_impulse);
|
||||
}
|
||||
|
||||
void BulletPhysicsServer3D::body_apply_impulse(RID p_body, const Vector3 &p_pos, const Vector3 &p_impulse) {
|
||||
void BulletPhysicsServer3D::body_apply_impulse(RID p_body, const Vector3 &p_impulse, const Vector3 &p_position) {
|
||||
RigidBodyBullet *body = rigid_body_owner.getornull(p_body);
|
||||
ERR_FAIL_COND(!body);
|
||||
|
||||
body->apply_impulse(p_pos, p_impulse);
|
||||
body->apply_impulse(p_impulse, p_position);
|
||||
}
|
||||
|
||||
void BulletPhysicsServer3D::body_apply_torque_impulse(RID p_body, const Vector3 &p_impulse) {
|
||||
|
@ -223,11 +223,11 @@ public:
|
||||
virtual Vector3 body_get_applied_torque(RID p_body) const;
|
||||
|
||||
virtual void body_add_central_force(RID p_body, const Vector3 &p_force);
|
||||
virtual void body_add_force(RID p_body, const Vector3 &p_force, const Vector3 &p_pos);
|
||||
virtual void body_add_force(RID p_body, const Vector3 &p_force, const Vector3 &p_position = Vector3());
|
||||
virtual void body_add_torque(RID p_body, const Vector3 &p_torque);
|
||||
|
||||
virtual void body_apply_central_impulse(RID p_body, const Vector3 &p_impulse);
|
||||
virtual void body_apply_impulse(RID p_body, const Vector3 &p_pos, const Vector3 &p_impulse);
|
||||
virtual void body_apply_impulse(RID p_body, const Vector3 &p_impulse, const Vector3 &p_position = Vector3());
|
||||
virtual void body_apply_torque_impulse(RID p_body, const Vector3 &p_impulse);
|
||||
virtual void body_set_axis_velocity(RID p_body, const Vector3 &p_axis_velocity);
|
||||
|
||||
|
@ -118,8 +118,8 @@ void BulletPhysicsDirectBodyState3D::add_central_force(const Vector3 &p_force) {
|
||||
body->apply_central_force(p_force);
|
||||
}
|
||||
|
||||
void BulletPhysicsDirectBodyState3D::add_force(const Vector3 &p_force, const Vector3 &p_pos) {
|
||||
body->apply_force(p_force, p_pos);
|
||||
void BulletPhysicsDirectBodyState3D::add_force(const Vector3 &p_force, const Vector3 &p_position) {
|
||||
body->apply_force(p_force, p_position);
|
||||
}
|
||||
|
||||
void BulletPhysicsDirectBodyState3D::add_torque(const Vector3 &p_torque) {
|
||||
@ -130,8 +130,8 @@ void BulletPhysicsDirectBodyState3D::apply_central_impulse(const Vector3 &p_impu
|
||||
body->apply_central_impulse(p_impulse);
|
||||
}
|
||||
|
||||
void BulletPhysicsDirectBodyState3D::apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse) {
|
||||
body->apply_impulse(p_pos, p_impulse);
|
||||
void BulletPhysicsDirectBodyState3D::apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position) {
|
||||
body->apply_impulse(p_impulse, p_position);
|
||||
}
|
||||
|
||||
void BulletPhysicsDirectBodyState3D::apply_torque_impulse(const Vector3 &p_impulse) {
|
||||
@ -604,23 +604,23 @@ Variant RigidBodyBullet::get_state(PhysicsServer3D::BodyState p_state) const {
|
||||
}
|
||||
|
||||
void RigidBodyBullet::apply_central_impulse(const Vector3 &p_impulse) {
|
||||
btVector3 btImpu;
|
||||
G_TO_B(p_impulse, btImpu);
|
||||
btVector3 btImpulse;
|
||||
G_TO_B(p_impulse, btImpulse);
|
||||
if (Vector3() != p_impulse) {
|
||||
btBody->activate();
|
||||
}
|
||||
btBody->applyCentralImpulse(btImpu);
|
||||
btBody->applyCentralImpulse(btImpulse);
|
||||
}
|
||||
|
||||
void RigidBodyBullet::apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse) {
|
||||
btVector3 btImpu;
|
||||
btVector3 btPos;
|
||||
G_TO_B(p_impulse, btImpu);
|
||||
G_TO_B(p_pos, btPos);
|
||||
void RigidBodyBullet::apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position) {
|
||||
btVector3 btImpulse;
|
||||
btVector3 btPosition;
|
||||
G_TO_B(p_impulse, btImpulse);
|
||||
G_TO_B(p_position, btPosition);
|
||||
if (Vector3() != p_impulse) {
|
||||
btBody->activate();
|
||||
}
|
||||
btBody->applyImpulse(btImpu, btPos);
|
||||
btBody->applyImpulse(btImpulse, btPosition);
|
||||
}
|
||||
|
||||
void RigidBodyBullet::apply_torque_impulse(const Vector3 &p_impulse) {
|
||||
@ -632,15 +632,15 @@ void RigidBodyBullet::apply_torque_impulse(const Vector3 &p_impulse) {
|
||||
btBody->applyTorqueImpulse(btImp);
|
||||
}
|
||||
|
||||
void RigidBodyBullet::apply_force(const Vector3 &p_force, const Vector3 &p_pos) {
|
||||
void RigidBodyBullet::apply_force(const Vector3 &p_force, const Vector3 &p_position) {
|
||||
btVector3 btForce;
|
||||
btVector3 btPos;
|
||||
btVector3 btPosition;
|
||||
G_TO_B(p_force, btForce);
|
||||
G_TO_B(p_pos, btPos);
|
||||
G_TO_B(p_position, btPosition);
|
||||
if (Vector3() != p_force) {
|
||||
btBody->activate();
|
||||
}
|
||||
btBody->applyForce(btForce, btPos);
|
||||
btBody->applyForce(btForce, btPosition);
|
||||
}
|
||||
|
||||
void RigidBodyBullet::apply_central_force(const Vector3 &p_force) {
|
||||
|
@ -111,10 +111,10 @@ public:
|
||||
virtual Transform get_transform() const;
|
||||
|
||||
virtual void add_central_force(const Vector3 &p_force);
|
||||
virtual void add_force(const Vector3 &p_force, const Vector3 &p_pos);
|
||||
virtual void add_force(const Vector3 &p_force, const Vector3 &p_position = Vector3());
|
||||
virtual void add_torque(const Vector3 &p_torque);
|
||||
virtual void apply_central_impulse(const Vector3 &p_impulse);
|
||||
virtual void apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse);
|
||||
virtual void apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position = Vector3());
|
||||
virtual void apply_torque_impulse(const Vector3 &p_impulse);
|
||||
|
||||
virtual void set_sleep_state(bool p_sleep);
|
||||
@ -284,12 +284,12 @@ public:
|
||||
void set_state(PhysicsServer3D::BodyState p_state, const Variant &p_variant);
|
||||
Variant get_state(PhysicsServer3D::BodyState p_state) const;
|
||||
|
||||
void apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse);
|
||||
void apply_central_impulse(const Vector3 &p_impulse);
|
||||
void apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position = Vector3());
|
||||
void apply_torque_impulse(const Vector3 &p_impulse);
|
||||
|
||||
void apply_force(const Vector3 &p_force, const Vector3 &p_pos);
|
||||
void apply_central_force(const Vector3 &p_force);
|
||||
void apply_force(const Vector3 &p_force, const Vector3 &p_position = Vector3());
|
||||
void apply_torque(const Vector3 &p_torque);
|
||||
|
||||
void set_applied_force(const Vector3 &p_force);
|
||||
|
@ -631,8 +631,8 @@ void RigidBody2D::apply_central_impulse(const Vector2 &p_impulse) {
|
||||
PhysicsServer2D::get_singleton()->body_apply_central_impulse(get_rid(), p_impulse);
|
||||
}
|
||||
|
||||
void RigidBody2D::apply_impulse(const Vector2 &p_offset, const Vector2 &p_impulse) {
|
||||
PhysicsServer2D::get_singleton()->body_apply_impulse(get_rid(), p_offset, p_impulse);
|
||||
void RigidBody2D::apply_impulse(const Vector2 &p_impulse, const Vector2 &p_position) {
|
||||
PhysicsServer2D::get_singleton()->body_apply_impulse(get_rid(), p_impulse, p_position);
|
||||
}
|
||||
|
||||
void RigidBody2D::apply_torque_impulse(float p_torque) {
|
||||
@ -659,8 +659,8 @@ void RigidBody2D::add_central_force(const Vector2 &p_force) {
|
||||
PhysicsServer2D::get_singleton()->body_add_central_force(get_rid(), p_force);
|
||||
}
|
||||
|
||||
void RigidBody2D::add_force(const Vector2 &p_offset, const Vector2 &p_force) {
|
||||
PhysicsServer2D::get_singleton()->body_add_force(get_rid(), p_offset, p_force);
|
||||
void RigidBody2D::add_force(const Vector2 &p_force, const Vector2 &p_position) {
|
||||
PhysicsServer2D::get_singleton()->body_add_force(get_rid(), p_force, p_position);
|
||||
}
|
||||
|
||||
void RigidBody2D::add_torque(const float p_torque) {
|
||||
@ -801,8 +801,8 @@ void RigidBody2D::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_continuous_collision_detection_mode"), &RigidBody2D::get_continuous_collision_detection_mode);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_axis_velocity", "axis_velocity"), &RigidBody2D::set_axis_velocity);
|
||||
ClassDB::bind_method(D_METHOD("apply_central_impulse", "impulse"), &RigidBody2D::apply_central_impulse);
|
||||
ClassDB::bind_method(D_METHOD("apply_impulse", "offset", "impulse"), &RigidBody2D::apply_impulse);
|
||||
ClassDB::bind_method(D_METHOD("apply_central_impulse", "impulse"), &RigidBody2D::apply_central_impulse, Vector2());
|
||||
ClassDB::bind_method(D_METHOD("apply_impulse", "impulse", "position"), &RigidBody2D::apply_impulse, Vector2());
|
||||
ClassDB::bind_method(D_METHOD("apply_torque_impulse", "torque"), &RigidBody2D::apply_torque_impulse);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_applied_force", "force"), &RigidBody2D::set_applied_force);
|
||||
@ -812,7 +812,7 @@ void RigidBody2D::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_applied_torque"), &RigidBody2D::get_applied_torque);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("add_central_force", "force"), &RigidBody2D::add_central_force);
|
||||
ClassDB::bind_method(D_METHOD("add_force", "offset", "force"), &RigidBody2D::add_force);
|
||||
ClassDB::bind_method(D_METHOD("add_force", "force", "position"), &RigidBody2D::add_force, Vector2());
|
||||
ClassDB::bind_method(D_METHOD("add_torque", "torque"), &RigidBody2D::add_torque);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_sleeping", "sleeping"), &RigidBody2D::set_sleeping);
|
||||
|
@ -237,7 +237,7 @@ public:
|
||||
CCDMode get_continuous_collision_detection_mode() const;
|
||||
|
||||
void apply_central_impulse(const Vector2 &p_impulse);
|
||||
void apply_impulse(const Vector2 &p_offset, const Vector2 &p_impulse);
|
||||
void apply_impulse(const Vector2 &p_impulse, const Vector2 &p_position = Vector2());
|
||||
void apply_torque_impulse(float p_torque);
|
||||
|
||||
void set_applied_force(const Vector2 &p_force);
|
||||
@ -247,7 +247,7 @@ public:
|
||||
float get_applied_torque() const;
|
||||
|
||||
void add_central_force(const Vector2 &p_force);
|
||||
void add_force(const Vector2 &p_offset, const Vector2 &p_force);
|
||||
void add_force(const Vector2 &p_force, const Vector2 &p_position = Vector2());
|
||||
void add_torque(float p_torque);
|
||||
|
||||
TypedArray<Node2D> get_colliding_bodies() const; //function for script
|
||||
|
@ -638,8 +638,9 @@ void RigidBody3D::add_central_force(const Vector3 &p_force) {
|
||||
PhysicsServer3D::get_singleton()->body_add_central_force(get_rid(), p_force);
|
||||
}
|
||||
|
||||
void RigidBody3D::add_force(const Vector3 &p_force, const Vector3 &p_pos) {
|
||||
PhysicsServer3D::get_singleton()->body_add_force(get_rid(), p_force, p_pos);
|
||||
void RigidBody3D::add_force(const Vector3 &p_force, const Vector3 &p_position) {
|
||||
PhysicsServer3D *singleton = PhysicsServer3D::get_singleton();
|
||||
singleton->body_add_force(get_rid(), p_force, p_position);
|
||||
}
|
||||
|
||||
void RigidBody3D::add_torque(const Vector3 &p_torque) {
|
||||
@ -650,8 +651,9 @@ void RigidBody3D::apply_central_impulse(const Vector3 &p_impulse) {
|
||||
PhysicsServer3D::get_singleton()->body_apply_central_impulse(get_rid(), p_impulse);
|
||||
}
|
||||
|
||||
void RigidBody3D::apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse) {
|
||||
PhysicsServer3D::get_singleton()->body_apply_impulse(get_rid(), p_pos, p_impulse);
|
||||
void RigidBody3D::apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position) {
|
||||
PhysicsServer3D *singleton = PhysicsServer3D::get_singleton();
|
||||
singleton->body_apply_impulse(get_rid(), p_impulse, p_position);
|
||||
}
|
||||
|
||||
void RigidBody3D::apply_torque_impulse(const Vector3 &p_impulse) {
|
||||
@ -782,11 +784,11 @@ void RigidBody3D::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_axis_velocity", "axis_velocity"), &RigidBody3D::set_axis_velocity);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("add_central_force", "force"), &RigidBody3D::add_central_force);
|
||||
ClassDB::bind_method(D_METHOD("add_force", "force", "position"), &RigidBody3D::add_force);
|
||||
ClassDB::bind_method(D_METHOD("add_force", "force", "position"), &RigidBody3D::add_force, Vector3());
|
||||
ClassDB::bind_method(D_METHOD("add_torque", "torque"), &RigidBody3D::add_torque);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("apply_central_impulse", "impulse"), &RigidBody3D::apply_central_impulse);
|
||||
ClassDB::bind_method(D_METHOD("apply_impulse", "position", "impulse"), &RigidBody3D::apply_impulse);
|
||||
ClassDB::bind_method(D_METHOD("apply_impulse", "impulse", "position"), &RigidBody3D::apply_impulse, Vector3());
|
||||
ClassDB::bind_method(D_METHOD("apply_torque_impulse", "impulse"), &RigidBody3D::apply_torque_impulse);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_sleeping", "sleeping"), &RigidBody3D::set_sleeping);
|
||||
@ -1370,8 +1372,8 @@ void PhysicalBone3D::apply_central_impulse(const Vector3 &p_impulse) {
|
||||
PhysicsServer3D::get_singleton()->body_apply_central_impulse(get_rid(), p_impulse);
|
||||
}
|
||||
|
||||
void PhysicalBone3D::apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse) {
|
||||
PhysicsServer3D::get_singleton()->body_apply_impulse(get_rid(), p_pos, p_impulse);
|
||||
void PhysicalBone3D::apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position) {
|
||||
PhysicsServer3D::get_singleton()->body_apply_impulse(get_rid(), p_impulse, p_position);
|
||||
}
|
||||
|
||||
void PhysicalBone3D::reset_physics_simulation_state() {
|
||||
@ -2097,7 +2099,7 @@ void PhysicalBone3D::_direct_state_changed(Object *p_state) {
|
||||
|
||||
void PhysicalBone3D::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("apply_central_impulse", "impulse"), &PhysicalBone3D::apply_central_impulse);
|
||||
ClassDB::bind_method(D_METHOD("apply_impulse", "position", "impulse"), &PhysicalBone3D::apply_impulse);
|
||||
ClassDB::bind_method(D_METHOD("apply_impulse", "impulse", "position"), &PhysicalBone3D::apply_impulse, Vector3());
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_direct_state_changed"), &PhysicalBone3D::_direct_state_changed);
|
||||
|
||||
|
@ -234,11 +234,11 @@ public:
|
||||
Array get_colliding_bodies() const;
|
||||
|
||||
void add_central_force(const Vector3 &p_force);
|
||||
void add_force(const Vector3 &p_force, const Vector3 &p_pos);
|
||||
void add_force(const Vector3 &p_force, const Vector3 &p_position = Vector3());
|
||||
void add_torque(const Vector3 &p_torque);
|
||||
|
||||
void apply_central_impulse(const Vector3 &p_impulse);
|
||||
void apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse);
|
||||
void apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position = Vector3());
|
||||
void apply_torque_impulse(const Vector3 &p_impulse);
|
||||
|
||||
virtual String get_configuration_warning() const;
|
||||
@ -597,7 +597,7 @@ public:
|
||||
bool get_axis_lock(PhysicsServer3D::BodyAxis p_axis) const;
|
||||
|
||||
void apply_central_impulse(const Vector3 &p_impulse);
|
||||
void apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse);
|
||||
void apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position = Vector3());
|
||||
|
||||
void reset_physics_simulation_state();
|
||||
void reset_to_rest_position();
|
||||
|
@ -794,7 +794,7 @@ void VehicleBody3D::_update_friction(PhysicsDirectBodyState3D *s) {
|
||||
s->get_transform().origin;
|
||||
|
||||
if (m_forwardImpulse[wheel] != real_t(0.)) {
|
||||
s->apply_impulse(rel_pos, m_forwardWS[wheel] * (m_forwardImpulse[wheel]));
|
||||
s->apply_impulse(m_forwardWS[wheel] * (m_forwardImpulse[wheel]), rel_pos);
|
||||
}
|
||||
if (m_sideImpulse[wheel] != real_t(0.)) {
|
||||
PhysicsBody3D *groundObject = wheelInfo.m_raycastInfo.m_groundObject;
|
||||
@ -812,7 +812,7 @@ void VehicleBody3D::_update_friction(PhysicsDirectBodyState3D *s) {
|
||||
#else
|
||||
rel_pos[1] *= wheelInfo.m_rollInfluence; //?
|
||||
#endif
|
||||
s->apply_impulse(rel_pos, sideImp);
|
||||
s->apply_impulse(sideImp, rel_pos);
|
||||
|
||||
//apply friction impulse on the ground
|
||||
//todo
|
||||
@ -850,10 +850,9 @@ void VehicleBody3D::_direct_state_changed(Object *p_state) {
|
||||
suspensionForce = wheel.m_maxSuspensionForce;
|
||||
}
|
||||
Vector3 impulse = wheel.m_raycastInfo.m_contactNormalWS * suspensionForce * step;
|
||||
Vector3 relpos = wheel.m_raycastInfo.m_contactPointWS - state->get_transform().origin;
|
||||
Vector3 relative_position = wheel.m_raycastInfo.m_contactPointWS - state->get_transform().origin;
|
||||
|
||||
state->apply_impulse(relpos, impulse);
|
||||
//getRigidBody()->applyImpulse(impulse, relpos);
|
||||
state->apply_impulse(impulse, relative_position);
|
||||
}
|
||||
|
||||
_update_friction(state);
|
||||
|
@ -107,4 +107,4 @@ Sky::Sky() {
|
||||
|
||||
Sky::~Sky() {
|
||||
RS::get_singleton()->free(sky);
|
||||
}
|
||||
}
|
||||
|
@ -203,18 +203,18 @@ public:
|
||||
linear_velocity += p_impulse * _inv_mass;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void apply_impulse(const Vector2 &p_offset, const Vector2 &p_impulse) {
|
||||
_FORCE_INLINE_ void apply_impulse(const Vector2 &p_impulse, const Vector2 &p_position = Vector2()) {
|
||||
linear_velocity += p_impulse * _inv_mass;
|
||||
angular_velocity += _inv_inertia * p_offset.cross(p_impulse);
|
||||
angular_velocity += _inv_inertia * p_position.cross(p_impulse);
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void apply_torque_impulse(real_t p_torque) {
|
||||
angular_velocity += _inv_inertia * p_torque;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void apply_bias_impulse(const Vector2 &p_pos, const Vector2 &p_j) {
|
||||
biased_linear_velocity += p_j * _inv_mass;
|
||||
biased_angular_velocity += _inv_inertia * p_pos.cross(p_j);
|
||||
_FORCE_INLINE_ void apply_bias_impulse(const Vector2 &p_impulse, const Vector2 &p_position = Vector2()) {
|
||||
biased_linear_velocity += p_impulse * _inv_mass;
|
||||
biased_angular_velocity += _inv_inertia * p_position.cross(p_impulse);
|
||||
}
|
||||
|
||||
void set_active(bool p_active);
|
||||
@ -246,9 +246,9 @@ public:
|
||||
applied_force += p_force;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void add_force(const Vector2 &p_offset, const Vector2 &p_force) {
|
||||
_FORCE_INLINE_ void add_force(const Vector2 &p_force, const Vector2 &p_position = Vector2()) {
|
||||
applied_force += p_force;
|
||||
applied_torque += p_offset.cross(p_force);
|
||||
applied_torque += p_position.cross(p_force);
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void add_torque(real_t p_torque) {
|
||||
@ -360,10 +360,10 @@ public:
|
||||
virtual Transform2D get_transform() const { return body->get_transform(); }
|
||||
|
||||
virtual void add_central_force(const Vector2 &p_force) { body->add_central_force(p_force); }
|
||||
virtual void add_force(const Vector2 &p_offset, const Vector2 &p_force) { body->add_force(p_offset, p_force); }
|
||||
virtual void add_force(const Vector2 &p_force, const Vector2 &p_position = Vector2()) { body->add_force(p_force, p_position); }
|
||||
virtual void add_torque(real_t p_torque) { body->add_torque(p_torque); }
|
||||
virtual void apply_central_impulse(const Vector2 &p_impulse) { body->apply_central_impulse(p_impulse); }
|
||||
virtual void apply_impulse(const Vector2 &p_offset, const Vector2 &p_force) { body->apply_impulse(p_offset, p_force); }
|
||||
virtual void apply_impulse(const Vector2 &p_impulse, const Vector2 &p_position = Vector2()) { body->apply_impulse(p_impulse, p_position); }
|
||||
virtual void apply_torque_impulse(real_t p_torque) { body->apply_torque_impulse(p_torque); }
|
||||
|
||||
virtual void set_sleep_state(bool p_enable) { body->set_active(!p_enable); }
|
||||
|
@ -427,10 +427,9 @@ bool BodyPair2DSW::setup(real_t p_step) {
|
||||
// Apply normal + friction impulse
|
||||
Vector2 P = c.acc_normal_impulse * c.normal + c.acc_tangent_impulse * tangent;
|
||||
|
||||
A->apply_impulse(c.rA, -P);
|
||||
B->apply_impulse(c.rB, P);
|
||||
A->apply_impulse(-P, c.rA);
|
||||
B->apply_impulse(P, c.rB);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
c.bounce = combine_bounce(A, B);
|
||||
@ -497,8 +496,8 @@ void BodyPair2DSW::solve(real_t p_step) {
|
||||
|
||||
Vector2 j = c.normal * (c.acc_normal_impulse - jnOld) + tangent * (c.acc_tangent_impulse - jtOld);
|
||||
|
||||
A->apply_impulse(c.rA, -j);
|
||||
B->apply_impulse(c.rB, j);
|
||||
A->apply_impulse(-j, c.rA);
|
||||
B->apply_impulse(j, c.rB);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,9 +136,9 @@ bool PinJoint2DSW::setup(real_t p_step) {
|
||||
bias = delta * -(get_bias() == 0 ? space->get_constraint_bias() : get_bias()) * (1.0 / p_step);
|
||||
|
||||
// apply accumulated impulse
|
||||
A->apply_impulse(rA, -P);
|
||||
A->apply_impulse(-P, rA);
|
||||
if (B) {
|
||||
B->apply_impulse(rB, P);
|
||||
B->apply_impulse(P, rB);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -161,9 +161,9 @@ void PinJoint2DSW::solve(real_t p_step) {
|
||||
|
||||
Vector2 impulse = M.basis_xform(bias - rel_vel - Vector2(softness, softness) * P);
|
||||
|
||||
A->apply_impulse(rA, -impulse);
|
||||
A->apply_impulse(-impulse, rA);
|
||||
if (B) {
|
||||
B->apply_impulse(rB, impulse);
|
||||
B->apply_impulse(impulse, rB);
|
||||
}
|
||||
|
||||
P += impulse;
|
||||
@ -301,8 +301,8 @@ bool GrooveJoint2DSW::setup(real_t p_step) {
|
||||
gbias = (delta * -(_b == 0 ? space->get_constraint_bias() : _b) * (1.0 / p_step)).clamped(get_max_bias());
|
||||
|
||||
// apply accumulated impulse
|
||||
A->apply_impulse(rA, -jn_acc);
|
||||
B->apply_impulse(rB, jn_acc);
|
||||
A->apply_impulse(-jn_acc, rA);
|
||||
B->apply_impulse(jn_acc, rB);
|
||||
|
||||
correct = true;
|
||||
return true;
|
||||
@ -320,8 +320,8 @@ void GrooveJoint2DSW::solve(real_t p_step) {
|
||||
|
||||
j = jn_acc - jOld;
|
||||
|
||||
A->apply_impulse(rA, -j);
|
||||
B->apply_impulse(rB, j);
|
||||
A->apply_impulse(-j, rA);
|
||||
B->apply_impulse(j, rB);
|
||||
}
|
||||
|
||||
GrooveJoint2DSW::GrooveJoint2DSW(const Vector2 &p_a_groove1, const Vector2 &p_a_groove2, const Vector2 &p_b_anchor, Body2DSW *p_body_a, Body2DSW *p_body_b) :
|
||||
@ -370,8 +370,8 @@ bool DampedSpringJoint2DSW::setup(real_t p_step) {
|
||||
real_t f_spring = (rest_length - dist) * stiffness;
|
||||
Vector2 j = n * f_spring * (p_step);
|
||||
|
||||
A->apply_impulse(rA, -j);
|
||||
B->apply_impulse(rB, j);
|
||||
A->apply_impulse(-j, rA);
|
||||
B->apply_impulse(j, rB);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -386,8 +386,8 @@ void DampedSpringJoint2DSW::solve(real_t p_step) {
|
||||
target_vrn = vrn + v_damp;
|
||||
Vector2 j = n * v_damp * n_mass;
|
||||
|
||||
A->apply_impulse(rA, -j);
|
||||
B->apply_impulse(rB, j);
|
||||
A->apply_impulse(-j, rA);
|
||||
B->apply_impulse(j, rB);
|
||||
}
|
||||
|
||||
void DampedSpringJoint2DSW::set_param(PhysicsServer2D::DampedStringParam p_param, real_t p_value) {
|
||||
|
@ -823,13 +823,13 @@ void PhysicsServer2DSW::body_apply_torque_impulse(RID p_body, real_t p_torque) {
|
||||
body->apply_torque_impulse(p_torque);
|
||||
}
|
||||
|
||||
void PhysicsServer2DSW::body_apply_impulse(RID p_body, const Vector2 &p_pos, const Vector2 &p_impulse) {
|
||||
void PhysicsServer2DSW::body_apply_impulse(RID p_body, const Vector2 &p_impulse, const Vector2 &p_position) {
|
||||
Body2DSW *body = body_owner.getornull(p_body);
|
||||
ERR_FAIL_COND(!body);
|
||||
|
||||
_update_shapes();
|
||||
|
||||
body->apply_impulse(p_pos, p_impulse);
|
||||
body->apply_impulse(p_impulse, p_position);
|
||||
body->wakeup();
|
||||
};
|
||||
|
||||
@ -841,11 +841,11 @@ void PhysicsServer2DSW::body_add_central_force(RID p_body, const Vector2 &p_forc
|
||||
body->wakeup();
|
||||
};
|
||||
|
||||
void PhysicsServer2DSW::body_add_force(RID p_body, const Vector2 &p_offset, const Vector2 &p_force) {
|
||||
void PhysicsServer2DSW::body_add_force(RID p_body, const Vector2 &p_force, const Vector2 &p_position) {
|
||||
Body2DSW *body = body_owner.getornull(p_body);
|
||||
ERR_FAIL_COND(!body);
|
||||
|
||||
body->add_force(p_offset, p_force);
|
||||
body->add_force(p_force, p_position);
|
||||
body->wakeup();
|
||||
};
|
||||
|
||||
|
@ -221,12 +221,12 @@ public:
|
||||
virtual real_t body_get_applied_torque(RID p_body) const;
|
||||
|
||||
virtual void body_add_central_force(RID p_body, const Vector2 &p_force);
|
||||
virtual void body_add_force(RID p_body, const Vector2 &p_offset, const Vector2 &p_force);
|
||||
virtual void body_add_force(RID p_body, const Vector2 &p_force, const Vector2 &p_position = Vector2());
|
||||
virtual void body_add_torque(RID p_body, real_t p_torque);
|
||||
|
||||
virtual void body_apply_central_impulse(RID p_body, const Vector2 &p_impulse);
|
||||
virtual void body_apply_torque_impulse(RID p_body, real_t p_torque);
|
||||
virtual void body_apply_impulse(RID p_body, const Vector2 &p_pos, const Vector2 &p_impulse);
|
||||
virtual void body_apply_impulse(RID p_body, const Vector2 &p_impulse, const Vector2 &p_position = Vector2());
|
||||
virtual void body_set_axis_velocity(RID p_body, const Vector2 &p_axis_velocity);
|
||||
|
||||
virtual void body_add_collision_exception(RID p_body, RID p_body_b);
|
||||
|
@ -216,23 +216,23 @@ public:
|
||||
_FORCE_INLINE_ const Vector3 &get_biased_linear_velocity() const { return biased_linear_velocity; }
|
||||
_FORCE_INLINE_ const Vector3 &get_biased_angular_velocity() const { return biased_angular_velocity; }
|
||||
|
||||
_FORCE_INLINE_ void apply_central_impulse(const Vector3 &p_j) {
|
||||
linear_velocity += p_j * _inv_mass;
|
||||
_FORCE_INLINE_ void apply_central_impulse(const Vector3 &p_impulse) {
|
||||
linear_velocity += p_impulse * _inv_mass;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void apply_impulse(const Vector3 &p_pos, const Vector3 &p_j) {
|
||||
linear_velocity += p_j * _inv_mass;
|
||||
angular_velocity += _inv_inertia_tensor.xform((p_pos - center_of_mass).cross(p_j));
|
||||
_FORCE_INLINE_ void apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position = Vector3()) {
|
||||
linear_velocity += p_impulse * _inv_mass;
|
||||
angular_velocity += _inv_inertia_tensor.xform((p_position - center_of_mass).cross(p_impulse));
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void apply_torque_impulse(const Vector3 &p_j) {
|
||||
angular_velocity += _inv_inertia_tensor.xform(p_j);
|
||||
_FORCE_INLINE_ void apply_torque_impulse(const Vector3 &p_impulse) {
|
||||
angular_velocity += _inv_inertia_tensor.xform(p_impulse);
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void apply_bias_impulse(const Vector3 &p_pos, const Vector3 &p_j, real_t p_max_delta_av = -1.0) {
|
||||
biased_linear_velocity += p_j * _inv_mass;
|
||||
_FORCE_INLINE_ void apply_bias_impulse(const Vector3 &p_impulse, const Vector3 &p_position = Vector3(), real_t p_max_delta_av = -1.0) {
|
||||
biased_linear_velocity += p_impulse * _inv_mass;
|
||||
if (p_max_delta_av != 0.0) {
|
||||
Vector3 delta_av = _inv_inertia_tensor.xform((p_pos - center_of_mass).cross(p_j));
|
||||
Vector3 delta_av = _inv_inertia_tensor.xform((p_position - center_of_mass).cross(p_impulse));
|
||||
if (p_max_delta_av > 0 && delta_av.length() > p_max_delta_av) {
|
||||
delta_av = delta_av.normalized() * p_max_delta_av;
|
||||
}
|
||||
@ -240,17 +240,17 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void apply_bias_torque_impulse(const Vector3 &p_j) {
|
||||
biased_angular_velocity += _inv_inertia_tensor.xform(p_j);
|
||||
_FORCE_INLINE_ void apply_bias_torque_impulse(const Vector3 &p_impulse) {
|
||||
biased_angular_velocity += _inv_inertia_tensor.xform(p_impulse);
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void add_central_force(const Vector3 &p_force) {
|
||||
applied_force += p_force;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void add_force(const Vector3 &p_force, const Vector3 &p_pos) {
|
||||
_FORCE_INLINE_ void add_force(const Vector3 &p_force, const Vector3 &p_position = Vector3()) {
|
||||
applied_force += p_force;
|
||||
applied_torque += (p_pos - center_of_mass).cross(p_force);
|
||||
applied_torque += (p_position - center_of_mass).cross(p_force);
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void add_torque(const Vector3 &p_torque) {
|
||||
@ -403,11 +403,15 @@ public:
|
||||
virtual Transform get_transform() const { return body->get_transform(); }
|
||||
|
||||
virtual void add_central_force(const Vector3 &p_force) { body->add_central_force(p_force); }
|
||||
virtual void add_force(const Vector3 &p_force, const Vector3 &p_pos) { body->add_force(p_force, p_pos); }
|
||||
virtual void add_force(const Vector3 &p_force, const Vector3 &p_position = Vector3()) {
|
||||
body->add_force(p_force, p_position);
|
||||
}
|
||||
virtual void add_torque(const Vector3 &p_torque) { body->add_torque(p_torque); }
|
||||
virtual void apply_central_impulse(const Vector3 &p_j) { body->apply_central_impulse(p_j); }
|
||||
virtual void apply_impulse(const Vector3 &p_pos, const Vector3 &p_j) { body->apply_impulse(p_pos, p_j); }
|
||||
virtual void apply_torque_impulse(const Vector3 &p_j) { body->apply_torque_impulse(p_j); }
|
||||
virtual void apply_central_impulse(const Vector3 &p_impulse) { body->apply_central_impulse(p_impulse); }
|
||||
virtual void apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position = Vector3()) {
|
||||
body->apply_impulse(p_impulse, p_position);
|
||||
}
|
||||
virtual void apply_torque_impulse(const Vector3 &p_impulse) { body->apply_torque_impulse(p_impulse); }
|
||||
|
||||
virtual void set_sleep_state(bool p_sleep) { body->set_active(!p_sleep); }
|
||||
virtual bool is_sleeping() const { return !body->is_active(); }
|
||||
|
@ -321,8 +321,8 @@ bool BodyPair3DSW::setup(real_t p_step) {
|
||||
c.depth = depth;
|
||||
|
||||
Vector3 j_vec = c.normal * c.acc_normal_impulse + c.acc_tangent_impulse;
|
||||
A->apply_impulse(c.rA + A->get_center_of_mass(), -j_vec);
|
||||
B->apply_impulse(c.rB + B->get_center_of_mass(), j_vec);
|
||||
A->apply_impulse(-j_vec, c.rA + A->get_center_of_mass());
|
||||
B->apply_impulse(j_vec, c.rB + B->get_center_of_mass());
|
||||
c.acc_bias_impulse = 0;
|
||||
c.acc_bias_impulse_center_of_mass = 0;
|
||||
|
||||
@ -404,8 +404,8 @@ void BodyPair3DSW::solve(real_t p_step) {
|
||||
|
||||
Vector3 j = c.normal * (c.acc_normal_impulse - jnOld);
|
||||
|
||||
A->apply_impulse(c.rA + A->get_center_of_mass(), -j);
|
||||
B->apply_impulse(c.rB + B->get_center_of_mass(), j);
|
||||
A->apply_impulse(-j, c.rA + A->get_center_of_mass());
|
||||
B->apply_impulse(j, c.rB + B->get_center_of_mass());
|
||||
|
||||
c.active = true;
|
||||
}
|
||||
@ -447,8 +447,8 @@ void BodyPair3DSW::solve(real_t p_step) {
|
||||
|
||||
jt = c.acc_tangent_impulse - jtOld;
|
||||
|
||||
A->apply_impulse(c.rA + A->get_center_of_mass(), -jt);
|
||||
B->apply_impulse(c.rB + B->get_center_of_mass(), jt);
|
||||
A->apply_impulse(-jt, c.rA + A->get_center_of_mass());
|
||||
B->apply_impulse(jt, c.rB + B->get_center_of_mass());
|
||||
|
||||
c.active = true;
|
||||
}
|
||||
|
@ -261,8 +261,8 @@ void ConeTwistJoint3DSW::solve(real_t p_timestep) {
|
||||
real_t impulse = depth * tau / p_timestep * jacDiagABInv - rel_vel * jacDiagABInv;
|
||||
m_appliedImpulse += impulse;
|
||||
Vector3 impulse_vector = normal * impulse;
|
||||
A->apply_impulse(pivotAInW - A->get_transform().origin, impulse_vector);
|
||||
B->apply_impulse(pivotBInW - B->get_transform().origin, -impulse_vector);
|
||||
A->apply_impulse(impulse_vector, pivotAInW - A->get_transform().origin);
|
||||
B->apply_impulse(-impulse_vector, pivotBInW - B->get_transform().origin);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -205,8 +205,8 @@ real_t G6DOFTranslationalLimitMotor3DSW::solveLinearAxis(
|
||||
normalImpulse = m_accumulatedImpulse[limit_index] - oldNormalImpulse;
|
||||
|
||||
Vector3 impulse_vector = axis_normal_on_a * normalImpulse;
|
||||
body1->apply_impulse(rel_pos1, impulse_vector);
|
||||
body2->apply_impulse(rel_pos2, -impulse_vector);
|
||||
body1->apply_impulse(impulse_vector, rel_pos1);
|
||||
body2->apply_impulse(-impulse_vector, rel_pos2);
|
||||
return normalImpulse;
|
||||
}
|
||||
|
||||
|
@ -275,8 +275,8 @@ void HingeJoint3DSW::solve(real_t p_step) {
|
||||
real_t impulse = depth * tau / p_step * jacDiagABInv - rel_vel * jacDiagABInv;
|
||||
m_appliedImpulse += impulse;
|
||||
Vector3 impulse_vector = normal * impulse;
|
||||
A->apply_impulse(pivotAInW - A->get_transform().origin, impulse_vector);
|
||||
B->apply_impulse(pivotBInW - B->get_transform().origin, -impulse_vector);
|
||||
A->apply_impulse(impulse_vector, pivotAInW - A->get_transform().origin);
|
||||
B->apply_impulse(-impulse_vector, pivotBInW - B->get_transform().origin);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,8 +119,8 @@ void PinJoint3DSW::solve(real_t p_step) {
|
||||
|
||||
m_appliedImpulse += impulse;
|
||||
Vector3 impulse_vector = normal * impulse;
|
||||
A->apply_impulse(pivotAInW - A->get_transform().origin, impulse_vector);
|
||||
B->apply_impulse(pivotBInW - B->get_transform().origin, -impulse_vector);
|
||||
A->apply_impulse(impulse_vector, pivotAInW - A->get_transform().origin);
|
||||
B->apply_impulse(-impulse_vector, pivotBInW - B->get_transform().origin);
|
||||
|
||||
normal[i] = 0;
|
||||
}
|
||||
|
@ -197,8 +197,8 @@ void SliderJoint3DSW::solve(real_t p_step) {
|
||||
// calcutate and apply impulse
|
||||
real_t normalImpulse = softness * (restitution * depth / p_step - damping * rel_vel) * m_jacLinDiagABInv[i];
|
||||
Vector3 impulse_vector = normal * normalImpulse;
|
||||
A->apply_impulse(m_relPosA, impulse_vector);
|
||||
B->apply_impulse(m_relPosB, -impulse_vector);
|
||||
A->apply_impulse(impulse_vector, m_relPosA);
|
||||
B->apply_impulse(-impulse_vector, m_relPosB);
|
||||
if (m_poweredLinMotor && (!i)) { // apply linear motor
|
||||
if (m_accumulatedLinMotorImpulse < m_maxLinMotorForce) {
|
||||
real_t desiredMotorVel = m_targetLinMotorVelocity;
|
||||
@ -218,8 +218,8 @@ void SliderJoint3DSW::solve(real_t p_step) {
|
||||
m_accumulatedLinMotorImpulse = new_acc;
|
||||
// apply clamped impulse
|
||||
impulse_vector = normal * normalImpulse;
|
||||
A->apply_impulse(m_relPosA, impulse_vector);
|
||||
B->apply_impulse(m_relPosB, -impulse_vector);
|
||||
A->apply_impulse(impulse_vector, m_relPosA);
|
||||
B->apply_impulse(-impulse_vector, m_relPosB);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -710,11 +710,11 @@ void PhysicsServer3DSW::body_add_central_force(RID p_body, const Vector3 &p_forc
|
||||
body->wakeup();
|
||||
}
|
||||
|
||||
void PhysicsServer3DSW::body_add_force(RID p_body, const Vector3 &p_force, const Vector3 &p_pos) {
|
||||
void PhysicsServer3DSW::body_add_force(RID p_body, const Vector3 &p_force, const Vector3 &p_position) {
|
||||
Body3DSW *body = body_owner.getornull(p_body);
|
||||
ERR_FAIL_COND(!body);
|
||||
|
||||
body->add_force(p_force, p_pos);
|
||||
body->add_force(p_force, p_position);
|
||||
body->wakeup();
|
||||
};
|
||||
|
||||
@ -736,13 +736,13 @@ void PhysicsServer3DSW::body_apply_central_impulse(RID p_body, const Vector3 &p_
|
||||
body->wakeup();
|
||||
}
|
||||
|
||||
void PhysicsServer3DSW::body_apply_impulse(RID p_body, const Vector3 &p_pos, const Vector3 &p_impulse) {
|
||||
void PhysicsServer3DSW::body_apply_impulse(RID p_body, const Vector3 &p_impulse, const Vector3 &p_position) {
|
||||
Body3DSW *body = body_owner.getornull(p_body);
|
||||
ERR_FAIL_COND(!body);
|
||||
|
||||
_update_shapes();
|
||||
|
||||
body->apply_impulse(p_pos, p_impulse);
|
||||
body->apply_impulse(p_impulse, p_position);
|
||||
body->wakeup();
|
||||
};
|
||||
|
||||
|
@ -206,11 +206,11 @@ public:
|
||||
virtual Vector3 body_get_applied_torque(RID p_body) const;
|
||||
|
||||
virtual void body_add_central_force(RID p_body, const Vector3 &p_force);
|
||||
virtual void body_add_force(RID p_body, const Vector3 &p_force, const Vector3 &p_pos);
|
||||
virtual void body_add_force(RID p_body, const Vector3 &p_force, const Vector3 &p_position = Vector3());
|
||||
virtual void body_add_torque(RID p_body, const Vector3 &p_torque);
|
||||
|
||||
virtual void body_apply_central_impulse(RID p_body, const Vector3 &p_impulse);
|
||||
virtual void body_apply_impulse(RID p_body, const Vector3 &p_pos, const Vector3 &p_impulse);
|
||||
virtual void body_apply_impulse(RID p_body, const Vector3 &p_impulse, const Vector3 &p_position = Vector3());
|
||||
virtual void body_apply_torque_impulse(RID p_body, const Vector3 &p_impulse);
|
||||
virtual void body_set_axis_velocity(RID p_body, const Vector3 &p_axis_velocity);
|
||||
|
||||
|
@ -91,11 +91,11 @@ void PhysicsDirectBodyState2D::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_transform"), &PhysicsDirectBodyState2D::get_transform);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("add_central_force", "force"), &PhysicsDirectBodyState2D::add_central_force);
|
||||
ClassDB::bind_method(D_METHOD("add_force", "offset", "force"), &PhysicsDirectBodyState2D::add_force);
|
||||
ClassDB::bind_method(D_METHOD("add_force", "force", "position"), &PhysicsDirectBodyState2D::add_force, Vector2());
|
||||
ClassDB::bind_method(D_METHOD("add_torque", "torque"), &PhysicsDirectBodyState2D::add_torque);
|
||||
ClassDB::bind_method(D_METHOD("apply_central_impulse", "impulse"), &PhysicsDirectBodyState2D::apply_central_impulse);
|
||||
ClassDB::bind_method(D_METHOD("apply_torque_impulse", "impulse"), &PhysicsDirectBodyState2D::apply_torque_impulse);
|
||||
ClassDB::bind_method(D_METHOD("apply_impulse", "offset", "impulse"), &PhysicsDirectBodyState2D::apply_impulse);
|
||||
ClassDB::bind_method(D_METHOD("apply_impulse", "impulse", "position"), &PhysicsDirectBodyState2D::apply_impulse, Vector2());
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_sleep_state", "enabled"), &PhysicsDirectBodyState2D::set_sleep_state);
|
||||
ClassDB::bind_method(D_METHOD("is_sleeping"), &PhysicsDirectBodyState2D::is_sleeping);
|
||||
@ -624,9 +624,9 @@ void PhysicsServer2D::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("body_apply_central_impulse", "body", "impulse"), &PhysicsServer2D::body_apply_central_impulse);
|
||||
ClassDB::bind_method(D_METHOD("body_apply_torque_impulse", "body", "impulse"), &PhysicsServer2D::body_apply_torque_impulse);
|
||||
ClassDB::bind_method(D_METHOD("body_apply_impulse", "body", "position", "impulse"), &PhysicsServer2D::body_apply_impulse);
|
||||
ClassDB::bind_method(D_METHOD("body_apply_impulse", "body", "impulse", "position"), &PhysicsServer2D::body_apply_impulse, Vector2());
|
||||
ClassDB::bind_method(D_METHOD("body_add_central_force", "body", "force"), &PhysicsServer2D::body_add_central_force);
|
||||
ClassDB::bind_method(D_METHOD("body_add_force", "body", "offset", "force"), &PhysicsServer2D::body_add_force);
|
||||
ClassDB::bind_method(D_METHOD("body_add_force", "body", "force", "position"), &PhysicsServer2D::body_add_force, Vector2());
|
||||
ClassDB::bind_method(D_METHOD("body_add_torque", "body", "torque"), &PhysicsServer2D::body_add_torque);
|
||||
ClassDB::bind_method(D_METHOD("body_set_axis_velocity", "body", "axis_velocity"), &PhysicsServer2D::body_set_axis_velocity);
|
||||
|
||||
|
@ -61,11 +61,11 @@ public:
|
||||
virtual Transform2D get_transform() const = 0;
|
||||
|
||||
virtual void add_central_force(const Vector2 &p_force) = 0;
|
||||
virtual void add_force(const Vector2 &p_offset, const Vector2 &p_force) = 0;
|
||||
virtual void add_force(const Vector2 &p_force, const Vector2 &p_position = Vector2()) = 0;
|
||||
virtual void add_torque(real_t p_torque) = 0;
|
||||
virtual void apply_central_impulse(const Vector2 &p_impulse) = 0;
|
||||
virtual void apply_torque_impulse(real_t p_torque) = 0;
|
||||
virtual void apply_impulse(const Vector2 &p_offset, const Vector2 &p_impulse) = 0;
|
||||
virtual void apply_impulse(const Vector2 &p_impulse, const Vector2 &p_position = Vector2()) = 0;
|
||||
|
||||
virtual void set_sleep_state(bool p_enable) = 0;
|
||||
virtual bool is_sleeping() const = 0;
|
||||
@ -452,12 +452,12 @@ public:
|
||||
virtual float body_get_applied_torque(RID p_body) const = 0;
|
||||
|
||||
virtual void body_add_central_force(RID p_body, const Vector2 &p_force) = 0;
|
||||
virtual void body_add_force(RID p_body, const Vector2 &p_offset, const Vector2 &p_force) = 0;
|
||||
virtual void body_add_force(RID p_body, const Vector2 &p_force, const Vector2 &p_position = Vector2()) = 0;
|
||||
virtual void body_add_torque(RID p_body, float p_torque) = 0;
|
||||
|
||||
virtual void body_apply_central_impulse(RID p_body, const Vector2 &p_impulse) = 0;
|
||||
virtual void body_apply_torque_impulse(RID p_body, float p_torque) = 0;
|
||||
virtual void body_apply_impulse(RID p_body, const Vector2 &p_offset, const Vector2 &p_impulse) = 0;
|
||||
virtual void body_apply_impulse(RID p_body, const Vector2 &p_impulse, const Vector2 &p_position = Vector2()) = 0;
|
||||
virtual void body_set_axis_velocity(RID p_body, const Vector2 &p_axis_velocity) = 0;
|
||||
|
||||
//fix
|
||||
|
@ -92,12 +92,12 @@ void PhysicsDirectBodyState3D::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_transform", "transform"), &PhysicsDirectBodyState3D::set_transform);
|
||||
ClassDB::bind_method(D_METHOD("get_transform"), &PhysicsDirectBodyState3D::get_transform);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("add_central_force", "force"), &PhysicsDirectBodyState3D::add_central_force);
|
||||
ClassDB::bind_method(D_METHOD("add_force", "force", "position"), &PhysicsDirectBodyState3D::add_force);
|
||||
ClassDB::bind_method(D_METHOD("add_central_force", "force"), &PhysicsDirectBodyState3D::add_central_force, Vector3());
|
||||
ClassDB::bind_method(D_METHOD("add_force", "force", "position"), &PhysicsDirectBodyState3D::add_force, Vector3());
|
||||
ClassDB::bind_method(D_METHOD("add_torque", "torque"), &PhysicsDirectBodyState3D::add_torque);
|
||||
ClassDB::bind_method(D_METHOD("apply_central_impulse", "j"), &PhysicsDirectBodyState3D::apply_central_impulse);
|
||||
ClassDB::bind_method(D_METHOD("apply_impulse", "position", "j"), &PhysicsDirectBodyState3D::apply_impulse);
|
||||
ClassDB::bind_method(D_METHOD("apply_torque_impulse", "j"), &PhysicsDirectBodyState3D::apply_torque_impulse);
|
||||
ClassDB::bind_method(D_METHOD("apply_central_impulse", "impulse"), &PhysicsDirectBodyState3D::apply_central_impulse, Vector3());
|
||||
ClassDB::bind_method(D_METHOD("apply_impulse", "impulse", "position"), &PhysicsDirectBodyState3D::apply_impulse, Vector3());
|
||||
ClassDB::bind_method(D_METHOD("apply_torque_impulse", "impulse"), &PhysicsDirectBodyState3D::apply_torque_impulse);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_sleep_state", "enabled"), &PhysicsDirectBodyState3D::set_sleep_state);
|
||||
ClassDB::bind_method(D_METHOD("is_sleeping"), &PhysicsDirectBodyState3D::is_sleeping);
|
||||
@ -486,11 +486,11 @@ void PhysicsServer3D::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("body_get_state", "body", "state"), &PhysicsServer3D::body_get_state);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("body_add_central_force", "body", "force"), &PhysicsServer3D::body_add_central_force);
|
||||
ClassDB::bind_method(D_METHOD("body_add_force", "body", "force", "position"), &PhysicsServer3D::body_add_force);
|
||||
ClassDB::bind_method(D_METHOD("body_add_force", "body", "force", "position"), &PhysicsServer3D::body_add_force, Vector3());
|
||||
ClassDB::bind_method(D_METHOD("body_add_torque", "body", "torque"), &PhysicsServer3D::body_add_torque);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("body_apply_central_impulse", "body", "impulse"), &PhysicsServer3D::body_apply_central_impulse);
|
||||
ClassDB::bind_method(D_METHOD("body_apply_impulse", "body", "position", "impulse"), &PhysicsServer3D::body_apply_impulse);
|
||||
ClassDB::bind_method(D_METHOD("body_apply_impulse", "body", "impulse", "position"), &PhysicsServer3D::body_apply_impulse, Vector3());
|
||||
ClassDB::bind_method(D_METHOD("body_apply_torque_impulse", "body", "impulse"), &PhysicsServer3D::body_apply_torque_impulse);
|
||||
ClassDB::bind_method(D_METHOD("body_set_axis_velocity", "body", "axis_velocity"), &PhysicsServer3D::body_set_axis_velocity);
|
||||
|
||||
|
@ -63,11 +63,11 @@ public:
|
||||
virtual Transform get_transform() const = 0;
|
||||
|
||||
virtual void add_central_force(const Vector3 &p_force) = 0;
|
||||
virtual void add_force(const Vector3 &p_force, const Vector3 &p_pos) = 0;
|
||||
virtual void add_force(const Vector3 &p_force, const Vector3 &p_position = Vector3()) = 0;
|
||||
virtual void add_torque(const Vector3 &p_torque) = 0;
|
||||
virtual void apply_central_impulse(const Vector3 &p_j) = 0;
|
||||
virtual void apply_impulse(const Vector3 &p_pos, const Vector3 &p_j) = 0;
|
||||
virtual void apply_torque_impulse(const Vector3 &p_j) = 0;
|
||||
virtual void apply_central_impulse(const Vector3 &p_impulse) = 0;
|
||||
virtual void apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position = Vector3()) = 0;
|
||||
virtual void apply_torque_impulse(const Vector3 &p_impulse) = 0;
|
||||
|
||||
virtual void set_sleep_state(bool p_sleep) = 0;
|
||||
virtual bool is_sleeping() const = 0;
|
||||
@ -429,11 +429,11 @@ public:
|
||||
virtual Vector3 body_get_applied_torque(RID p_body) const = 0;
|
||||
|
||||
virtual void body_add_central_force(RID p_body, const Vector3 &p_force) = 0;
|
||||
virtual void body_add_force(RID p_body, const Vector3 &p_force, const Vector3 &p_pos) = 0;
|
||||
virtual void body_add_force(RID p_body, const Vector3 &p_force, const Vector3 &p_position = Vector3()) = 0;
|
||||
virtual void body_add_torque(RID p_body, const Vector3 &p_torque) = 0;
|
||||
|
||||
virtual void body_apply_central_impulse(RID p_body, const Vector3 &p_impulse) = 0;
|
||||
virtual void body_apply_impulse(RID p_body, const Vector3 &p_pos, const Vector3 &p_impulse) = 0;
|
||||
virtual void body_apply_impulse(RID p_body, const Vector3 &p_impulse, const Vector3 &p_position = Vector3()) = 0;
|
||||
virtual void body_apply_torque_impulse(RID p_body, const Vector3 &p_impulse) = 0;
|
||||
virtual void body_set_axis_velocity(RID p_body, const Vector3 &p_axis_velocity) = 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user