Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
f52399a931 | |||
7be7d40c8a |
@ -1,4 +1,5 @@
|
|||||||
use std::collections::{HashMap,HashSet};
|
use std::collections::{HashMap,HashSet};
|
||||||
|
use crate::model::DirectedEdge;
|
||||||
use crate::model::{self as model_physics,PhysicsMesh,PhysicsMeshTransform,TransformedMesh,MeshQuery,PhysicsMeshId,PhysicsSubmeshId};
|
use crate::model::{self as model_physics,PhysicsMesh,PhysicsMeshTransform,TransformedMesh,MeshQuery,PhysicsMeshId,PhysicsSubmeshId};
|
||||||
use strafesnet_common::bvh;
|
use strafesnet_common::bvh;
|
||||||
use strafesnet_common::map;
|
use strafesnet_common::map;
|
||||||
@ -280,7 +281,8 @@ impl PhysicsCamera{
|
|||||||
.clamp(Self::ANGLE_PITCH_LOWER_LIMIT,Self::ANGLE_PITCH_UPPER_LIMIT);
|
.clamp(Self::ANGLE_PITCH_LOWER_LIMIT,Self::ANGLE_PITCH_UPPER_LIMIT);
|
||||||
mat3::from_rotation_yx(ax,ay)
|
mat3::from_rotation_yx(ax,ay)
|
||||||
}
|
}
|
||||||
fn rotation(&self)->Planar64Mat3{
|
#[inline]
|
||||||
|
pub fn rotation(&self)->Planar64Mat3{
|
||||||
self.get_rotation(self.clamped_mouse_pos)
|
self.get_rotation(self.clamped_mouse_pos)
|
||||||
}
|
}
|
||||||
fn simulate_move_rotation(&self,mouse_delta:glam::IVec2)->Planar64Mat3{
|
fn simulate_move_rotation(&self,mouse_delta:glam::IVec2)->Planar64Mat3{
|
||||||
@ -980,6 +982,34 @@ impl PhysicsContext<'_>{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl PhysicsData{
|
impl PhysicsData{
|
||||||
|
pub fn trace_ray(&self,ray:strafesnet_common::ray::Ray)->Option<ModelId>{
|
||||||
|
let (_time,convex_mesh_id)=self.bvh.sample_ray(&ray,Time::ZERO,Time::MAX/4,|&model,ray|{
|
||||||
|
let mesh=self.models.mesh(model);
|
||||||
|
// brute force trace every face
|
||||||
|
mesh.faces().filter_map(|face_id|{
|
||||||
|
let (n,d)=mesh.face_nd(face_id);
|
||||||
|
// trace ray onto face
|
||||||
|
// n.(o+d*t)==n.p
|
||||||
|
// n.o + n.d * t == n.p
|
||||||
|
// t == (n.p - n.o)/n.d
|
||||||
|
let nd=n.dot(ray.direction);
|
||||||
|
if nd.is_zero(){
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let t=(d-n.dot(ray.origin))/nd;
|
||||||
|
// check if point of intersection is behind face edges
|
||||||
|
// *2 because average of 2 vertices
|
||||||
|
let p=ray.extrapolate(t)*2;
|
||||||
|
mesh.face_edges(face_id).iter().all(|&directed_edge_id|{
|
||||||
|
let edge_n=mesh.directed_edge_n(directed_edge_id);
|
||||||
|
let cross_n=edge_n.cross(n);
|
||||||
|
let &[vert0,vert1]=mesh.edge_verts(directed_edge_id.as_undirected()).as_ref();
|
||||||
|
cross_n.dot(p)<cross_n.dot(mesh.vert(vert0)+mesh.vert(vert1))
|
||||||
|
}).then(||t)
|
||||||
|
}).min().map(Into::into)
|
||||||
|
})?;
|
||||||
|
Some(convex_mesh_id.model_id.into())
|
||||||
|
}
|
||||||
/// use with caution, this is the only non-instruction way to mess with physics
|
/// use with caution, this is the only non-instruction way to mess with physics
|
||||||
pub fn generate_models(&mut self,map:&map::CompleteMap){
|
pub fn generate_models(&mut self,map:&map::CompleteMap){
|
||||||
let mut modes=map.modes.clone().denormalize();
|
let mut modes=map.modes.clone().denormalize();
|
||||||
|
@ -161,6 +161,7 @@ pub struct Session{
|
|||||||
recording:Recording,
|
recording:Recording,
|
||||||
//players:HashMap<PlayerId,Simulation>,
|
//players:HashMap<PlayerId,Simulation>,
|
||||||
replays:HashMap<BotId,Replay>,
|
replays:HashMap<BotId,Replay>,
|
||||||
|
last_ray_hit:Option<strafesnet_common::model::ModelId>,
|
||||||
}
|
}
|
||||||
impl Session{
|
impl Session{
|
||||||
pub fn new(
|
pub fn new(
|
||||||
@ -177,6 +178,7 @@ impl Session{
|
|||||||
view_state:ViewState::Play,
|
view_state:ViewState::Play,
|
||||||
recording:Default::default(),
|
recording:Default::default(),
|
||||||
replays:HashMap::new(),
|
replays:HashMap::new(),
|
||||||
|
last_ray_hit:None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn clear_recording(&mut self){
|
fn clear_recording(&mut self){
|
||||||
@ -194,6 +196,19 @@ impl Session{
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn debug_raycast_print_model_id_if_changed(&mut self,time:SessionTime){
|
||||||
|
if let Some(frame_state)=self.get_frame_state(time){
|
||||||
|
let ray=strafesnet_common::ray::Ray{
|
||||||
|
origin:frame_state.body.extrapolated_position(self.simulation.timer.time(time)),
|
||||||
|
direction:-frame_state.camera.rotation().z_axis,
|
||||||
|
};
|
||||||
|
let model_id=self.geometry_shared.trace_ray(ray);
|
||||||
|
if model_id!=self.last_ray_hit{
|
||||||
|
println!("hit={model_id:?}");
|
||||||
|
self.last_ray_hit=model_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
pub fn user_settings(&self)->&UserSettings{
|
pub fn user_settings(&self)->&UserSettings{
|
||||||
&self.user_settings
|
&self.user_settings
|
||||||
}
|
}
|
||||||
|
@ -77,5 +77,8 @@ pub fn new<'a>(
|
|||||||
run_session_instruction!(ins.time,SessionInstruction::LoadReplay(bot));
|
run_session_instruction!(ins.time,SessionInstruction::LoadReplay(bot));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//whatever just do it
|
||||||
|
session.debug_raycast_print_model_id_if_changed(ins.time);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user