mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Move eye sight and scale in body.rs, mounts tweaks
This commit is contained in:
parent
43c81b3dd6
commit
93642428f2
@ -133,6 +133,8 @@ impl<
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Body {
|
impl Body {
|
||||||
|
pub const DEFAULT_EYE_HEIGHT: f32 = 1.65;
|
||||||
|
|
||||||
pub fn is_humanoid(&self) -> bool { matches!(self, Body::Humanoid(_)) }
|
pub fn is_humanoid(&self) -> bool { matches!(self, Body::Humanoid(_)) }
|
||||||
|
|
||||||
// Note: this might need to be refined to something more complex for realistic
|
// Note: this might need to be refined to something more complex for realistic
|
||||||
@ -140,7 +142,7 @@ impl Body {
|
|||||||
pub fn radius(&self) -> f32 {
|
pub fn radius(&self) -> f32 {
|
||||||
// TODO: Improve these values (some might be reliant on more info in inner type)
|
// TODO: Improve these values (some might be reliant on more info in inner type)
|
||||||
match self {
|
match self {
|
||||||
Body::Humanoid(body) => 0.5 * body.scale(),
|
Body::Humanoid(_) => 0.5 * self.scale(),
|
||||||
Body::QuadrupedSmall(_) => 0.4,
|
Body::QuadrupedSmall(_) => 0.4,
|
||||||
Body::QuadrupedMedium(body) => match body.species {
|
Body::QuadrupedMedium(body) => match body.species {
|
||||||
quadruped_medium::Species::Grolgar => 1.9,
|
quadruped_medium::Species::Grolgar => 1.9,
|
||||||
@ -172,7 +174,7 @@ impl Body {
|
|||||||
|
|
||||||
pub fn height(&self) -> f32 {
|
pub fn height(&self) -> f32 {
|
||||||
match self {
|
match self {
|
||||||
Body::Humanoid(body) => 1.9 * body.scale(),
|
Body::Humanoid(_) => 1.9 * self.scale(),
|
||||||
Body::QuadrupedSmall(body) => match body.species {
|
Body::QuadrupedSmall(body) => match body.species {
|
||||||
quadruped_small::Species::Dodarock => 1.5,
|
quadruped_small::Species::Dodarock => 1.5,
|
||||||
quadruped_small::Species::Holladon => 1.5,
|
quadruped_small::Species::Holladon => 1.5,
|
||||||
@ -199,7 +201,7 @@ impl Body {
|
|||||||
_ => 1.1,
|
_ => 1.1,
|
||||||
},
|
},
|
||||||
Body::FishMedium(_) => 1.1,
|
Body::FishMedium(_) => 1.1,
|
||||||
Body::Dragon(_) => 20.0,
|
Body::Dragon(_) => 16.0,
|
||||||
Body::BirdSmall(_) => 1.1,
|
Body::BirdSmall(_) => 1.1,
|
||||||
Body::FishSmall(_) => 0.9,
|
Body::FishSmall(_) => 0.9,
|
||||||
Body::BipedLarge(_) => 4.6,
|
Body::BipedLarge(_) => 4.6,
|
||||||
@ -525,6 +527,37 @@ impl Body {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the eye height for this humanoid.
|
||||||
|
pub fn eye_height(&self) -> f32 { Self::DEFAULT_EYE_HEIGHT * self.scale() }
|
||||||
|
|
||||||
|
pub fn scale(&self) -> f32 {
|
||||||
|
match self {
|
||||||
|
Body::Humanoid(humanoid) => match (humanoid.species, humanoid.body_type) {
|
||||||
|
(humanoid::Species::Orc, humanoid::BodyType::Male) => 1.14,
|
||||||
|
(humanoid::Species::Orc, humanoid::BodyType::Female) => 1.02,
|
||||||
|
(humanoid::Species::Human, humanoid::BodyType::Male) => 1.02,
|
||||||
|
(humanoid::Species::Human, humanoid::BodyType::Female) => 0.96,
|
||||||
|
(humanoid::Species::Elf, humanoid::BodyType::Male) => 1.02,
|
||||||
|
(humanoid::Species::Elf, humanoid::BodyType::Female) => 0.96,
|
||||||
|
(humanoid::Species::Dwarf, humanoid::BodyType::Male) => 0.84,
|
||||||
|
(humanoid::Species::Dwarf, humanoid::BodyType::Female) => 0.78,
|
||||||
|
(humanoid::Species::Undead, humanoid::BodyType::Male) => 0.96,
|
||||||
|
(humanoid::Species::Undead, humanoid::BodyType::Female) => 0.9,
|
||||||
|
(humanoid::Species::Danari, humanoid::BodyType::Male) => 0.696,
|
||||||
|
(humanoid::Species::Danari, humanoid::BodyType::Female) => 0.696,
|
||||||
|
},
|
||||||
|
Body::BipedLarge(_) => 2.5,
|
||||||
|
Body::BirdMedium(_) => 0.7,
|
||||||
|
Body::Dragon(_) => 16.0,
|
||||||
|
Body::Golem(_) => 2.0,
|
||||||
|
Body::QuadrupedMedium(_) => 1.0,
|
||||||
|
Body::QuadrupedLow(_) => 0.9,
|
||||||
|
Body::QuadrupedSmall(_) => 0.5,
|
||||||
|
Body::Theropod(_) => 2.0,
|
||||||
|
_ => 1.0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn default_light_offset(&self) -> Vec3<f32> {
|
pub fn default_light_offset(&self) -> Vec3<f32> {
|
||||||
// TODO: Make this a manifest
|
// TODO: Make this a manifest
|
||||||
match self {
|
match self {
|
||||||
|
@ -63,32 +63,7 @@ impl Body {
|
|||||||
.accessory
|
.accessory
|
||||||
.min(self.species.num_accessories(self.body_type) - 1);
|
.min(self.species.num_accessories(self.body_type) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a scale value relative to the average humanoid
|
|
||||||
pub fn scale(&self) -> f32 {
|
|
||||||
use BodyType::*;
|
|
||||||
use Species::*;
|
|
||||||
match (self.species, self.body_type) {
|
|
||||||
(Orc, Male) => 1.14,
|
|
||||||
(Orc, Female) => 1.02,
|
|
||||||
(Human, Male) => 1.02,
|
|
||||||
(Human, Female) => 0.96,
|
|
||||||
(Elf, Male) => 1.02,
|
|
||||||
(Elf, Female) => 0.96,
|
|
||||||
(Dwarf, Male) => 0.84,
|
|
||||||
(Dwarf, Female) => 0.78,
|
|
||||||
(Undead, Male) => 0.96,
|
|
||||||
(Undead, Female) => 0.9,
|
|
||||||
(Danari, Male) => 0.696,
|
|
||||||
(Danari, Female) => 0.696,
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the eye height for this humanoid.
|
|
||||||
pub fn eye_height(&self) -> f32 { DEFAULT_HUMANOID_EYE_HEIGHT * self.scale() }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const DEFAULT_HUMANOID_EYE_HEIGHT: f32 = 1.65;
|
|
||||||
|
|
||||||
impl From<Body> for super::Body {
|
impl From<Body> for super::Body {
|
||||||
fn from(body: Body) -> Self { super::Body::Humanoid(body) }
|
fn from(body: Body) -> Self { super::Body::Humanoid(body) }
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
comp::{
|
comp::{beam, CharacterState, EnergyChange, EnergySource, Ori, Pos, StateUpdate},
|
||||||
beam, humanoid, Body, CharacterState, EnergyChange, EnergySource, Ori, Pos, StateUpdate,
|
|
||||||
},
|
|
||||||
event::ServerEvent,
|
event::ServerEvent,
|
||||||
states::utils::*,
|
states::utils::*,
|
||||||
sync::Uid,
|
sync::Uid,
|
||||||
@ -91,10 +89,8 @@ impl CharacterBehavior for Data {
|
|||||||
timer: Duration::default(),
|
timer: Duration::default(),
|
||||||
});
|
});
|
||||||
// Gets offset
|
// Gets offset
|
||||||
let eye_height = match data.body {
|
let eye_height = data.body.eye_height();
|
||||||
Body::Humanoid(body) => body.eye_height(),
|
|
||||||
_ => humanoid::DEFAULT_HUMANOID_EYE_HEIGHT,
|
|
||||||
};
|
|
||||||
// Build up
|
// Build up
|
||||||
update.character = CharacterState::BasicBeam(Data {
|
update.character = CharacterState::BasicBeam(Data {
|
||||||
timer: Duration::default(),
|
timer: Duration::default(),
|
||||||
|
@ -343,20 +343,11 @@ impl<'a> System<'a> for Sys {
|
|||||||
) {
|
) {
|
||||||
controller.actions.push(ControlAction::Wield);
|
controller.actions.push(ControlAction::Wield);
|
||||||
|
|
||||||
let eye_offset = match body {
|
let eye_offset = body.map_or(1.0, |b| b.eye_height());
|
||||||
Some(body) => match body {
|
|
||||||
Body::Humanoid(body) => body.eye_height(),
|
let tgt_eye_offset =
|
||||||
_ => 0.4 * body.height(),
|
bodies.get(*target).map_or(1.0, |b| b.eye_height());
|
||||||
},
|
|
||||||
_ => 0.0,
|
|
||||||
};
|
|
||||||
let tgt_eye_offset = match bodies.get(*target) {
|
|
||||||
Some(body) => match body {
|
|
||||||
Body::Humanoid(body) => body.eye_height(),
|
|
||||||
_ => 0.4 * body.height(),
|
|
||||||
},
|
|
||||||
_ => 0.0,
|
|
||||||
};
|
|
||||||
let distance_offset = match tactic {
|
let distance_offset = match tactic {
|
||||||
Tactic::Bow => 0.0004 * pos.0.distance_squared(tgt_pos.0),
|
Tactic::Bow => 0.0004 * pos.0.distance_squared(tgt_pos.0),
|
||||||
Tactic::Staff => 0.0015 * pos.0.distance_squared(tgt_pos.0),
|
Tactic::Staff => 0.0015 * pos.0.distance_squared(tgt_pos.0),
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
comp::{Controller, MountState, Mounting, Ori, Pos, Vel},
|
comp::{Body, Controller, MountState, Mounting, Ori, Pos, Vel},
|
||||||
metrics::SysMetrics,
|
metrics::SysMetrics,
|
||||||
span,
|
span,
|
||||||
sync::UidAllocator,
|
sync::UidAllocator,
|
||||||
};
|
};
|
||||||
use specs::{
|
use specs::{
|
||||||
saveload::{Marker, MarkerAllocator},
|
saveload::{Marker, MarkerAllocator},
|
||||||
Entities, Join, Read, ReadExpect, System, WriteStorage,
|
Entities, Join, Read, ReadExpect, ReadStorage, System, WriteStorage,
|
||||||
};
|
};
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
@ -18,6 +18,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
Read<'a, UidAllocator>,
|
Read<'a, UidAllocator>,
|
||||||
ReadExpect<'a, SysMetrics>,
|
ReadExpect<'a, SysMetrics>,
|
||||||
Entities<'a>,
|
Entities<'a>,
|
||||||
|
ReadStorage<'a, Body>,
|
||||||
WriteStorage<'a, Controller>,
|
WriteStorage<'a, Controller>,
|
||||||
WriteStorage<'a, MountState>,
|
WriteStorage<'a, MountState>,
|
||||||
WriteStorage<'a, Mounting>,
|
WriteStorage<'a, Mounting>,
|
||||||
@ -32,6 +33,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
uid_allocator,
|
uid_allocator,
|
||||||
sys_metrics,
|
sys_metrics,
|
||||||
entities,
|
entities,
|
||||||
|
bodies,
|
||||||
mut controllers,
|
mut controllers,
|
||||||
mut mount_state,
|
mut mount_state,
|
||||||
mut mountings,
|
mut mountings,
|
||||||
@ -43,7 +45,9 @@ impl<'a> System<'a> for Sys {
|
|||||||
let start_time = std::time::Instant::now();
|
let start_time = std::time::Instant::now();
|
||||||
span!(_guard, "run", "mount::Sys::run");
|
span!(_guard, "run", "mount::Sys::run");
|
||||||
// Mounted entities.
|
// Mounted entities.
|
||||||
for (entity, mut mount_states) in (&entities, &mut mount_state.restrict_mut()).join() {
|
for (entity, mut mount_states, body) in
|
||||||
|
(&entities, &mut mount_state.restrict_mut(), bodies.maybe()).join()
|
||||||
|
{
|
||||||
match mount_states.get_unchecked() {
|
match mount_states.get_unchecked() {
|
||||||
MountState::Unmounted => {},
|
MountState::Unmounted => {},
|
||||||
MountState::MountedBy(mounter_uid) => {
|
MountState::MountedBy(mounter_uid) => {
|
||||||
@ -61,8 +65,9 @@ impl<'a> System<'a> for Sys {
|
|||||||
let pos = positions.get(entity).copied();
|
let pos = positions.get(entity).copied();
|
||||||
let ori = orientations.get(entity).copied();
|
let ori = orientations.get(entity).copied();
|
||||||
let vel = velocities.get(entity).copied();
|
let vel = velocities.get(entity).copied();
|
||||||
|
let scale = body.map_or(1.0, |b| b.scale());
|
||||||
if let (Some(pos), Some(ori), Some(vel)) = (pos, ori, vel) {
|
if let (Some(pos), Some(ori), Some(vel)) = (pos, ori, vel) {
|
||||||
let _ = positions.insert(mounter, Pos(pos.0 + Vec3::unit_z() * 1.0));
|
let _ = positions.insert(mounter, Pos(pos.0 + Vec3::unit_z() * scale));
|
||||||
let _ = orientations.insert(mounter, ori);
|
let _ = orientations.insert(mounter, ori);
|
||||||
let _ = velocities.insert(mounter, vel);
|
let _ = velocities.insert(mounter, vel);
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,8 @@ use crate::{sys, Server, StateExt};
|
|||||||
use common::{
|
use common::{
|
||||||
character::CharacterId,
|
character::CharacterId,
|
||||||
comp::{
|
comp::{
|
||||||
self, beam, humanoid::DEFAULT_HUMANOID_EYE_HEIGHT, shockwave, Agent, Alignment, Body,
|
self, beam, shockwave, Agent, Alignment, Body, Gravity, Health, Item, ItemDrop,
|
||||||
Gravity, Health, Item, ItemDrop, LightEmitter, Loadout, Ori, Pos, Projectile, Scale, Stats,
|
LightEmitter, Loadout, Ori, Pos, Projectile, Scale, Stats, Vel, WaypointArea,
|
||||||
Vel, WaypointArea,
|
|
||||||
},
|
},
|
||||||
outcome::Outcome,
|
outcome::Outcome,
|
||||||
util::Dir,
|
util::Dir,
|
||||||
@ -115,10 +114,12 @@ pub fn handle_shoot(
|
|||||||
.write_resource::<Vec<Outcome>>()
|
.write_resource::<Vec<Outcome>>()
|
||||||
.push(Outcome::ProjectileShot { pos, body, vel });
|
.push(Outcome::ProjectileShot { pos, body, vel });
|
||||||
|
|
||||||
let eye_height = match state.ecs().read_storage::<comp::Body>().get(entity) {
|
let eye_height = state
|
||||||
Some(comp::Body::Humanoid(body)) => body.eye_height(),
|
.ecs()
|
||||||
_ => DEFAULT_HUMANOID_EYE_HEIGHT,
|
.read_storage::<comp::Body>()
|
||||||
};
|
.get(entity)
|
||||||
|
.map(|b| b.scale())
|
||||||
|
.unwrap_or(1.0);
|
||||||
|
|
||||||
pos.z += eye_height;
|
pos.z += eye_height;
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ impl<'a> From<&'a Body> for SkeletonAttr {
|
|||||||
fn from(body: &'a Body) -> Self {
|
fn from(body: &'a Body) -> Self {
|
||||||
use comp::humanoid::{BodyType::*, Species::*};
|
use comp::humanoid::{BodyType::*, Species::*};
|
||||||
Self {
|
Self {
|
||||||
scaler: body.scale(),
|
scaler: comp::Body::Humanoid(*body).scale(),
|
||||||
head_scale: match (body.species, body.body_type) {
|
head_scale: match (body.species, body.body_type) {
|
||||||
(Orc, Male) => 0.9,
|
(Orc, Male) => 0.9,
|
||||||
(Orc, Female) => 0.9,
|
(Orc, Female) => 0.9,
|
||||||
|
@ -26,7 +26,6 @@ use crate::{
|
|||||||
use client::Client;
|
use client::Client;
|
||||||
use common::{
|
use common::{
|
||||||
comp,
|
comp,
|
||||||
comp::humanoid::DEFAULT_HUMANOID_EYE_HEIGHT,
|
|
||||||
outcome::Outcome,
|
outcome::Outcome,
|
||||||
span,
|
span,
|
||||||
state::{DeltaTime, State},
|
state::{DeltaTime, State},
|
||||||
@ -468,25 +467,21 @@ impl Scene {
|
|||||||
.get(scene_data.player_entity)
|
.get(scene_data.player_entity)
|
||||||
.map(|p| p.on_ground);
|
.map(|p| p.on_ground);
|
||||||
|
|
||||||
let player_scale = match scene_data
|
let player_scale = scene_data
|
||||||
.state
|
.state
|
||||||
.ecs()
|
.ecs()
|
||||||
.read_storage::<comp::Body>()
|
.read_storage::<comp::Body>()
|
||||||
.get(scene_data.player_entity)
|
.get(scene_data.player_entity)
|
||||||
{
|
.map(|b| b.scale())
|
||||||
Some(comp::Body::Humanoid(body)) => body.scale(),
|
.unwrap_or(1.0);
|
||||||
_ => 1_f32,
|
|
||||||
};
|
|
||||||
|
|
||||||
let eye_height = match scene_data
|
let eye_height = scene_data
|
||||||
.state
|
.state
|
||||||
.ecs()
|
.ecs()
|
||||||
.read_storage::<comp::Body>()
|
.read_storage::<comp::Body>()
|
||||||
.get(scene_data.player_entity)
|
.get(scene_data.player_entity)
|
||||||
{
|
.map(|b| b.eye_height())
|
||||||
Some(comp::Body::Humanoid(body)) => body.eye_height(),
|
.unwrap_or(1.0);
|
||||||
_ => DEFAULT_HUMANOID_EYE_HEIGHT,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Add the analog input to camera
|
// Add the analog input to camera
|
||||||
self.camera
|
self.camera
|
||||||
|
Loading…
Reference in New Issue
Block a user