Skip to content

Instantly share code, notes, and snippets.

@sjhalayka
Created January 17, 2024 20:38
Show Gist options
  • Save sjhalayka/e11580248caf2449f4a96b6fa5621676 to your computer and use it in GitHub Desktop.
Save sjhalayka/e11580248caf2449f4a96b6fa5621676 to your computer and use it in GitHub Desktop.
custom_math::vector_3 grav_acceleration(const custom_math::vector_3 &pos, const custom_math::vector_3 &vel, const double G)
{
custom_math::vector_3 grav_dir = sun_pos - pos;
float distance = grav_dir.length();
grav_dir.normalize();
float alpha = (vel.length()*vel.length()) / (speed_of_light * speed_of_light);
alpha = pow(alpha, 0.01); // suit to taste
float G_factor = G*(2.0f - sqrt(1 - alpha));
custom_math::vector_3 accel = grav_dir * (G_factor*sun_mass / pow(distance, 2.0));
return accel;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment