Skip to content

Commit

Permalink
Finish capsule collider ray tracing draft
Browse files Browse the repository at this point in the history
  • Loading branch information
patowen committed Dec 5, 2022
1 parent 545f5b1 commit 0bff8bf
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
2 changes: 1 addition & 1 deletion client/shaders/fog.frag
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ void main() {
if (length(scaled_view_pos.xy) < 0.01) {
fog = vec4(0.0, 0.0, 0.0, 0.3);
} else {
fog = vec4(0.5, 0.65, 0.9, dist < 0.02 ? 0.5 : exp(-pow(dist * fog_density, 5)));
fog = vec4(0.5, 0.65, 0.9, exp(-pow(dist * fog_density, 5)));
}
}
39 changes: 36 additions & 3 deletions client/src/capsule_chunk_ray_tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,29 @@ impl CapsuleChunkRayTracingPass<'_, '_> {
// Compute triangle normal
let normal = math::lorentz_normalize(&math::triangle_normal(vertex0, vertex1, vertex2));
self.trace_ray_for_sphere_polygon(&normal, [vertex0, vertex1, vertex2, vertex3]);

let lower_vertex0 = self.get_lower_point(vertex0);
let lower_vertex1 = self.get_lower_point(vertex1);
let lower_vertex2 = self.get_lower_point(vertex2);
let lower_vertex3 = self.get_lower_point(vertex3);

self.trace_ray_for_sphere_polygon(
&math::lorentz_normalize(&math::triangle_normal(
&lower_vertex0,
&lower_vertex1,
&lower_vertex2,
)),
[&lower_vertex0, &lower_vertex1, &lower_vertex2],
);
self.trace_ray_for_sphere_polygon(
&math::lorentz_normalize(&math::triangle_normal(
&lower_vertex0,
&lower_vertex2,
&lower_vertex3,
)),
[&lower_vertex0, &lower_vertex2, &lower_vertex3],
);
self.trace_ray_for_sphere_segment(&lower_vertex0, &lower_vertex2);
}

fn trace_ray_for_segment(
Expand All @@ -116,9 +139,19 @@ impl CapsuleChunkRayTracingPass<'_, '_> {

self.trace_ray_for_sphere_segment(&lower_endpoint0, &lower_endpoint1);

let normal = math::lorentz_normalize(&math::triangle_normal(endpoint0, endpoint1, &lower_endpoint1));
self.trace_ray_for_sphere_polygon(&normal, [endpoint0, endpoint1, &lower_endpoint1, &lower_endpoint0]);
self.trace_ray_for_sphere_polygon(&(-normal), [endpoint1, endpoint0, &lower_endpoint0, &lower_endpoint1]);
let normal = math::lorentz_normalize(&math::triangle_normal(
endpoint0,
endpoint1,
&lower_endpoint1,
));
self.trace_ray_for_sphere_polygon(
&normal,
[endpoint0, endpoint1, &lower_endpoint1, &lower_endpoint0],
);
self.trace_ray_for_sphere_polygon(
&(-normal),
[endpoint1, endpoint0, &lower_endpoint0, &lower_endpoint1],
);
}

fn trace_ray_for_point(&mut self, point: &na::Vector4<f64>) {
Expand Down
12 changes: 9 additions & 3 deletions client/src/sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub struct Sim {
jump_speed: f64,
max_cos_slope: f64,
radius: f64,
height: f64,
}

impl Sim {
Expand Down Expand Up @@ -105,6 +106,7 @@ impl Sim {
jump_speed: 0.4,
max_cos_slope: 0.5,
radius: 0.02,
height: 0.04,
}
}

Expand Down Expand Up @@ -248,7 +250,9 @@ impl Sim {
self.params.as_ref().unwrap().chunk_size as usize,
&PointChunkRayTracer {},
self.position_node,
&(self.position_local * na::Vector4::w()),
&(self.position_local
* math::translate_along(&na::Vector3::y_axis(), self.height)
* na::Vector4::w()),
&(self.position_local
* self.get_orientation().cast().to_homogeneous()
* -na::Vector4::z()),
Expand Down Expand Up @@ -557,7 +561,9 @@ impl Sim {

pub fn view(&self) -> Position {
Position {
local: self.position_local.cast::<f32>() * self.get_orientation().to_homogeneous(),
local: self.position_local.cast::<f32>()
* math::translate_along(&na::Vector3::y_axis(), self.height as f32)
* self.get_orientation().to_homogeneous(),
node: self.position_node,
}
}
Expand Down Expand Up @@ -847,7 +853,7 @@ impl PlayerPhysicsPass<'_> {
self.sim.params.as_ref().unwrap().chunk_size as usize,
&CapsuleChunkRayTracer {
radius: self.sim.radius,
height: self.sim.radius * 2.0, // TODO: Make height separately configured
height: self.sim.height,
},
self.sim.position_node,
&(self.sim.position_local * na::Vector4::w()),
Expand Down

0 comments on commit 0bff8bf

Please sign in to comment.