mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
code-quality edits
This commit is contained in:
parent
5b00d41cd4
commit
f4aa9ecbe3
@ -1359,25 +1359,21 @@ impl PlayState for SessionState {
|
|||||||
let entity_ray_end = ray_start + cam_dir * 500.0;
|
let entity_ray_end = ray_start + cam_dir * 500.0;
|
||||||
let terrain_ray_end = ray_start + cam_dir * 1000.0;
|
let terrain_ray_end = ray_start + cam_dir * 1000.0;
|
||||||
|
|
||||||
let aim_point = match ray_entities(
|
let aim_point =
|
||||||
&client,
|
match ray_entities(&client, ray_start, entity_ray_end, 500.0) {
|
||||||
ray_start,
|
Some((dist, _)) => ray_start + cam_dir * dist,
|
||||||
entity_ray_end,
|
None => {
|
||||||
500.0,
|
let terrain_ray_distance = client
|
||||||
) {
|
.state()
|
||||||
Some((dist, _)) => ray_start + cam_dir * dist,
|
.terrain()
|
||||||
None => {
|
.ray(ray_start, terrain_ray_end)
|
||||||
let terrain_ray_distance = client
|
.max_iter(1000)
|
||||||
.state()
|
.until(Block::is_solid)
|
||||||
.terrain()
|
.cast()
|
||||||
.ray(ray_start, terrain_ray_end)
|
.0;
|
||||||
.max_iter(1000)
|
ray_start + cam_dir * terrain_ray_distance
|
||||||
.until(Block::is_solid)
|
},
|
||||||
.cast()
|
};
|
||||||
.0;
|
|
||||||
ray_start + cam_dir * terrain_ray_distance
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Get player orientation
|
// Get player orientation
|
||||||
let ori = client
|
let ori = client
|
||||||
|
@ -257,24 +257,24 @@ pub(super) fn ray_entities(
|
|||||||
)
|
)
|
||||||
.join()
|
.join()
|
||||||
.filter(|(e, _, _)| *e != player_entity)
|
.filter(|(e, _, _)| *e != player_entity)
|
||||||
.filter_map(|(e, p, c)| {
|
.map(|(e, p, c)| {
|
||||||
let height = c.get_height();
|
let height = c.get_height();
|
||||||
let radius = c.bounding_radius().max(height / 2.0);
|
let radius = c.bounding_radius().max(height / 2.0);
|
||||||
// Move position up from the feet
|
// Move position up from the feet
|
||||||
let pos = Vec3::new(p.0.x, p.0.y, p.0.z + c.get_z_limits(1.0).0 + height/2.0);
|
let pos = Vec3::new(p.0.x, p.0.y, p.0.z + c.get_z_limits(1.0).0 + height/2.0);
|
||||||
// Distance squared from start to the entity
|
// Distance squared from start to the entity
|
||||||
let dist_sqr = pos.distance_squared(start);
|
let dist_sqr = pos.distance_squared(start);
|
||||||
Some((e, pos, radius, dist_sqr, c))
|
(e, pos, radius, dist_sqr, c)
|
||||||
})
|
})
|
||||||
// Roughly filter out entities farther than ray distance
|
// Roughly filter out entities farther than ray distance
|
||||||
.filter(|(_, _, _, d_sqr, c)| *d_sqr <= cast_dist.powi(2))
|
.filter(|(_, _, _, d_sqr, _)| *d_sqr <= cast_dist.powi(2))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
// Sort by distance
|
// Sort by distance
|
||||||
nearby.sort_unstable_by(|a, b| a.3.partial_cmp(&b.3).unwrap());
|
nearby.sort_unstable_by(|a, b| a.3.partial_cmp(&b.3).unwrap());
|
||||||
|
|
||||||
let seg_ray = LineSegment3 { start, end };
|
let seg_ray = LineSegment3 { start, end };
|
||||||
|
|
||||||
let entity = nearby.iter().find_map(|(e, p, r, d_sqr, c)| {
|
let entity = nearby.iter().find_map(|(e, p, r, _, c)| {
|
||||||
let nearest = seg_ray.projected_point(*p);
|
let nearest = seg_ray.projected_point(*p);
|
||||||
|
|
||||||
return match c {
|
return match c {
|
||||||
@ -336,7 +336,7 @@ pub(super) fn ray_entities(
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
return entity;
|
entity
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get closest point between 2 line segments https://math.stackexchange.com/a/4289668
|
// Get closest point between 2 line segments https://math.stackexchange.com/a/4289668
|
||||||
|
Loading…
Reference in New Issue
Block a user