Skip to content

Commit

Permalink
chatgpt helps me out
Browse files Browse the repository at this point in the history
  • Loading branch information
philiplinden committed Aug 7, 2024
1 parent 0ac9766 commit a384f8c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
9 changes: 9 additions & 0 deletions docs/devlog/v0.2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,12 @@ Verdict: **[egui](https://www.egui.rs/) now, [lunex](https://bytestring-net.gith
- Made a basic UI with egui
- Added basic entity spawner
- Added [todo.md](../todo.md)

# 2024-08-06

ChatGPT read https://arxiv.org/abs/2402.11150 and my time dilation notes and
affirmed that I have a correct understanding and my math is mostly right. The
suspicious deviation of my results from wikipedia's results is a units error.
Wikipedia uses microseconds per day, but I show microseconds per second.

ChatGPT helped me make a stupid-simple demo to get started with time dilation.
7 changes: 6 additions & 1 deletion src/physics/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
mod time_dilation;

use avian2d::prelude::*;
use bevy::prelude::*;

pub(super) fn plugin(app: &mut App) {
app.add_plugins(PhysicsPlugins::default().with_length_unit(1.0));
app.add_plugins((
PhysicsPlugins::default().with_length_unit(1.0),
time_dilation::plugin,
));

// we will handle gravity ourselves
app.insert_resource(Gravity(Vec2::ZERO.into()));
Expand Down
46 changes: 46 additions & 0 deletions src/physics/time_dilation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use bevy::prelude::*;
use bevy_egui::{egui, EguiContexts};

pub(super) fn plugin(app: &mut App) {
app.add_systems(Startup, setup);
app.add_systems(Update, (update_time_dilation, update_ui));
}

#[derive(Component)]
struct TimeDilation {
proper_time: f32,
coordinate_time: f32,
velocity: f32, // Fraction of the speed of light
}

fn setup(
mut commands: Commands,
) {
commands.spawn(TimeDilation {
proper_time: 0.0,
coordinate_time: 0.0,
velocity: 0.1, // Example value for v/c
});
}

fn update_time_dilation(mut query: Query<&mut TimeDilation>, time: Res<Time>) {
for mut time_dilation in query.iter_mut() {
time_dilation.coordinate_time += time.delta_seconds();
time_dilation.proper_time +=
time.delta_seconds() * (1.0 / (1.0 - time_dilation.velocity.powi(2)).sqrt());
}
}

fn update_ui(
mut egui_context: EguiContexts,
query: Query<&TimeDilation>
) {
let time_dilation = query.single();
egui::CentralPanel::default().show(egui_context.ctx_mut(), |ui| {
ui.label(format!(
"Coordinate Time: {:.2}\nProper Time: {:.2}",
time_dilation.coordinate_time,
time_dilation.proper_time
));
});
}

0 comments on commit a384f8c

Please sign in to comment.