diff --git a/Cargo.toml b/Cargo.toml index 6d7460c..98da09b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,11 @@ edition = "2021" opt-level = 1 [profile.dev.package."*"] -opt-level = 3 +opt-level = 3 + +[profile.release] +opt-level = 's' +lto = "thin" [build-dependencies] embed-resource = "1.6.3" diff --git a/assets/bodies.sim b/assets/bodies.sim index 2fa3274..6abc4c0 100644 --- a/assets/bodies.sim +++ b/assets/bodies.sim @@ -1 +1 @@ -{"bodies":[{"data":{"mass":1.9885E30,"starting_position":{"x":-1253558.344523507,"y":-331931.4431501561,"z":31972.046837662},"starting_velocity":{"x":0.006931107133912123,"y":-0.01362000313964326,"z":-4.54388831820406E-5},"name":"Sol","model_path":"sun.glb","diameter":1392000.0,"rotation_speed":38880.0,"axial_tilt":7.25,"simulate":true},"children":[{"data":{"mass":5.97219E24,"starting_position":{"x":1.47358878457139E8,"y":1.854315256927273E7,"z":29904.29803438578},"starting_velocity":{"x":-4.226365231723641,"y":29.41379349033467,"z":-0.002828583292782128},"name":"Earth","model_path":"earth.glb","diameter":12742.0,"rotation_speed":1436.0,"axial_tilt":23.4392811,"simulate":true},"children":[{"data":{"mass":7.348E22,"starting_position":{"x":1.4768044919678E8,"y":1.872052246844263E7,"z":32437.75744153466},"starting_velocity":{"x":-4.694794112410923,"y":30.37390017058626,"z":0.09549595923954257},"name":"Moon","model_path":"moon.glb","diameter":1738.1,"rotation_speed":39343.68,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":420000.0,"starting_position":{"x":1.473527157673001E8,"y":1.854377197753885E7,"z":32687.02643421665},"starting_velocity":{"x":-1.45562616429677,"y":26.86558693275802,"z":6.676360863324918},"name":"ISS","model_path":"iss.glb","diameter":0.11,"rotation_speed":0.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":12200.0,"starting_position":{"x":1.473574824275498E8,"y":1.853650067043575E7,"z":31105.44444823079},"starting_velocity":{"x":2.337654024613603,"y":28.72201739576322,"z":3.768849345271146},"name":"Hubble","model_path":"hubble.glb","diameter":0.013,"rotation_speed":0.0,"axial_tilt":0.0,"simulate":true},"children":[]}]},{"data":{"mass":5.6834E26,"starting_position":{"x":1.317721699784666E9,"y":-6.263762138853518E8,"z":-4.157355925955266E7},"starting_velocity":{"x":3.608323540191913,"y":8.705880483493228,"z":-0.2953903588682212},"name":"Saturn","model_path":"saturn.glb","diameter":116464.0,"rotation_speed":633.0,"axial_tilt":26.73,"simulate":true},"children":[{"data":{"mass":1.3452E23,"starting_position":{"x":1.317062395789841E9,"y":-6.254109541976979E8,"z":-4.200566301576936E7},"starting_velocity":{"x":-1.060852998165573,"y":6.402666517530363,"z":1.357634287951674},"name":"Titan","model_path":"titan.glb","diameter":5149.46,"rotation_speed":22920.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":2.3064854E21,"starting_position":{"x":1.317198227126551E9,"y":-6.263121286545614E8,"z":-4.155952859529075E7},"starting_velocity":{"x":2.806558904291587,"y":1.2701482567137,"z":3.694364144037066},"name":"Rhea","model_path":"rhea.glb","diameter":763.5,"rotation_speed":6480.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":1.8056591E21,"starting_position":{"x":1.320855160609993E9,"y":-6.278521340465181E8,"z":-4.186440417667893E7},"starting_velocity":{"x":4.854646792968393,"y":11.66248870085356,"z":-1.230081930411274},"name":"Iapetus","model_path":"iapetus.glb","diameter":1470.0,"rotation_speed":113760.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":1.0954867999999999E21,"starting_position":{"x":1.318063919760553E9,"y":-6.26526636509911E8,"z":-4.152808612631324E7},"starting_velocity":{"x":7.705841565764674,"y":16.66690708035977,"z":-4.861168661971909},"name":"Dione","model_path":"dione.glb","diameter":1123.0,"rotation_speed":3941.1576,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":6.174959E20,"starting_position":{"x":1.317498514533114E9,"y":-6.261968167390172E8,"z":-4.164324520863017E7},"starting_velocity":{"x":-3.711987600444088,"y":1.440318005837302,"z":4.443003247932851},"name":"Tethys","model_path":"tethys.glb","diameter":1062.0,"rotation_speed":2718.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":3.75094E19,"starting_position":{"x":1.317862368973109E9,"y":-6.262736478866278E8,"z":-4.163625521668619E7},"starting_velocity":{"x":-5.466336813759373,"y":18.80368314533501,"z":-4.960595064530139},"name":"Mimas","model_path":"mimas.glb","diameter":396.0,"rotation_speed":1356.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":1.080318E20,"starting_position":{"x":1.317897357123477E9,"y":-6.265236953599699E8,"z":-4.15133347885673E7},"starting_velocity":{"x":12.03172552201499,"y":16.74134008425769,"z":-5.324491936368194},"name":"Enceladus","model_path":"enceladus.glb","diameter":504.0,"rotation_speed":1973.11392,"axial_tilt":0.0,"simulate":true},"children":[]}]},{"data":{"mass":1.8982E27,"starting_position":{"x":5.91116405042928E8,"y":4.48612773658671E8,"z":-1.508610682481316E7},"starting_velocity":{"x":-8.045068878300311,"y":11.02381638213635,"z":0.1341531152888358},"name":"Jupiter","model_path":"jupiter.glb","diameter":139822.0,"rotation_speed":595.0,"axial_tilt":3.13,"simulate":true},"children":[{"data":{"mass":8.931938E22,"starting_position":{"x":5.910424467821088E8,"y":4.481963687394117E8,"z":-1.510185010929203E7},"starting_velocity":{"x":8.957736595686779,"y":7.959026250920237,"z":0.2787009746093063},"name":"Io","model_path":"io.glb","diameter":3643.2,"rotation_speed":2547.36,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":4.799844E22,"starting_position":{"x":5.917799042824603E8,"y":4.486983281930672E8,"z":-1.506823606685701E7},"starting_velocity":{"x":-9.693151465294227,"y":24.69741639214316,"z":0.569429680046083},"name":"Europa","model_path":"europa.glb","diameter":1560.8,"rotation_speed":5113.70064,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":1.4819E23,"starting_position":{"x":5.920393829735433E8,"y":4.480741128331422E8,"z":-1.509370908536822E7},"starting_velocity":{"x":-2.558462326557859,"y":20.43120719962253,"z":0.5697972593813327},"name":"Ganymede","model_path":"ganymede.glb","diameter":5268.2,"rotation_speed":10303.2,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":1.075938E23,"starting_position":{"x":5.928184462926141E8,"y":4.478344900349652E8,"z":-1.508781974881226E7},"starting_velocity":{"x":-4.643871215581399,"y":18.53965996642426,"z":0.4153266498041814},"name":"Callisto","model_path":"callisto.glb","diameter":4820.6,"rotation_speed":24032.16,"axial_tilt":0.0,"simulate":true},"children":[]}]},{"data":{"mass":4.8675E24,"starting_position":{"x":8.476483460935698E7,"y":6.527795533113867E7,"z":-4030295.749102697},"starting_velocity":{"x":-21.33838684070412,"y":27.68230884313838,"z":1.611943339470342},"name":"Venus","model_path":"venus.glb","diameter":12103.6,"rotation_speed":349946.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":3.3011E23,"starting_position":{"x":-2.65823594034951E7,"y":4.047607508223532E7,"z":5690109.263829736},"starting_velocity":{"x":-51.19740738494808,"y":-23.82829179403439,"z":2.750476586235273},"name":"Mercury","model_path":"mercury.glb","diameter":4880.0,"rotation_speed":84480.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":8.681E25,"starting_position":{"x":1.876848145196212E9,"y":2.256742495428547E9,"z":-1.593333878791571E7},"starting_velocity":{"x":-5.285944969180821,"y":4.037177487005098,"z":0.0832885977451503},"name":"Uranus","model_path":"uranus.glb","diameter":50724.0,"rotation_speed":1034.0,"axial_tilt":0.0,"simulate":true},"children":[{"data":{"mass":6.4E19,"starting_position":{"x":1.876793591976653E9,"y":2.256780204161452E9,"z":-1.582184453453541E7},"starting_velocity":{"x":0.5593250277603632,"y":3.223358609129066,"z":3.227082066969737},"name":"Miranda","model_path":"miranda.glb","diameter":471.6,"rotation_speed":2035.40976,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":1.251E21,"starting_position":{"x":1.87669550752492E9,"y":2.256760167205151E9,"z":-1.604669083471954E7},"starting_velocity":{"x":-8.385308784191833,"y":5.318928951790138,"z":4.453089305595049},"name":"Ariel","model_path":"ariel.glb","diameter":1157.8,"rotation_speed":3629.34576,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":1.275E21,"starting_position":{"x":1.877032097119599E9,"y":2.256677176877903E9,"z":-1.611531210892296E7},"starting_velocity":{"x":-8.506198828430891,"y":4.275436104814067,"z":-3.265378937492151},"name":"Umbriel","model_path":"umbriel.glb","diameter":1169.4,"rotation_speed":5904.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":3.4E21,"starting_position":{"x":1.876446721049093E9,"y":2.256849468855134E9,"z":-1.579768942792165E7},"starting_velocity":{"x":-4.077764161868127,"y":4.250690343060523,"z":3.508220529443759},"name":"Titania","model_path":"titania.glb","diameter":1576.8,"rotation_speed":12528.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":3.076E21,"starting_position":{"x":1.876691132612216E9,"y":2.256854991280804E9,"z":-1.538266894913125E7},"starting_velocity":{"x":-2.324170074400168,"y":3.526797505106853,"z":1.030057319525953},"name":"Oberon","model_path":"oberon.glb","diameter":1522.8,"rotation_speed":19440.0,"axial_tilt":0.0,"simulate":true},"children":[]}]},{"data":{"mass":1.024E26,"starting_position":{"x":4.46073781433013E9,"y":-3.117194956197202E8,"z":-9.638308729856475E7},"starting_velocity":{"x":0.3424898338191547,"y":5.454448402599064,"z":-0.1196973250551823},"name":"Neptune","model_path":"neptune.glb","diameter":49244.0,"rotation_speed":960.0,"axial_tilt":28.32,"simulate":true},"children":[{"data":{"mass":2.139E22,"starting_position":{"x":4.46043565553476E9,"y":-3.118210796191955E8,"z":-9.622740008927625E7},"starting_velocity":{"x":0.6549830743821887,"y":8.816651890055235,"z":2.683376921837763},"name":"Triton","model_path":"triton.glb","diameter":2706.8,"rotation_speed":8496.0,"axial_tilt":0.0,"simulate":true},"children":[]}]},{"data":{"mass":1.303E22,"starting_position":{"x":2.534605027840262E9,"y":-4.550728311952005E9,"z":-2.46201602553565E8},"starting_velocity":{"x":4.90550581768183,"y":1.466573354685091,"z":-1.58125012378935},"name":"Pluto","model_path":"pluto.glb","diameter":2376.6,"rotation_speed":9201.0,"axial_tilt":0.0,"simulate":true},"children":[{"data":{"mass":1.586E21,"starting_position":{"x":2.534602841613384E9,"y":-4.550740270530462E9,"z":-2.46216972222549E8},"starting_velocity":{"x":4.743470035507049,"y":1.357540337784795,"z":-1.47338180231602},"name":"Charon","model_path":"charon.glb","diameter":1212.0,"rotation_speed":9197.28,"axial_tilt":0.0,"simulate":false},"children":[]}]},{"data":{"mass":6.4171E23,"starting_position":{"x":-2.046893400400904E8,"y":-1.250136923437167E8,"z":2409131.185058415},"starting_velocity":{"x":13.57395490411145,"y":-18.60254221026088,"z":-0.7224152414868863},"name":"Mars","model_path":"mars.glb","diameter":6779.0,"rotation_speed":1476.0,"axial_tilt":25.19,"simulate":true},"children":[{"data":{"mass":1.0659E16,"starting_position":{"x":-2.046811201572424E8,"y":-1.250112401183025E8,"z":2405122.029878475},"starting_velocity":{"x":13.1724712527701,"y":-16.55773129437739,"z":-0.3519634910822811},"name":"Phobos","model_path":"phobos.glb","diameter":22.16,"rotation_speed":0.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":1.4762E15,"starting_position":{"x":-2.046898065944895E8,"y":-1.24990331767902E8,"z":2411141.282914884},"starting_velocity":{"x":12.33964871357277,"y":-18.67418157402109,"z":-0.1763597828023391},"name":"Deimos","model_path":"deimos.glb","diameter":12.54,"rotation_speed":0.0,"axial_tilt":0.0,"simulate":true},"children":[]}]},{"data":{"mass":9.38392E20,"starting_position":{"x":-2.762371221893816E8,"y":-2.903518150199021E8,"z":4.151164079416633E7},"starting_velocity":{"x":12.07056566717051,"y":-13.70357563530193,"z":-2.655445328553542},"name":"Ceres","model_path":"ceres.glb","diameter":939.4,"rotation_speed":540.0,"axial_tilt":0.0,"simulate":false},"children":[]},{"data":{"mass":1.6466E22,"starting_position":{"x":1.280400740948511E10,"y":5.796599006941406E9,"z":-2.733004417387743E9},"starting_velocity":{"x":-0.7745567938606255,"y":1.50385470985689,"z":1.614258646777714},"name":"Eris","model_path":"eris.glb","diameter":2326.0,"rotation_speed":1554.0,"axial_tilt":0.0,"simulate":false},"children":[]},{"data":{"mass":2.2E14,"starting_position":{"x":-2.974525169762023E9,"y":4.071518952895051E9,"z":-1.489577717564979E9},"starting_velocity":{"x":0.7036787387939378,"y":0.567179895714418,"z":0.09880162683010832},"name":"Halley's Comet","model_path":"deimos.glb","diameter":11.0,"rotation_speed":0.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":721.9,"starting_position":{"x":5.567899398702804E9,"y":-1.48929564919915E10,"z":-1.234693053386691E10},"starting_velocity":{"x":4.222130606182812,"y":-9.357402996434875,"z":-11.33474239077342},"name":"Voyager-2","model_path":"voyager.glb","diameter":0.001,"rotation_speed":0.0,"axial_tilt":0.0,"simulate":true},"children":[]}]}],"starting_time_millis":1696118400000} \ No newline at end of file +{"bodies":[{"data":{"mass":1.9885E30,"starting_position":{"x":-1253558.344523507,"y":-331931.4431501561,"z":31972.046837662},"starting_velocity":{"x":0.006931107133912123,"y":-0.01362000313964326,"z":-4.54388831820406E-5},"name":"Sol","model_path":"sun.glb","diameter":1392000.0,"rotation_speed":38880.0,"axial_tilt":7.25,"simulate":true},"children":[{"data":{"mass":5.97219E24,"starting_position":{"x":1.47358878457139E8,"y":1.854315256927273E7,"z":29904.29803438578},"starting_velocity":{"x":-4.226365231723641,"y":29.41379349033467,"z":-0.002828583292782128},"name":"Earth","model_path":"earth.glb","diameter":12742.0,"rotation_speed":1436.0,"axial_tilt":23.4392811,"simulate":true},"children":[{"data":{"mass":7.348E22,"starting_position":{"x":1.4768044919678E8,"y":1.872052246844263E7,"z":32437.75744153466},"starting_velocity":{"x":-4.694794112410923,"y":30.37390017058626,"z":0.09549595923954257},"name":"Moon","model_path":"moon.glb","diameter":1738.1,"rotation_speed":39343.68,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":420000.0,"starting_position":{"x":1.473527157673001E8,"y":1.854377197753885E7,"z":32687.02643421665},"starting_velocity":{"x":-1.45562616429677,"y":26.86558693275802,"z":6.676360863324918},"name":"ISS","model_path":"iss.glb","diameter":0.11,"rotation_speed":0.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":12200.0,"starting_position":{"x":1.473574824275498E8,"y":1.853650067043575E7,"z":31105.44444823079},"starting_velocity":{"x":2.337654024613603,"y":28.72201739576322,"z":3.768849345271146},"name":"Hubble","model_path":"hubble.glb","diameter":0.013,"rotation_speed":0.0,"axial_tilt":0.0,"simulate":true},"children":[]}]},{"data":{"mass":5.6834E26,"starting_position":{"x":1.317721699784666E9,"y":-6.263762138853518E8,"z":-4.157355925955266E7},"starting_velocity":{"x":3.608323540191913,"y":8.705880483493228,"z":-0.2953903588682212},"name":"Saturn","model_path":"saturn.glb","diameter":116464.0,"rotation_speed":633.0,"axial_tilt":26.73,"simulate":true},"children":[{"data":{"mass":1.3452E23,"starting_position":{"x":1.317062395789841E9,"y":-6.254109541976979E8,"z":-4.200566301576936E7},"starting_velocity":{"x":-1.060852998165573,"y":6.402666517530363,"z":1.357634287951674},"name":"Titan","model_path":"titan.glb","diameter":5149.46,"rotation_speed":22920.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":2.3064854E21,"starting_position":{"x":1.317198227126551E9,"y":-6.263121286545614E8,"z":-4.155952859529075E7},"starting_velocity":{"x":2.806558904291587,"y":1.2701482567137,"z":3.694364144037066},"name":"Rhea","model_path":"rhea.glb","diameter":763.5,"rotation_speed":6480.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":1.8056591E21,"starting_position":{"x":1.320855160609993E9,"y":-6.278521340465181E8,"z":-4.186440417667893E7},"starting_velocity":{"x":4.854646792968393,"y":11.66248870085356,"z":-1.230081930411274},"name":"Iapetus","model_path":"iapetus.glb","diameter":1470.0,"rotation_speed":113760.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":1.0954867999999999E21,"starting_position":{"x":1.318063919760553E9,"y":-6.26526636509911E8,"z":-4.152808612631324E7},"starting_velocity":{"x":7.705841565764674,"y":16.66690708035977,"z":-4.861168661971909},"name":"Dione","model_path":"dione.glb","diameter":1123.0,"rotation_speed":3941.1576,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":6.174959E20,"starting_position":{"x":1.317498514533114E9,"y":-6.261968167390172E8,"z":-4.164324520863017E7},"starting_velocity":{"x":-3.711987600444088,"y":1.440318005837302,"z":4.443003247932851},"name":"Tethys","model_path":"tethys.glb","diameter":1062.0,"rotation_speed":2718.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":3.75094E19,"starting_position":{"x":1.317862368973109E9,"y":-6.262736478866278E8,"z":-4.163625521668619E7},"starting_velocity":{"x":-5.466336813759373,"y":18.80368314533501,"z":-4.960595064530139},"name":"Mimas","model_path":"mimas.glb","diameter":396.0,"rotation_speed":1356.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":1.080318E20,"starting_position":{"x":1.317897357123477E9,"y":-6.265236953599699E8,"z":-4.15133347885673E7},"starting_velocity":{"x":12.03172552201499,"y":16.74134008425769,"z":-5.324491936368194},"name":"Enceladus","model_path":"enceladus.glb","diameter":504.0,"rotation_speed":1973.11392,"axial_tilt":0.0,"simulate":true},"children":[]}]},{"data":{"mass":1.8982E27,"starting_position":{"x":5.91116405042928E8,"y":4.48612773658671E8,"z":-1.508610682481316E7},"starting_velocity":{"x":-8.045068878300311,"y":11.02381638213635,"z":0.1341531152888358},"name":"Jupiter","model_path":"jupiter.glb","diameter":139822.0,"rotation_speed":595.0,"axial_tilt":3.13,"simulate":true},"children":[{"data":{"mass":8.931938E22,"starting_position":{"x":5.910424467821088E8,"y":4.481963687394117E8,"z":-1.510185010929203E7},"starting_velocity":{"x":8.957736595686779,"y":7.959026250920237,"z":0.2787009746093063},"name":"Io","model_path":"io.glb","diameter":3643.2,"rotation_speed":2547.36,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":4.799844E22,"starting_position":{"x":5.917799042824603E8,"y":4.486983281930672E8,"z":-1.506823606685701E7},"starting_velocity":{"x":-9.693151465294227,"y":24.69741639214316,"z":0.569429680046083},"name":"Europa","model_path":"europa.glb","diameter":1560.8,"rotation_speed":5113.70064,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":1.4819E23,"starting_position":{"x":5.920393829735433E8,"y":4.480741128331422E8,"z":-1.509370908536822E7},"starting_velocity":{"x":-2.558462326557859,"y":20.43120719962253,"z":0.5697972593813327},"name":"Ganymede","model_path":"ganymede.glb","diameter":5268.2,"rotation_speed":10303.2,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":1.075938E23,"starting_position":{"x":5.928184462926141E8,"y":4.478344900349652E8,"z":-1.508781974881226E7},"starting_velocity":{"x":-4.643871215581399,"y":18.53965996642426,"z":0.4153266498041814},"name":"Callisto","model_path":"callisto.glb","diameter":4820.6,"rotation_speed":24032.16,"axial_tilt":0.0,"simulate":true},"children":[]}]},{"data":{"mass":4.8675E24,"starting_position":{"x":8.476483460935698E7,"y":6.527795533113867E7,"z":-4030295.749102697},"starting_velocity":{"x":-21.33838684070412,"y":27.68230884313838,"z":1.611943339470342},"name":"Venus","model_path":"venus.glb","diameter":12103.6,"rotation_speed":349946.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":3.3011E23,"starting_position":{"x":-2.65823594034951E7,"y":4.047607508223532E7,"z":5690109.263829736},"starting_velocity":{"x":-51.19740738494808,"y":-23.82829179403439,"z":2.750476586235273},"name":"Mercury","model_path":"mercury.glb","diameter":4880.0,"rotation_speed":84480.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":8.681E25,"starting_position":{"x":1.876848145196212E9,"y":2.256742495428547E9,"z":-1.593333878791571E7},"starting_velocity":{"x":-5.285944969180821,"y":4.037177487005098,"z":0.0832885977451503},"name":"Uranus","model_path":"uranus.glb","diameter":50724.0,"rotation_speed":1034.0,"axial_tilt":0.0,"simulate":true},"children":[{"data":{"mass":6.4E19,"starting_position":{"x":1.876793591976653E9,"y":2.256780204161452E9,"z":-1.582184453453541E7},"starting_velocity":{"x":0.5593250277603632,"y":3.223358609129066,"z":3.227082066969737},"name":"Miranda","model_path":"miranda.glb","diameter":471.6,"rotation_speed":2035.40976,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":1.251E21,"starting_position":{"x":1.87669550752492E9,"y":2.256760167205151E9,"z":-1.604669083471954E7},"starting_velocity":{"x":-8.385308784191833,"y":5.318928951790138,"z":4.453089305595049},"name":"Ariel","model_path":"ariel.glb","diameter":1157.8,"rotation_speed":3629.34576,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":1.275E21,"starting_position":{"x":1.877032097119599E9,"y":2.256677176877903E9,"z":-1.611531210892296E7},"starting_velocity":{"x":-8.506198828430891,"y":4.275436104814067,"z":-3.265378937492151},"name":"Umbriel","model_path":"umbriel.glb","diameter":1169.4,"rotation_speed":5904.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":3.4E21,"starting_position":{"x":1.876446721049093E9,"y":2.256849468855134E9,"z":-1.579768942792165E7},"starting_velocity":{"x":-4.077764161868127,"y":4.250690343060523,"z":3.508220529443759},"name":"Titania","model_path":"titania.glb","diameter":1576.8,"rotation_speed":12528.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":3.076E21,"starting_position":{"x":1.876691132612216E9,"y":2.256854991280804E9,"z":-1.538266894913125E7},"starting_velocity":{"x":-2.324170074400168,"y":3.526797505106853,"z":1.030057319525953},"name":"Oberon","model_path":"oberon.glb","diameter":1522.8,"rotation_speed":19440.0,"axial_tilt":0.0,"simulate":true},"children":[]}]},{"data":{"mass":1.024E26,"starting_position":{"x":4.46073781433013E9,"y":-3.117194956197202E8,"z":-9.638308729856475E7},"starting_velocity":{"x":0.3424898338191547,"y":5.454448402599064,"z":-0.1196973250551823},"name":"Neptune","model_path":"neptune.glb","diameter":49244.0,"rotation_speed":960.0,"axial_tilt":28.32,"simulate":true},"children":[{"data":{"mass":2.139E22,"starting_position":{"x":4.46043565553476E9,"y":-3.118210796191955E8,"z":-9.622740008927625E7},"starting_velocity":{"x":0.6549830743821887,"y":8.816651890055235,"z":2.683376921837763},"name":"Triton","model_path":"triton.glb","diameter":2706.8,"rotation_speed":8496.0,"axial_tilt":0.0,"simulate":true},"children":[]}]},{"data":{"mass":1.303E22,"starting_position":{"x":2.534605027840262E9,"y":-4.550728311952005E9,"z":-2.46201602553565E8},"starting_velocity":{"x":4.90550581768183,"y":1.466573354685091,"z":-1.58125012378935},"name":"Pluto","model_path":"pluto.glb","diameter":2376.6,"rotation_speed":9201.0,"axial_tilt":0.0,"simulate":true},"children":[{"data":{"mass":1.586E21,"starting_position":{"x":2.534602841613384E9,"y":-4.550740270530462E9,"z":-2.46216972222549E8},"starting_velocity":{"x":4.743470035507049,"y":1.357540337784795,"z":-1.47338180231602},"name":"Charon","model_path":"charon.glb","diameter":1212.0,"rotation_speed":9197.28,"axial_tilt":0.0,"simulate":false},"children":[]}]},{"data":{"mass":6.4171E23,"starting_position":{"x":-2.046893400400904E8,"y":-1.250136923437167E8,"z":2409131.185058415},"starting_velocity":{"x":13.57395490411145,"y":-18.60254221026088,"z":-0.7224152414868863},"name":"Mars","model_path":"mars.glb","diameter":6779.0,"rotation_speed":1476.0,"axial_tilt":25.19,"simulate":true},"children":[{"data":{"mass":1.0659E16,"starting_position":{"x":-2.046811201572424E8,"y":-1.250112401183025E8,"z":2405122.029878475},"starting_velocity":{"x":13.1724712527701,"y":-16.55773129437739,"z":-0.3519634910822811},"name":"Phobos","model_path":"phobos.glb","diameter":22.16,"rotation_speed":0.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":1.4762E15,"starting_position":{"x":-2.046898065944895E8,"y":-1.24990331767902E8,"z":2411141.282914884},"starting_velocity":{"x":12.33964871357277,"y":-18.67418157402109,"z":-0.1763597828023391},"name":"Deimos","model_path":"deimos.glb","diameter":12.54,"rotation_speed":0.0,"axial_tilt":0.0,"simulate":true},"children":[]}]},{"data":{"mass":9.38392E20,"starting_position":{"x":-2.762371221893816E8,"y":-2.903518150199021E8,"z":4.151164079416633E7},"starting_velocity":{"x":12.07056566717051,"y":-13.70357563530193,"z":-2.655445328553542},"name":"Ceres","model_path":"ceres.glb","diameter":939.4,"rotation_speed":540.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":1.6466E22,"starting_position":{"x":1.280400740948511E10,"y":5.796599006941406E9,"z":-2.733004417387743E9},"starting_velocity":{"x":-0.7745567938606255,"y":1.50385470985689,"z":1.614258646777714},"name":"Eris","model_path":"eris.glb","diameter":2326.0,"rotation_speed":1554.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":2.2E14,"starting_position":{"x":-2.974525169762023E9,"y":4.071518952895051E9,"z":-1.489577717564979E9},"starting_velocity":{"x":0.7036787387939378,"y":0.567179895714418,"z":0.09880162683010832},"name":"Halley's Comet","model_path":"deimos.glb","diameter":11.0,"rotation_speed":0.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":721.9,"starting_position":{"x":5.567899398702804E9,"y":-1.48929564919915E10,"z":-1.234693053386691E10},"starting_velocity":{"x":4.222130606182812,"y":-9.357402996434875,"z":-11.33474239077342},"name":"Voyager-2","model_path":"voyager.glb","diameter":0.001,"rotation_speed":0.0,"axial_tilt":0.0,"simulate":true},"children":[]},{"data":{"mass":3.1E21,"starting_position":{"x":-6.899004382898172E9,"y":-1.090297370986418E9,"z":3.649000392627125E9},"starting_velocity":{"x":0.2044745917565618,"y":-3.731030512801199,"z":-0.4904247640299213},"name":"Makemake","model_path":"makemake.glb","diameter":1430.0,"rotation_speed":1350.0,"axial_tilt":28.96,"simulate":true},"children":[]}]}],"starting_time_millis":1696118400000} \ No newline at end of file diff --git a/src/input.rs b/src/input.rs index d669a54..b4e4063 100644 --- a/src/input.rs +++ b/src/input.rs @@ -1,4 +1,5 @@ use bevy::{prelude::{App, in_state, Input, IntoSystemConfigs, KeyCode, Plugin, Query, Res, ResMut, Update, Vec3}, window::{Window, WindowMode}}; +use bevy_egui::{egui::{self}, EguiContexts, EguiSettings}; use crate::{camera::PanOrbitCamera, SimState, ui::{UiState, StepType}, physics::{Pause, SubSteps}, speed::Speed}; @@ -8,19 +9,64 @@ impl Plugin for InputPlugin { fn build(&self, app: &mut App) { app - .add_systems(Update, input_system.run_if(in_state(SimState::Simulation))); + .add_systems(Update, global_input_system) + .add_systems(Update, key_window.run_if(in_state(SimState::Simulation))) + .add_systems(Update, sim_input_system.run_if(in_state(SimState::Simulation))); } } -fn input_system( +fn key_window( + mut egui_ctx: EguiContexts, + mut ui_state: ResMut, +) { + if !ui_state.visible { + return; + } + egui::Window::new("Keybind Information") + .open(&mut ui_state.show_keys) + .collapsible(true) + .constrain(true) + .scroll2([true, true]) + .default_width(250.0) + .show(egui_ctx.ctx_mut(), |ui| { + ui.label("F11 - Toggle Fullscreen"); + ui.label("F10 - Hide Ui"); + ui.label("Space - Pause"); + ui.label("Left Arrow - 2x Speed"); + ui.label("Right Arrow - 1/2 Speed"); + ui.label("Left Alt - Change Step Type"); + ui.label("C - Reset Camera"); + ui.label("Left Mouse - Rotate Camera"); + ui.label("Right Mouse - Move Camera"); + ui.label("Ctrl + , - Increase Ui Scale"); + ui.label("Ctrl + . - Decrease Ui Scale"); + }); +} + +fn global_input_system( + keys: Res>, + mut windows: Query<&mut Window>, +) { + if keys.just_pressed(KeyCode::F11) { + let mut window = windows.single_mut(); + let current = window.mode; + if current == WindowMode::Windowed { + window.mode = WindowMode::BorderlessFullscreen; + } else { + window.mode = WindowMode::Windowed; + } + } +} + +fn sim_input_system( keys: Res>, mut ui_state: ResMut, mut camera: Query<&mut PanOrbitCamera>, - mut windows: Query<&mut Window>, mut pause: ResMut, mut speed: ResMut, - mut sub_steps: ResMut + mut sub_steps: ResMut, + mut egui_settings: ResMut, ) { let timestep_selected = match ui_state.step_type { StepType::SUBSTEPS => false, @@ -30,14 +76,6 @@ fn input_system( ui_state.visible = !ui_state.visible } else if keys.just_pressed(KeyCode::C) { camera.single_mut().focus = Vec3::ZERO; - } else if keys.just_pressed(KeyCode::F11) { - let mut window = windows.single_mut(); - let current = window.mode; - if current == WindowMode::Windowed { - window.mode = WindowMode::BorderlessFullscreen; - } else { - window.mode = WindowMode::Windowed; - } } else if keys.just_pressed(KeyCode::Space) { pause.0 = !pause.0; } else if keys.just_pressed(KeyCode::Left) { @@ -58,5 +96,9 @@ fn input_system( } else { ui_state.step_type = StepType::TIMESTEPS; } + } else if keys.pressed(KeyCode::ControlLeft) && keys.just_pressed(KeyCode::Comma) { + egui_settings.scale_factor *= 1.1; + } else if keys.pressed(KeyCode::ControlLeft) && keys.just_pressed(KeyCode::Period) { + egui_settings.scale_factor *= 0.9; } } diff --git a/src/ui.rs b/src/ui.rs index 90a9bac..8279469 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -9,7 +9,7 @@ use bevy::{ }; use bevy::app::Update; use bevy::prelude::{in_state, Window}; -use bevy_egui::{egui::{self, InnerResponse, Response, Ui}, EguiContexts}; +use bevy_egui::{egui::{self, InnerResponse, Response, Ui, ScrollArea}, EguiContexts}; use bevy_inspector_egui::egui::{RichText, TextEdit}; use chrono::{Days, NaiveDateTime}; @@ -42,12 +42,13 @@ pub struct UiState { pub visible: bool, pub step_type: StepType, pub show_debug: bool, + pub show_keys: bool, pub dyn_hide_orbit_lines: bool } impl Default for UiState { fn default() -> Self { - UiState { visible: true, step_type: StepType::SUBSTEPS, show_debug: false, dyn_hide_orbit_lines: true } + UiState { visible: true, step_type: StepType::SUBSTEPS, show_debug: false, dyn_hide_orbit_lines: true, show_keys: false } } } @@ -251,84 +252,80 @@ pub fn system_ui( if let Ok((entity, mut camera, mut pan, skybox)) = camera.get_single_mut() { let ctrl_hold = keys.pressed(KeyCode::ControlLeft); egui::SidePanel::left("system_panel") - .default_width(400.0) + // .default_width(250.0) .resizable(true) .show(egui_context.ctx_mut(), |ui| { - ui.heading("Bodies"); - for (s_name, s_children, s_entity, _) in &mut star_query { - let s_old_selected = selected_entity.entity == Some(s_entity); - let mut s_selected = s_old_selected; - body_tree(ui, &mut s_selected, s_name, true, |ui| { - for planet_child in &s_children.0 { - if let Ok((p_name, p_children, p_entity, _)) = planet_query.get_mut(*planet_child) { - let p_old_selected = selected_entity.entity == Some(p_entity); - let mut p_selected = p_old_selected; - body_tree(ui, &mut p_selected, p_name, false, |ui| { - for moon_child in &p_children.0 { - if let Ok((m_name, m_entity, _)) = moon_query.get_mut(*moon_child) { - let m_old_selected = selected_entity.entity == Some(m_entity); - let mut m_selected = m_old_selected; - ui.horizontal(|ui| { - ui.toggle_value(&mut m_selected, m_name.as_str()); - }); - if m_selected && !m_old_selected { - selected_entity.change_entity(m_entity, ctrl_hold) + ScrollArea::vertical() + .auto_shrink(true) + .show(ui, |ui| { + ui.heading("Bodies"); + for (s_name, s_children, s_entity, _) in &mut star_query { + let s_old_selected = selected_entity.entity == Some(s_entity); + let mut s_selected = s_old_selected; + body_tree(ui, &mut s_selected, s_name, true, |ui| { + for planet_child in &s_children.0 { + if let Ok((p_name, p_children, p_entity, _)) = planet_query.get_mut(*planet_child) { + let p_old_selected = selected_entity.entity == Some(p_entity); + let mut p_selected = p_old_selected; + body_tree(ui, &mut p_selected, p_name, false, |ui| { + for moon_child in &p_children.0 { + if let Ok((m_name, m_entity, _)) = moon_query.get_mut(*moon_child) { + let m_old_selected = selected_entity.entity == Some(m_entity); + let mut m_selected = m_old_selected; + ui.horizontal(|ui| { + ui.toggle_value(&mut m_selected, m_name.as_str()); + }); + if m_selected && !m_old_selected { + selected_entity.change_entity(m_entity, ctrl_hold) + } + } } + }); + if p_selected && !p_old_selected { + selected_entity.change_entity(p_entity, ctrl_hold) } } - }); - if p_selected && !p_old_selected { - selected_entity.change_entity(p_entity, ctrl_hold) } + }); + if s_selected && !s_old_selected { + selected_entity.change_entity(s_entity, ctrl_hold) } } - }); - if s_selected && !s_old_selected { - selected_entity.change_entity(s_entity, ctrl_hold) - } - } - ui.heading("Options"); - ui.checkbox(&mut camera.hdr, "HDR/Bloom"); - let skybox_enabled = skybox.is_some(); - let mut skybox_setting = skybox_enabled; - ui.checkbox(&mut skybox_setting, "Milky Way Skybox"); - - if skybox_enabled && !skybox_setting { - commands.entity(entity).remove::(); - cubemap.activated = false; - } else if !skybox_enabled && skybox_setting { - commands.entity(entity).insert(Skybox(cubemap.image_handle.clone())); - cubemap.activated = true; - } - - ui.checkbox(&mut config.aabb.draw_all, "Draw Outlines"); - ui.checkbox(&mut billboard.show, "Show Body Names"); - if ui.checkbox(&mut orbit_offset.enabled, "Offset body to zero").changed() { - if orbit_offset.enabled { - pan.focus = Vec3::ZERO; - } - } - ui.checkbox(&mut ui_state.dyn_hide_orbit_lines, "Dynamically hide orbit lines"); - if ui.button("Open Debug Window").clicked() { - ui_state.show_debug = true; - } - ui.add_space(5.0); - ui.label("F11 - Toggle Fullscreen"); - ui.label("F10 - Hide Ui"); - ui.label("Space - Pause"); - ui.label("Left Arrow - 2x Speed"); - ui.label("Right Arrow - 1/2 Speed"); - ui.label("Left Alt - Change Step Type"); - ui.label("C - Reset Camera"); - ui.label("Left Mouse - Rotate Camera"); - ui.label("Right Mouse - Move Camera"); - - ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| { - if ui.button("Back to Menu").clicked() { - let _ = state.set(SimState::ExitToMainMenu); - } - }); + ui.heading("Options"); + ui.checkbox(&mut camera.hdr, "HDR/Bloom"); + let skybox_enabled = skybox.is_some(); + let mut skybox_setting = skybox_enabled; + ui.checkbox(&mut skybox_setting, "Milky Way Skybox"); + + if skybox_enabled && !skybox_setting { + commands.entity(entity).remove::(); + cubemap.activated = false; + } else if !skybox_enabled && skybox_setting { + commands.entity(entity).insert(Skybox(cubemap.image_handle.clone())); + cubemap.activated = true; + } + + ui.checkbox(&mut config.aabb.draw_all, "Draw Outlines"); + ui.checkbox(&mut billboard.show, "Show Body Names"); + if ui.checkbox(&mut orbit_offset.enabled, "Offset body to zero").changed() { + if orbit_offset.enabled { + pan.focus = Vec3::ZERO; + } + } + ui.checkbox(&mut ui_state.dyn_hide_orbit_lines, "Dynamically hide orbit lines"); + if ui.button("Open Debug Window").clicked() { + ui_state.show_debug = true; + } + ui.add_space(5.0); + if ui.button("Open Keybind Window").clicked() { + ui_state.show_keys = true; + } + ui.separator(); + if ui.button("Back to Menu").clicked() { + let _ = state.set(SimState::ExitToMainMenu); + } }); + }); } } @@ -382,183 +379,185 @@ fn body_ui( } if let Some((name, entity, pos, velocity, rotation_speed, diameter, mut orbit, mut transform, mut mass, apsis, scale, _)) = selected { egui::SidePanel::right("body_panel") - .max_width(250.0) + // .max_width(250.0) .resizable(true) .show(egui_context.ctx_mut(), |ui| { - ui.heading(name.as_str()); - - //Mass block - ui.label(RichText::new("Mass").size(16.0).underline()); - ui.horizontal(|ui| { - let f_mass = mass.0 * 10e-24; - ui.label(format!("{:.3} 10^24 kg", f_mass)); - }); - ui.horizontal(|ui| { - if ui.button(":5").clicked() { - mass.0 /= 5.0; - } - if ui.button(":2").clicked() { - mass.0 /= 2.0; - } - if ui.button("x2").clicked() { - mass.0 *= 2.0; - } - if ui.button("x5").clicked() { - mass.0 *= 5.0; - } - }); - if scale.0 != 0.0 { - ui.label( - RichText::new("Body Scale") - .size(16.0) - .underline(), - ); - let mut n_scale = transform.scale.x / scale.0; - ui.horizontal(|ui| { - ui.add( - egui::Slider::new(&mut n_scale, 0.001..=100.0) - .clamp_to_range(true) - .logarithmic(true)); - }); - transform.scale = Vec3::splat(n_scale * scale.0); - ui.label( - RichText::new("Equator Diameter") - .size(16.0) - .underline(), - ); - let scaled_diameter = (diameter.num / M_TO_UNIT as f32) * n_scale; - ui.label(format!("{} km", scaled_diameter / 1000.0)); - } - - // Velocity Orbit Velocity around parent - let actual_velocity = match &parent { - Some((_, vel, _, _)) => (vel.0 - velocity.0).length() / 1000.0, - None => velocity.0.length() / 1000.0, - }; - let velocity_prefix = if parent.is_some() { - "Orbital" - } else { - "Total" - }; - ui.label(RichText::new(format!("{} Velocity", velocity_prefix)).size(16.0).underline()); - ui.horizontal(|ui| { - ui.label(format!("{:.3} km/s", actual_velocity)); - if actual_velocity < 10.0 { - ui.label(format!("({:.3} km/h)", actual_velocity * 3600.0)); - } - }); - - let mut new_apsis = None; - if let Some((_, _, _, p_mass)) = parent { - if let Some(apsis) = apsis { - let distance = ((apsis.aphelion.distance + apsis.perihelion.distance) / 2.0) as f64; - orbit.period = 2.0 * std::f64::consts::PI * f64::sqrt(f64::powf(distance, 3.0) / (G * (p_mass.0 + mass.0))); - ui.label(RichText::new("Orbital Period").size(16.0).underline()); - ui.label(format!("{}", format_seconds(orbit.period))); - new_apsis = Some(apsis); - } - } - - ui.label(RichText::new("Rotation Period").size(16.0).underline()); - ui.label(format!("{}", format_seconds(rotation_speed.0 * 60.0))); - - ui.label(RichText::new("Distance to Camera").size(16.0).underline()); - let (_, camera_pos, _) = camera.single(); - let c_distance_in_units = camera_pos.translation.distance(transform.translation) as f64; - ui.label(format!("{}", format_length((c_distance_in_units / M_TO_UNIT) as f32))); - ui.label(format!("{:.3} au", c_distance_in_units / M_TO_UNIT * M_TO_AU as f64)); - - // Distance to parent - if let Some((parent_pos, _, p_name, _)) = parent { - ui.label(RichText::new(format!("Distance to {}", p_name)).size(16.0).underline()); - let distance_in_m = parent_pos.0.distance(pos.0); - ui.label(format!("{}", format_length(distance_in_m as f32))); - ui.label(format!("{:.3} au", distance_in_m * (M_TO_AU as f64))); - - if let Some(mut apsis) = new_apsis { - //Apsis - ui.label(RichText::new(format!("Periapsis ({})", p_name)).size(16.0).underline()); - ui.label(format!("{}", format_length(apsis.perihelion.distance))); - ui.label(format!("{:.3} au", apsis.perihelion.distance * M_TO_AU)); + ScrollArea::vertical() + .auto_shrink(true) + .show(ui, |ui| { + ui.heading(name.as_str()); - ui.label(RichText::new(format!("Apoapsis ({})", p_name)).size(16.0).underline()); - ui.label(format!("{}", format_length(apsis.aphelion.distance))); - ui.label(format!("{:.3} au", apsis.aphelion.distance * M_TO_AU)); - if ui.button("Reset Apsides").clicked() { - apsis.aphelion.distance = 0.0; - apsis.perihelion.distance = 0.0; + //Mass block + ui.label(RichText::new("Mass").size(16.0).underline()); + ui.horizontal(|ui| { + let f_mass = mass.0 * 10e-24; + ui.label(format!("{:.3} 10^24 kg", f_mass)); + }); + ui.horizontal(|ui| { + if ui.button(":5").clicked() { + mass.0 /= 5.0; + } + if ui.button(":2").clicked() { + mass.0 /= 2.0; + } + if ui.button("x2").clicked() { + mass.0 *= 2.0; + } + if ui.button("x5").clicked() { + mass.0 *= 5.0; + } + }); + if scale.0 != 0.0 { + ui.label( + RichText::new("Body Scale") + .size(16.0) + .underline(), + ); + let mut n_scale = transform.scale.x / scale.0; + ui.horizontal(|ui| { + ui.add( + egui::Slider::new(&mut n_scale, 0.001..=100.0) + .clamp_to_range(true) + .logarithmic(true)); + }); + transform.scale = Vec3::splat(n_scale * scale.0); + ui.label( + RichText::new("Equator Diameter") + .size(16.0) + .underline(), + ); + let scaled_diameter = (diameter.num / M_TO_UNIT as f32) * n_scale; + ui.label(format!("{} km", scaled_diameter / 1000.0)); } + + // Velocity Orbit Velocity around parent + let actual_velocity = match &parent { + Some((_, vel, _, _)) => (vel.0 - velocity.0).length() / 1000.0, + None => velocity.0.length() / 1000.0, + }; + let velocity_prefix = if parent.is_some() { + "Orbital" + } else { + "Total" + }; + ui.label(RichText::new(format!("{} Velocity", velocity_prefix)).size(16.0).underline()); + ui.horizontal(|ui| { + ui.label(format!("{:.3} km/s", actual_velocity)); + if actual_velocity < 10.0 { + ui.label(format!("({:.3} km/h)", actual_velocity * 3600.0)); + } + }); - let mut new_draw_lines = orbit.draw_lines; - ui.checkbox(&mut new_draw_lines, "Draw Orbit lines"); - if new_draw_lines != orbit.draw_lines { - orbit.draw_lines = new_draw_lines; - if !new_draw_lines { - orbit.lines.clear(); - } + let mut new_apsis = None; + if let Some((_, _, _, p_mass)) = parent { + if let Some(apsis) = apsis { + let distance = ((apsis.aphelion.distance + apsis.perihelion.distance) / 2.0) as f64; + orbit.period = 2.0 * std::f64::consts::PI * f64::sqrt(f64::powf(distance, 3.0) / (G * (p_mass.0 + mass.0))); + ui.label(RichText::new("Orbital Period").size(16.0).underline()); + ui.label(format!("{}", format_seconds(orbit.period))); + new_apsis = Some(apsis); + } } - } - } + + ui.label(RichText::new("Rotation Period").size(16.0).underline()); + ui.label(format!("{}", format_seconds(rotation_speed.0 * 60.0))); + + ui.label(RichText::new("Distance to Camera").size(16.0).underline()); + let (_, camera_pos, _) = camera.single(); + let c_distance_in_units = camera_pos.translation.distance(transform.translation) as f64; + ui.label(format!("{}", format_length((c_distance_in_units / M_TO_UNIT) as f32))); + ui.label(format!("{:.3} au", c_distance_in_units / M_TO_UNIT * M_TO_AU as f64)); + + // Distance to parent + if let Some((parent_pos, _, p_name, _)) = parent { + ui.label(RichText::new(format!("Distance to {}", p_name)).size(16.0).underline()); + let distance_in_m = parent_pos.0.distance(pos.0); + ui.label(format!("{}", format_length(distance_in_m as f32))); + ui.label(format!("{:.3} au", distance_in_m * (M_TO_AU as f64))); + + if let Some(mut apsis) = new_apsis { + //Apsis + ui.label(RichText::new(format!("Periapsis ({})", p_name)).size(16.0).underline()); + ui.label(format!("{}", format_length(apsis.perihelion.distance))); + ui.label(format!("{:.3} au", apsis.perihelion.distance * M_TO_AU)); - if s_children.iter().count() > 0 { - let old_draw_children_orbits = s_children.iter().all(|(_, orbit)| { - orbit.draw_lines - }); - let mut draw_children_orbits = old_draw_children_orbits; - ui.checkbox(&mut draw_children_orbits, "Draw Children Orbits"); - if draw_children_orbits != old_draw_children_orbits { - for (_, orbit) in s_children.iter_mut() { - orbit.draw_lines = draw_children_orbits; - if !draw_children_orbits { - orbit.lines.clear(); + ui.label(RichText::new(format!("Apoapsis ({})", p_name)).size(16.0).underline()); + ui.label(format!("{}", format_length(apsis.aphelion.distance))); + ui.label(format!("{:.3} au", apsis.aphelion.distance * M_TO_AU)); + if ui.button("Reset Apsides").clicked() { + apsis.aphelion.distance = 0.0; + apsis.perihelion.distance = 0.0; + } + + let mut new_draw_lines = orbit.draw_lines; + ui.checkbox(&mut new_draw_lines, "Draw Orbit lines"); + if new_draw_lines != orbit.draw_lines { + orbit.draw_lines = new_draw_lines; + if !new_draw_lines { + orbit.lines.clear(); + } + } } } - } - } - - ui.horizontal(|ui| { - ui.label("Orbit Color"); - let mut rgb = [orbit.color.r(), orbit.color.g(), orbit.color.b()]; - ui.color_edit_button_rgb(&mut rgb); - orbit.color = Color::rgb(rgb[0], rgb[1], rgb[2]); - }); - - ui.label( - RichText::new("Arrows") - .size(16.0) - .underline(), - ); - ui.checkbox(&mut orbit.display_force, "Display force arrow"); - ui.checkbox(&mut orbit.display_velocity, "Display velocity arrow"); - ui.label( - RichText::new("Scale") - .size(14.0) - ); - ui.add( - egui::Slider::new(&mut orbit.arrow_scale, 1..=100000000) - .clamp_to_range(true) - .logarithmic(true) - ); - - // ui.label("Max Orbit Points"); - // let mut old_length = orbit.lines.capacity(); - // ui.add(egui::DragValue::new(&mut old_length).speed(1.0)); - - // if old_length != orbit.lines.capacity() { - // orbit.lines.resize(old_length, Vec3::ZERO); - // } - - ui.with_layout(egui::Layout::bottom_up(egui::Align::Center), |ui| { - if ui.button("Delete Children").clicked() { - for (entity, _) in s_children { + + if s_children.iter().count() > 0 { + let old_draw_children_orbits = s_children.iter().all(|(_, orbit)| { + orbit.draw_lines + }); + let mut draw_children_orbits = old_draw_children_orbits; + ui.checkbox(&mut draw_children_orbits, "Draw Children Orbits"); + if draw_children_orbits != old_draw_children_orbits { + for (_, orbit) in s_children.iter_mut() { + orbit.draw_lines = draw_children_orbits; + if !draw_children_orbits { + orbit.lines.clear(); + } + } + } + } + + ui.horizontal(|ui| { + ui.label("Orbit Color"); + let mut rgb = [orbit.color.r(), orbit.color.g(), orbit.color.b()]; + ui.color_edit_button_rgb(&mut rgb); + orbit.color = Color::rgb(rgb[0], rgb[1], rgb[2]); + }); + + ui.label( + RichText::new("Arrows") + .size(16.0) + .underline(), + ); + ui.checkbox(&mut orbit.display_force, "Display force arrow"); + ui.checkbox(&mut orbit.display_velocity, "Display velocity arrow"); + ui.label( + RichText::new("Scale") + .size(14.0) + ); + ui.add( + egui::Slider::new(&mut orbit.arrow_scale, 1..=100000000) + .clamp_to_range(true) + .logarithmic(true) + ); + + // ui.label("Max Orbit Points"); + // let mut old_length = orbit.lines.capacity(); + // ui.add(egui::DragValue::new(&mut old_length).speed(1.0)); + + // if old_length != orbit.lines.capacity() { + // orbit.lines.resize(old_length, Vec3::ZERO); + // } + ui.separator(); + if ui.button("Delete Children").clicked() { + for (entity, _) in s_children { + commands.entity(entity).despawn_recursive(); + } + } + if ui.button("Delete").clicked() { commands.entity(entity).despawn_recursive(); } - } - if ui.button("Delete").clicked() { - commands.entity(entity).despawn_recursive(); - } }); - }); + }); } } } diff --git a/wasm/index.html b/wasm/index.html index 3d50acf..a1ab5e8 100644 --- a/wasm/index.html +++ b/wasm/index.html @@ -1,17 +1,24 @@ - - + diff --git a/wasm/style.css b/wasm/style.css new file mode 100644 index 0000000..c1948b0 --- /dev/null +++ b/wasm/style.css @@ -0,0 +1,12 @@ +body, html { + margin: 0; + padding: 0; + width: 100%; + height: 100%; +} + +canvas { + display: block; + width: 100vw; + height: 100vh; +} \ No newline at end of file