why is my slider rendering wrong

This commit is contained in:
Michael Zhang 2021-01-08 01:52:06 -06:00
parent 74d63a216e
commit b1b5050105
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
4 changed files with 23 additions and 14 deletions

2
Cargo.lock generated
View file

@ -1132,7 +1132,7 @@ checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a"
[[package]] [[package]]
name = "libosu" name = "libosu"
version = "0.0.12" version = "0.0.12"
source = "git+https://github.com/iptq/libosu?rev=7acc09af59b789f78c21c259d4e1e246e9cf0b08#7acc09af59b789f78c21c259d4e1e246e9cf0b08" source = "git+https://github.com/iptq/libosu?rev=5a8501aec0f4f2232507f80a65b8b31be8756414#5a8501aec0f4f2232507f80a65b8b31be8756414"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bitflags", "bitflags",

View file

@ -19,4 +19,4 @@ num = "0.3.1"
[dependencies.libosu] [dependencies.libosu]
git = "https://github.com/iptq/libosu" git = "https://github.com/iptq/libosu"
rev = "7acc09af59b789f78c21c259d4e1e246e9cf0b08" rev = "5a8501aec0f4f2232507f80a65b8b31be8756414"

View file

@ -6,7 +6,8 @@ use anyhow::Result;
use ggez::{ use ggez::{
event::{EventHandler, KeyCode, KeyMods}, event::{EventHandler, KeyCode, KeyMods},
graphics::{ graphics::{
self, DrawMode, DrawParam, FillOptions, FilterMode, Mesh, Rect, StrokeOptions, Text, WHITE, self, Color, DrawMode, DrawParam, FillOptions, FilterMode, Mesh, Rect, StrokeOptions, Text,
WHITE,
}, },
Context, GameError, GameResult, Context, GameError, GameResult,
}; };
@ -68,6 +69,14 @@ impl Game {
graphics::clear(ctx, [0.0, 0.0, 0.0, 1.0].into()); graphics::clear(ctx, [0.0, 0.0, 0.0, 1.0].into());
let playfield = Mesh::new_rectangle(
ctx,
DrawMode::Stroke(StrokeOptions::default()),
EDITOR_SCREEN,
Color::new(1.0, 1.0, 1.0, 0.5),
)?;
graphics::draw(ctx, &playfield, DrawParam::default())?;
let time = self.song.as_ref().unwrap().position()?; let time = self.song.as_ref().unwrap().position()?;
let text = Text::new(format!("time: {}", time).as_ref()); let text = Text::new(format!("time: {}", time).as_ref());
graphics::queue_text(ctx, &text, [0.0, 0.0], Some(WHITE)); graphics::queue_text(ctx, &text, [0.0, 0.0], Some(WHITE));
@ -84,7 +93,7 @@ impl Game {
let osupx_scale_x = EDITOR_SCREEN.w / 512.0; let osupx_scale_x = EDITOR_SCREEN.w / 512.0;
let osupx_scale_y = EDITOR_SCREEN.h / 384.0; let osupx_scale_y = EDITOR_SCREEN.h / 384.0;
let cs_osupx = 54.4 - 4.48 * self.beatmap.difficulty.circle_size; let cs_osupx = self.beatmap.difficulty.circle_size_osupx();
let cs_real = cs_osupx * osupx_scale_x; let cs_real = cs_osupx * osupx_scale_x;
for ho in visible_hitobjects.iter() { for ho in visible_hitobjects.iter() {

View file

@ -1,13 +1,8 @@
use std::collections::{HashMap, VecDeque}; use std::collections::VecDeque;
use std::mem;
use std::sync::Arc;
use anyhow::Result; use anyhow::Result;
use ggez::{ use ggez::{
conf::NumSamples, graphics::{self, DrawMode, DrawParam, LineCap, LineJoin, Mesh, Rect, StrokeOptions},
graphics::{
self, Canvas, Color, DrawMode, DrawParam, LineCap, LineJoin, Mesh, Rect, StrokeOptions,
},
nalgebra::Point2, nalgebra::Point2,
Context, Context,
}; };
@ -32,7 +27,7 @@ pub fn render_slider(
let osupx_scale_x = rect.w as f64 / 512.0; let osupx_scale_x = rect.w as f64 / 512.0;
let osupx_scale_y = rect.h as f64 / 384.0; let osupx_scale_y = rect.h as f64 / 384.0;
let cs_osupx = 54.4 - 4.48 * beatmap.difficulty.circle_size as f64; let cs_osupx = beatmap.difficulty.circle_size_osupx() as f64;
let cs_real = cs_osupx * osupx_scale_x; let cs_real = cs_osupx * osupx_scale_x;
let (mut boundx, mut boundy, mut boundw, mut boundh) = (0.0f64, 0.0f64, 0.0f64, 0.0f64); let (mut boundx, mut boundy, mut boundw, mut boundh) = (0.0f64, 0.0f64, 0.0f64, 0.0f64);
@ -75,9 +70,14 @@ fn get_spline(
let points = control_points let points = control_points
.iter() .iter()
.map(|p| Point(p.0 as f64, p.1 as f64)) .map(|p| Point(p.0 as f64, p.1 as f64))
.collect(); .collect::<Vec<_>>();
match kind { match kind {
SliderSplineKind::Linear => points, SliderSplineKind::Linear => {
let start = points[0];
let unit = (points[1] - points[0]).norm();
let end = points[0] + unit * pixel_length;
vec![start, end]
}
SliderSplineKind::Perfect => { SliderSplineKind::Perfect => {
let (p1, p2, p3) = (points[0], points[1], points[2]); let (p1, p2, p3) = (points[0], points[1], points[2]);
let (center, radius) = Math::circumcircle(p1, p2, p3); let (center, radius) = Math::circumcircle(p1, p2, p3);