Skip to content

Commit

Permalink
[#42] Start sole rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Orchaldir committed Sep 23, 2023
1 parent 34e40e2 commit 91ba9dd
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
2 changes: 1 addition & 1 deletion rpg_tools_rendering/src/rendering/body/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn render_legs(
) {
let leg_width = config.body.get_leg_width(body);
let leg_y = config.body.get_leg_y();
let foot_y = config.body.get_foot_y();
let foot_y = config.body.y_foot;
let left_leg_start_x = config.body.get_left_leg_x(body);
let right_leg_x = config.body.get_right_leg_x(body);

Expand Down
18 changes: 10 additions & 8 deletions rpg_tools_rendering/src/rendering/config/body/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct BodyConfig {
pub y_upper: f32,
pub y_waist: f32,
pub y_lower: f32,
pub y_foot: f32,
}

impl BodyConfig {
Expand Down Expand Up @@ -92,10 +93,6 @@ impl BodyConfig {
self.get_torso_bottom() - 0.05
}

pub fn get_foot_y(&self) -> f32 {
1.0
}

pub fn get_distance_between_hands(&self, body: &Body) -> f32 {
self.get_torso_width(body) + 0.08
}
Expand All @@ -118,13 +115,18 @@ impl BodyConfig {
* self.get_torso_config(body.shape).legs_width
}

pub fn get_feet_centers(&self, body: &Body, aabb: &AABB) -> (Point2d, Point2d) {
pub fn get_feet_center_x(&self, body: &Body) -> (f32, f32) {
let leg_half = self.get_leg_width(body) / 2.0;
let foot_y = self.get_foot_y();
let left_leg_start_x = self.get_left_leg_x(body);
let right_leg_x = self.get_right_leg_x(body);
let left = aabb.get_point(left_leg_start_x + leg_half, foot_y);
let right = aabb.get_point(right_leg_x + leg_half, foot_y);

(left_leg_start_x + leg_half, right_leg_x + leg_half)
}

pub fn get_feet_centers(&self, body: &Body, aabb: &AABB) -> (Point2d, Point2d) {
let (left_x, right_x) = self.get_feet_center_x(body);
let left = aabb.get_point(left_x, self.y_foot);
let right = aabb.get_point(right_x, self.y_foot);

(left, right)
}
Expand Down
1 change: 1 addition & 0 deletions rpg_tools_rendering/src/rendering/config/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub fn create_config() -> RenderConfig {
y_upper: 0.3,
y_waist: 0.5,
y_lower: 0.75,
y_foot: 1.0,
},
hair: HairConfig {
hairline: HairlineConfig {
Expand Down
38 changes: 32 additions & 6 deletions rpg_tools_rendering/src/rendering/equipment/footwear.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
use crate::math::aabb2d::AABB;
use crate::math::polygon2d::builder::Polygon2dBuilder;
use crate::renderer::Renderer;
use crate::rendering::body::torso::create_torso;
use crate::rendering::body::{get_left_arm, get_left_arm_short};
use crate::rendering::config::body::torso::TorsoConfig;
use crate::rendering::config::equipment::shirt::ShirtConfig;
use crate::rendering::config::RenderConfig;
use rpg_tools_core::model::character::appearance::body::Body;
use rpg_tools_core::model::equipment::appearance::footwear::Footwear;
use rpg_tools_core::model::equipment::appearance::shirt::{Neckline, Shirt, SleeveStyle};
use rpg_tools_core::model::width::Width;

pub fn render_footwear(
renderer: &mut dyn Renderer,
Expand All @@ -18,7 +14,20 @@ pub fn render_footwear(
footwear: &Footwear,
from_front: bool,
) {
render_sole(renderer, config, aabb, body, footwear);
render_soles(renderer, config, aabb, body, footwear);
}

fn render_soles(
renderer: &mut dyn Renderer,
config: &RenderConfig,
aabb: &AABB,
body: &Body,
footwear: &Footwear,
) {
let (left_center, right_center) = config.body.get_feet_center_x(body);

render_sole(renderer, config, aabb, body, footwear, left_center);
render_sole(renderer, config, aabb, body, footwear, right_center);
}

fn render_sole(
Expand All @@ -27,5 +36,22 @@ fn render_sole(
aabb: &AABB,
body: &Body,
footwear: &Footwear,
center_x: f32,
) {
let options = config.get_options(footwear.sole.color);
let width = config.body.get_foot_radius_factor(body) * 2.0;
let y_start = config.body.y_foot;
let y_end = y_start
+ match footwear.sole.width {
Width::Thin => 0.02,
Width::Average => 0.04,
Width::Wide => 0.06,
};
let mut builder = Polygon2dBuilder::new();

builder.add_horizontal_pair(aabb, width, center_x, y_start, true);
builder.add_horizontal_pair(aabb, width, center_x, y_end, true);
let polygon = builder.build();

renderer.render_polygon(&polygon, &options);
}

0 comments on commit 91ba9dd

Please sign in to comment.