mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Moved weapon offset functions up a level. Should allow gliders and arrows to be handled better.
This commit is contained in:
parent
6ba8af5434
commit
eacd43be16
@ -50,7 +50,7 @@ pub use self::{
|
||||
talk::TalkAnimation, wallrun::WallrunAnimation, wield::WieldAnimation,
|
||||
};
|
||||
use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton};
|
||||
use common::comp;
|
||||
use common::comp::{self, tool::ToolKind};
|
||||
use core::{convert::TryFrom, f32::consts::PI};
|
||||
|
||||
pub type Body = comp::humanoid::Body;
|
||||
@ -149,6 +149,20 @@ impl Skeleton for CharacterSkeleton {
|
||||
// FIXME: Should this be control_l_mat?
|
||||
make_bone(control_mat * hand_l_mat * Mat4::<f32>::from(self.hold)),
|
||||
];
|
||||
let weapon_offsets = |tool| {
|
||||
let lengths = match tool {
|
||||
Some(ToolKind::Sword) => (0.0, 29.25),
|
||||
Some(ToolKind::Axe) => (10.0, 19.25),
|
||||
Some(ToolKind::Hammer) => (10.0, 19.25),
|
||||
Some(ToolKind::Staff) => (10.0, 19.25),
|
||||
Some(ToolKind::Sceptre) => (10.0, 19.25),
|
||||
_ => (0.0, 0.0),
|
||||
};
|
||||
(
|
||||
Vec4::new(0.0, 0.0, lengths.0, 1.0),
|
||||
Vec4::new(0.0, 0.0, lengths.1, 1.0),
|
||||
)
|
||||
};
|
||||
Offsets {
|
||||
lantern: Some((lantern_mat * Vec4::new(0.0, 0.5, -6.0, 1.0)).xyz()),
|
||||
// TODO: see quadruped_medium for how to animate this
|
||||
@ -159,8 +173,10 @@ impl Skeleton for CharacterSkeleton {
|
||||
.into(),
|
||||
..Default::default()
|
||||
},
|
||||
main_weapon_trail_mat: self.main_weapon_trail.then_some(main_mat),
|
||||
off_weapon_trail_mat: self.off_weapon_trail.then_some(second_mat),
|
||||
main_weapon_trail_mat: self.main_weapon_trail.then_some((main_mat, weapon_offsets)),
|
||||
off_weapon_trail_mat: self
|
||||
.off_weapon_trail
|
||||
.then_some((second_mat, weapon_offsets)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -69,6 +69,7 @@ pub mod vek;
|
||||
|
||||
use self::vek::*;
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use common::comp::tool::ToolKind;
|
||||
#[cfg(feature = "use-dyn-lib")]
|
||||
use {
|
||||
lazy_static::lazy_static, std::ffi::CStr, std::sync::Arc, std::sync::Mutex,
|
||||
@ -103,8 +104,8 @@ pub fn init() { lazy_static::initialize(&LIB); }
|
||||
pub struct Offsets {
|
||||
pub lantern: Option<Vec3<f32>>,
|
||||
pub mount_bone: Transform<f32, f32, f32>,
|
||||
pub main_weapon_trail_mat: Option<Mat4<f32>>,
|
||||
pub off_weapon_trail_mat: Option<Mat4<f32>>,
|
||||
pub main_weapon_trail_mat: Option<(Mat4<f32>, fn(Option<ToolKind>) -> (Vec4<f32>, Vec4<f32>))>,
|
||||
pub off_weapon_trail_mat: Option<(Mat4<f32>, fn(Option<ToolKind>) -> (Vec4<f32>, Vec4<f32>))>,
|
||||
}
|
||||
|
||||
pub trait Skeleton: Send + Sync + 'static {
|
||||
|
@ -6443,27 +6443,19 @@ impl<S: Skeleton> FigureState<S> {
|
||||
// Handle weapon trails
|
||||
fn handle_weapon_trails(
|
||||
trail_mgr: &mut TrailMgr,
|
||||
new_weapon_trail_mat: Option<anim::vek::Mat4<f32>>,
|
||||
new_weapon_trail_mat: Option<(
|
||||
anim::vek::Mat4<f32>,
|
||||
fn(Option<ToolKind>) -> (anim::vek::Vec4<f32>, anim::vek::Vec4<f32>),
|
||||
)>,
|
||||
old_abs_trail_points: &mut Option<(anim::vek::Vec3<f32>, anim::vek::Vec3<f32>)>,
|
||||
entity: EcsEntity,
|
||||
is_main_weapon: bool,
|
||||
pos: anim::vek::Vec3<f32>,
|
||||
tools: (Option<ToolKind>, Option<ToolKind>),
|
||||
) {
|
||||
let weapon_offsets = new_weapon_trail_mat.map(|mat| {
|
||||
let (trail_start, trail_end) = match tools.0 {
|
||||
Some(ToolKind::Sword) => (0.0, 29.25),
|
||||
// TODO: Make sure these are good positions, only did tweaking on sword
|
||||
Some(ToolKind::Axe) => (10.0, 19.25),
|
||||
Some(ToolKind::Hammer) => (10.0, 19.25),
|
||||
Some(ToolKind::Staff) => (10.0, 19.25),
|
||||
Some(ToolKind::Sceptre) => (10.0, 19.25),
|
||||
_ => (0.0, 0.0),
|
||||
};
|
||||
(
|
||||
(mat * anim::vek::Vec4::new(0.0, 0.0, trail_start, 1.0)).xyz(),
|
||||
(mat * anim::vek::Vec4::new(0.0, 0.0, trail_end, 1.0)).xyz(),
|
||||
)
|
||||
let weapon_offsets = new_weapon_trail_mat.map(|(mat, offsets)| {
|
||||
let (trail_start, trail_end) = offsets(tools.0);
|
||||
((mat * trail_start).xyz(), (mat * trail_end).xyz())
|
||||
});
|
||||
let new_abs_trail_points = weapon_offsets.map(|(a, b)| (a + pos, b + pos));
|
||||
let trail_mgr_offset = trail_mgr.offset;
|
||||
|
Loading…
Reference in New Issue
Block a user