@@ -61,11 +61,28 @@ fn desmos_list(name: &str, values: &[f64]) -> String {
6161
6262#[ derive( Serialize ) ]
6363struct PhysicsThing {
64- rails1 : Vec < ( f64 , f64 , f64 ) > ,
65- rails2 : Vec < ( f64 , f64 , f64 ) > ,
64+ rails1 : Vec < [ f64 ; 3 ] > ,
65+ rails2 : Vec < [ f64 ; 3 ] > ,
6666 cross_support : Vec < bool > ,
67- hl_pos : Vec < ( f64 , f64 , f64 ) > ,
68- hl_up : Vec < ( f64 , f64 , f64 ) > ,
67+ hl_pos : Vec < [ f64 ; 3 ] > ,
68+ hl_up : Vec < [ f64 ; 3 ] > ,
69+ hl_fwd : Vec < [ f64 ; 3 ] > ,
70+ is_extra : Vec < bool > ,
71+ }
72+
73+ fn codegen ( thing : & PhysicsThing ) -> String {
74+ format ! ( r#"
75+ class_name Data
76+
77+ var rail1 = {:?}
78+ var rail2 = {:?}
79+ var cross = {:?}
80+ var pos = {:?}
81+ var up = {:?}
82+ var fwd = {:?}
83+ var is_extra = {:?}
84+ "#
85+ , thing. rails1, thing. rails2, thing. cross_support, thing. hl_pos, thing. hl_up, thing. hl_fwd, thing. is_extra)
6986}
7087
7188fn main ( ) {
@@ -139,29 +156,48 @@ fn main() {
139156 cross_support : Vec :: new ( ) ,
140157 hl_pos : Vec :: new ( ) ,
141158 hl_up : Vec :: new ( ) ,
159+ hl_fwd : Vec :: new ( ) ,
160+ is_extra : Vec :: new ( ) ,
142161 } ;
143162 let mut phys = physics:: PhysicsStateV3 :: new ( 1.0 , -0.01 , & curve, 0.5 , MU ) ;
144163 let mut i = 0 ;
164+ const CROSS_DIST : f64 = 2.0 ;
165+ let mut last_cl_pos: Option < MyVector3 < f64 > > = None ;
166+ let mut distance_since_last_cross = 0.0 ;
167+ const RAIL_MULT : f64 = 0.75 ;
145168 while phys. step ( & 0.05 , & curve) . is_some ( ) {
146169 i += 1 ;
147- if i % 20 != 0 {
170+ if i % 5 != 0 {
148171 continue ;
149172 }
150- let track_centerline = phys. x ( ) . inner ( ) - phys. hl_normal ( ) . clone ( ) * 1.0 * * phys. o ( ) ;
173+ let track_centerline = phys. x ( ) . inner ( ) - phys. hl_normal ( ) . clone ( ) * RAIL_MULT * * phys. o ( ) ;
174+ if let Some ( p) = & last_cl_pos {
175+ distance_since_last_cross += ( track_centerline. clone ( ) - p. clone ( ) ) . magnitude ( ) ;
176+ if distance_since_last_cross > CROSS_DIST {
177+ distance_since_last_cross = 0.0 ;
178+ thing. cross_support . push ( true ) ;
179+ } else {
180+ thing. cross_support . push ( false ) ;
181+ }
182+ } else {
183+ thing. cross_support . push ( false ) ;
184+ }
185+ last_cl_pos = Some ( track_centerline. clone ( ) ) ;
151186 let binormal = phys. v ( ) . inner ( ) . cross ( phys. hl_normal ( ) ) . normalize ( ) ;
152- let rail1 = track_centerline. clone ( ) + binormal. clone ( ) * * phys. o ( ) ;
153- let rail2 = track_centerline. clone ( ) - binormal * * phys. o ( ) ;
187+ let rail1 = track_centerline. clone ( ) + binormal. clone ( ) * * phys. o ( ) * RAIL_MULT ;
188+ let rail2 = track_centerline. clone ( ) - binormal * * phys. o ( ) * RAIL_MULT ;
154189 println ! ( "{:.4?} {:.4?} {:.4?}" , track_centerline, rail1, rail2) ;
155- thing. rails1 . push ( ( rail1. x , rail1. y , rail1. z ) ) ;
156- thing. rails2 . push ( ( rail2. x , rail2. y , rail2. z ) ) ;
157- thing. cross_support . push ( false ) ;
190+ thing. rails1 . push ( [ rail1. x , rail1. y , rail1. z ] ) ;
191+ thing. rails2 . push ( [ rail2. x , rail2. y , rail2. z ] ) ;
158192 let hl_pos = curve. curve_at ( phys. u ( ) ) . unwrap ( ) ;
159- thing. hl_pos . push ( ( hl_pos. x , hl_pos. y , hl_pos. z ) ) ;
193+ thing. hl_pos . push ( [ hl_pos. x , hl_pos. y , hl_pos. z ] ) ;
160194 let hl_up = phys. hl_normal ( ) ;
161- thing. hl_up . push ( ( hl_up. x , hl_up. y , hl_up. z ) ) ;
195+ thing. hl_up . push ( [ hl_up. x , hl_up. y , hl_up. z ] ) ;
196+ let hl_fwd = phys. v ( ) . inner ( ) ;
197+ thing. hl_fwd . push ( [ hl_fwd. x , hl_fwd. y , hl_fwd. z ] ) ;
198+ thing. is_extra . push ( false ) ;
162199 }
163200
164- //let mut extras = vec![];
165201 for c in & curve. additional {
166202 let mut u = 0.0 ;
167203 while u <= 1.0 {
@@ -171,37 +207,67 @@ fn main() {
171207 . make_ortho_to ( & tangent)
172208 . normalize ( ) ;
173209 let com_pos = hl_pos. clone ( ) - up. clone ( ) * * phys. o ( ) ;
174- let track_centerline = hl_pos. clone ( ) - up. clone ( ) * * phys. o ( ) * 2.0 ;
210+ let track_centerline = hl_pos. clone ( ) - up. clone ( ) * * phys. o ( ) * ( 1.0 + RAIL_MULT ) ;
211+ if let Some ( p) = & last_cl_pos {
212+ distance_since_last_cross += ( track_centerline. clone ( ) - p. clone ( ) ) . magnitude ( ) ;
213+ if distance_since_last_cross > CROSS_DIST {
214+ distance_since_last_cross = 0.0 ;
215+ thing. cross_support . push ( true ) ;
216+ } else {
217+ thing. cross_support . push ( false ) ;
218+ }
219+ } else {
220+ thing. cross_support . push ( false ) ;
221+ }
222+ last_cl_pos = Some ( track_centerline. clone ( ) ) ;
175223 let binormal = up. cross ( & tangent) . normalize ( ) ;
176- let rail1 = track_centerline. clone ( ) - binormal. clone ( ) * * phys. o ( ) ;
177- let rail2 = track_centerline. clone ( ) + binormal. clone ( ) * * phys. o ( ) ;
224+ let rail1 = track_centerline. clone ( ) - binormal. clone ( ) * * phys. o ( ) * RAIL_MULT ;
225+ let rail2 = track_centerline. clone ( ) + binormal. clone ( ) * * phys. o ( ) * RAIL_MULT ;
178226
179- thing. rails1 . push ( ( rail1. x , rail1. y , rail1. z ) ) ;
180- thing. rails2 . push ( ( rail2. x , rail2. y , rail2. z ) ) ;
181- thing. cross_support . push ( false ) ;
227+ thing. rails1 . push ( [ rail1. x , rail1. y , rail1. z ] ) ;
228+ thing. rails2 . push ( [ rail2. x , rail2. y , rail2. z ] ) ;
229+ thing. is_extra . push ( true ) ;
182230
183231 //let hl_pos = curve.curve_at(phys.u()).unwrap();
184- thing. hl_pos . push ( ( hl_pos. x , hl_pos. y , hl_pos. z ) ) ;
232+ // thing.hl_pos.push((hl_pos.x, hl_pos.y, hl_pos.z));
185233 //let hl_up = phys.hl_normal();
186- thing. hl_up . push ( ( up. x , up. y , up. z ) ) ;
234+ // thing.hl_up.push((up.x, up.y, up.z));
187235
188236 /*extras.push((
189237 Vector3::new(com_pos.x as f32, com_pos.y as f32, com_pos.z as f32),
190238 0.0,
191239 true,
192240 ));*/
193- u += 0.1 ;
241+ u += 0.001 ;
194242 }
195243 }
196244
197- File :: create ( "/tmp/rail1.json" )
245+ File :: create ( "/tmp/data.gd" ) . unwrap ( ) . write_all ( codegen ( & thing) . as_bytes ( ) ) . unwrap ( ) ;
246+ /*File::create("/tmp/rail1.json")
198247 .unwrap()
199248 .write_all(&format!("{:?}", thing.rails1).as_bytes())
200249 .unwrap();
201250 File::create("/tmp/rail2.json")
202251 .unwrap()
203252 .write_all(&format!("{:?}", thing.rails2).as_bytes())
204253 .unwrap();
254+ File::create("/tmp/cross.json")
255+ .unwrap()
256+ .write_all(&format!("{:?}", thing.cross_support).as_bytes())
257+ .unwrap();
258+ File::create("/tmp/pos.json")
259+ .unwrap()
260+ .write_all(&format!("{:?}", thing.hl_pos).as_bytes())
261+ .unwrap();
262+ File::create("/tmp/fwd.json")
263+ .unwrap()
264+ .write_all(&format!("{:?}", thing.hl_fwd).as_bytes())
265+ .unwrap();
266+ File::create("/tmp/up.json")
267+ .unwrap()
268+ .write_all(&format!("{:?}", thing.hl_up).as_bytes())
269+ .unwrap();*/
270+
205271
206272 println ! ( "{}" , thing. rails1. len( ) ) ;
207273 println ! ( "{:?}" , thing. rails1) ;
0 commit comments