This commit is contained in:
Quaternions 2024-09-11 13:15:23 -07:00
parent 5b5ed4f38e
commit bd72b50db6

View File

@ -69,10 +69,12 @@ impl JumpImpulse{
&JumpImpulse::Height(height)=>{
//height==-v.y*v.y/(2*g.y);
//use energy to determine max height
let g=gravity.length_squared().sqrt().halve_precision();
let gg=gravity.length_squared();
let g:Planar64=gg.sqrt().fix();
let v_g=gravity.dot(velocity);
//do it backwards
velocity-(*gravity*((v_g*v_g+g*height*(fixed_wide::fixed::Fixed::<2,64>::ONE*2)).sqrt().halve_precision()+v_g)/g).divide()
let radicand=v_g*v_g+(g*height*2).fix::<Fixed<4,128>>();
velocity-(*gravity*(radicand.sqrt().fix::<Planar64>()+v_g)/gg).divide().map(|t|t.fix::<Planar64>())
},
&JumpImpulse::Linear(jump_speed)=>velocity+jump_dir.with_length(jump_speed),
&JumpImpulse::Energy(energy)=>{