physics.rs cleared
This commit is contained in:
parent
fc7d4b7e0c
commit
bbc9a89ad7
@ -410,7 +410,7 @@ impl HitboxMesh{
|
|||||||
let transform=PhysicsMeshTransform::new(transform);
|
let transform=PhysicsMeshTransform::new(transform);
|
||||||
let transformed_mesh=TransformedMesh::new(mesh.complete_mesh_view(),&transform);
|
let transformed_mesh=TransformedMesh::new(mesh.complete_mesh_view(),&transform);
|
||||||
for vert in transformed_mesh.verts(){
|
for vert in transformed_mesh.verts(){
|
||||||
aabb.grow(vert);
|
aabb.grow(vert.fix_1());
|
||||||
}
|
}
|
||||||
Self{
|
Self{
|
||||||
halfsize:aabb.size()>>1,
|
halfsize:aabb.size()>>1,
|
||||||
@ -438,7 +438,7 @@ impl StyleHelper for StyleModifiers{
|
|||||||
|
|
||||||
fn get_control_dir(&self,controls:Controls)->Planar64Vec3{
|
fn get_control_dir(&self,controls:Controls)->Planar64Vec3{
|
||||||
//don't get fancy just do it
|
//don't get fancy just do it
|
||||||
let mut control_dir:Planar64Vec3 = vec3::ZERO;
|
let mut control_dir:Planar64Vec3=vec3::ZERO;
|
||||||
//Apply mask after held check so you can require non-allowed keys to be held for some reason
|
//Apply mask after held check so you can require non-allowed keys to be held for some reason
|
||||||
let controls=controls.intersection(self.controls_mask);
|
let controls=controls.intersection(self.controls_mask);
|
||||||
if controls.contains(Controls::MoveForward){
|
if controls.contains(Controls::MoveForward){
|
||||||
@ -475,7 +475,10 @@ impl StyleHelper for StyleModifiers{
|
|||||||
gameplay_style::HitboxMesh::Box=>PhysicsMesh::unit_cube(),
|
gameplay_style::HitboxMesh::Box=>PhysicsMesh::unit_cube(),
|
||||||
gameplay_style::HitboxMesh::Cylinder=>PhysicsMesh::unit_cylinder(),
|
gameplay_style::HitboxMesh::Cylinder=>PhysicsMesh::unit_cylinder(),
|
||||||
};
|
};
|
||||||
let transform=mat3::from_diagonal(self.hitbox.halfsize).extend_column(vec3::ZERO);
|
let transform=integer::Planar64Affine3::new(
|
||||||
|
mat3::from_diagonal(self.hitbox.halfsize),
|
||||||
|
vec3::ZERO
|
||||||
|
);
|
||||||
HitboxMesh::new(mesh,transform)
|
HitboxMesh::new(mesh,transform)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -766,9 +769,9 @@ impl TouchingState{
|
|||||||
//TODO: trey push solve
|
//TODO: trey push solve
|
||||||
for contact in &self.contacts{
|
for contact in &self.contacts{
|
||||||
let n=contact_normal(models,hitbox_mesh,contact);
|
let n=contact_normal(models,hitbox_mesh,contact);
|
||||||
let d=n.dot128(*velocity);
|
let d=n.dot(*velocity);
|
||||||
if d<0{
|
if d.is_negative(){
|
||||||
*velocity-=n*Planar64::raw(((d<<32)/n.dot128(n)) as i64);
|
*velocity-=(n*d/n.length_squared()).divide().fix_1();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -776,9 +779,9 @@ impl TouchingState{
|
|||||||
//TODO: trey push solve
|
//TODO: trey push solve
|
||||||
for contact in &self.contacts{
|
for contact in &self.contacts{
|
||||||
let n=contact_normal(models,hitbox_mesh,contact);
|
let n=contact_normal(models,hitbox_mesh,contact);
|
||||||
let d=n.dot128(*acceleration);
|
let d=n.dot(*acceleration);
|
||||||
if d<0{
|
if d.is_negative(){
|
||||||
*acceleration-=n*Planar64::raw(((d<<32)/n.dot128(n)) as i64);
|
*acceleration-=(n*d/n.length_squared()).divide().fix_1();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -855,19 +858,19 @@ impl Body{
|
|||||||
//v+a*t==0
|
//v+a*t==0
|
||||||
//goober code
|
//goober code
|
||||||
if !self.acceleration.x.is_zero(){
|
if !self.acceleration.x.is_zero(){
|
||||||
let t=Time::from(-self.velocity.x/self.acceleration.x);
|
let t=Time::from(-(self.velocity.x/self.acceleration.x).divide().fix_1());
|
||||||
if t0<t&&t<t1{
|
if t0<t&&t<t1{
|
||||||
aabb.grow(self.extrapolated_position(t));
|
aabb.grow(self.extrapolated_position(t));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !self.acceleration.y.is_zero(){
|
if !self.acceleration.y.is_zero(){
|
||||||
let t=Time::from(-self.velocity.y/self.acceleration.y);
|
let t=Time::from(-(self.velocity.y/self.acceleration.y).divide().fix_1());
|
||||||
if t0<t&&t<t1{
|
if t0<t&&t<t1{
|
||||||
aabb.grow(self.extrapolated_position(t));
|
aabb.grow(self.extrapolated_position(t));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !self.acceleration.z.is_zero(){
|
if !self.acceleration.z.is_zero(){
|
||||||
let t=Time::from(-self.velocity.z/self.acceleration.z);
|
let t=Time::from(-(self.velocity.z/self.acceleration.z).divide().fix_1());
|
||||||
if t0<t&&t<t1{
|
if t0<t&&t<t1{
|
||||||
aabb.grow(self.extrapolated_position(t));
|
aabb.grow(self.extrapolated_position(t));
|
||||||
}
|
}
|
||||||
@ -1157,7 +1160,7 @@ impl PhysicsContext{
|
|||||||
let mut aabb=aabb::Aabb::default();
|
let mut aabb=aabb::Aabb::default();
|
||||||
let transformed_mesh=TransformedMesh::new(view,transform);
|
let transformed_mesh=TransformedMesh::new(view,transform);
|
||||||
for v in transformed_mesh.verts(){
|
for v in transformed_mesh.verts(){
|
||||||
aabb.grow(v);
|
aabb.grow(v.fix_1());
|
||||||
}
|
}
|
||||||
(ConvexMeshId{
|
(ConvexMeshId{
|
||||||
model_id,
|
model_id,
|
||||||
@ -1408,7 +1411,8 @@ fn teleport_to_spawn(
|
|||||||
)->Result<(),TeleportToSpawnError>{
|
)->Result<(),TeleportToSpawnError>{
|
||||||
const EPSILON:Planar64=Planar64::raw((1<<32)/16);
|
const EPSILON:Planar64=Planar64::raw((1<<32)/16);
|
||||||
let transform=models.get_model_transform(stage.spawn()).ok_or(TeleportToSpawnError::NoModel)?;
|
let transform=models.get_model_transform(stage.spawn()).ok_or(TeleportToSpawnError::NoModel)?;
|
||||||
let point=transform.vertex.y_axis+Planar64Vec3::new([Planar64::ZERO,style.hitbox.halfsize.y+EPSILON,Planar64::ZERO]);
|
//TODO: transform.vertex.matrix3.col(1)+transform.vertex.translation
|
||||||
|
let point=transform.vertex.transform_point3(vec3::Y).fix_1()+Planar64Vec3::new([Planar64::ZERO,style.hitbox.halfsize.y+EPSILON,Planar64::ZERO]);
|
||||||
teleport(point,move_state,body,touching,run,mode_state,Some(mode),models,hitbox_mesh,bvh,style,camera,input_state,time);
|
teleport(point,move_state,body,touching,run,mode_state,Some(mode),models,hitbox_mesh,bvh,style,camera,input_state,time);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -1496,7 +1500,7 @@ fn run_teleport_behaviour(
|
|||||||
}
|
}
|
||||||
if let Some(&gameplay_attributes::Wormhole{destination_model})=wormhole{
|
if let Some(&gameplay_attributes::Wormhole{destination_model})=wormhole{
|
||||||
if let (Some(origin),Some(destination))=(models.get_model_transform(model_id),models.get_model_transform(destination_model)){
|
if let (Some(origin),Some(destination))=(models.get_model_transform(model_id),models.get_model_transform(destination_model)){
|
||||||
let point=body.position-origin.vertex.col(3)+destination.vertex.col(3);
|
let point=body.position-origin.vertex.translation+destination.vertex.translation;
|
||||||
//TODO: camera angles
|
//TODO: camera angles
|
||||||
teleport(point,move_state,body,touching,run,mode_state,mode,models,hitbox_mesh,bvh,style,camera,input_state,time);
|
teleport(point,move_state,body,touching,run,mode_state,mode,models,hitbox_mesh,bvh,style,camera,input_state,time);
|
||||||
}
|
}
|
||||||
@ -1529,7 +1533,7 @@ fn collision_start_contact(
|
|||||||
Some(gameplay_attributes::ContactingBehaviour::Surf)=>println!("I'm surfing!"),
|
Some(gameplay_attributes::ContactingBehaviour::Surf)=>println!("I'm surfing!"),
|
||||||
Some(gameplay_attributes::ContactingBehaviour::Cling)=>println!("Unimplemented!"),
|
Some(gameplay_attributes::ContactingBehaviour::Cling)=>println!("Unimplemented!"),
|
||||||
&Some(gameplay_attributes::ContactingBehaviour::Elastic(elasticity))=>{
|
&Some(gameplay_attributes::ContactingBehaviour::Elastic(elasticity))=>{
|
||||||
let reflected_velocity=body.velocity+(body.velocity-incident_velocity)*Planar64::raw(elasticity as i64+1);
|
let reflected_velocity=body.velocity+((body.velocity-incident_velocity)*Planar64::raw(elasticity as i64+1)).fix_1();
|
||||||
set_velocity(body,touching,models,hitbox_mesh,reflected_velocity);
|
set_velocity(body,touching,models,hitbox_mesh,reflected_velocity);
|
||||||
},
|
},
|
||||||
Some(gameplay_attributes::ContactingBehaviour::Ladder(contacting_ladder))=>
|
Some(gameplay_attributes::ContactingBehaviour::Ladder(contacting_ladder))=>
|
||||||
@ -1547,7 +1551,7 @@ fn collision_start_contact(
|
|||||||
},
|
},
|
||||||
Some(gameplay_attributes::ContactingBehaviour::NoJump)=>todo!("nyi"),
|
Some(gameplay_attributes::ContactingBehaviour::NoJump)=>todo!("nyi"),
|
||||||
None=>if let Some(walk_settings)=&style.walk{
|
None=>if let Some(walk_settings)=&style.walk{
|
||||||
if walk_settings.is_slope_walkable(contact_normal(models,hitbox_mesh,&contact),Planar64Vec3::Y){
|
if walk_settings.is_slope_walkable(contact_normal(models,hitbox_mesh,&contact),vec3::Y){
|
||||||
//ground
|
//ground
|
||||||
let (gravity,target_velocity)=ground_things(walk_settings,&contact,touching,models,hitbox_mesh,style,camera,input_state);
|
let (gravity,target_velocity)=ground_things(walk_settings,&contact,touching,models,hitbox_mesh,style,camera,input_state);
|
||||||
let walk_state=ContactMoveState::ground(walk_settings,body,gravity,target_velocity,contact);
|
let walk_state=ContactMoveState::ground(walk_settings,body,gravity,target_velocity,contact);
|
||||||
@ -1847,7 +1851,7 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI
|
|||||||
//TODO: spawn at the bottom of the start zone plus the hitbox size
|
//TODO: spawn at the bottom of the start zone plus the hitbox size
|
||||||
//TODO: set camera andles to face the same way as the start zone
|
//TODO: set camera andles to face the same way as the start zone
|
||||||
data.models.get_model_transform(mode.get_start().into()).map(|transform|
|
data.models.get_model_transform(mode.get_start().into()).map(|transform|
|
||||||
transform.vertex.col(3)
|
transform.vertex.translation
|
||||||
)
|
)
|
||||||
).unwrap_or(vec3::ZERO);
|
).unwrap_or(vec3::ZERO);
|
||||||
set_position(spawn_point,&mut state.move_state,&mut state.body,&mut state.touching,&mut state.run,&mut state.mode_state,mode,&data.models,&data.hitbox_mesh,&data.bvh,&state.style,&state.camera,&state.input_state,state.time);
|
set_position(spawn_point,&mut state.move_state,&mut state.body,&mut state.touching,&mut state.run,&mut state.mode_state,mode,&data.models,&data.hitbox_mesh,&data.bvh,&state.style,&state.camera,&state.input_state,state.time);
|
||||||
@ -1917,7 +1921,7 @@ mod test{
|
|||||||
use strafesnet_common::integer::{vec3::{self,int as int3},mat3};
|
use strafesnet_common::integer::{vec3::{self,int as int3},mat3};
|
||||||
use super::*;
|
use super::*;
|
||||||
fn test_collision_axis_aligned(relative_body:Body,expected_collision_time:Option<Time>){
|
fn test_collision_axis_aligned(relative_body:Body,expected_collision_time:Option<Time>){
|
||||||
let h0=HitboxMesh::new(PhysicsMesh::unit_cube(),mat3::from_diagonal(int3(5,1,5)>>1).extend_column(vec3::ZERO));
|
let h0=HitboxMesh::new(PhysicsMesh::unit_cube(),integer::Planar64Affine3::new(mat3::from_diagonal(int3(5,1,5)>>1),vec3::ZERO));
|
||||||
let h1=StyleModifiers::roblox_bhop().calculate_mesh();
|
let h1=StyleModifiers::roblox_bhop().calculate_mesh();
|
||||||
let hitbox_mesh=h1.transformed_mesh();
|
let hitbox_mesh=h1.transformed_mesh();
|
||||||
let platform_mesh=h0.transformed_mesh();
|
let platform_mesh=h0.transformed_mesh();
|
||||||
@ -1927,11 +1931,14 @@ mod test{
|
|||||||
}
|
}
|
||||||
fn test_collision_rotated(relative_body:Body,expected_collision_time:Option<Time>){
|
fn test_collision_rotated(relative_body:Body,expected_collision_time:Option<Time>){
|
||||||
let h0=HitboxMesh::new(PhysicsMesh::unit_cube(),
|
let h0=HitboxMesh::new(PhysicsMesh::unit_cube(),
|
||||||
integer::Planar64Mat3::from_rows([
|
integer::Planar64Affine3::new(
|
||||||
int3(5,0,1)>>1,
|
integer::Planar64Mat3::from_rows([
|
||||||
int3(0,1,0)>>1,
|
int3(5,0,1)>>1,
|
||||||
int3(-1,0,5)>>1,
|
int3(0,1,0)>>1,
|
||||||
]).extend_column(vec3::ZERO),
|
int3(-1,0,5)>>1,
|
||||||
|
]),
|
||||||
|
vec3::ZERO
|
||||||
|
),
|
||||||
);
|
);
|
||||||
let h1=StyleModifiers::roblox_bhop().calculate_mesh();
|
let h1=StyleModifiers::roblox_bhop().calculate_mesh();
|
||||||
let hitbox_mesh=h1.transformed_mesh();
|
let hitbox_mesh=h1.transformed_mesh();
|
||||||
|
Loading…
Reference in New Issue
Block a user