Initial idle animation work

This commit is contained in:
Snowram 2020-05-03 02:03:21 +02:00 committed by jshipsey
parent 33f8a47cfa
commit 7f0d1e9543
3 changed files with 152 additions and 93 deletions

View File

@ -1,5 +1,5 @@
use super::{super::Animation, DragonSkeleton, SkeletonAttr};
//use std::{f32::consts::PI, ops::Mul};
use std::ops::Mul;
use vek::*;
pub struct IdleAnimation;
@ -10,109 +10,122 @@ impl Animation for IdleAnimation {
fn update_skeleton(
skeleton: &Self::Skeleton,
_global_time: Self::Dependency,
_anim_time: f64,
global_time: Self::Dependency,
anim_time: f64,
_rate: &mut f32,
_skeleton_attr: &SkeletonAttr,
skeleton_attr: &SkeletonAttr,
) -> Self::Skeleton {
let mut next = (*skeleton).clone();
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const HEAD_X: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const HEAD_Z: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const CHEST_F_X: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const CHEST_F_Z: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const CHEST_R_X: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const CHEST_R_Z: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const TAIL_F_X: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const TAIL_F_Z: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const TAIL_R_X: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const TAIL_R_Z: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const WING_IN_X: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const WING_IN_Y: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const WING_IN_Z: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const WING_OUT_X: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const WING_OUT_Y: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const WING_OUT_Z: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const FEET_F_X: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const FEET_F_Y: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const FEET_F_Z: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const FEET_B_X: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const FEET_B_Y: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const FEET_B_Z: f32 = 0.0;
let wave_slow = (anim_time as f32 * 4.5).sin();
let wave_slow_cos = (anim_time as f32 * 4.5).cos();
next.head.offset = Vec3::new(0.0, *HEAD_X, *HEAD_Z);
next.head.ori = Quaternion::rotation_z(0.0) * Quaternion::rotation_x(0.0);
next.head.scale = Vec3::one() * 1.01;
let duck_head_look = Vec2::new(
((global_time + anim_time) as f32 / 8.0)
.floor()
.mul(7331.0)
.sin()
* 0.5,
((global_time + anim_time) as f32 / 8.0)
.floor()
.mul(1337.0)
.sin()
* 0.25,
);
next.chest_front.offset = Vec3::new(0.0, *CHEST_F_X, *CHEST_F_Z);
next.chest_front.ori = Quaternion::rotation_x(0.0);
next.chest_front.scale = Vec3::one() * 1.01;
next.head.offset = Vec3::new(0.0, skeleton_attr.head.0, skeleton_attr.head.1);
next.head.ori = Quaternion::rotation_z(duck_head_look.x)
* Quaternion::rotation_x(-duck_head_look.y.abs() + wave_slow_cos * 0.03);
next.head.scale = Vec3::one();
next.chest_rear.offset = Vec3::new(0.0, *CHEST_R_X, *CHEST_R_Z);
next.chest_rear.ori = Quaternion::rotation_x(0.0);
next.chest_rear.scale = Vec3::one() * 1.01;
next.chest_front.offset = Vec3::new(
0.0,
skeleton_attr.chest_front.0,
wave_slow * 0.3 + skeleton_attr.chest_front.1,
) * 1.05;
next.chest_front.ori = Quaternion::rotation_y(wave_slow * 0.03);
next.chest_front.scale = Vec3::one() * 1.05;
next.tail_front.offset = Vec3::new(0.0, *TAIL_F_X, *TAIL_F_Z);
next.tail_front.ori = Quaternion::rotation_x(0.0);
next.tail_front.scale = Vec3::one() * 1.01;
next.chest_rear.offset = Vec3::new(
0.0,
skeleton_attr.chest_rear.0,
wave_slow * 0.3 + skeleton_attr.chest_rear.1,
) * 1.05;
next.chest_rear.ori = Quaternion::rotation_y(wave_slow * 0.03);
next.chest_rear.scale = Vec3::one() * 1.05;
next.tail_rear.offset = Vec3::new(0.0, *TAIL_R_X, *TAIL_R_Z);
next.tail_rear.ori = Quaternion::rotation_x(0.0);
next.tail_rear.scale = Vec3::one() * 1.01;
next.tail_front.offset = Vec3::new(0.0, skeleton_attr.tail_front.0, skeleton_attr.tail_front.1);
next.tail_front.ori = Quaternion::rotation_x(wave_slow_cos * 0.03);
next.tail_front.scale = Vec3::one();
next.wing_in_l.offset = Vec3::new(*WING_IN_X, *WING_IN_Y, *WING_IN_Z);
next.wing_in_l.ori = Quaternion::rotation_x(0.0);
next.wing_in_l.scale = Vec3::one() * 1.01;
next.tail_rear.offset = Vec3::new(0.0, skeleton_attr.tail_rear.0, skeleton_attr.tail_rear.1);
next.tail_rear.ori = Quaternion::rotation_x(wave_slow_cos * 0.03);
next.tail_rear.scale = Vec3::one();
next.wing_in_r.offset = Vec3::new(-*WING_IN_X, *WING_IN_Y, *WING_IN_Z);
next.wing_in_r.ori = Quaternion::rotation_x(0.0);
next.wing_in_r.scale = Vec3::one() * 1.01;
next.wing_in_l.offset = Vec3::new(
-skeleton_attr.wing_in.0,
skeleton_attr.wing_in.1,
skeleton_attr.wing_in.2,
);
next.wing_in_l.ori = Quaternion::rotation_z(0.0);
next.wing_in_l.scale = Vec3::one() * 1.05;
next.wing_out_l.offset = Vec3::new(*WING_OUT_X, *WING_OUT_Y, *WING_OUT_Z);
next.wing_out_l.ori = Quaternion::rotation_x(0.0);
next.wing_out_l.scale = Vec3::one() * 1.01;
next.wing_in_r.offset = Vec3::new(
skeleton_attr.wing_in.0,
skeleton_attr.wing_in.1,
skeleton_attr.wing_in.2,
);
next.wing_in_r.ori = Quaternion::rotation_y(0.0);
next.wing_in_r.scale = Vec3::one() * 1.05;
next.wing_out_r.offset = Vec3::new(-*WING_OUT_X, *WING_OUT_Y, *WING_OUT_Z);
next.wing_out_r.ori = Quaternion::rotation_x(0.0);
next.wing_out_r.scale = Vec3::one() * 1.01;
next.wing_out_l.offset = Vec3::new(
-skeleton_attr.wing_out.0,
skeleton_attr.wing_out.1,
skeleton_attr.wing_out.2,
);
next.wing_out_l.ori = Quaternion::rotation_z(0.0);
next.wing_out_l.scale = Vec3::one() * 1.05;
next.foot_fl.offset = Vec3::new(*FEET_F_X, *FEET_F_Y, *FEET_F_Z);
next.wing_in_r.offset = Vec3::new(
skeleton_attr.wing_out.0,
skeleton_attr.wing_out.1,
skeleton_attr.wing_out.2,
);
next.wing_out_r.ori = Quaternion::rotation_y(0.0);
next.wing_out_r.scale = Vec3::one() * 1.05;
next.foot_fl.offset = Vec3::new(
-skeleton_attr.feet_f.0,
skeleton_attr.feet_f.1,
skeleton_attr.feet_f.2,
) * 1.05;
next.foot_fl.ori = Quaternion::rotation_x(0.0);
next.foot_fl.scale = Vec3::one() * 1.01;
next.foot_fl.scale = Vec3::one() * 1.05;
next.foot_fr.offset = Vec3::new(-*FEET_F_X, *FEET_F_Y, *FEET_F_Z);
next.foot_fr.offset = Vec3::new(
skeleton_attr.feet_f.0,
skeleton_attr.feet_f.1,
skeleton_attr.feet_f.2,
) * 1.05;
next.foot_fr.ori = Quaternion::rotation_x(0.0);
next.foot_fr.scale = Vec3::one() * 1.01;
next.foot_fr.scale = Vec3::one() * 1.05;
next.foot_bl.offset = Vec3::new(*FEET_F_X, *FEET_B_Y, *FEET_B_Z);
next.foot_bl.offset = Vec3::new(
-skeleton_attr.feet_b.0,
skeleton_attr.feet_b.1,
skeleton_attr.feet_b.2,
) * 1.05;
next.foot_bl.ori = Quaternion::rotation_x(0.0);
next.foot_bl.scale = Vec3::one() * 1.01;
next.foot_bl.scale = Vec3::one() * 1.05;
next.foot_br.offset = Vec3::new(-*FEET_F_X, *FEET_B_Y, *FEET_B_Z);
next.foot_br.offset = Vec3::new(
skeleton_attr.feet_b.0,
skeleton_attr.feet_b.1,
skeleton_attr.feet_b.2,
) * 1.05;
next.foot_br.ori = Quaternion::rotation_x(0.0);
next.foot_br.scale = Vec3::one() * 1.01;
next.foot_br.scale = Vec3::one() * 1.05;
next
}
}

View File

@ -10,6 +10,51 @@ use crate::render::FigureBoneData;
use common::comp::{self};
use vek::Vec3;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const HEAD_X: f32 = 4.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const HEAD_Z: f32 = 11.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const CHEST_F_X: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const CHEST_F_Z: f32 = 14.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const CHEST_R_X: f32 = -13.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const CHEST_R_Z: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const TAIL_F_X: f32 = -11.5;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const TAIL_F_Z: f32 = 16.5;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const TAIL_R_X: f32 = -25.5;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const TAIL_R_Z: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const WING_IN_X: f32 = 10.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const WING_IN_Y: f32 = -32.5;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const WING_IN_Z: f32 = -19.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const WING_OUT_X: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const WING_OUT_Y: f32 = 1.5;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const WING_OUT_Z: f32 = -10.5;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const FEET_F_X: f32 = 4.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const FEET_F_Y: f32 = 0.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const FEET_F_Z: f32 = 1.5;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const FEET_B_X: f32 = 4.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const FEET_B_Y: f32 = -15.0;
#[const_tweaker::tweak(min = -40.0, max = 40.0, step = 0.5)]
const FEET_B_Z: f32 = 3.0;
#[derive(Clone, Default)]
pub struct DragonSkeleton {
head: Bone,
@ -148,31 +193,31 @@ impl<'a> From<&'a comp::dragon::Body> for SkeletonAttr {
use comp::dragon::Species::*;
Self {
head: match (body.species, body.body_type) {
(Reddragon, _) => (0.0, 0.0),
(Reddragon, _) => (*HEAD_X, *HEAD_Z),
},
chest_front: match (body.species, body.body_type) {
(Reddragon, _) => (0.0, 0.0),
(Reddragon, _) => (*CHEST_F_X, *CHEST_F_Z),
},
chest_rear: match (body.species, body.body_type) {
(Reddragon, _) => (0.0, 0.0),
(Reddragon, _) => (*CHEST_R_X, *CHEST_R_Z),
},
tail_front: match (body.species, body.body_type) {
(Reddragon, _) => (0.0, 0.0),
(Reddragon, _) => (*TAIL_F_X, *TAIL_F_Z),
},
tail_rear: match (body.species, body.body_type) {
(Reddragon, _) => (0.0, 0.0),
(Reddragon, _) => (*TAIL_R_X, *TAIL_R_Z),
},
wing_in: match (body.species, body.body_type) {
(Reddragon, _) => (0.0, 0.0, 0.0),
(Reddragon, _) => (*WING_IN_X, *WING_IN_Y, *WING_IN_Z),
},
wing_out: match (body.species, body.body_type) {
(Reddragon, _) => (0.0, 0.0, 0.0),
(Reddragon, _) => (*WING_OUT_X, *WING_OUT_Y, *WING_OUT_Z),
},
feet_f: match (body.species, body.body_type) {
(Reddragon, _) => (0.0, 0.0, 0.0),
(Reddragon, _) => (*FEET_F_X, *FEET_F_Y, *FEET_F_Z),
},
feet_b: match (body.species, body.body_type) {
(Reddragon, _) => (0.0, 0.0, 0.0),
(Reddragon, _) => (*FEET_B_X, *FEET_B_Y, *FEET_B_Z),
},
}
}

View File

@ -1052,7 +1052,7 @@ impl FigureMgr {
is_player,
);
},
Body::Dragon(_) => {
Body::Dragon(dragon_body) => {
let skeleton_attr = &self
.dragon_model_cache
.get_or_create_model(
@ -1064,6 +1064,7 @@ impl FigureMgr {
None,
)
.1;
let ref skeleton_attr = dragon_body.into();
let state = self
.dragon_states