mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'snowram/eye-sight' into 'master'
Move eye sight and scale in body.rs See merge request veloren/veloren!1519
This commit is contained in:
commit
26957d4fd4
@ -944,7 +944,7 @@ impl From<(&CharacterAbility, AbilityKey)> for CharacterState {
|
||||
timer: Duration::default(),
|
||||
stage_section: StageSection::Buildup,
|
||||
particle_ori: None::<Vec3<f32>>,
|
||||
offset: 0.0,
|
||||
offset: Vec3::zero(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
@ -137,10 +137,25 @@ impl Body {
|
||||
|
||||
// Note: this might need to be refined to something more complex for realistic
|
||||
// behavior with less cylindrical bodies (e.g. wolfs)
|
||||
#[allow(unreachable_patterns)]
|
||||
pub fn radius(&self) -> f32 {
|
||||
// TODO: Improve these values (some might be reliant on more info in inner type)
|
||||
match self {
|
||||
Body::Humanoid(body) => 0.5 * body.scale(),
|
||||
Body::Humanoid(humanoid) => match (humanoid.species, humanoid.body_type) {
|
||||
(humanoid::Species::Orc, humanoid::BodyType::Male) => 0.57,
|
||||
(humanoid::Species::Orc, humanoid::BodyType::Female) => 0.51,
|
||||
(humanoid::Species::Human, humanoid::BodyType::Male) => 0.51,
|
||||
(humanoid::Species::Human, humanoid::BodyType::Female) => 0.48,
|
||||
(humanoid::Species::Elf, humanoid::BodyType::Male) => 0.51,
|
||||
(humanoid::Species::Elf, humanoid::BodyType::Female) => 0.48,
|
||||
(humanoid::Species::Dwarf, humanoid::BodyType::Male) => 0.42,
|
||||
(humanoid::Species::Dwarf, humanoid::BodyType::Female) => 0.39,
|
||||
(humanoid::Species::Undead, humanoid::BodyType::Male) => 0.48,
|
||||
(humanoid::Species::Undead, humanoid::BodyType::Female) => 0.45,
|
||||
(humanoid::Species::Danari, humanoid::BodyType::Male) => 0.348,
|
||||
(humanoid::Species::Danari, humanoid::BodyType::Female) => 0.348,
|
||||
_ => 0.5,
|
||||
},
|
||||
Body::QuadrupedSmall(_) => 0.4,
|
||||
Body::QuadrupedMedium(body) => match body.species {
|
||||
quadruped_medium::Species::Grolgar => 1.9,
|
||||
@ -172,7 +187,20 @@ impl Body {
|
||||
|
||||
pub fn height(&self) -> f32 {
|
||||
match self {
|
||||
Body::Humanoid(body) => 1.9 * body.scale(),
|
||||
Body::Humanoid(humanoid) => match (humanoid.species, humanoid.body_type) {
|
||||
(humanoid::Species::Orc, humanoid::BodyType::Male) => 2.17,
|
||||
(humanoid::Species::Orc, humanoid::BodyType::Female) => 1.94,
|
||||
(humanoid::Species::Human, humanoid::BodyType::Male) => 1.94,
|
||||
(humanoid::Species::Human, humanoid::BodyType::Female) => 1.82,
|
||||
(humanoid::Species::Elf, humanoid::BodyType::Male) => 1.94,
|
||||
(humanoid::Species::Elf, humanoid::BodyType::Female) => 1.82,
|
||||
(humanoid::Species::Dwarf, humanoid::BodyType::Male) => 1.60,
|
||||
(humanoid::Species::Dwarf, humanoid::BodyType::Female) => 1.48,
|
||||
(humanoid::Species::Undead, humanoid::BodyType::Male) => 1.82,
|
||||
(humanoid::Species::Undead, humanoid::BodyType::Female) => 1.71,
|
||||
(humanoid::Species::Danari, humanoid::BodyType::Male) => 1.32,
|
||||
(humanoid::Species::Danari, humanoid::BodyType::Female) => 1.32,
|
||||
},
|
||||
Body::QuadrupedSmall(body) => match body.species {
|
||||
quadruped_small::Species::Dodarock => 1.5,
|
||||
quadruped_small::Species::Holladon => 1.5,
|
||||
@ -199,7 +227,7 @@ impl Body {
|
||||
_ => 1.1,
|
||||
},
|
||||
Body::FishMedium(_) => 1.1,
|
||||
Body::Dragon(_) => 20.0,
|
||||
Body::Dragon(_) => 16.0,
|
||||
Body::BirdSmall(_) => 1.1,
|
||||
Body::FishSmall(_) => 0.9,
|
||||
Body::BipedLarge(_) => 4.6,
|
||||
@ -525,6 +553,9 @@ impl Body {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the eye height for this humanoid.
|
||||
pub fn eye_height(&self) -> f32 { self.height() * 0.9 }
|
||||
|
||||
pub fn default_light_offset(&self) -> Vec3<f32> {
|
||||
// TODO: Make this a manifest
|
||||
match self {
|
||||
|
@ -63,33 +63,8 @@ impl Body {
|
||||
.accessory
|
||||
.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 {
|
||||
fn from(body: Body) -> Self { super::Body::Humanoid(body) }
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
use crate::{
|
||||
comp::{
|
||||
beam, humanoid, Body, CharacterState, EnergyChange, EnergySource, Ori, Pos, StateUpdate,
|
||||
},
|
||||
comp::{beam, CharacterState, EnergyChange, EnergySource, Ori, Pos, StateUpdate},
|
||||
event::ServerEvent,
|
||||
states::utils::*,
|
||||
sync::Uid,
|
||||
@ -56,7 +54,7 @@ pub struct Data {
|
||||
/// Used for particle stuffs
|
||||
pub particle_ori: Option<Vec3<f32>>,
|
||||
/// Used to offset beam and particles
|
||||
pub offset: f32,
|
||||
pub offset: Vec3<f32>,
|
||||
}
|
||||
|
||||
impl CharacterBehavior for Data {
|
||||
@ -90,17 +88,18 @@ impl CharacterBehavior for Data {
|
||||
tick_dur: Duration::from_secs_f32(1.0 / self.static_data.tick_rate),
|
||||
timer: Duration::default(),
|
||||
});
|
||||
// Gets offset
|
||||
let eye_height = match data.body {
|
||||
Body::Humanoid(body) => body.eye_height(),
|
||||
_ => humanoid::DEFAULT_HUMANOID_EYE_HEIGHT,
|
||||
};
|
||||
// Gets offsets
|
||||
let body_offsets = Vec3::new(
|
||||
data.body.radius() * 3.0 * data.inputs.look_dir.x,
|
||||
data.body.radius() * 3.0 * data.inputs.look_dir.y,
|
||||
data.body.eye_height(),
|
||||
) * 0.55;
|
||||
// Build up
|
||||
update.character = CharacterState::BasicBeam(Data {
|
||||
timer: Duration::default(),
|
||||
stage_section: StageSection::Cast,
|
||||
particle_ori: Some(*data.inputs.look_dir),
|
||||
offset: eye_height * 0.55,
|
||||
offset: body_offsets,
|
||||
..*self
|
||||
});
|
||||
}
|
||||
@ -136,7 +135,13 @@ impl CharacterBehavior for Data {
|
||||
duration: self.static_data.beam_duration,
|
||||
owner: Some(*data.uid),
|
||||
};
|
||||
let pos = Pos(data.pos.0 + Vec3::new(0.0, 0.0, self.offset));
|
||||
// Gets offsets
|
||||
let body_offsets = Vec3::new(
|
||||
data.body.radius() + 2.0 * data.inputs.look_dir.x,
|
||||
data.body.radius() + 2.0 * data.inputs.look_dir.y,
|
||||
data.body.eye_height(),
|
||||
) * 0.55;
|
||||
let pos = Pos(data.pos.0 + body_offsets);
|
||||
// Create beam segment
|
||||
update.server_events.push_front(ServerEvent::BeamSegment {
|
||||
properties,
|
||||
@ -149,6 +154,7 @@ impl CharacterBehavior for Data {
|
||||
.checked_add(Duration::from_secs_f32(data.dt.0))
|
||||
.unwrap_or_default(),
|
||||
particle_ori: Some(*data.inputs.look_dir),
|
||||
offset: body_offsets,
|
||||
..*self
|
||||
});
|
||||
|
||||
|
@ -343,20 +343,11 @@ impl<'a> System<'a> for Sys {
|
||||
) {
|
||||
controller.actions.push(ControlAction::Wield);
|
||||
|
||||
let eye_offset = match body {
|
||||
Some(body) => match body {
|
||||
Body::Humanoid(body) => body.eye_height(),
|
||||
_ => 0.4 * body.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 eye_offset = body.map_or(0.0, |b| b.eye_height());
|
||||
|
||||
let tgt_eye_offset =
|
||||
bodies.get(*target).map_or(0.0, |b| b.eye_height());
|
||||
|
||||
let distance_offset = match tactic {
|
||||
Tactic::Bow => 0.0004 * pos.0.distance_squared(tgt_pos.0),
|
||||
Tactic::Staff => 0.0015 * pos.0.distance_squared(tgt_pos.0),
|
||||
|
@ -2,9 +2,8 @@ use crate::{sys, Server, StateExt};
|
||||
use common::{
|
||||
character::CharacterId,
|
||||
comp::{
|
||||
self, beam, humanoid::DEFAULT_HUMANOID_EYE_HEIGHT, shockwave, Agent, Alignment, Body,
|
||||
Gravity, Health, Item, ItemDrop, LightEmitter, Loadout, Ori, Pos, Projectile, Scale, Stats,
|
||||
Vel, WaypointArea,
|
||||
self, beam, shockwave, Agent, Alignment, Body, Gravity, Health, Item, ItemDrop,
|
||||
LightEmitter, Loadout, Ori, Pos, Projectile, Scale, Stats, Vel, WaypointArea,
|
||||
},
|
||||
outcome::Outcome,
|
||||
util::Dir,
|
||||
@ -115,10 +114,11 @@ pub fn handle_shoot(
|
||||
.write_resource::<Vec<Outcome>>()
|
||||
.push(Outcome::ProjectileShot { pos, body, vel });
|
||||
|
||||
let eye_height = match state.ecs().read_storage::<comp::Body>().get(entity) {
|
||||
Some(comp::Body::Humanoid(body)) => body.eye_height(),
|
||||
_ => DEFAULT_HUMANOID_EYE_HEIGHT,
|
||||
};
|
||||
let eye_height = state
|
||||
.ecs()
|
||||
.read_storage::<comp::Body>()
|
||||
.get(entity)
|
||||
.map_or(0.0, |b| b.eye_height());
|
||||
|
||||
pos.z += eye_height;
|
||||
|
||||
|
@ -197,7 +197,21 @@ impl<'a> From<&'a Body> for SkeletonAttr {
|
||||
fn from(body: &'a Body) -> Self {
|
||||
use comp::humanoid::{BodyType::*, Species::*};
|
||||
Self {
|
||||
scaler: body.scale(),
|
||||
scaler: match (body.species, body.body_type) {
|
||||
// TODO : Derive scale from body proportions
|
||||
(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.70,
|
||||
(Danari, Female) => 0.70,
|
||||
},
|
||||
head_scale: match (body.species, body.body_type) {
|
||||
(Orc, Male) => 0.9,
|
||||
(Orc, Female) => 0.9,
|
||||
|
@ -26,7 +26,6 @@ use crate::{
|
||||
use client::Client;
|
||||
use common::{
|
||||
comp,
|
||||
comp::humanoid::DEFAULT_HUMANOID_EYE_HEIGHT,
|
||||
outcome::Outcome,
|
||||
span,
|
||||
state::{DeltaTime, State},
|
||||
@ -468,25 +467,12 @@ impl Scene {
|
||||
.get(scene_data.player_entity)
|
||||
.map(|p| p.on_ground);
|
||||
|
||||
let player_scale = match scene_data
|
||||
let (player_height, player_eye_height) = scene_data
|
||||
.state
|
||||
.ecs()
|
||||
.read_storage::<comp::Body>()
|
||||
.get(scene_data.player_entity)
|
||||
{
|
||||
Some(comp::Body::Humanoid(body)) => body.scale(),
|
||||
_ => 1_f32,
|
||||
};
|
||||
|
||||
let eye_height = match scene_data
|
||||
.state
|
||||
.ecs()
|
||||
.read_storage::<comp::Body>()
|
||||
.get(scene_data.player_entity)
|
||||
{
|
||||
Some(comp::Body::Humanoid(body)) => body.eye_height(),
|
||||
_ => DEFAULT_HUMANOID_EYE_HEIGHT,
|
||||
};
|
||||
.map_or((1.0, 0.0), |b| (b.height(), b.eye_height()));
|
||||
|
||||
// Add the analog input to camera
|
||||
self.camera
|
||||
@ -501,15 +487,15 @@ impl Scene {
|
||||
let up = match self.camera.get_mode() {
|
||||
CameraMode::FirstPerson => {
|
||||
if player_rolling {
|
||||
player_scale * 0.8
|
||||
player_height * 0.42
|
||||
} else if is_running && on_ground.unwrap_or(false) {
|
||||
eye_height + (scene_data.state.get_time() as f32 * 17.0).sin() * 0.05
|
||||
player_eye_height + (scene_data.state.get_time() as f32 * 17.0).sin() * 0.05
|
||||
} else {
|
||||
eye_height
|
||||
player_eye_height
|
||||
}
|
||||
},
|
||||
CameraMode::ThirdPerson if scene_data.is_aiming => player_scale * 2.2,
|
||||
CameraMode::ThirdPerson => eye_height,
|
||||
CameraMode::ThirdPerson if scene_data.is_aiming => player_height * 1.16,
|
||||
CameraMode::ThirdPerson => player_eye_height,
|
||||
CameraMode::Freefly => 0.0,
|
||||
};
|
||||
|
||||
|
@ -375,10 +375,8 @@ impl ParticleMgr {
|
||||
b.static_data.beam_duration,
|
||||
time + i as f64 / 1000.0,
|
||||
ParticleMode::HealingBeam,
|
||||
pos.0 + particle_ori * 0.5 + Vec3::new(0.0, 0.0, b.offset),
|
||||
pos.0
|
||||
+ particle_ori * b.static_data.range
|
||||
+ Vec3::new(0.0, 0.0, b.offset),
|
||||
pos.0 + particle_ori * 0.5 + b.offset,
|
||||
pos.0 + particle_ori * b.static_data.range + b.offset,
|
||||
));
|
||||
}
|
||||
} else {
|
||||
@ -404,10 +402,8 @@ impl ParticleMgr {
|
||||
b.static_data.beam_duration,
|
||||
time,
|
||||
ParticleMode::FlameThrower,
|
||||
pos.0 + random_ori * 0.5 + Vec3::new(0.0, 0.0, b.offset),
|
||||
pos.0
|
||||
+ random_ori * b.static_data.range
|
||||
+ Vec3::new(0.0, 0.0, b.offset),
|
||||
pos.0 + random_ori * 0.5 + b.offset,
|
||||
pos.0 + random_ori * b.static_data.range + b.offset,
|
||||
)
|
||||
},
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user