Fixed volume mount orientation

This commit is contained in:
Joshua Barretto 2023-05-25 03:16:27 +01:00
parent 9127d6cbf2
commit 4fa799e7c7
8 changed files with 24 additions and 15 deletions

View File

@ -227,7 +227,7 @@
13: Air(Window1, 2),
14: Air(Crate, 0),
15: Air(Cauldron, 2),
16: Air(Tent, 0),
16: Air(ChairSingle, 0),
17: Air(CookingPot, 0),
18: Air(WallLampSmall, 4),
19: Air(Lantern, 4),

BIN
assets/common/voxel/carriage/structure.vox (Stored with Git LFS)

Binary file not shown.

View File

@ -211,10 +211,11 @@ impl VolumePos {
uid_allocator: &UidAllocator,
mut read_pos_and_ori: impl FnMut(Entity) -> Option<(comp::Pos, comp::Ori)>,
colliders: &ReadStorage<comp::Collider>,
) -> Option<(Mat4<f32>, Block)> {
) -> Option<(Mat4<f32>, comp::Ori, Block)> {
match self.kind {
Volume::Terrain => Some((
Mat4::translation_3d(self.pos.as_()),
comp::Ori::default(),
*terrain.get(self.pos).ok()?,
)),
Volume::Entity(uid) => {
@ -234,7 +235,7 @@ impl VolumePos {
let trans = Mat4::from(ori.to_quat()).translated_3d(pos.0)
* Mat4::<f32>::translation_3d(local_translation);
Some((trans, block))
Some((trans, ori, block))
})
},
}

View File

@ -642,7 +642,9 @@ pub fn handle_orientation(
// very rough guess
let ticks_from_target_guess = ori_absdiff(&update.ori, &target_ori) / half_turns_per_tick;
let instantaneous = ticks_from_target_guess < 1.0;
update.ori = if instantaneous {
update.ori = if data.volume_mount_data.is_some() {
update.ori
} else if instantaneous {
target_ori
} else {
let target_fraction = {

View File

@ -103,7 +103,7 @@ impl<'a> System<'a> for Sys {
// For each volume rider.
for (entity, is_volume_rider) in (&entities, &is_volume_riders).join() {
if let Some((mut mat, _)) = is_volume_rider.pos.get_block_and_transform(
if let Some((mut mat, volume_ori, _)) = is_volume_rider.pos.get_block_and_transform(
&terrain,
&uid_allocator,
|e| positions.get(e).copied().zip(orientations.get(e).copied()),
@ -114,21 +114,27 @@ impl<'a> System<'a> for Sys {
continue;
};
if let Some(ori) = is_volume_rider.block.get_ori() {
let mount_block_ori = if let Some(ori) = is_volume_rider.block.get_ori() {
mat *= Mat4::identity()
.translated_3d(mount_offset)
.rotated_z(std::f32::consts::PI * 0.25 * ori as f32)
.translated_3d(Vec3::new(0.5, 0.5, 0.0));
ori
} else {
mat *= Mat4::identity().translated_3d(mount_offset + Vec3::new(0.5, 0.5, 0.0));
}
0
};
if let Some(pos) = positions.get_mut(entity) {
pos.0 = mat.mul_point(Vec3::zero());
}
if let Some(ori) = orientations.get_mut(entity) {
*ori = Ori::from_unnormalized_vec(mat.mul_direction(mount_dir))
.unwrap_or_default();
*ori = volume_ori.rotated(
Ori::from_unnormalized_vec(mount_dir)
.unwrap_or_default()
.to_quat()
.rotated_z(std::f32::consts::PI * 0.25 * mount_block_ori as f32),
);
}
}
let v = match is_volume_rider.pos.kind {

View File

@ -158,7 +158,7 @@ pub fn handle_mount_volume(server: &mut Server, rider: EcsEntity, volume_pos: Vo
&state.read_storage(),
);
if let Some((mat, block)) = block_transform
if let Some((mat, _, block)) = block_transform
&& let Some(mount_offset) = block.mount_offset() {
let mount_pos = (mat * mount_offset.0.with_w(1.0)).xyz();
let within_range = {

View File

@ -801,7 +801,7 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
},
&state.read_storage(),
)
.map(|(mat, _)| mat.mul_point(Vec3::broadcast(0.5)))
.map(|(mat, _, _)| mat.mul_point(Vec3::broadcast(0.5)))
});
if !in_range {
debug!(

View File

@ -2042,7 +2042,7 @@ impl Hud {
// Render overtime for an interactable block
if let Some(Interactable::Block(block, pos, interaction)) = interactable
&& let Some((mat, _)) = pos.get_block_and_transform(
&& let Some((mat, _, _)) = pos.get_block_and_transform(
&ecs.read_resource(),
&ecs.read_resource(),
|e| ecs.read_storage::<vcomp::Interpolated>().get(e).map(|interpolated| (comp::Pos(interpolated.pos), interpolated.ori)),
@ -4751,7 +4751,7 @@ impl Hud {
},
&client.state().read_storage(),
)
.map_or(false, |(mat, block)| {
.map_or(false, |(mat, _, block)| {
block.get_sprite() == Some(*sprite)
&& mat.mul_point(Vec3::broadcast(0.5)).distance(player_pos)
< MAX_PICKUP_RANGE