Skip to content

Commit

Permalink
Place the cylinder at the center of the coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Dec 22, 2024
1 parent 0cf7292 commit 3b39af7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions shaders/terrain-draw.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn cartesian_to_radial(p: vec3f) -> RadialCoordinates {
}

fn sample_map(rc: RadialCoordinates) -> vec4f {
let tc = vec2f(rc.alpha / (2.0 * PI), rc.depth / g_terrain_params.length);
let tc = vec2f(rc.alpha / (2.0 * PI), rc.depth / g_terrain_params.length + 0.5);
return textureSampleLevel(g_terrain, g_terrain_sampler, tc, 0.0);
}

Expand All @@ -70,7 +70,7 @@ fn intersect_ray_with_map_radius(dir: vec2f, radius: f32) -> vec2f {
fn compute_ray_distance(dir: vec3f) -> vec2f {
var result = vec2f(g_camera.clip_near, g_camera.clip_far);
// intersect with bottom or top
let limit = (select(0.0, g_terrain_params.length, dir.z > 0.0) - g_camera.pos.z) / dir.z;
let limit = (g_terrain_params.length * select(-0.5, 0.5, dir.z > 0.0) - g_camera.pos.z) / dir.z;
result.y = min(result.y, limit);
if (result.x >= result.y) {
// outside of the cylinder length
Expand Down
11 changes: 9 additions & 2 deletions src/physics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,17 @@ impl rapier3d::geometry::RayCast for TerrainShape {

impl rapier3d::geometry::Shape for TerrainShape {
fn compute_local_aabb(&self) -> rapier3d::parry::bounding_volume::Aabb {
self.cylinder(1.0).compute_local_aabb()
let r = self.radius.end;
rapier3d::parry::bounding_volume::Aabb {
mins: nalgebra::Point3::new(-r, -r, -0.5 * self.length),
maxs: nalgebra::Point3::new(r, r, 0.5 * self.length),
}
}
fn compute_local_bounding_sphere(&self) -> rapier3d::parry::bounding_volume::BoundingSphere {
self.cylinder(1.0).compute_local_bounding_sphere()
rapier3d::parry::bounding_volume::BoundingSphere {
center: nalgebra::Point3::default(),
radius: nalgebra::Vector2::new(self.radius.end, 0.5 * self.length).norm(),
}
}
fn clone_dyn(&self) -> Box<dyn rapier3d::geometry::Shape> {
Box::new(self.clone())
Expand Down

0 comments on commit 3b39af7

Please sign in to comment.