Creature viewpoint

This commit is contained in:
IsseW 2022-11-02 03:00:40 +01:00 committed by Isse
parent ba62cc853e
commit 54bad4b205
23 changed files with 393 additions and 159 deletions

View File

@ -108,6 +108,7 @@ impl Skeleton for ArthropodSkeleton {
Offsets {
lantern: None,
viewpoint: Some((head_mat * Vec4::new(0.0, 7.0, 0.0, 1.0)).xyz()),
mount_bone: Transform {
position: mount_position,
orientation: mount_orientation,

View File

@ -104,9 +104,11 @@ impl Skeleton for BipedLargeSkeleton {
let head_mat = upper_torso_mat * Mat4::<f32>::from(self.head);
let hand_l_mat = Mat4::<f32>::from(self.hand_l);
let jaw_mat = head_mat * Mat4::<f32>::from(self.jaw);
*(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [
make_bone(head_mat),
make_bone(head_mat * Mat4::<f32>::from(self.jaw)),
make_bone(jaw_mat),
make_bone(upper_torso_mat),
make_bone(lower_torso_mat),
make_bone(lower_torso_mat * Mat4::<f32>::from(self.tail)),
@ -129,6 +131,7 @@ impl Skeleton for BipedLargeSkeleton {
];
Offsets {
lantern: None,
viewpoint: Some((jaw_mat * Vec4::new(0.0, 4.0, 0.0, 1.0)).xyz()),
// TODO: see quadruped_medium for how to animate this
mount_bone: Transform {
position: comp::Body::BipedLarge(body)

View File

@ -62,8 +62,9 @@ impl Skeleton for BipedSmallSkeleton {
let control_mat = chest_mat * Mat4::<f32>::from(self.control);
let control_l_mat = Mat4::<f32>::from(self.control_l);
let control_r_mat = Mat4::<f32>::from(self.control_r);
let head_mat = chest_mat * Mat4::<f32>::from(self.head);
*(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [
make_bone(chest_mat * Mat4::<f32>::from(self.head)),
make_bone(head_mat),
make_bone(chest_mat),
make_bone(pants_mat),
make_bone(pants_mat * Mat4::<f32>::from(self.tail)),
@ -75,6 +76,7 @@ impl Skeleton for BipedSmallSkeleton {
];
Offsets {
lantern: None,
viewpoint: Some((head_mat * Vec4::new(0.0, 0.0, 0.0, 1.0)).xyz()),
// TODO: see quadruped_medium for how to animate this
mount_bone: Transform {
position: comp::Body::BipedSmall(body)

View File

@ -98,6 +98,7 @@ impl Skeleton for BirdLargeSkeleton {
];
Offsets {
lantern: None,
viewpoint: Some((head_mat * Vec4::new(0.0, 3.0, 6.0, 1.0)).xyz()),
// TODO: see quadruped_medium for how to animate this
mount_bone: Transform {
position: comp::Body::BirdLarge(body)

View File

@ -40,9 +40,10 @@ impl Skeleton for BirdMediumSkeleton {
) -> Offsets {
let base_mat = base_mat * Mat4::scaling_3d(1.0 / 11.0);
let torso_mat = base_mat * Mat4::<f32>::from(self.torso);
let head_mat = torso_mat * Mat4::<f32>::from(self.head);
*(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [
make_bone(torso_mat * Mat4::<f32>::from(self.head)),
make_bone(head_mat),
make_bone(torso_mat),
make_bone(torso_mat * Mat4::<f32>::from(self.tail)),
make_bone(torso_mat * Mat4::<f32>::from(self.wing_l)),
@ -50,8 +51,13 @@ impl Skeleton for BirdMediumSkeleton {
make_bone(base_mat * Mat4::<f32>::from(self.leg_l)),
make_bone(base_mat * Mat4::<f32>::from(self.leg_r)),
];
use common::comp::body::bird_medium::Species::*;
Offsets {
lantern: None,
viewpoint: match body.species {
Bat => Some((head_mat * Vec4::new(0.0, 5.0, -4.0, 1.0)).xyz()),
_ => Some((head_mat * Vec4::new(0.0, 3.0, 2.0, 1.0)).xyz()),
},
// TODO: see quadruped_medium for how to animate this
mount_bone: Transform {
position: comp::Body::BirdMedium(body)

View File

@ -165,6 +165,7 @@ impl Skeleton for CharacterSkeleton {
let weapon_trails = self.main_weapon_trail || self.off_weapon_trail;
Offsets {
lantern: Some((lantern_mat * Vec4::new(0.0, 0.5, -6.0, 1.0)).xyz()),
viewpoint: Some((head_mat * Vec4::new(0.0, 0.0, 4.0, 1.0)).xyz()),
// TODO: see quadruped_medium for how to animate this
mount_bone: Transform {
position: comp::Body::Humanoid(body)

View File

@ -73,6 +73,7 @@ impl Skeleton for DragonSkeleton {
];
Offsets {
lantern: None,
viewpoint: Some((head_upper_mat * Vec4::new(0.0, 8.0, 0.0, 1.0)).xyz()),
// TODO: see quadruped_medium for how to animate this
mount_bone: Transform {
position: comp::Body::Dragon(body).mount_offset().into_tuple().into(),

View File

@ -39,11 +39,11 @@ impl Skeleton for FishMediumSkeleton {
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);
let head_mat = chest_front_mat * Mat4::<f32>::from(self.head);
*(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [
make_bone(chest_front_mat * head_mat),
make_bone(chest_front_mat * head_mat * Mat4::<f32>::from(self.jaw)),
make_bone(head_mat),
make_bone(head_mat * Mat4::<f32>::from(self.jaw)),
make_bone(chest_front_mat),
make_bone(chest_front_mat * chest_back_mat),
make_bone(chest_front_mat * chest_back_mat * Mat4::<f32>::from(self.tail)),
@ -52,6 +52,7 @@ impl Skeleton for FishMediumSkeleton {
];
Offsets {
lantern: None,
viewpoint: Some((head_mat * Vec4::new(0.0, 5.0, 0.0, 1.0)).xyz()),
// TODO: see quadruped_medium for how to animate this
mount_bone: Transform {
position: comp::Body::FishMedium(body)

View File

@ -43,6 +43,7 @@ impl Skeleton for FishSmallSkeleton {
];
Offsets {
lantern: None,
viewpoint: Some((chest_mat * Vec4::new(0.0, 3.0, 0.0, 1.0)).xyz()),
// TODO: see quadruped_medium for how to animate this
mount_bone: Transform {
position: comp::Body::FishSmall(body)

View File

@ -36,6 +36,7 @@ impl Skeleton for FixtureSkeleton {
buf[0] = make_bone(base_mat);
Offsets {
lantern: None,
viewpoint: None,
mount_bone: Transform::default(),
primary_trail_mat: None,
secondary_trail_mat: None,

View File

@ -58,9 +58,10 @@ impl Skeleton for GolemSkeleton {
let leg_r_mat = lower_torso_mat * Mat4::<f32>::from(self.leg_r);
let shoulder_l_mat = upper_torso_mat * Mat4::<f32>::from(self.shoulder_l);
let shoulder_r_mat = upper_torso_mat * Mat4::<f32>::from(self.shoulder_r);
let head_mat = upper_torso_mat * Mat4::<f32>::from(self.head);
*(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [
make_bone(upper_torso_mat * Mat4::<f32>::from(self.head)),
make_bone(head_mat),
make_bone(upper_torso_mat * Mat4::<f32>::from(self.head) * Mat4::<f32>::from(self.jaw)),
make_bone(upper_torso_mat),
make_bone(lower_torso_mat),
@ -75,6 +76,7 @@ impl Skeleton for GolemSkeleton {
];
Offsets {
lantern: None,
viewpoint: Some((head_mat * Vec4::new(0.0, 0.0, 5.0, 1.0)).xyz()),
// TODO: see quadruped_medium for how to animate this
mount_bone: Transform {
position: comp::Body::Golem(body).mount_offset().into_tuple().into(),

View File

@ -36,6 +36,7 @@ impl Skeleton for ItemDropSkeleton {
[make_bone(bone0_mat)];
Offsets {
lantern: None,
viewpoint: None,
mount_bone: Transform {
position: comp::Body::ItemDrop(body)
.mount_offset()

View File

@ -107,6 +107,7 @@ pub fn init() { lazy_static::initialize(&LIB); }
// Offsets that will be returned after computing the skeleton matrices
pub struct Offsets {
pub lantern: Option<Vec3<f32>>,
pub viewpoint: Option<Vec3<f32>>,
pub mount_bone: Transform<f32, f32, f32>,
pub primary_trail_mat: Option<(Mat4<f32>, TrailSource)>,
pub secondary_trail_mat: Option<(Mat4<f32>, TrailSource)>,

View File

@ -41,6 +41,7 @@ impl Skeleton for ObjectSkeleton {
];
Offsets {
lantern: None,
viewpoint: None,
// TODO: see quadruped_medium for how to animate this
mount_bone: Transform {
position: comp::Body::Object(body).mount_offset().into_tuple().into(),

View File

@ -95,6 +95,7 @@ impl Skeleton for QuadrupedLowSkeleton {
Offsets {
lantern: None,
viewpoint: Some((head_upper_mat * Vec4::new(0.0, 4.0, 1.0, 1.0)).xyz()),
mount_bone: Transform {
position: mount_position,
orientation: mount_orientation,

View File

@ -105,6 +105,30 @@ impl Skeleton for QuadrupedMediumSkeleton {
Offsets {
lantern: None,
viewpoint: match body.species {
Akhlut | Catoblepas | Lion => {
Some((head_mat * Vec4::new(0.0, 8.0, 0.0, 1.0)).xyz())
},
Barghest | Saber => Some((head_mat * Vec4::new(0.0, 8.0, 3.0, 1.0)).xyz()),
Cattle | Highland | Bonerattler | Ngoubou | Yak => {
Some((head_mat * Vec4::new(0.0, 6.0, -1.0, 1.0)).xyz())
},
Antelope | Deer | Donkey | Bear | Mouflon | Panda => {
Some((head_mat * Vec4::new(0.0, 3.0, 3.0, 1.0)).xyz())
},
Camel | Hirdrasil | Horse | Kelpie | Zebra => {
Some((head_mat * Vec4::new(0.0, 2.0, 5.0, 1.0)).xyz())
},
Darkhound | Llama | Snowleopard | Tiger | Wolf => {
Some((head_mat * Vec4::new(0.0, 4.0, 1.0, 1.0)).xyz())
},
Dreadhorn | Mammoth | Moose | Tarasque => {
Some((head_mat * Vec4::new(0.0, 13.0, -3.0, 1.0)).xyz())
},
Frostfang => Some((head_mat * Vec4::new(0.0, 5.0, 3.0, 1.0)).xyz()),
Grolgar | Roshwalr => Some((head_mat * Vec4::new(0.0, 8.0, 6.0, 1.0)).xyz()),
_ => Some((head_mat * Vec4::new(0.0, 2.0, 0.0, 1.0)).xyz()),
},
mount_bone: Transform {
position: mount_position,
orientation: mount_orientation,

View File

@ -65,6 +65,7 @@ impl Skeleton for QuadrupedSmallSkeleton {
Offsets {
lantern: None,
viewpoint: Some((head_mat * Vec4::new(0.0, 3.0, 0.0, 1.0)).xyz()),
mount_bone: Transform {
position: mount_position,
orientation: mount_orientation,

View File

@ -43,6 +43,7 @@ impl Skeleton for ShipSkeleton {
];
Offsets {
lantern: None,
viewpoint: None,
// TODO: see quadruped_medium for how to animate this
mount_bone: Transform {
position: (base_mat * scale_mat)

View File

@ -76,6 +76,7 @@ impl Skeleton for TheropodSkeleton {
];
Offsets {
lantern: None,
viewpoint: Some((head_mat * Vec4::new(0.0, 2.0, 0.0, 1.0)).xyz()),
// TODO: see quadruped_medium for how to animate this
mount_bone: Transform {
position: comp::Body::Theropod(body)

View File

@ -1078,12 +1078,16 @@ make_vox_spec!(
central: QuadrupedSmallCentralSpec = "voxygen.voxel.quadruped_small_central_manifest",
lateral: QuadrupedSmallLateralSpec = "voxygen.voxel.quadruped_small_lateral_manifest",
},
|FigureKey { body, .. }, spec| {
|FigureKey { body, extra, .. }, spec| {
let third_person = extra.as_ref().and_then(|loadout| loadout.third_person.as_ref());
[
Some(spec.central.read().0.mesh_head(
third_person.map(|_| {
spec.central.read().0.mesh_head(
body.species,
body.body_type,
)),
)
}),
Some(spec.central.read().0.mesh_chest(
body.species,
body.body_type,
@ -1282,20 +1286,28 @@ make_vox_spec!(
central: QuadrupedMediumCentralSpec = "voxygen.voxel.quadruped_medium_central_manifest",
lateral: QuadrupedMediumLateralSpec = "voxygen.voxel.quadruped_medium_lateral_manifest",
},
|FigureKey { body, .. }, spec| {
|FigureKey { body, extra, .. }, spec| {
let third_person = extra.as_ref().and_then(|loadout| loadout.third_person.as_ref());
[
Some(spec.central.read().0.mesh_head(
third_person.map(|_| {
spec.central.read().0.mesh_head(
body.species,
body.body_type,
)),
Some(spec.central.read().0.mesh_neck(
)
}),
third_person.map(|_| {
spec.central.read().0.mesh_neck(
body.species,
body.body_type,
)),
Some(spec.central.read().0.mesh_jaw(
)
}),
third_person.map(|_| {
spec.central.read().0.mesh_jaw(
body.species,
body.body_type,
)),
)
}),
Some(spec.central.read().0.mesh_tail(
body.species,
body.body_type,
@ -1308,10 +1320,12 @@ make_vox_spec!(
body.species,
body.body_type,
)),
Some(spec.central.read().0.mesh_ears(
third_person.map(|_| {
spec.central.read().0.mesh_ears(
body.species,
body.body_type,
)),
)
}),
Some(spec.lateral.read().0.mesh_leg_fl(
body.species,
body.body_type,
@ -1631,12 +1645,16 @@ make_vox_spec!(
central: BirdMediumCentralSpec = "voxygen.voxel.bird_medium_central_manifest",
lateral: BirdMediumLateralSpec = "voxygen.voxel.bird_medium_lateral_manifest",
},
|FigureKey { body, .. }, spec| {
|FigureKey { body, extra, .. }, spec| {
let third_person = extra.as_ref().and_then(|loadout| loadout.third_person.as_ref());
[
Some(spec.central.read().0.mesh_head(
third_person.map(|_| {
spec.central.read().0.mesh_head(
body.species,
body.body_type,
)),
)
}),
Some(spec.central.read().0.mesh_torso(
body.species,
body.body_type,
@ -1830,16 +1848,22 @@ make_vox_spec!(
central: TheropodCentralSpec = "voxygen.voxel.theropod_central_manifest",
lateral: TheropodLateralSpec = "voxygen.voxel.theropod_lateral_manifest",
},
|FigureKey { body, .. }, spec| {
|FigureKey { body, extra, .. }, spec| {
let third_person = extra.as_ref().and_then(|loadout| loadout.third_person.as_ref());
[
Some(spec.central.read().0.mesh_head(
third_person.map(|_| {
spec.central.read().0.mesh_head(
body.species,
body.body_type,
)),
Some(spec.central.read().0.mesh_jaw(
)
}),
third_person.map(|_| {
spec.central.read().0.mesh_jaw(
body.species,
body.body_type,
)),
)
}),
Some(spec.central.read().0.mesh_neck(
body.species,
body.body_type,
@ -2147,24 +2171,32 @@ make_vox_spec!(
central: ArthropodCentralSpec = "voxygen.voxel.arthropod_central_manifest",
lateral: ArthropodLateralSpec = "voxygen.voxel.arthropod_lateral_manifest",
},
|FigureKey { body, .. }, spec| {
|FigureKey { body, extra, .. }, spec| {
let third_person = extra.as_ref().and_then(|loadout| loadout.third_person.as_ref());
[
Some(spec.central.read().0.mesh_head(
third_person.map(|_| {
spec.central.read().0.mesh_head(
body.species,
body.body_type,
)),
)
}),
Some(spec.central.read().0.mesh_chest(
body.species,
body.body_type,
)),
Some(spec.lateral.read().0.mesh_mandible_l(
third_person.map(|_| {
spec.lateral.read().0.mesh_mandible_l(
body.species,
body.body_type,
)),
Some(spec.lateral.read().0.mesh_mandible_r(
)
}),
third_person.map(|_| {
spec.lateral.read().0.mesh_mandible_r(
body.species,
body.body_type,
)),
)
}),
Some(spec.lateral.read().0.mesh_wing_fl(
body.species,
body.body_type,
@ -2515,12 +2547,16 @@ make_vox_spec!(
central: FishMediumCentralSpec = "voxygen.voxel.fish_medium_central_manifest",
lateral: FishMediumLateralSpec = "voxygen.voxel.fish_medium_lateral_manifest",
},
|FigureKey { body, .. }, spec| {
|FigureKey { body, extra, .. }, spec| {
let third_person = extra.as_ref().and_then(|loadout| loadout.third_person.as_ref());
[
Some(spec.central.read().0.mesh_head(
third_person.map(|_| {
spec.central.read().0.mesh_head(
body.species,
body.body_type,
)),
)
}),
Some(spec.central.read().0.mesh_jaw(
body.species,
body.body_type,
@ -2707,12 +2743,16 @@ make_vox_spec!(
central: FishSmallCentralSpec = "voxygen.voxel.fish_small_central_manifest",
lateral: FishSmallLateralSpec = "voxygen.voxel.fish_small_lateral_manifest",
},
|FigureKey { body, .. }, spec| {
|FigureKey { body, extra, .. }, spec| {
let third_person = extra.as_ref().and_then(|loadout| loadout.third_person.as_ref());
[
Some(spec.central.read().0.mesh_chest(
third_person.map(|_| {
spec.central.read().0.mesh_chest(
body.species,
body.body_type,
)),
)
}),
Some(spec.central.read().0.mesh_tail(
body.species,
body.body_type,
@ -2856,7 +2896,7 @@ make_vox_spec!(
let foot = loadout.foot.as_deref();
[
[
third_person.map(|loadout| {
spec.armor_head.read().0.mesh_head(
loadout.head.as_deref(),
@ -3131,20 +3171,26 @@ make_vox_spec!(
central: DragonCentralSpec = "voxygen.voxel.dragon_central_manifest",
lateral: DragonLateralSpec = "voxygen.voxel.dragon_lateral_manifest",
},
|FigureKey { body, .. }, spec| {
|FigureKey { body, extra, .. }, spec| {
let third_person = extra.as_ref().and_then(|loadout| loadout.third_person.as_ref());
[
Some(spec.central.read().0.mesh_head_upper(
third_person.map(|_| {
spec.central.read().0.mesh_head_upper(
body.species,
body.body_type,
)),
)
}),
Some(spec.central.read().0.mesh_head_lower(
body.species,
body.body_type,
)),
Some(spec.central.read().0.mesh_jaw(
third_person.map(|_| {
spec.central.read().0.mesh_jaw(
body.species,
body.body_type,
)),
)
}),
Some(spec.central.read().0.mesh_chest_front(
body.species,
body.body_type,
@ -3488,16 +3534,22 @@ make_vox_spec!(
central: BirdLargeCentralSpec = "voxygen.voxel.bird_large_central_manifest",
lateral: BirdLargeLateralSpec = "voxygen.voxel.bird_large_lateral_manifest",
},
|FigureKey { body, .. }, spec| {
|FigureKey { body, extra, .. }, spec| {
let third_person = extra.as_ref().and_then(|loadout| loadout.third_person.as_ref());
[
Some(spec.central.read().0.mesh_head(
third_person.map(|_| {
spec.central.read().0.mesh_head(
body.species,
body.body_type,
)),
Some(spec.central.read().0.mesh_beak(
)
}),
third_person.map(|_| {
spec.central.read().0.mesh_beak(
body.species,
body.body_type,
)),
)
}),
Some(spec.central.read().0.mesh_neck(
body.species,
body.body_type,
@ -3879,21 +3931,29 @@ make_vox_spec!(
// TODO: This is bad code, maybe this method should return Option<_>
let loadout = extra.as_deref().unwrap_or(&DEFAULT_LOADOUT);
let third_person = loadout.third_person.as_ref();
//let third_person = loadout.third_person.as_ref();
let tool = loadout.tool.as_ref();
[
Some(spec.central.read().0.mesh_head(
third_person.map(|_| {
spec.central.read().0.mesh_head(
body.species,
body.body_type,
)),
Some(spec.central.read().0.mesh_jaw(
)
}),
third_person.map(|_| {
spec.central.read().0.mesh_jaw(
body.species,
body.body_type,
)),
Some(spec.central.read().0.mesh_torso_upper(
)
}),
third_person.map(|_| {
spec.central.read().0.mesh_torso_upper(
body.species,
body.body_type,
)),
)
}),
Some(spec.central.read().0.mesh_torso_lower(
body.species,
body.body_type,
@ -4262,16 +4322,22 @@ make_vox_spec!(
central: GolemCentralSpec = "voxygen.voxel.golem_central_manifest",
lateral: GolemLateralSpec = "voxygen.voxel.golem_lateral_manifest",
},
|FigureKey { body, .. }, spec| {
|FigureKey { body, extra, .. }, spec| {
let third_person = extra.as_ref().and_then(|loadout| loadout.third_person.as_ref());
[
Some(spec.central.read().0.mesh_head(
third_person.map(|_| {
spec.central.read().0.mesh_head(
body.species,
body.body_type,
)),
Some(spec.central.read().0.mesh_jaw(
)
}),
third_person.map(|_| {
spec.central.read().0.mesh_jaw(
body.species,
body.body_type,
)),
)
}),
Some(spec.central.read().0.mesh_torso_upper(
body.species,
body.body_type,
@ -4556,20 +4622,28 @@ make_vox_spec!(
central: QuadrupedLowCentralSpec = "voxygen.voxel.quadruped_low_central_manifest",
lateral: QuadrupedLowLateralSpec = "voxygen.voxel.quadruped_low_lateral_manifest",
},
|FigureKey { body, .. }, spec| {
|FigureKey { body, extra, .. }, spec| {
let third_person = extra.as_ref().and_then(|loadout| loadout.third_person.as_ref());
[
Some(spec.central.read().0.mesh_head_upper(
third_person.map(|_| {
spec.central.read().0.mesh_head_upper(
body.species,
body.body_type,
)),
Some(spec.central.read().0.mesh_head_lower(
)
}),
third_person.map(|_| {
spec.central.read().0.mesh_head_lower(
body.species,
body.body_type,
)),
Some(spec.central.read().0.mesh_jaw(
)
}),
third_person.map(|_| {
spec.central.read().0.mesh_jaw(
body.species,
body.body_type,
)),
)
}),
Some(spec.central.read().0.mesh_chest(
body.species,
body.body_type,

View File

@ -6517,6 +6517,103 @@ impl FigureMgr {
}
}
pub fn viewpoint_offset(&self, scene_data: &SceneData, entity: EcsEntity) -> Vec3<f32> {
scene_data
.state
.ecs()
.read_storage::<Body>()
.get(entity)
.and_then(|b| match b {
Body::Humanoid(_) => self
.states
.character_states
.get(&entity)
.and_then(|state| state.viewpoint_offset),
Body::QuadrupedSmall(_) => self
.states
.quadruped_small_states
.get(&entity)
.and_then(|state| state.viewpoint_offset),
Body::QuadrupedMedium(_) => self
.states
.quadruped_medium_states
.get(&entity)
.and_then(|state| state.viewpoint_offset),
Body::BirdMedium(_) => self
.states
.bird_medium_states
.get(&entity)
.and_then(|state| state.viewpoint_offset),
Body::FishMedium(_) => self
.states
.fish_medium_states
.get(&entity)
.and_then(|state| state.viewpoint_offset),
Body::Dragon(_) => self
.states
.dragon_states
.get(&entity)
.and_then(|state| state.viewpoint_offset),
Body::BirdLarge(_) => self
.states
.bird_large_states
.get(&entity)
.and_then(|state| state.viewpoint_offset),
Body::FishSmall(_) => self
.states
.fish_small_states
.get(&entity)
.and_then(|state| state.viewpoint_offset),
Body::BipedLarge(_) => self
.states
.biped_large_states
.get(&entity)
.and_then(|state| state.viewpoint_offset),
Body::BipedSmall(_) => self
.states
.biped_small_states
.get(&entity)
.and_then(|state| state.viewpoint_offset),
Body::Golem(_) => self
.states
.golem_states
.get(&entity)
.and_then(|state| state.viewpoint_offset),
Body::Theropod(_) => self
.states
.theropod_states
.get(&entity)
.and_then(|state| state.viewpoint_offset),
Body::QuadrupedLow(_) => self
.states
.quadruped_low_states
.get(&entity)
.and_then(|state| state.viewpoint_offset),
Body::Arthropod(_) => self
.states
.arthropod_states
.get(&entity)
.and_then(|state| state.viewpoint_offset),
Body::Object(_) => self
.states
.object_states
.get(&entity)
.and_then(|state| state.viewpoint_offset),
Body::Ship(_) => self
.states
.ship_states
.get(&entity)
.and_then(|state| state.viewpoint_offset),
Body::ItemDrop(_) => self
.states
.item_drop_states
.get(&entity)
.and_then(|state| state.viewpoint_offset),
})
.map(|viewpoint| viewpoint.into())
.unwrap_or_else(Vec3::zero)
}
pub fn figure_count(&self) -> usize { self.states.count() }
pub fn figure_count_visible(&self) -> usize { self.states.count_visible() }
@ -6625,6 +6722,7 @@ impl FigureColLights {
pub struct FigureStateMeta {
lantern_offset: Option<anim::vek::Vec3<f32>>,
viewpoint_offset: Option<anim::vek::Vec3<f32>>,
main_abs_trail_points: Option<(anim::vek::Vec3<f32>, anim::vek::Vec3<f32>)>,
off_abs_trail_points: Option<(anim::vek::Vec3<f32>, anim::vek::Vec3<f32>)>,
// Animation to be applied to rider of this entity
@ -6710,6 +6808,7 @@ impl<S: Skeleton> FigureState<S> {
Self {
meta: FigureStateMeta {
lantern_offset: offsets.lantern,
viewpoint_offset: offsets.viewpoint,
main_abs_trail_points: None,
off_abs_trail_points: None,
mount_transform: offsets.mount_bone,
@ -6890,6 +6989,7 @@ impl<S: Skeleton> FigureState<S> {
renderer.update_consts(&mut self.meta.bound.1, &new_bone_consts[0..S::BONE_COUNT]);
self.lantern_offset = offsets.lantern;
self.viewpoint_offset = offsets.viewpoint;
// Handle weapon trails
fn handle_weapon_trails(
trail_mgr: &mut TrailMgr,

View File

@ -59,6 +59,7 @@ impl anim::Skeleton for VolumeKey {
anim::Offsets {
lantern: None,
viewpoint: None,
mount_bone: anim::vek::Transform::default(),
primary_trail_mat: None,
secondary_trail_mat: None,

View File

@ -524,28 +524,16 @@ impl Scene {
.get(scene_data.viewpoint_entity)
.map_or(Quaternion::identity(), |ori| ori.to_quat());
let viewpoint_rolling = ecs
.read_storage::<comp::CharacterState>()
.get(scene_data.viewpoint_entity)
.map_or(false, |cs| cs.is_dodge());
let is_running = ecs
.read_storage::<comp::Vel>()
.get(scene_data.viewpoint_entity)
.map(|v| v.0.magnitude_squared() > RUNNING_THRESHOLD.powi(2))
.unwrap_or(false);
let on_ground = ecs
.read_storage::<comp::PhysicsState>()
.get(scene_data.viewpoint_entity)
.map(|p| p.on_ground.is_some());
let (viewpoint_height, viewpoint_eye_height) = scene_data
.state
.ecs()
let (is_humanoid, viewpoint_height, viewpoint_eye_height) = ecs
.read_storage::<comp::Body>()
.get(scene_data.viewpoint_entity)
.map_or((1.0, 0.0), |b| (b.height(), b.eye_height()));
.map_or((false, 1.0, 0.0), |b| {
(
matches!(b, comp::Body::Humanoid(_)),
b.height(),
b.eye_height(),
)
});
if scene_data.mutable_viewpoint || matches!(self.camera.get_mode(), CameraMode::Freefly)
{
@ -576,9 +564,22 @@ impl Scene {
.set_orientation_instant(Vec3::new(-yaw, pitch, roll));
}
// Alter camera position to match player.
let tilt = self.camera.get_orientation().y;
let dist = self.camera.get_distance();
let viewpoint_offset = if is_humanoid {
let viewpoint_rolling = ecs
.read_storage::<comp::CharacterState>()
.get(scene_data.viewpoint_entity)
.map_or(false, |cs| cs.is_dodge());
let is_running = ecs
.read_storage::<comp::Vel>()
.get(scene_data.viewpoint_entity)
.map(|v| v.0.magnitude_squared() > RUNNING_THRESHOLD.powi(2))
.unwrap_or(false);
let on_ground = ecs
.read_storage::<comp::PhysicsState>()
.get(scene_data.viewpoint_entity)
.map(|p| p.on_ground.is_some());
let up = match self.camera.get_mode() {
CameraMode::FirstPerson => {
@ -595,12 +596,19 @@ impl Scene {
CameraMode::ThirdPerson => viewpoint_eye_height,
CameraMode::Freefly => 0.0,
};
// Alter camera position to match player.
let tilt = self.camera.get_orientation().y;
let dist = self.camera.get_distance();
Vec3::unit_z() * (up - tilt.min(0.0).sin() * dist * 0.6)
} else {
self.figure_mgr
.viewpoint_offset(scene_data, scene_data.viewpoint_entity)
};
match self.camera.get_mode() {
CameraMode::FirstPerson | CameraMode::ThirdPerson => {
self.camera.set_focus_pos(
viewpoint_pos + Vec3::unit_z() * (up - tilt.min(0.0).sin() * dist * 0.6),
);
self.camera.set_focus_pos(viewpoint_pos + viewpoint_offset);
},
CameraMode::Freefly => {},
};