Skip to content

Commit

Permalink
[#72] Fix arms
Browse files Browse the repository at this point in the history
  • Loading branch information
Orchaldir committed Sep 20, 2023
1 parent a891229 commit 667f90e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
11 changes: 6 additions & 5 deletions rpg_tools_rendering/src/rendering/body/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::math::size2d::Size2d;
use crate::renderer::{RenderOptions, Renderer};
use crate::rendering::body::torso::render_torso;
use crate::rendering::config::RenderConfig;
use crate::rendering::equipment::pants::interpolate;
use rpg_tools_core::model::character::appearance::body::Body;
use std::ops::Mul;

Expand Down Expand Up @@ -52,9 +53,8 @@ fn render_legs(
pub fn render_hands(renderer: &mut dyn Renderer, config: &RenderConfig, aabb: &AABB, body: &Body) {
let options = config.get_skin_options(&body.skin);
let hand_radius = config.body.get_hand_radius(body, aabb);
let distance_between_hands = config.body.get_shoulder_width(body)
+ config.body.get_arm_width(body)
+ config.body.get_fat_offset_factor(body);
let distance_between_hands =
config.body.get_distance_between_hands(body) + config.body.get_hand_radius_factor(body);
let hand_y = config.body.get_arm_y() + config.body.height_arm;
let (left_hand_center, right_hand_center) =
aabb.get_mirrored_points(distance_between_hands, hand_y);
Expand All @@ -79,7 +79,7 @@ fn render_arms(
pub fn get_left_arm(config: &RenderConfig, aabb: &AABB, body: &Body) -> Polygon2dBuilder {
let mut builder = get_left_arm_short(config, aabb, body, false);
let width = config.body.get_arm_width(body);
let bottom_x = get_end_x(config.body.get_torso_width(body));
let bottom_x = get_end_x(config.body.get_distance_between_hands(body));
let y = config.body.get_arm_y() + config.body.height_arm;

builder.add_point(aabb.get_point(bottom_x, y), false);
Expand All @@ -97,7 +97,8 @@ pub fn get_left_arm_short(
let mut builder = Polygon2dBuilder::new();
let width = config.body.get_arm_width(body);
let top_x = get_end_x(config.body.get_shoulder_width(body) * 0.94);
let bottom_x = get_end_x(config.body.get_torso_width(body));
let bottom_x = get_end_x(config.body.get_distance_between_hands(body));
let bottom_x = interpolate(top_x, bottom_x, 0.7);
let y = config.body.get_arm_y();
let mid_y = y + 0.2;

Expand Down
14 changes: 7 additions & 7 deletions rpg_tools_rendering/src/rendering/config/body/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ impl BodyConfig {
self.get_torso_bottom() - 0.05
}

pub fn get_fat_offset_factor(&self, body: &Body) -> f32 {
if body.shape == BodyShape::Fat {
self.get_hip_width(body) - self.get_shoulder_width(body)
} else {
0.0
}
pub fn get_distance_between_hands(&self, body: &Body) -> f32 {
self.get_torso_width(body) + 0.08
}

pub fn get_hand_radius(&self, body: &Body, aabb: &AABB) -> u32 {
aabb.convert_to_height(self.hand_factor * self.get_width_factor(body))
aabb.convert_to_height(self.get_hand_radius_factor(body))
}

pub fn get_hand_radius_factor(&self, body: &Body) -> f32 {
self.hand_factor * self.get_width_factor(body)
}

pub fn get_foot_radius(&self, body: &Body, aabb: &AABB) -> u32 {
Expand Down
2 changes: 1 addition & 1 deletion rpg_tools_rendering/src/rendering/equipment/pants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ fn get_base(config: &RenderConfig, aabb: &AABB, body: &Body) -> Polygon2dBuilder
builder
}

fn interpolate(start: f32, end: f32, factor: f32) -> f32 {
pub fn interpolate(start: f32, end: f32, factor: f32) -> f32 {
start * (1.0 - factor) + end * factor
}

0 comments on commit 667f90e

Please sign in to comment.