Skip to content

Commit

Permalink
[#46] Fix bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
Orchaldir committed Nov 1, 2023
1 parent d053a3a commit 517b014
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion resources/characters/characters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
type: Glasses
style:
frame_color: Black
frame_type: Wire
frame_type: FullRimmed
lens_color: Aqua
lens_shape: Oval
lens_transparency: High
Expand Down
7 changes: 3 additions & 4 deletions rpg_tools_rendering/src/rendering/config/equipment/eyewear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ impl EyewearConfig {
(radius_x as f32 * self.radius_y_factor) as u32
}

pub fn get_bridge_height(&self, width: u32, frame_type: FrameType) -> u32 {
let thickness = match frame_type {
pub fn get_bridge_thickness(&self, frame_type: FrameType) -> f32 {
match frame_type {
FrameType::Rimless => self.thickness_wire,
_ => self.get_frame_thickness(frame_type),
};
(width as f32 * self.bridge_factor * thickness) as u32
}
}

pub fn get_frame_thickness(&self, frame_type: FrameType) -> f32 {
Expand Down
4 changes: 2 additions & 2 deletions rpg_tools_rendering/src/rendering/config/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ pub fn create_config() -> RenderConfig {
bridge_factor: 0.1,
radius_factor: 1.4,
radius_y_factor: 0.8,
thickness_horn: 5.0,
thickness_rimmed: 3.0,
thickness_horn: 3.0,
thickness_rimmed: 2.0,
thickness_wire: 1.0,
},
footwear: FootwearConfig {
Expand Down
15 changes: 7 additions & 8 deletions rpg_tools_rendering/src/rendering/equipment/eyewear.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use crate::math::aabb2d::AABB;
use crate::math::point2d::Point2d;
use crate::math::size2d::Size2d;
use crate::renderer::color::WebColor;
use crate::renderer::{RenderOptions, Renderer};
use crate::rendering::config::RenderConfig;
use rpg_tools_core::model::equipment::appearance::eyewear::{Eyewear, LensShape, LensStyle};
use rpg_tools_core::model::side::Side;
use std::ops::{Add, Div};

pub fn render_eyewear(
renderer: &mut dyn Renderer,
Expand Down Expand Up @@ -49,13 +47,14 @@ fn render_bridge(
right: &Point2d,
radius: u32,
) {
let width = left.calculate_distance(right) as u32 - 2 * radius;
let height = config.eyewear.get_bridge_height(width, style.frame_type);
let center = left.add(*right).div(2.0);
let aabb = AABB::with_center(center, Size2d::new(width, height));
let options = RenderOptions::no_line(WebColor::from_color(style.frame_color));
let options = config.line_with_color(
style.frame_color,
config.eyewear.get_bridge_thickness(style.frame_type),
);
let start = Point2d::new(left.x + radius as i32, left.y);
let end = Point2d::new(right.x - radius as i32, right.y);

renderer.render_rectangle(&aabb, &options);
renderer.render_line(&(start, end).into(), &options);
}

fn render_lens(
Expand Down

0 comments on commit 517b014

Please sign in to comment.