Created
June 5, 2019 18:41
-
-
Save mooman219/afa12348e6e3d924faabab761c52655f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pub fn tick(sprite: &mut SpriteDescription, particle: &mut Particle, delta: f32) { | |
| let length_squared = particle.pos.x * particle.pos.x + particle.pos.y * particle.pos.y; | |
| let length = f32::sqrt(length_squared); | |
| let norm = particle.pos / length; | |
| let norm_squared = particle.pos / length_squared; | |
| particle.acceleration = -(norm * (Self::G * Self::MASS)).div_element_wise(norm_squared); | |
| particle.velocity += particle.acceleration; | |
| particle.pos += particle.velocity; | |
| let velocity = particle.velocity + particle.acceleration * delta; | |
| let position = particle.pos + velocity * delta; | |
| sprite.set_pos(position.extend(0.0)); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fix norm_squared