Fixed bug in physics simulator
This commit is contained in:
parent
a8ad12a9e7
commit
360b8410a6
@ -129,16 +129,8 @@ void physics_update(R4BetaState* st, float t){
|
||||
* m2 is the mass of bullet. `v` is the speed of bullet */
|
||||
void RigidBodyState_when_shot(RigidBodyState* self, vec3 imp, float m2, vec3 v){
|
||||
vec3 IO = vec3_minus(imp);
|
||||
float IO_norm_sq = vec3_dot(IO, IO);
|
||||
|
||||
vec3 linear_speed_gain;
|
||||
if (IO_norm_sq < 0.00001f) {
|
||||
linear_speed_gain = v;
|
||||
} else {
|
||||
vec3 v_projected = vec3_mul_scal(IO, vec3_dot(IO, v) / IO_norm_sq);
|
||||
linear_speed_gain = vec3_mul_scal(v_projected, m2 / self->p.mass);
|
||||
}
|
||||
self->speed = vec3_add_vec3(self->speed, linear_speed_gain);
|
||||
self->speed = vec3_add_vec3(self->speed, vec3_mul_scal(v, m2 / self->p.mass));
|
||||
|
||||
|
||||
vec3 www = vec3_mul_scal(vec3_cross(v, IO), m2);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user