Make the mounter animations dependant of the mountee animation

This commit is contained in:
Snowram 2021-04-29 02:42:38 +02:00 committed by Imbris
parent efdb9bef6c
commit 09cbb90f61
23 changed files with 596 additions and 133 deletions

View File

@ -159,7 +159,7 @@
central: ("npc.tuskram.male.neck"),
),
jaw: (
offset: (-5.0, 0.0, -1.5),
offset: (-5.0, 0.0, -8.0),
central: ("npc.tuskram.male.jaw"),
),
torso_front: (

View File

@ -764,12 +764,60 @@ impl Body {
)
}
// Physical offset relative to the mountee
pub fn mounting_offset(&self) -> Vec3<f32> {
match self {
Body::Ship(ship::Body::DefaultAirship) => Vec3::from([0.0, 0.0, 10.0]),
Body::Ship(ship::Body::AirBalloon) => Vec3::from([0.0, 0.0, 5.0]),
_ => Vec3::unit_z(),
Body::QuadrupedMedium(quadruped_medium) => {
match (quadruped_medium.species, quadruped_medium.body_type) {
(quadruped_medium::Species::Grolgar, _) => [0.5, 0.5, 1.8],
(quadruped_medium::Species::Saber, _) => [0.3, 0.3, 1.3],
(quadruped_medium::Species::Tiger, _) => [0.2, 0.2, 1.4],
(quadruped_medium::Species::Tuskram, _) => [-0.5, -0.5, 1.5],
(quadruped_medium::Species::Lion, _) => [0.3, 0.3, 1.5],
(quadruped_medium::Species::Tarasque, _) => [0.6, 0.6, 2.0],
(quadruped_medium::Species::Wolf, _) => [0.5, 0.5, 1.3],
(quadruped_medium::Species::Frostfang, _) => [0.5, 0.5, 1.2],
(quadruped_medium::Species::Mouflon, _) => [0.3, 0.3, 1.2],
(quadruped_medium::Species::Catoblepas, _) => [0.0, 0.0, 2.0],
(quadruped_medium::Species::Bonerattler, _) => [0.5, 0.5, 1.2],
(quadruped_medium::Species::Deer, _) => [0.2, 0.2, 1.3],
(quadruped_medium::Species::Hirdrasil, _) => [0.0, 0.0, 1.4],
(quadruped_medium::Species::Roshwalr, _) => [0.5, 0.5, 1.8],
(quadruped_medium::Species::Donkey, _) => [0.5, 0.5, 1.5],
(quadruped_medium::Species::Camel, _) => [-0.1, -0.1, 2.8],
(quadruped_medium::Species::Zebra, _) => [0.5, 0.5, 1.8],
(quadruped_medium::Species::Antelope, _) => [0.3, 0.3, 1.4],
(quadruped_medium::Species::Kelpie, _) => [0.5, 0.5, 1.9],
(quadruped_medium::Species::Horse, _) => [0.0, 0.0, 2.0],
(quadruped_medium::Species::Barghest, _) => [0.5, 0.5, 2.2],
(quadruped_medium::Species::Cattle, quadruped_medium::BodyType::Male) => {
[0.5, 0.5, 2.6]
},
(quadruped_medium::Species::Cattle, quadruped_medium::BodyType::Female) => {
[0.7, 0.7, 2.2]
},
(quadruped_medium::Species::Darkhound, _) => [0.5, 0.5, 1.4],
(quadruped_medium::Species::Highland, _) => [0.5, 0.5, 2.3],
(quadruped_medium::Species::Yak, _) => [0.0, 0.0, 3.0],
(quadruped_medium::Species::Panda, _) => [-0.2, -0.2, 1.4],
(quadruped_medium::Species::Bear, _) => [-0.4, -0.4, 2.5],
(quadruped_medium::Species::Dreadhorn, _) => [0.2, 0.2, 3.5],
(quadruped_medium::Species::Moose, _) => [-0.6, -0.6, 2.1],
(quadruped_medium::Species::Snowleopard, _) => [-0.5, -0.5, 1.4],
// TODO: Fill in these values
(quadruped_medium::Species::Mammoth, _) => [0.0, 0.0, 0.0],
(quadruped_medium::Species::Ngoubou, _) => [0.0, 0.0, 0.0],
(quadruped_medium::Species::Llama, _) => [0.0, 0.0, 0.0],
(quadruped_medium::Species::Alpaca, _) => [0.0, 0.0, 0.0],
}
},
Body::Ship(ship) => match ship {
ship::Body::DefaultAirship => [0.0, 0.0, 10.0],
ship::Body::AirBalloon => [0.0, 0.0, 5.0],
},
_ => [0.0, 0.0, 0.0],
}
.into()
}
}

View File

@ -352,11 +352,10 @@ impl<'a> System<'a> for Sys {
// Mounted occurs after control actions have been handled
// If mounted, character state is controlled by mount
// TODO: Make mounting a state
if let Some(Mounting(_)) = read_data.mountings.get(entity) {
let sit_state = CharacterState::Sit {};
if join_struct.char_state.get_unchecked() != &sit_state {
*join_struct.char_state.get_mut_unchecked() = sit_state;
let idle_state = CharacterState::Idle {};
if join_struct.char_state.get_unchecked() != &idle_state {
*join_struct.char_state.get_mut_unchecked() = idle_state;
}
continue;
}

View File

@ -68,7 +68,14 @@ impl<'a> System<'a> for Sys {
if let (Some(pos), Some(ori), Some(vel)) = (pos, ori, vel) {
let mounting_offset =
body.map_or(Vec3::unit_z(), Body::mounting_offset);
let _ = positions.insert(mounter, Pos(pos.0 + mounting_offset));
let _ = positions.insert(
mounter,
Pos(Vec3 {
x: pos.0.x + ori.look_dir().x * mounting_offset.x,
y: pos.0.y + ori.look_dir().y * mounting_offset.y,
z: pos.0.z + mounting_offset.z,
}),
);
let _ = orientations.insert(mounter, ori);
let _ = velocities.insert(mounter, vel);
}

View File

@ -31,7 +31,7 @@ pub use self::{
wield::WieldAnimation,
};
use super::{make_bone, vek::*, FigureBoneData, Skeleton};
use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton};
use common::comp::{self};
use core::{convert::TryFrom, f32::consts::PI};
@ -79,7 +79,7 @@ impl Skeleton for BipedLargeSkeleton {
&self,
base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> {
) -> Offsets {
let upper_torso = Mat4::<f32>::from(self.upper_torso);
let torso_mat = base_mat * Mat4::<f32>::from(self.torso);
@ -126,7 +126,10 @@ impl Skeleton for BipedLargeSkeleton {
// FIXME: Should this be control_l_mat?
make_bone(upper_torso_mat * control_mat * hand_l_mat * Mat4::<f32>::from(self.hold)),
];
Vec3::default()
Offsets {
lantern: Vec3::default(),
mount_bone: self.torso,
}
}
}

View File

@ -12,7 +12,7 @@ pub use self::{
shoot::ShootAnimation, stunned::StunnedAnimation, wield::WieldAnimation,
};
use super::{make_bone, vek::*, FigureBoneData, Skeleton};
use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton};
use common::comp::{self};
use core::convert::TryFrom;
@ -47,7 +47,7 @@ impl Skeleton for BipedSmallSkeleton {
&self,
base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> {
) -> Offsets {
let chest_mat = base_mat * Mat4::<f32>::from(self.chest);
let pants_mat = chest_mat * Mat4::<f32>::from(self.pants);
let control_mat = chest_mat * Mat4::<f32>::from(self.control);
@ -64,7 +64,10 @@ impl Skeleton for BipedSmallSkeleton {
make_bone(base_mat * Mat4::<f32>::from(self.foot_l)),
make_bone(base_mat * Mat4::<f32>::from(self.foot_r)),
];
Vec3::default()
Offsets {
lantern: Vec3::default(),
mount_bone: self.chest,
}
}
}

View File

@ -18,7 +18,7 @@ pub use self::{
shoot::ShootAnimation, stunned::StunnedAnimation, summon::SummonAnimation, swim::SwimAnimation,
};
use super::{make_bone, vek::*, FigureBoneData, Skeleton};
use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton};
use common::comp::{self};
use core::convert::TryFrom;
@ -57,7 +57,7 @@ impl Skeleton for BirdLargeSkeleton {
&self,
base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> {
) -> Offsets {
let chest_mat = base_mat * Mat4::<f32>::from(self.chest);
let neck_mat = chest_mat * Mat4::<f32>::from(self.neck);
let head_mat = neck_mat * Mat4::<f32>::from(self.head);
@ -93,7 +93,10 @@ impl Skeleton for BirdLargeSkeleton {
make_bone(foot_l_mat),
make_bone(foot_r_mat),
];
Vec3::default()
Offsets {
lantern: Vec3::default(),
mount_bone: self.chest,
}
}
}

View File

@ -6,7 +6,7 @@ pub mod run;
// Reexports
pub use self::{feed::FeedAnimation, fly::FlyAnimation, idle::IdleAnimation, run::RunAnimation};
use super::{make_bone, vek::*, FigureBoneData, Skeleton};
use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton};
use common::comp::{self};
use core::convert::TryFrom;
@ -36,7 +36,7 @@ impl Skeleton for BirdMediumSkeleton {
&self,
base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> {
) -> Offsets {
let torso_mat = base_mat * Mat4::<f32>::from(self.torso);
*(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [
@ -48,7 +48,10 @@ impl Skeleton for BirdMediumSkeleton {
make_bone(base_mat * Mat4::<f32>::from(self.leg_l)),
make_bone(base_mat * Mat4::<f32>::from(self.leg_r)),
];
Vec3::default()
Offsets {
lantern: Vec3::default(),
mount_bone: self.torso,
}
}
}

View File

@ -13,6 +13,7 @@ pub mod gliding;
pub mod idle;
pub mod jump;
pub mod leapmelee;
pub mod mount;
pub mod repeater;
pub mod roll;
pub mod run;
@ -36,13 +37,14 @@ pub use self::{
chargeswing::ChargeswingAnimation, climb::ClimbAnimation, consume::ConsumeAnimation,
dance::DanceAnimation, dash::DashAnimation, equip::EquipAnimation,
glidewield::GlideWieldAnimation, gliding::GlidingAnimation, idle::IdleAnimation,
jump::JumpAnimation, leapmelee::LeapAnimation, repeater::RepeaterAnimation,
roll::RollAnimation, run::RunAnimation, shockwave::ShockwaveAnimation, shoot::ShootAnimation,
sit::SitAnimation, sneak::SneakAnimation, spin::SpinAnimation, spinmelee::SpinMeleeAnimation,
staggered::StaggeredAnimation, stand::StandAnimation, stunned::StunnedAnimation,
swim::SwimAnimation, swimwield::SwimWieldAnimation, talk::TalkAnimation, wield::WieldAnimation,
jump::JumpAnimation, leapmelee::LeapAnimation, mount::MountAnimation,
repeater::RepeaterAnimation, roll::RollAnimation, run::RunAnimation,
shockwave::ShockwaveAnimation, shoot::ShootAnimation, sit::SitAnimation, sneak::SneakAnimation,
spin::SpinAnimation, spinmelee::SpinMeleeAnimation, staggered::StaggeredAnimation,
stand::StandAnimation, stunned::StunnedAnimation, swim::SwimAnimation,
swimwield::SwimWieldAnimation, talk::TalkAnimation, wield::WieldAnimation,
};
use super::{make_bone, vek::*, FigureBoneData, Skeleton};
use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton};
use common::comp;
use core::{convert::TryFrom, f32::consts::PI};
@ -71,12 +73,20 @@ skeleton_impls!(struct CharacterSkeleton {
control_r,
:: // Begin non-bone fields
holding_lantern: bool,
offsets: Option<Transform<f32, f32, f32>>,
mountee_body: Option<comp::Body>,
});
impl CharacterSkeleton {
pub fn new(holding_lantern: bool) -> Self {
pub fn new(
holding_lantern: bool,
offsets: Option<Transform<f32, f32, f32>>,
mountee_body: Option<comp::Body>,
) -> Self {
Self {
holding_lantern,
offsets,
mountee_body,
..Self::default()
}
}
@ -96,8 +106,22 @@ impl Skeleton for CharacterSkeleton {
&self,
base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> {
let torso_mat = base_mat * Mat4::<f32>::from(self.torso);
) -> Offsets {
let torso_mat = base_mat
* if let Some((offset, body)) = self.offsets.zip(self.mountee_body) {
let hitbox_offsets = body.mounting_offset();
let visual_offset = mounting_offset(body);
Mat4::<f32>::from(Transform {
position: offset.position
- Vec3::from([0.0, hitbox_offsets.y, hitbox_offsets.z]),
orientation: offset.orientation,
scale: Vec3::<f32>::one(),
}) * Mat4::<f32>::from(self.torso).translated_3d(visual_offset)
} else {
Mat4::<f32>::from(self.torso)
};
let chest_mat = torso_mat * Mat4::<f32>::from(self.chest);
let head_mat = chest_mat * Mat4::<f32>::from(self.head);
let shorts_mat = chest_mat * Mat4::<f32>::from(self.shorts);
@ -132,7 +156,10 @@ impl Skeleton for CharacterSkeleton {
// FIXME: Should this be control_l_mat?
make_bone(control_mat * hand_l_mat * Mat4::<f32>::from(self.hold)),
];
(lantern_mat * Vec4::new(0.0, 0.0, -4.0, 1.0)).xyz()
Offsets {
lantern: (lantern_mat * Vec4::new(0.0, 0.0, -4.0, 1.0)).xyz(),
mount_bone: self.chest,
}
}
}
@ -329,3 +356,53 @@ impl<'a> From<&'a Body> for SkeletonAttr {
}
}
}
pub fn mounting_offset(body: comp::Body) -> Vec3<f32> {
match body {
comp::Body::QuadrupedMedium(quadruped_medium) => {
match (quadruped_medium.species, quadruped_medium.body_type) {
(comp::quadruped_medium::Species::Grolgar, _) => Vec3::from([0.0, -0.6, 0.5]),
(comp::quadruped_medium::Species::Saber, _) => Vec3::from([0.0, -0.75, 0.23]),
(comp::quadruped_medium::Species::Tiger, _) => Vec3::from([0.0, -0.75, 0.23]),
(comp::quadruped_medium::Species::Tuskram, _) => Vec3::from([0.0, -0.75, 0.25]),
(comp::quadruped_medium::Species::Lion, _) => Vec3::from([0.0, -0.9, 0.25]),
(comp::quadruped_medium::Species::Tarasque, _) => Vec3::from([0.0, -1.1, 0.3]),
(comp::quadruped_medium::Species::Wolf, _) => Vec3::from([0.0, -0.7, 0.15]),
(comp::quadruped_medium::Species::Frostfang, _) => Vec3::from([0.0, -0.8, 0.1]),
(comp::quadruped_medium::Species::Mouflon, _) => Vec3::from([0.0, -0.8, 0.1]),
(comp::quadruped_medium::Species::Catoblepas, _) => Vec3::from([0.0, -0.4, 0.4]),
(comp::quadruped_medium::Species::Bonerattler, _) => Vec3::from([0.0, -0.3, 0.2]),
(comp::quadruped_medium::Species::Deer, _) => Vec3::from([0.0, -0.9, 0.1]),
(comp::quadruped_medium::Species::Hirdrasil, _) => Vec3::from([0.0, -1.0, 0.0]),
(comp::quadruped_medium::Species::Roshwalr, _) => Vec3::from([0.0, -0.2, 0.7]),
(comp::quadruped_medium::Species::Donkey, _) => Vec3::from([0.0, -0.5, 0.15]),
(comp::quadruped_medium::Species::Camel, _) => Vec3::from([0.0, -1.4, 0.3]),
(comp::quadruped_medium::Species::Zebra, _) => Vec3::from([0.0, -0.6, 0.1]),
(comp::quadruped_medium::Species::Antelope, _) => Vec3::from([0.0, -0.8, 0.1]),
(comp::quadruped_medium::Species::Kelpie, _) => Vec3::from([0.0, -0.8, 0.05]),
(comp::quadruped_medium::Species::Horse, _) => Vec3::from([0.0, -0.8, 0.1]),
(comp::quadruped_medium::Species::Barghest, _) => Vec3::from([0.0, -0.8, 0.6]),
(
comp::quadruped_medium::Species::Cattle,
comp::quadruped_medium::BodyType::Male,
) => Vec3::from([0.0, -0.4, 0.7]),
(
comp::quadruped_medium::Species::Cattle,
comp::quadruped_medium::BodyType::Female,
) => Vec3::from([0.0, -0.3, 0.5]),
(comp::quadruped_medium::Species::Darkhound, _) => Vec3::from([0.0, -0.5, 0.2]),
(comp::quadruped_medium::Species::Highland, _) => Vec3::from([0.0, -0.2, 0.8]),
(comp::quadruped_medium::Species::Yak, _) => Vec3::from([0.0, -0.2, 0.8]),
(comp::quadruped_medium::Species::Panda, _) => Vec3::from([0.0, -0.8, 0.2]),
(comp::quadruped_medium::Species::Bear, _) => Vec3::from([0.0, -1.5, 0.6]),
(comp::quadruped_medium::Species::Dreadhorn, _) => Vec3::from([0.0, -1.5, 1.6]),
(comp::quadruped_medium::Species::Moose, _) => Vec3::from([0.0, -0.9, 0.3]),
(comp::quadruped_medium::Species::Snowleopard, _) => Vec3::from([0.0, -0.9, 0.2]),
}
},
comp::Body::Ship(comp::ship::Body::DefaultAirship) => Vec3::from([0.0, 0.0, 10.0]),
comp::Body::Dragon(_) => Vec3::from([0.0, -0.7, 6.4]),
_ => Vec3::unit_z(),
}
}

View File

@ -0,0 +1,217 @@
use super::{
super::{vek::*, Animation},
CharacterSkeleton, SkeletonAttr,
};
use common::comp::item::{Hands, ToolKind};
use std::{f32::consts::PI, ops::Mul};
pub struct MountAnimation;
impl Animation for MountAnimation {
#[allow(clippy::type_complexity)]
type Dependency<'a> = (
Option<ToolKind>,
Option<ToolKind>,
(Option<Hands>, Option<Hands>),
f32,
Vec3<f32>,
Vec3<f32>,
Vec3<f32>,
Vec3<f32>,
);
type Skeleton = CharacterSkeleton;
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"character_mount\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_mount")]
fn update_skeleton_inner<'a>(
skeleton: &Self::Skeleton,
(
active_tool_kind,
second_tool_kind,
hands,
global_time,
velocity,
avg_vel,
orientation,
last_ori,
): Self::Dependency<'a>,
anim_time: f32,
_rate: &mut f32,
s_a: &SkeletonAttr,
) -> Self::Skeleton {
let mut next = (*skeleton).clone();
let slow = (anim_time * 1.0).sin();
let slowa = (anim_time * 1.0 + PI / 2.0).sin();
let stop = (anim_time * 3.0).min(PI / 2.0).sin();
let head_look = Vec2::new(
(global_time * 0.05 + anim_time / 15.0)
.floor()
.mul(7331.0)
.sin()
* 0.25,
(global_time * 0.05 + anim_time / 15.0)
.floor()
.mul(1337.0)
.sin()
* 0.125,
);
let ori: Vec2<f32> = Vec2::from(orientation);
let last_ori = Vec2::from(last_ori);
let speed = (Vec2::<f32>::from(velocity).magnitude()).min(24.0);
let canceler = (speed / 24.0).powf(0.6);
let _x_tilt = avg_vel.z.atan2(avg_vel.xy().magnitude()) * canceler;
let _tilt = if ::vek::Vec2::new(ori, last_ori)
.map(|o| o.magnitude_squared())
.map(|m| m > 0.001 && m.is_finite())
.reduce_and()
&& ori.angle_between(last_ori).is_finite()
{
ori.angle_between(last_ori).min(0.2)
* last_ori.determine_side(Vec2::zero(), ori).signum()
} else {
0.0
} * 1.3;
next.head.scale = Vec3::one() * s_a.head_scale;
next.chest.scale = Vec3::one() * 1.01;
next.hand_l.scale = Vec3::one() * 1.04;
next.hand_r.scale = Vec3::one() * 1.04;
next.back.scale = Vec3::one() * 1.02;
next.hold.scale = Vec3::one() * 0.0;
next.lantern.scale = Vec3::one() * 0.65;
next.torso.scale = Vec3::one() / 11.0 * s_a.scaler;
next.shoulder_l.scale = Vec3::one() * 1.1;
next.shoulder_r.scale = Vec3::one() * 1.1;
next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1 + slow * 0.1 + stop * -0.8);
next.head.orientation = Quaternion::rotation_z(head_look.x + slow * 0.2 - slow * 0.1)
* Quaternion::rotation_x((0.4 + slowa * -0.1 + slow * 0.1 + head_look.y).abs());
next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1);
next.chest.orientation = Quaternion::rotation_x(-0.6 + stop * 0.15);
next.belt.position = Vec3::new(0.0, s_a.belt.0 + stop * 1.2, s_a.belt.1);
next.belt.orientation = Quaternion::rotation_x(stop * 0.3);
next.back.position = Vec3::new(0.0, s_a.back.0, s_a.back.1);
next.shorts.position = Vec3::new(0.0, s_a.shorts.0 + stop * 2.5, s_a.shorts.1 + stop * 0.6);
next.shorts.orientation = Quaternion::rotation_x(stop * 0.6);
next.hand_l.position = Vec3::new(
-s_a.hand.0 + 4.0,
s_a.hand.1 + slowa * 0.15 + stop * 8.0,
s_a.hand.2 + slow * 0.7 + stop * 4.0,
);
next.hand_l.orientation =
Quaternion::rotation_x(PI / 2.0) * Quaternion::rotation_z(-PI / 2.0);
next.hand_r.position = Vec3::new(
s_a.hand.0 - 4.0,
s_a.hand.1 + slowa * 0.15 + stop * 8.0,
s_a.hand.2 + slow * 0.7 + stop * 4.0,
);
next.hand_r.orientation =
Quaternion::rotation_x(PI / 2.0) * Quaternion::rotation_z(PI / 2.0);
next.foot_l.position = Vec3::new(-s_a.foot.0 - 2.0, 4.0 + s_a.foot.1, s_a.foot.2);
next.foot_l.orientation = Quaternion::rotation_x(slow * 0.1 + stop * 0.4 + slow * 0.1)
* Quaternion::rotation_y(0.5);
next.foot_r.position = Vec3::new(s_a.foot.0 + 2.0, 4.0 + s_a.foot.1, s_a.foot.2);
next.foot_r.orientation = Quaternion::rotation_x(slowa * 0.1 + stop * 0.4 + slowa * 0.1)
* Quaternion::rotation_y(-0.5);
next.shoulder_l.position = Vec3::new(-s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
next.shoulder_l.orientation = Quaternion::rotation_x(0.0);
next.shoulder_r.position = Vec3::new(s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
next.shoulder_r.orientation = Quaternion::rotation_x(0.0);
next.torso.position = Vec3::new(0.0, 0.0, stop * -0.16) * s_a.scaler;
if skeleton.holding_lantern {
next.hand_r.position = Vec3::new(
s_a.hand.0 + 1.0 - head_look.x * 8.0,
s_a.hand.1 + 5.0 + head_look.x * 6.0,
s_a.hand.2 + 9.0 + head_look.y * 6.0,
);
next.hand_r.orientation = Quaternion::rotation_x(2.25)
* Quaternion::rotation_z(0.9)
* Quaternion::rotation_y(head_look.x * 3.0)
* Quaternion::rotation_x(head_look.y * 3.0);
let fast = (anim_time * 5.0).sin();
let fast2 = (anim_time * 4.5 + 8.0).sin();
next.lantern.position = Vec3::new(-0.5, -0.5, -2.5);
next.lantern.orientation = next.hand_r.orientation.inverse()
* Quaternion::rotation_x(fast * 0.1)
* Quaternion::rotation_y(fast2 * 0.1);
}
next.glider.position = Vec3::new(0.0, 0.0, 10.0);
next.glider.scale = Vec3::one() * 0.0;
next.hold.position = Vec3::new(0.4, -0.3, -5.8);
match hands {
(Some(Hands::Two), _) | (None, Some(Hands::Two)) => match active_tool_kind {
Some(ToolKind::Bow) => {
next.main.position = Vec3::new(0.0, -5.0, 6.0);
next.main.orientation =
Quaternion::rotation_y(2.5) * Quaternion::rotation_z(1.57);
},
Some(ToolKind::Staff) | Some(ToolKind::Sceptre) => {
next.main.position = Vec3::new(2.0, -5.0, -1.0);
next.main.orientation =
Quaternion::rotation_y(-0.5) * Quaternion::rotation_z(1.57);
},
_ => {
next.main.position = Vec3::new(-7.0, -5.0, 15.0);
next.main.orientation =
Quaternion::rotation_y(2.5) * Quaternion::rotation_z(1.57);
},
},
(_, _) => {},
};
match hands {
(Some(Hands::One), _) => match active_tool_kind {
Some(ToolKind::Axe) | Some(ToolKind::Hammer) | Some(ToolKind::Sword) => {
next.main.position = Vec3::new(-4.0, -5.0, 10.0);
next.main.orientation =
Quaternion::rotation_y(2.35) * Quaternion::rotation_z(1.57);
},
_ => {},
},
(_, _) => {},
};
match hands {
(None | Some(Hands::One), Some(Hands::One)) => match second_tool_kind {
Some(ToolKind::Axe) | Some(ToolKind::Hammer) | Some(ToolKind::Sword) => {
next.second.position = Vec3::new(4.0, -6.0, 10.0);
next.second.orientation =
Quaternion::rotation_y(-2.5) * Quaternion::rotation_z(-1.57);
},
_ => {},
},
(_, _) => {},
};
next.second.scale = match hands {
(Some(Hands::One), Some(Hands::One)) => Vec3::one(),
(_, _) => Vec3::zero(),
};
if let (None, Some(Hands::Two)) = hands {
next.second = next.main;
}
next
}
}

View File

@ -5,7 +5,7 @@ pub mod run;
// Reexports
pub use self::{fly::FlyAnimation, idle::IdleAnimation, run::RunAnimation};
use super::{make_bone, vek::*, FigureBoneData, Skeleton};
use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton};
use common::comp::{self};
use core::convert::TryFrom;
@ -43,7 +43,7 @@ impl Skeleton for DragonSkeleton {
&self,
base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> {
) -> Offsets {
let chest_front_mat = base_mat * Mat4::<f32>::from(self.chest_front);
let chest_rear_mat = chest_front_mat * Mat4::<f32>::from(self.chest_rear);
let head_lower_mat = chest_front_mat * Mat4::<f32>::from(self.head_lower);
@ -69,7 +69,10 @@ impl Skeleton for DragonSkeleton {
make_bone(chest_rear_mat * Mat4::<f32>::from(self.foot_bl)),
make_bone(chest_rear_mat * Mat4::<f32>::from(self.foot_br)),
];
Vec3::default()
Offsets {
lantern: Vec3::default(),
mount_bone: self.chest_front,
}
}
}

View File

@ -4,7 +4,7 @@ pub mod swim;
// Reexports
pub use self::{idle::IdleAnimation, swim::SwimAnimation};
use super::{make_bone, vek::*, FigureBoneData, Skeleton};
use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton};
use common::comp::{self};
use core::convert::TryFrom;
@ -33,7 +33,7 @@ impl Skeleton for FishMediumSkeleton {
&self,
base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> {
) -> Offsets {
let chest_front_mat = base_mat * Mat4::<f32>::from(self.chest_front);
let chest_back_mat = Mat4::<f32>::from(self.chest_back);
let head_mat = Mat4::<f32>::from(self.head);
@ -47,7 +47,10 @@ impl Skeleton for FishMediumSkeleton {
make_bone(chest_front_mat * Mat4::<f32>::from(self.fin_l)),
make_bone(chest_front_mat * Mat4::<f32>::from(self.fin_r)),
];
Vec3::default()
Offsets {
lantern: Vec3::default(),
mount_bone: self.chest_front,
}
}
}

View File

@ -4,7 +4,7 @@ pub mod swim;
// Reexports
pub use self::{idle::IdleAnimation, swim::SwimAnimation};
use super::{make_bone, vek::*, FigureBoneData, Skeleton};
use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton};
use common::comp::{self};
use core::convert::TryFrom;
@ -30,7 +30,7 @@ impl Skeleton for FishSmallSkeleton {
&self,
base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> {
) -> Offsets {
let chest_mat = base_mat * Mat4::<f32>::from(self.chest);
*(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [
@ -39,7 +39,10 @@ impl Skeleton for FishSmallSkeleton {
make_bone(chest_mat * Mat4::<f32>::from(self.fin_l)),
make_bone(chest_mat * Mat4::<f32>::from(self.fin_r)),
];
Vec3::default()
Offsets {
lantern: Vec3::default(),
mount_bone: self.chest,
}
}
}

View File

@ -1,4 +1,4 @@
use super::{make_bone, vek::*, FigureBoneData, Skeleton};
use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton};
pub type Body = ();
@ -31,9 +31,12 @@ impl Skeleton for FixtureSkeleton {
&self,
base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> {
) -> Offsets {
buf[0] = make_bone(base_mat);
Vec3::default()
Offsets {
lantern: Vec3::default(),
mount_bone: Transform::default(),
}
}
}

View File

@ -12,7 +12,7 @@ pub use self::{
shockwave::ShockwaveAnimation, shoot::ShootAnimation, spinmelee::SpinMeleeAnimation,
};
use super::{make_bone, vek::*, FigureBoneData, Skeleton};
use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton};
use common::comp::{self};
use core::convert::TryFrom;
@ -47,7 +47,7 @@ impl Skeleton for GolemSkeleton {
&self,
base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> {
) -> Offsets {
let torso_mat = base_mat * Mat4::<f32>::from(self.torso);
let upper_torso_mat = torso_mat * Mat4::<f32>::from(self.upper_torso);
let lower_torso_mat = upper_torso_mat * Mat4::<f32>::from(self.lower_torso);
@ -70,7 +70,10 @@ impl Skeleton for GolemSkeleton {
make_bone(leg_l_mat * Mat4::<f32>::from(self.foot_l)),
make_bone(leg_r_mat * Mat4::<f32>::from(self.foot_r)),
];
Vec3::default()
Offsets {
lantern: Vec3::default(),
mount_bone: self.torso,
}
}
}

View File

@ -98,6 +98,12 @@ lazy_static! {
#[cfg(feature = "use-dyn-lib")]
pub fn init() { lazy_static::initialize(&LIB); }
// Offsets that will be returned after computing the skeleton matrices
pub struct Offsets {
pub lantern: Vec3<f32>,
pub mount_bone: Transform<f32, f32, f32>,
}
pub trait Skeleton: Send + Sync + 'static {
type Attr;
type Body;
@ -111,14 +117,14 @@ pub trait Skeleton: Send + Sync + 'static {
&self,
base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; MAX_BONE_COUNT],
) -> Vec3<f32>;
) -> Offsets;
}
pub fn compute_matrices<S: Skeleton>(
skeleton: &S,
base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; MAX_BONE_COUNT],
) -> Vec3<f32> {
) -> Offsets {
#[cfg(not(feature = "use-dyn-lib"))]
{
S::compute_matrices_inner(skeleton, base_mat, buf)
@ -130,7 +136,7 @@ pub fn compute_matrices<S: Skeleton>(
#[allow(clippy::type_complexity)]
let compute_fn: voxygen_dynlib::Symbol<
fn(&S, Mat4<f32>, &mut [FigureBoneData; MAX_BONE_COUNT]) -> Vec3<f32>,
fn(&S, Mat4<f32>, &mut [FigureBoneData; MAX_BONE_COUNT]) -> Offsets,
> = unsafe { lib.get(S::COMPUTE_FN) }.unwrap_or_else(|e| {
panic!(
"Trying to use: {} but had error: {:?}",

View File

@ -5,7 +5,7 @@ pub mod shoot;
// Reexports
pub use self::{beam::BeamAnimation, idle::IdleAnimation, shoot::ShootAnimation};
use super::{make_bone, vek::*, FigureBoneData, Skeleton};
use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton};
use common::comp::{self};
use core::convert::TryFrom;
@ -29,14 +29,17 @@ impl Skeleton for ObjectSkeleton {
&self,
base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> {
) -> Offsets {
let bone0_mat = base_mat * Mat4::<f32>::from(self.bone0);
*(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [
make_bone(bone0_mat * Mat4::scaling_3d(1.0 / 11.0)),
make_bone(Mat4::<f32>::from(self.bone1) * Mat4::scaling_3d(1.0 / 11.0)), /* Decorellated from ori */
];
Vec3::unit_z() * 0.5
Offsets {
lantern: Vec3::default(),
mount_bone: self.bone0,
}
}
}

View File

@ -16,7 +16,7 @@ pub use self::{
stunned::StunnedAnimation, tailwhip::TailwhipAnimation,
};
use super::{make_bone, vek::*, FigureBoneData, Skeleton};
use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton};
use common::comp::{self};
use core::convert::TryFrom;
@ -48,7 +48,7 @@ impl Skeleton for QuadrupedLowSkeleton {
&self,
base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> {
) -> Offsets {
let chest_mat = base_mat * Mat4::<f32>::from(self.chest);
let tail_front = chest_mat * Mat4::<f32>::from(self.tail_front);
let head_lower_mat = chest_mat * Mat4::<f32>::from(self.head_lower);
@ -66,7 +66,10 @@ impl Skeleton for QuadrupedLowSkeleton {
make_bone(chest_mat * Mat4::<f32>::from(self.foot_bl)),
make_bone(chest_mat * Mat4::<f32>::from(self.foot_br)),
];
Vec3::default()
Offsets {
lantern: Vec3::default(),
mount_bone: self.chest,
}
}
}

View File

@ -16,7 +16,7 @@ pub use self::{
run::RunAnimation, stunned::StunnedAnimation,
};
use super::{make_bone, vek::*, FigureBoneData, Skeleton};
use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton};
use common::comp::{self};
use core::convert::TryFrom;
@ -38,6 +38,7 @@ skeleton_impls!(struct QuadrupedMediumSkeleton {
+ foot_fr,
+ foot_bl,
+ foot_br,
mount,
});
impl Skeleton for QuadrupedMediumSkeleton {
@ -53,7 +54,7 @@ impl Skeleton for QuadrupedMediumSkeleton {
&self,
base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> {
) -> Offsets {
let torso_front_mat = base_mat * Mat4::<f32>::from(self.torso_front);
let torso_back_mat = torso_front_mat * Mat4::<f32>::from(self.torso_back);
let neck_mat = torso_front_mat * Mat4::<f32>::from(self.neck);
@ -80,7 +81,10 @@ impl Skeleton for QuadrupedMediumSkeleton {
make_bone(leg_bl_mat * Mat4::<f32>::from(self.foot_bl)),
make_bone(leg_br_mat * Mat4::<f32>::from(self.foot_br)),
];
Vec3::default()
Offsets {
lantern: Vec3::default(),
mount_bone: self.torso_front,
}
}
}
@ -152,7 +156,7 @@ impl<'a> From<&'a Body> for SkeletonAttr {
(Frostfang, _) => (1.0, -2.0),
(Mouflon, _) => (0.5, 1.5),
(Catoblepas, _) => (-1.0, -6.5),
(Bonerattler, _) => (1.0, 2.5),
(Bonerattler, _) => (0.0, 1.5),
(Deer, Male) => (1.5, 3.5),
(Deer, Female) => (1.5, 3.5),
(Hirdrasil, _) => (0.0, 5.0),
@ -191,7 +195,7 @@ impl<'a> From<&'a Body> for SkeletonAttr {
(Frostfang, _) => (0.5, 1.5),
(Mouflon, _) => (-1.0, 1.0),
(Catoblepas, _) => (19.5, -2.0),
(Bonerattler, _) => (9.0, -0.5),
(Bonerattler, _) => (7.0, -0.5),
(Deer, _) => (-2.5, 1.0),
(Hirdrasil, _) => (-1.0, 0.5),
(Roshwalr, _) => (0.0, 1.0),
@ -303,7 +307,7 @@ impl<'a> From<&'a Body> for SkeletonAttr {
(Frostfang, _) => (9.0, 11.5),
(Mouflon, _) => (11.0, 14.0),
(Catoblepas, _) => (7.5, 19.5),
(Bonerattler, _) => (6.0, 12.5),
(Bonerattler, _) => (6.0, 11.0),
(Deer, _) => (11.0, 13.5),
(Hirdrasil, _) => (11.0, 14.5),
(Roshwalr, _) => (6.0, 12.5),
@ -415,7 +419,7 @@ impl<'a> From<&'a Body> for SkeletonAttr {
(Frostfang, _) => (5.5, -5.5, -2.0),
(Mouflon, _) => (4.0, -5.0, -4.0),
(Catoblepas, _) => (7.0, 2.0, -5.0),
(Bonerattler, _) => (5.5, 5.0, -4.0),
(Bonerattler, _) => (5.5, 5.0, -2.5),
(Deer, _) => (3.5, -4.5, -3.5),
(Hirdrasil, _) => (4.5, -5.0, -2.5),
(Roshwalr, _) => (8.0, -2.5, -2.5),
@ -452,7 +456,7 @@ impl<'a> From<&'a Body> for SkeletonAttr {
(Frostfang, _) => (3.5, -4.5, -2.0),
(Mouflon, _) => (3.5, -8.0, -3.5),
(Catoblepas, _) => (6.0, -2.5, -2.5),
(Bonerattler, _) => (6.0, -8.0, -4.0),
(Bonerattler, _) => (6.0, -8.0, -2.5),
(Deer, _) => (3.0, -6.5, -3.5),
(Hirdrasil, _) => (4.0, -6.5, -3.0),
(Roshwalr, _) => (7.0, -7.0, -2.5),

View File

@ -11,7 +11,7 @@ pub use self::{
run::RunAnimation, stunned::StunnedAnimation,
};
use super::{make_bone, vek::*, FigureBoneData, Skeleton};
use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton};
use common::comp::{self};
use core::convert::TryFrom;
@ -40,7 +40,7 @@ impl Skeleton for QuadrupedSmallSkeleton {
&self,
base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> {
) -> Offsets {
let chest_mat = base_mat * Mat4::<f32>::from(self.chest);
*(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [
@ -52,7 +52,10 @@ impl Skeleton for QuadrupedSmallSkeleton {
make_bone(chest_mat * Mat4::<f32>::from(self.leg_br)),
make_bone(chest_mat * Mat4::<f32>::from(self.tail)),
];
Vec3::default()
Offsets {
lantern: Vec3::default(),
mount_bone: self.chest,
}
}
}

View File

@ -3,7 +3,7 @@ pub mod idle;
// Reexports
pub use self::idle::IdleAnimation;
use super::{make_bone, vek::*, FigureBoneData, Skeleton};
use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton};
use common::comp::{self};
use core::convert::TryFrom;
@ -29,7 +29,7 @@ impl Skeleton for ShipSkeleton {
&self,
base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> {
) -> Offsets {
let bone0_mat = base_mat * Mat4::<f32>::from(self.bone0);
*(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [
@ -38,7 +38,10 @@ impl Skeleton for ShipSkeleton {
make_bone(bone0_mat * Mat4::<f32>::from(self.bone2) * Mat4::scaling_3d(1.0 / 11.0)), /* Decorellated from ori */
make_bone(bone0_mat * Mat4::<f32>::from(self.bone3) * Mat4::scaling_3d(1.0 / 11.0)), /* Decorellated from ori */
];
Vec3::unit_z() * 0.5
Offsets {
lantern: Vec3::default(),
mount_bone: self.bone0,
}
}
}

View File

@ -11,7 +11,7 @@ pub use self::{
jump::JumpAnimation, run::RunAnimation,
};
use super::{make_bone, vek::*, FigureBoneData, Skeleton};
use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton};
use common::comp::{self};
use core::convert::TryFrom;
@ -47,7 +47,7 @@ impl Skeleton for TheropodSkeleton {
&self,
base_mat: Mat4<f32>,
buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
) -> Vec3<f32> {
) -> Offsets {
let chest_front_mat = base_mat * Mat4::<f32>::from(self.chest_front);
let neck_mat = chest_front_mat * Mat4::<f32>::from(self.neck);
let head_mat = neck_mat * Mat4::<f32>::from(self.head);
@ -71,7 +71,10 @@ impl Skeleton for TheropodSkeleton {
make_bone(leg_l_mat * Mat4::<f32>::from(self.foot_l)),
make_bone(leg_r_mat * Mat4::<f32>::from(self.foot_r)),
];
Vec3::default()
Offsets {
lantern: Vec3::default(),
mount_bone: self.chest_front,
}
}
}

View File

@ -31,11 +31,12 @@ use common::{
inventory::slot::EquipSlot,
item::{Hands, ItemKind, ToolKind},
Body, CharacterState, Controller, Health, Inventory, Item, Last, LightAnimation,
LightEmitter, Ori, PhysicsState, PoiseState, Pos, Scale, Vel,
LightEmitter, Mounting, Ori, PhysicsState, PoiseState, Pos, Scale, Vel,
},
resources::DeltaTime,
states::utils::StageSection,
terrain::TerrainChunk,
uid::UidAllocator,
vol::RectRasterableVol,
};
use common_base::span;
@ -48,7 +49,7 @@ use core::{
};
use guillotiere::AtlasAllocator;
use hashbrown::HashMap;
use specs::{Entity as EcsEntity, Join, LazyUpdate, WorldExt};
use specs::{saveload::MarkerAllocator, Entity as EcsEntity, Join, LazyUpdate, WorldExt};
use treeculler::{BVol, BoundingSphere};
use vek::*;
@ -572,6 +573,10 @@ impl FigureMgr {
let mut update_buf = [Default::default(); anim::MAX_BONE_COUNT];
let uid_allocator = ecs.read_resource::<UidAllocator>();
let bodies = ecs.read_storage::<Body>();
for (
i,
(
@ -589,6 +594,7 @@ impl FigureMgr {
inventory,
item,
light_emitter,
mountings,
),
) in (
&ecs.entities(),
@ -605,6 +611,7 @@ impl FigureMgr {
ecs.read_storage::<Inventory>().maybe(),
ecs.read_storage::<Item>().maybe(),
ecs.read_storage::<LightEmitter>().maybe(),
ecs.read_storage::<Mounting>().maybe(),
)
.join()
.enumerate()
@ -687,7 +694,7 @@ impl FigureMgr {
// shadow correctly until their next update. For now, we treat this
// as an acceptable tradeoff.
let radius = scale.unwrap_or(&Scale(1.0)).0 * 2.0;
let (in_frustum, lpindex) = if let Some(mut meta) = state {
let (in_frustum, lpindex) = if let Some(ref mut meta) = state {
let (in_frustum, lpindex) = BoundingSphere::new(pos.0.into_array(), radius)
.coherent_test_against_frustum(frustum, meta.lpindex);
let in_frustum = in_frustum || matches!(body, Body::Ship(_));
@ -748,6 +755,16 @@ impl FigureMgr {
let hands = (active_tool_hand, second_tool_hand);
// If a mountee exists, get its physical mounting offsets and its body
let (mountee_offsets, mountee_body) = (|| -> Option<_> {
let Mounting(entity) = mountings?;
let entity = uid_allocator.retrieve_entity_internal((*entity).into())?;
let body = *bodies.get(entity)?;
let meta = self.states.get_mut(&body, &entity)?;
Some((Some(meta.mountee_offset), Some(body)))
})()
.unwrap_or((None, None));
match body {
Body::Humanoid(body) => {
let (model, skeleton_attr) = self.model_cache.get_or_create_model(
@ -775,7 +792,14 @@ impl FigureMgr {
.character_states
.entry(entity)
.or_insert_with(|| {
FigureState::new(renderer, CharacterSkeleton::new(holding_lantern))
FigureState::new(
renderer,
CharacterSkeleton::new(
holding_lantern,
mountee_offsets,
mountee_body,
),
)
});
// Average velocity relative to the current ground
@ -794,63 +818,82 @@ impl FigureMgr {
physics.on_ground.is_some(),
rel_vel.magnitude_squared() > MOVING_THRESHOLD_SQR, // Moving
physics.in_liquid().is_some(), // In water
mountings.is_some(),
) {
// Standing
(true, false, false) => anim::character::StandAnimation::update_skeleton(
&CharacterSkeleton::new(holding_lantern),
(
active_tool_kind,
second_tool_kind,
hands,
// TODO: Update to use the quaternion.
ori * anim::vek::Vec3::<f32>::unit_y(),
state.last_ori * anim::vek::Vec3::<f32>::unit_y(),
time,
rel_avg_vel,
),
state.state_time,
&mut state_animation_rate,
skeleton_attr,
),
(true, false, false, false) => {
anim::character::StandAnimation::update_skeleton(
&CharacterSkeleton::new(
holding_lantern,
mountee_offsets,
mountee_body,
),
(
active_tool_kind,
second_tool_kind,
hands,
// TODO: Update to use the quaternion.
ori * anim::vek::Vec3::<f32>::unit_y(),
state.last_ori * anim::vek::Vec3::<f32>::unit_y(),
time,
rel_avg_vel,
),
state.state_time,
&mut state_animation_rate,
skeleton_attr,
)
},
// Running
(true, true, false) => anim::character::RunAnimation::update_skeleton(
&CharacterSkeleton::new(holding_lantern),
(
active_tool_kind,
second_tool_kind,
hands,
rel_vel,
// TODO: Update to use the quaternion.
ori * anim::vek::Vec3::<f32>::unit_y(),
state.last_ori * anim::vek::Vec3::<f32>::unit_y(),
time,
rel_avg_vel,
state.acc_vel,
),
state.state_time,
&mut state_animation_rate,
skeleton_attr,
),
(true, true, false, false) => {
anim::character::RunAnimation::update_skeleton(
&CharacterSkeleton::new(
holding_lantern,
mountee_offsets,
mountee_body,
),
(
active_tool_kind,
second_tool_kind,
hands,
rel_vel,
// TODO: Update to use the quaternion.
ori * anim::vek::Vec3::<f32>::unit_y(),
state.last_ori * anim::vek::Vec3::<f32>::unit_y(),
time,
rel_avg_vel,
state.acc_vel,
),
state.state_time,
&mut state_animation_rate,
skeleton_attr,
)
},
// In air
(false, _, false) => anim::character::JumpAnimation::update_skeleton(
&CharacterSkeleton::new(holding_lantern),
(
active_tool_kind,
second_tool_kind,
hands,
rel_vel,
// TODO: Update to use the quaternion.
ori * anim::vek::Vec3::<f32>::unit_y(),
state.last_ori * anim::vek::Vec3::<f32>::unit_y(),
time,
),
state.state_time,
&mut state_animation_rate,
skeleton_attr,
),
(false, _, false, false) => {
anim::character::JumpAnimation::update_skeleton(
&CharacterSkeleton::new(
holding_lantern,
mountee_offsets,
mountee_body,
),
(
active_tool_kind,
second_tool_kind,
hands,
rel_vel,
// TODO: Update to use the quaternion.
ori * anim::vek::Vec3::<f32>::unit_y(),
state.last_ori * anim::vek::Vec3::<f32>::unit_y(),
time,
),
state.state_time,
&mut state_animation_rate,
skeleton_attr,
)
},
// Swim
(_, _, true) => anim::character::SwimAnimation::update_skeleton(
&CharacterSkeleton::new(holding_lantern),
(_, _, true, false) => anim::character::SwimAnimation::update_skeleton(
&CharacterSkeleton::new(holding_lantern, mountee_offsets, mountee_body),
(
active_tool_kind,
second_tool_kind,
@ -866,6 +909,24 @@ impl FigureMgr {
&mut state_animation_rate,
skeleton_attr,
),
// Mount
(_, _, _, true) => anim::character::MountAnimation::update_skeleton(
&CharacterSkeleton::new(holding_lantern, mountee_offsets, mountee_body),
(
active_tool_kind,
second_tool_kind,
hands,
time,
rel_vel,
rel_avg_vel,
// TODO: Update to use the quaternion.
ori * anim::vek::Vec3::<f32>::unit_y(),
state.last_ori * anim::vek::Vec3::<f32>::unit_y(),
),
state.state_time,
&mut state_animation_rate,
skeleton_attr,
),
};
let target_bones = match &character {
CharacterState::Roll(s) => {
@ -5331,6 +5392,7 @@ impl FigureColLights {
pub struct FigureStateMeta {
lantern_offset: anim::vek::Vec3<f32>,
mountee_offset: anim::vek::Transform<f32, f32, f32>,
state_time: f32,
last_ori: anim::vek::Quaternion<f32>,
lpindex: u8,
@ -5371,12 +5433,12 @@ impl<S> DerefMut for FigureState<S> {
impl<S: Skeleton> FigureState<S> {
pub fn new(renderer: &mut Renderer, skeleton: S) -> Self {
let mut buf = [Default::default(); anim::MAX_BONE_COUNT];
let lantern_offset =
anim::compute_matrices(&skeleton, anim::vek::Mat4::identity(), &mut buf);
let offsets = anim::compute_matrices(&skeleton, anim::vek::Mat4::identity(), &mut buf);
let bone_consts = figure_bone_data_from_anim(&buf);
Self {
meta: FigureStateMeta {
lantern_offset,
lantern_offset: offsets.lantern,
mountee_offset: offsets.mount_bone,
state_time: 0.0,
last_ori: Ori::default().into(),
lpindex: 0,
@ -5501,12 +5563,13 @@ impl<S: Skeleton> FigureState<S> {
);
renderer.update_consts(&mut self.meta.bound.0, &[locals]);
let lantern_offset = anim::compute_matrices(&self.skeleton, mat, buf);
let offsets = anim::compute_matrices(&self.skeleton, mat, buf);
let new_bone_consts = figure_bone_data_from_anim(buf);
renderer.update_consts(&mut self.meta.bound.1, &new_bone_consts[0..S::BONE_COUNT]);
self.lantern_offset = lantern_offset;
self.lantern_offset = offsets.lantern;
self.mountee_offset = offsets.mount_bone;
let smoothing = (5.0 * dt).min(1.0);
if let Some(last_pos) = self.last_pos {