2019-01-14 14:40:22 +00:00
|
|
|
pub mod character;
|
2019-05-18 19:03:13 +00:00
|
|
|
pub mod fixture;
|
2019-07-21 12:42:45 +00:00
|
|
|
pub mod object;
|
2019-05-13 23:43:10 +00:00
|
|
|
pub mod quadruped;
|
2019-05-26 14:25:56 +00:00
|
|
|
pub mod quadrupedmedium;
|
2019-05-18 19:03:13 +00:00
|
|
|
|
2019-01-13 20:53:55 +00:00
|
|
|
use crate::render::FigureBoneData;
|
2019-07-29 13:44:16 +00:00
|
|
|
use common::comp::{self, item::Tool};
|
2019-06-06 14:48:41 +00:00
|
|
|
use vek::*;
|
2019-01-13 20:53:55 +00:00
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
pub struct Bone {
|
|
|
|
pub offset: Vec3<f32>,
|
|
|
|
pub ori: Quaternion<f32>,
|
2019-04-12 22:19:19 +00:00
|
|
|
pub scale: Vec3<f32>,
|
2019-01-13 20:53:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Bone {
|
|
|
|
pub fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
offset: Vec3::zero(),
|
|
|
|
ori: Quaternion::identity(),
|
2019-04-12 22:19:19 +00:00
|
|
|
scale: Vec3::broadcast(1.0 / 11.0),
|
2019-01-13 20:53:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn compute_base_matrix(&self) -> Mat4<f32> {
|
2019-04-29 20:37:19 +00:00
|
|
|
Mat4::<f32>::translation_3d(self.offset)
|
|
|
|
* Mat4::scaling_3d(self.scale)
|
|
|
|
* Mat4::from(self.ori)
|
2019-01-13 20:53:55 +00:00
|
|
|
}
|
2019-04-16 18:15:49 +00:00
|
|
|
|
2019-05-17 09:22:32 +00:00
|
|
|
/// Change the current bone to be more like `target`.
|
2019-06-16 17:45:01 +00:00
|
|
|
fn interpolate(&mut self, target: &Bone, dt: f32) {
|
2019-05-17 09:22:32 +00:00
|
|
|
// TODO: Make configurable.
|
2019-06-26 16:22:28 +00:00
|
|
|
let factor = (15.0 * dt).min(1.0);
|
2019-04-16 18:15:49 +00:00
|
|
|
self.offset += (target.offset - self.offset) * factor;
|
2019-04-16 18:43:13 +00:00
|
|
|
self.ori = vek::ops::Slerp::slerp(self.ori, target.ori, factor);
|
|
|
|
self.scale += (target.scale - self.scale) * factor;
|
2019-04-16 18:15:49 +00:00
|
|
|
}
|
2019-01-13 20:53:55 +00:00
|
|
|
}
|
|
|
|
|
2019-04-10 21:51:14 +00:00
|
|
|
pub trait Skeleton: Send + Sync + 'static {
|
2019-01-14 14:18:58 +00:00
|
|
|
fn compute_matrices(&self) -> [FigureBoneData; 16];
|
2019-04-16 18:15:49 +00:00
|
|
|
|
2019-05-17 09:22:32 +00:00
|
|
|
/// Change the current skeleton to be more like `target`.
|
2019-06-16 17:45:01 +00:00
|
|
|
fn interpolate(&mut self, target: &Self, dt: f32);
|
2019-01-13 20:53:55 +00:00
|
|
|
}
|
|
|
|
|
2019-06-28 08:24:13 +00:00
|
|
|
pub struct SkeletonAttr {
|
|
|
|
scaler: f32,
|
|
|
|
head_scale: f32,
|
|
|
|
neck_height: f32,
|
|
|
|
neck_forward: f32,
|
2019-06-28 14:45:02 +00:00
|
|
|
neck_right: f32,
|
2019-06-28 08:24:13 +00:00
|
|
|
weapon_x: f32,
|
|
|
|
weapon_y: f32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for SkeletonAttr {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
scaler: 1.0,
|
|
|
|
head_scale: 1.0,
|
|
|
|
neck_height: 1.0,
|
|
|
|
neck_forward: 1.0,
|
2019-06-28 14:45:02 +00:00
|
|
|
neck_right: 1.0,
|
2019-06-28 08:24:13 +00:00
|
|
|
weapon_x: 1.0,
|
|
|
|
weapon_y: 1.0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-28 23:42:51 +00:00
|
|
|
impl<'a> From<&'a comp::humanoid::Body> for SkeletonAttr {
|
|
|
|
fn from(body: &'a comp::humanoid::Body) -> Self {
|
|
|
|
use comp::humanoid::{BodyType::*, Race::*};
|
2019-06-28 08:24:13 +00:00
|
|
|
Self {
|
|
|
|
scaler: match (body.race, body.body_type) {
|
2019-06-28 23:42:51 +00:00
|
|
|
(Orc, Male) => 1.2,
|
|
|
|
(Orc, Female) => 1.0,
|
|
|
|
(Human, Male) => 1.0,
|
|
|
|
(Human, Female) => 0.90,
|
|
|
|
(Elf, Male) => 1.0,
|
|
|
|
(Elf, Female) => 1.0,
|
|
|
|
(Dwarf, Male) => 0.92,
|
|
|
|
(Dwarf, Female) => 0.89,
|
|
|
|
(Undead, Male) => 0.98,
|
|
|
|
(Undead, Female) => 0.93,
|
|
|
|
(Danari, Male) => 0.85,
|
|
|
|
(Danari, Female) => 0.82,
|
2019-06-28 08:24:13 +00:00
|
|
|
},
|
|
|
|
head_scale: match (body.race, body.body_type) {
|
2019-06-28 23:42:51 +00:00
|
|
|
(Orc, Male) => 0.9,
|
|
|
|
(Orc, Female) => 1.0,
|
|
|
|
(Human, Male) => 1.0,
|
|
|
|
(Human, Female) => 1.0,
|
|
|
|
(Elf, Male) => 1.0,
|
|
|
|
(Elf, Female) => 1.0,
|
|
|
|
(Dwarf, Male) => 1.0,
|
|
|
|
(Dwarf, Female) => 1.0,
|
|
|
|
(Undead, Male) => 1.0,
|
|
|
|
(Undead, Female) => 1.0,
|
|
|
|
(Danari, Male) => 1.11,
|
|
|
|
(Danari, Female) => 1.11,
|
2019-06-28 08:24:13 +00:00
|
|
|
},
|
|
|
|
neck_height: match (body.race, body.body_type) {
|
2019-06-28 23:42:51 +00:00
|
|
|
(Orc, Male) => -2.0,
|
2019-07-14 14:34:47 +00:00
|
|
|
(Orc, Female) => 0.0,
|
|
|
|
(Human, Male) => -0.75,
|
2019-06-28 23:42:51 +00:00
|
|
|
(Human, Female) => -2.0,
|
2019-07-14 14:34:47 +00:00
|
|
|
(Elf, Male) => -0.75,
|
2019-08-04 11:23:01 +00:00
|
|
|
(Elf, Female) => -2.45,
|
2019-06-28 23:42:51 +00:00
|
|
|
(Dwarf, Male) => -0.0,
|
2019-08-04 11:23:01 +00:00
|
|
|
(Dwarf, Female) => -1.25,
|
2019-06-28 23:42:51 +00:00
|
|
|
(Undead, Male) => -1.0,
|
|
|
|
(Undead, Female) => -0.5,
|
|
|
|
(Danari, Male) => 0.5,
|
2019-08-04 11:23:01 +00:00
|
|
|
(Danari, Female) => -0.75,
|
2019-06-28 08:24:13 +00:00
|
|
|
},
|
|
|
|
neck_forward: match (body.race, body.body_type) {
|
2019-07-14 14:34:47 +00:00
|
|
|
(Orc, Male) => 0.0,
|
|
|
|
(Orc, Female) => -2.0,
|
2019-06-28 23:42:51 +00:00
|
|
|
(Human, Male) => 0.0,
|
|
|
|
(Human, Female) => -1.0,
|
2019-07-14 14:34:47 +00:00
|
|
|
(Elf, Male) => 0.0,
|
2019-06-28 23:42:51 +00:00
|
|
|
(Elf, Female) => -0.5,
|
|
|
|
(Dwarf, Male) => 2.0,
|
|
|
|
(Dwarf, Female) => 0.0,
|
|
|
|
(Undead, Male) => 1.0,
|
2019-08-04 11:23:01 +00:00
|
|
|
(Undead, Female) => 0.75,
|
2019-06-28 23:42:51 +00:00
|
|
|
(Danari, Male) => 0.5,
|
2019-08-04 11:23:01 +00:00
|
|
|
(Danari, Female) => -3.0,
|
2019-06-28 08:24:13 +00:00
|
|
|
},
|
2019-06-28 14:45:02 +00:00
|
|
|
neck_right: match (body.race, body.body_type) {
|
2019-06-28 23:42:51 +00:00
|
|
|
(Orc, Male) => 0.0,
|
|
|
|
(Orc, Female) => 0.0,
|
|
|
|
(Human, Male) => 0.0,
|
|
|
|
(Human, Female) => 0.0,
|
2019-06-30 17:59:29 +00:00
|
|
|
(Elf, Male) => 0.0,
|
2019-08-04 11:23:01 +00:00
|
|
|
(Elf, Female) => 0.0,
|
2019-06-28 23:42:51 +00:00
|
|
|
(Dwarf, Male) => 0.0,
|
|
|
|
(Dwarf, Female) => 0.0,
|
|
|
|
(Undead, Male) => -0.5,
|
|
|
|
(Undead, Female) => 0.0,
|
|
|
|
(Danari, Male) => 0.0,
|
|
|
|
(Danari, Female) => 0.0,
|
2019-06-28 14:45:02 +00:00
|
|
|
},
|
2019-07-29 13:44:16 +00:00
|
|
|
weapon_x: match Tool::Hammer {
|
2019-06-28 23:42:51 +00:00
|
|
|
// TODO: Inventory
|
2019-07-29 13:44:16 +00:00
|
|
|
Tool::Sword => 0.0,
|
|
|
|
Tool::Axe => 3.0,
|
|
|
|
Tool::Hammer => 0.0,
|
|
|
|
Tool::SwordShield => 3.0,
|
|
|
|
Tool::Staff => 3.0,
|
|
|
|
Tool::Bow => 0.0,
|
|
|
|
Tool::Daggers => 0.0,
|
2019-06-28 08:24:13 +00:00
|
|
|
},
|
2019-07-29 13:44:16 +00:00
|
|
|
weapon_y: match Tool::Hammer {
|
2019-06-28 23:42:51 +00:00
|
|
|
// TODO: Inventory
|
2019-07-29 13:44:16 +00:00
|
|
|
Tool::Sword => -1.25,
|
|
|
|
Tool::Axe => 0.0,
|
|
|
|
Tool::Hammer => -2.0,
|
|
|
|
Tool::SwordShield => 0.0,
|
|
|
|
Tool::Staff => 0.0,
|
|
|
|
Tool::Bow => -2.0,
|
|
|
|
Tool::Daggers => -2.0,
|
2019-06-28 08:24:13 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-14 14:18:58 +00:00
|
|
|
pub trait Animation {
|
|
|
|
type Skeleton;
|
|
|
|
type Dependency;
|
|
|
|
|
2019-05-17 09:22:32 +00:00
|
|
|
/// Returns a new skeleton that is generated by the animation.
|
2019-05-09 17:58:16 +00:00
|
|
|
fn update_skeleton(
|
|
|
|
skeleton: &Self::Skeleton,
|
|
|
|
dependency: Self::Dependency,
|
|
|
|
anim_time: f64,
|
2019-09-09 19:11:40 +00:00
|
|
|
rate: &mut f32,
|
2019-06-28 08:24:13 +00:00
|
|
|
skeleton_attr: &SkeletonAttr,
|
2019-05-09 17:58:16 +00:00
|
|
|
) -> Self::Skeleton;
|
2019-01-14 14:18:58 +00:00
|
|
|
}
|