use new convenience functions
This commit is contained in:
parent
e8a6f4dab3
commit
b9f280f94b
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -51,6 +51,8 @@ dependencies = [
|
|||||||
name = "linear_ops"
|
name = "linear_ops"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"fixed_wide",
|
||||||
|
"paste",
|
||||||
"ratio_ops",
|
"ratio_ops",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -74,9 +74,9 @@ impl JumpImpulse{
|
|||||||
let v_g=gravity.dot(velocity);
|
let v_g=gravity.dot(velocity);
|
||||||
//do it backwards
|
//do it backwards
|
||||||
let radicand=v_g*v_g+(g*height*2).fix_4();
|
let radicand=v_g*v_g+(g*height*2).fix_4();
|
||||||
velocity-(*gravity*(radicand.sqrt().fix_2()+v_g)/gg).divide().map(|t|t.fix_1())
|
velocity-(*gravity*(radicand.sqrt().fix_2()+v_g)/gg).divide().fix_1()
|
||||||
},
|
},
|
||||||
&JumpImpulse::Linear(jump_speed)=>velocity+(jump_dir*jump_speed/jump_dir.length_squared().sqrt()).divide().map(|t|t.fix_1()),
|
&JumpImpulse::Linear(jump_speed)=>velocity+(jump_dir*jump_speed/jump_dir.length()).divide().fix_1(),
|
||||||
&JumpImpulse::Energy(energy)=>{
|
&JumpImpulse::Energy(energy)=>{
|
||||||
//calculate energy
|
//calculate energy
|
||||||
//let e=gravity.dot(velocity);
|
//let e=gravity.dot(velocity);
|
||||||
@ -90,8 +90,8 @@ impl JumpImpulse{
|
|||||||
pub fn get_jump_deltav(&self,gravity:&Planar64Vec3,mass:Planar64)->Planar64{
|
pub fn get_jump_deltav(&self,gravity:&Planar64Vec3,mass:Planar64)->Planar64{
|
||||||
//gravity.length() is actually the proper calculation because the jump is always opposite the gravity direction
|
//gravity.length() is actually the proper calculation because the jump is always opposite the gravity direction
|
||||||
match self{
|
match self{
|
||||||
&JumpImpulse::Time(time)=>(gravity.length_squared().sqrt().fix_1()*time/2).divide().fix_1(),
|
&JumpImpulse::Time(time)=>(gravity.length().fix_1()*time/2).divide().fix_1(),
|
||||||
&JumpImpulse::Height(height)=>(gravity.length_squared().sqrt()*height*2).sqrt().fix_1(),
|
&JumpImpulse::Height(height)=>(gravity.length()*height*2).sqrt().fix_1(),
|
||||||
&JumpImpulse::Linear(deltav)=>deltav,
|
&JumpImpulse::Linear(deltav)=>deltav,
|
||||||
&JumpImpulse::Energy(energy)=>(energy.sqrt()*2/mass.sqrt()).divide().fix_1(),
|
&JumpImpulse::Energy(energy)=>(energy.sqrt()*2/mass.sqrt()).divide().fix_1(),
|
||||||
}
|
}
|
||||||
@ -128,7 +128,7 @@ impl JumpSettings{
|
|||||||
let js=jump_speed.fix_2();
|
let js=jump_speed.fix_2();
|
||||||
if j<js{
|
if j<js{
|
||||||
//weak booster: just do a regular jump
|
//weak booster: just do a regular jump
|
||||||
boost_vel+(jump_dir*(js-j)/jump_dir.length_squared().sqrt()).divide().map(|t|t.fix_1())
|
boost_vel+jump_dir.with_length(js-j).divide().fix_1()
|
||||||
}else{
|
}else{
|
||||||
//activate booster normally, jump does nothing
|
//activate booster normally, jump does nothing
|
||||||
boost_vel
|
boost_vel
|
||||||
@ -144,10 +144,10 @@ impl JumpSettings{
|
|||||||
let js=jump_speed.fix_2();
|
let js=jump_speed.fix_2();
|
||||||
if j<js{
|
if j<js{
|
||||||
//speed in direction of jump cannot be lower than amount
|
//speed in direction of jump cannot be lower than amount
|
||||||
boost_vel+(jump_dir*(js-j)/jump_dir.length_squared().sqrt()).divide().map(|t|t.fix_1())
|
boost_vel+jump_dir.with_length(js-j).divide().fix_1()
|
||||||
}else{
|
}else{
|
||||||
//boost and jump add together
|
//boost and jump add together
|
||||||
boost_vel+(jump_dir*js/jump_dir.length_squared().sqrt()).divide().map(|t|t.fix_1())
|
boost_vel+jump_dir.with_length(js).divide().fix_1()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(false,JumpCalculation::Max)=>{
|
(false,JumpCalculation::Max)=>{
|
||||||
@ -161,7 +161,7 @@ impl JumpSettings{
|
|||||||
let js=jump_speed.fix_2();
|
let js=jump_speed.fix_2();
|
||||||
if boost_dot<js{
|
if boost_dot<js{
|
||||||
//weak boost is extended to jump speed
|
//weak boost is extended to jump speed
|
||||||
boost_vel+(jump_dir*(js-boost_dot)/jump_dir.length_squared().sqrt()).divide().map(|t|t.fix_1())
|
boost_vel+jump_dir.with_length(js-boost_dot).divide().fix_1()
|
||||||
}else{
|
}else{
|
||||||
//activate booster normally, jump does nothing
|
//activate booster normally, jump does nothing
|
||||||
boost_vel
|
boost_vel
|
||||||
@ -173,7 +173,7 @@ impl JumpSettings{
|
|||||||
Some(booster)=>booster.boost(rel_velocity),
|
Some(booster)=>booster.boost(rel_velocity),
|
||||||
None=>rel_velocity,
|
None=>rel_velocity,
|
||||||
};
|
};
|
||||||
boost_vel+(jump_dir*jump_speed/jump_dir.length_squared().sqrt()).divide().map(|t|t.fix_1())
|
boost_vel+jump_dir.with_length(jump_speed).divide().fix_1()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -268,7 +268,7 @@ impl StrafeSettings{
|
|||||||
let d=velocity.dot(control_dir);
|
let d=velocity.dot(control_dir);
|
||||||
let mv=self.mv.fix_2();
|
let mv=self.mv.fix_2();
|
||||||
match d<mv{
|
match d<mv{
|
||||||
true=>Some(velocity+(control_dir*self.air_accel_limit.map_or(mv-d,|limit|limit.fix_2().min(mv-d))).map(|t|t.fix_1())),
|
true=>Some(velocity+(control_dir*self.air_accel_limit.map_or(mv-d,|limit|limit.fix_2().min(mv-d))).fix_1()),
|
||||||
false=>None,
|
false=>None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -289,7 +289,7 @@ pub struct PropulsionSettings{
|
|||||||
}
|
}
|
||||||
impl PropulsionSettings{
|
impl PropulsionSettings{
|
||||||
pub fn acceleration(&self,control_dir:Planar64Vec3)->Planar64Vec3{
|
pub fn acceleration(&self,control_dir:Planar64Vec3)->Planar64Vec3{
|
||||||
(control_dir*self.magnitude).map(|t|t.fix_1())
|
(control_dir*self.magnitude).fix_1()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,7 +309,7 @@ pub struct WalkSettings{
|
|||||||
impl WalkSettings{
|
impl WalkSettings{
|
||||||
pub fn accel(&self,target_diff:Planar64Vec3,gravity:Planar64Vec3)->Planar64{
|
pub fn accel(&self,target_diff:Planar64Vec3,gravity:Planar64Vec3)->Planar64{
|
||||||
//TODO: fallible walk accel
|
//TODO: fallible walk accel
|
||||||
let diff_len=target_diff.length_squared().sqrt().fix_1();
|
let diff_len=target_diff.length().fix_1();
|
||||||
let friction=if diff_len<self.accelerate.topspeed{
|
let friction=if diff_len<self.accelerate.topspeed{
|
||||||
self.static_friction
|
self.static_friction
|
||||||
}else{
|
}else{
|
||||||
@ -330,7 +330,7 @@ impl WalkSettings{
|
|||||||
if cr==crate::integer::vec3::ZERO_2{
|
if cr==crate::integer::vec3::ZERO_2{
|
||||||
crate::integer::vec3::ZERO
|
crate::integer::vec3::ZERO
|
||||||
}else{
|
}else{
|
||||||
(cr.cross(normal)*self.accelerate.topspeed/(n*(nm*nm-d*d).sqrt())).divide().map(|t|t.fix_1())
|
(cr.cross(normal)*self.accelerate.topspeed/(n*(nm*nm-d*d).sqrt())).divide().fix_1()
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
crate::integer::vec3::ZERO
|
crate::integer::vec3::ZERO
|
||||||
@ -339,7 +339,7 @@ impl WalkSettings{
|
|||||||
pub fn is_slope_walkable(&self,normal:Planar64Vec3,up:Planar64Vec3)->bool{
|
pub fn is_slope_walkable(&self,normal:Planar64Vec3,up:Planar64Vec3)->bool{
|
||||||
//normal is not guaranteed to be unit length
|
//normal is not guaranteed to be unit length
|
||||||
let ny=normal.dot(up);
|
let ny=normal.dot(up);
|
||||||
let h=normal.length_squared().sqrt().fix_1();
|
let h=normal.length().fix_1();
|
||||||
//remember this is a normal vector
|
//remember this is a normal vector
|
||||||
ny.is_negative()&&h*self.surf_dot<ny
|
ny.is_negative()&&h*self.surf_dot<ny
|
||||||
}
|
}
|
||||||
@ -381,7 +381,7 @@ impl LadderSettings{
|
|||||||
if cr==crate::integer::vec3::ZERO_2{
|
if cr==crate::integer::vec3::ZERO_2{
|
||||||
crate::integer::vec3::ZERO
|
crate::integer::vec3::ZERO
|
||||||
}else{
|
}else{
|
||||||
(cr.cross(normal)*self.accelerate.topspeed/(n*(nm*nm-d*d).sqrt())).divide().map(|t|t.fix_1())
|
(cr.cross(normal)*self.accelerate.topspeed/(n*(nm*nm-d*d).sqrt())).divide().fix_1()
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
crate::integer::vec3::ZERO
|
crate::integer::vec3::ZERO
|
||||||
@ -413,7 +413,7 @@ impl Hitbox{
|
|||||||
}
|
}
|
||||||
pub fn source()->Self{
|
pub fn source()->Self{
|
||||||
Self{
|
Self{
|
||||||
halfsize:((int3(33,73,33)>>1)*VALVE_SCALE).map(|t|t.fix_1()),
|
halfsize:((int3(33,73,33)>>1)*VALVE_SCALE).fix_1(),
|
||||||
mesh:HitboxMesh::Box,
|
mesh:HitboxMesh::Box,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -538,7 +538,7 @@ impl StyleModifiers{
|
|||||||
calculation:JumpCalculation::JumpThenBoost,
|
calculation:JumpCalculation::JumpThenBoost,
|
||||||
limit_minimum:true,
|
limit_minimum:true,
|
||||||
}),
|
}),
|
||||||
gravity:(int3(0,-800,0)*VALVE_SCALE).map(|t|t.fix_1()),
|
gravity:(int3(0,-800,0)*VALVE_SCALE).fix_1(),
|
||||||
mass:int(1),
|
mass:int(1),
|
||||||
rocket:None,
|
rocket:None,
|
||||||
walk:Some(WalkSettings{
|
walk:Some(WalkSettings{
|
||||||
@ -561,7 +561,7 @@ impl StyleModifiers{
|
|||||||
magnitude:int(12),//?
|
magnitude:int(12),//?
|
||||||
}),
|
}),
|
||||||
hitbox:Hitbox::source(),
|
hitbox:Hitbox::source(),
|
||||||
camera_offset:((int3(0,64,0)-(int3(0,73,0)>>1))*VALVE_SCALE).map(|t|t.fix_1()),
|
camera_offset:((int3(0,64,0)-(int3(0,73,0)>>1))*VALVE_SCALE).fix_1(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn source_surf()->Self{
|
pub fn source_surf()->Self{
|
||||||
@ -579,7 +579,7 @@ impl StyleModifiers{
|
|||||||
calculation:JumpCalculation::JumpThenBoost,
|
calculation:JumpCalculation::JumpThenBoost,
|
||||||
limit_minimum:true,
|
limit_minimum:true,
|
||||||
}),
|
}),
|
||||||
gravity:(int3(0,-800,0)*VALVE_SCALE).map(|t|t.fix_1()),
|
gravity:(int3(0,-800,0)*VALVE_SCALE).fix_1(),
|
||||||
mass:int(1),
|
mass:int(1),
|
||||||
rocket:None,
|
rocket:None,
|
||||||
walk:Some(WalkSettings{
|
walk:Some(WalkSettings{
|
||||||
@ -602,7 +602,7 @@ impl StyleModifiers{
|
|||||||
magnitude:int(12),//?
|
magnitude:int(12),//?
|
||||||
}),
|
}),
|
||||||
hitbox:Hitbox::source(),
|
hitbox:Hitbox::source(),
|
||||||
camera_offset:((int3(0,64,0)-(int3(0,73,0)>>1))*VALVE_SCALE).map(|t|t.fix_1()),
|
camera_offset:((int3(0,64,0)-(int3(0,73,0)>>1))*VALVE_SCALE).fix_1(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user