forked from StrafesNET/strafe-client
use bvh
This commit is contained in:
parent
2b47827383
commit
fc91d644e6
@ -297,6 +297,7 @@ pub struct PhysicsState{
|
|||||||
pub grounded:bool,
|
pub grounded:bool,
|
||||||
//all models
|
//all models
|
||||||
pub models:Vec<ModelPhysics>,
|
pub models:Vec<ModelPhysics>,
|
||||||
|
pub bvh:crate::bvh::BvhNode,
|
||||||
|
|
||||||
pub modes:Vec<crate::model::ModeDescription>,
|
pub modes:Vec<crate::model::ModeDescription>,
|
||||||
pub mode_from_mode_id:std::collections::HashMap::<u32,usize>,
|
pub mode_from_mode_id:std::collections::HashMap::<u32,usize>,
|
||||||
@ -428,6 +429,7 @@ impl Default for PhysicsState{
|
|||||||
contacts: std::collections::HashMap::new(),
|
contacts: std::collections::HashMap::new(),
|
||||||
intersects: std::collections::HashMap::new(),
|
intersects: std::collections::HashMap::new(),
|
||||||
models: Vec::new(),
|
models: Vec::new(),
|
||||||
|
bvh:crate::bvh::BvhNode::default(),
|
||||||
walk: WalkState::new(),
|
walk: WalkState::new(),
|
||||||
camera: PhysicsCamera::from_offset(glam::vec3(0.0,4.5-2.5,0.0)),
|
camera: PhysicsCamera::from_offset(glam::vec3(0.0,4.5-2.5,0.0)),
|
||||||
next_mouse: MouseState::default(),
|
next_mouse: MouseState::default(),
|
||||||
@ -564,6 +566,7 @@ impl PhysicsState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self.bvh=crate::bvh::generate_bvh(self.models.iter().map(|m|m.mesh().clone()).collect());
|
||||||
//I don't wanna write structs for temporary structures
|
//I don't wanna write structs for temporary structures
|
||||||
//this code builds ModeDescriptions from the unsorted lists at the top of the function
|
//this code builds ModeDescriptions from the unsorted lists at the top of the function
|
||||||
starts.sort_by_key(|tup|tup.0);
|
starts.sort_by_key(|tup|tup.0);
|
||||||
@ -1036,13 +1039,15 @@ impl crate::instruction::InstructionEmitter<PhysicsInstruction> for PhysicsState
|
|||||||
// collector.collect(self.predict_collision_end2(self.time,time_limit,collision_data));
|
// collector.collect(self.predict_collision_end2(self.time,time_limit,collision_data));
|
||||||
// }
|
// }
|
||||||
//check for collision start instructions (against every part in the game with no optimization!!)
|
//check for collision start instructions (against every part in the game with no optimization!!)
|
||||||
for i in 0..self.models.len() {
|
let mut aabb=crate::aabb::Aabb::new();
|
||||||
let i=i as u32;
|
aabb.grow(self.body.extrapolated_position(self.time));
|
||||||
if self.contacts.contains_key(&i)||self.intersects.contains_key(&i){
|
aabb.grow(self.body.extrapolated_position(time_limit));
|
||||||
continue;
|
aabb.inflate(self.style.hitbox_halfsize);
|
||||||
}
|
self.bvh.the_tester(&aabb,&mut |id|{
|
||||||
collector.collect(self.predict_collision_start(self.time,time_limit,i));
|
if !(self.contacts.contains_key(&id)||self.intersects.contains_key(&id)){
|
||||||
|
collector.collect(self.predict_collision_start(self.time,time_limit,id));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
if self.grounded {
|
if self.grounded {
|
||||||
//walk maintenance
|
//walk maintenance
|
||||||
collector.collect(self.next_walk_instruction());
|
collector.collect(self.next_walk_instruction());
|
||||||
|
Loading…
Reference in New Issue
Block a user