diff --git a/Tools/dora-rust/dora-test/src/tests/contact.rs b/Tools/dora-rust/dora-test/src/tests/contact.rs index f742e30a8..d35c41243 100644 --- a/Tools/dora-rust/dora-test/src/tests/contact.rs +++ b/Tools/dora-rust/dora-test/src/tests/contact.rs @@ -15,8 +15,8 @@ pub fn test() { let radius = 300.0; let mut vertices = vec![]; for i in 0..=count { - let angle = 2.0 * std::f32::consts::PI * i as f32 / count as f32; - vertices.push(Vec2::new(radius * angle.cos(), radius * angle.sin())); + let angle = 2.0 * Math::PI * i as f32 / count as f32; + vertices.push(Vec2::new(radius * Math::cos(angle), radius * Math::sin(angle))); } terrain_def.attach_chain(&vertices, 0.4, 0.0); terrain_def.attach_disk_with_center(&Vec2::new(0.0, -270.0), 30.0, 1.0, 0.0, 1.0); diff --git a/Tools/dora-rust/dora-test/src/tests/entity_move.rs b/Tools/dora-rust/dora-test/src/tests/entity_move.rs index 1272300fe..c5e2c58eb 100644 --- a/Tools/dora-rust/dora-test/src/tests/entity_move.rs +++ b/Tools/dora-rust/dora-test/src/tests/entity_move.rs @@ -31,8 +31,9 @@ pub fn test() { get_scene() ) { if let Some(mut sprite) = Sprite::with_file(&image) { + sprite.set_size(&Size::new(300.0, 300.0)); sprite.add_to(&scene); - sprite.run_action_def(ActionDef::scale(0.5, 0.0, 0.5, EaseType::OutBack), false); + sprite.run_action_def(ActionDef::scale(0.5, 0.0, 1.0, EaseType::OutBack), false); entity.set("sprite", sprite.obj()); } } @@ -73,7 +74,7 @@ pub fn test() { return false; } let dir = (target - position).normalize(); - let angle = dir.x.atan2(dir.y).to_degrees(); + let angle = Math::deg(Math::atan2(dir.x, dir.y)); let new_pos = position + dir * speed; let new_pos = new_pos.clamp(&position, &target); entity.set("position", new_pos); @@ -162,7 +163,7 @@ pub fn test() { if let Some(mut sprite) = get_sprite(&entity) { sprite.run_action_def( ActionDef::sequence(&vec![ - ActionDef::scale(0.5, 0.5, 0.0, EaseType::InBack), + ActionDef::scale(0.5, 1.0, 0.0, EaseType::InBack), ActionDef::event("Destroy", "") ]), false); sprite.slot("Destroy", Box::new(move |_| { diff --git a/Tools/dora-rust/dora/src/dora.rs b/Tools/dora-rust/dora/src/dora.rs index 80124937d..f5e538902 100644 --- a/Tools/dora-rust/dora/src/dora.rs +++ b/Tools/dora-rust/dora/src/dora.rs @@ -5702,6 +5702,81 @@ impl Nvg { } } +// math + +extern "C" { + fn math_abs(v: f64) -> f64; + fn math_acos(v: f32) -> f32; + fn math_asin(v: f32) -> f32; + fn math_atan(v: f32) -> f32; + fn math_atan2(y: f32, x: f32) -> f32; + fn math_ceil(v: f32) -> f32; + fn math_cos(v: f32) -> f32; + fn math_deg(v: f32) -> f32; + fn math_exp(v: f32) -> f32; + fn math_floor(v: f32) -> f32; + fn math_fmod(x: f32, y: f32) -> f32; + fn math_log(v: f32) -> f32; + fn math_rad(v: f32) -> f32; + fn math_sin(v: f32) -> f32; + fn math_sqrt(v: f32) -> f32; + fn math_tan(v: f32) -> f32; +} + +pub struct Math {} + +impl Math { + pub const PI: f32 = std::f32::consts::PI; + pub fn abs(v: f64) -> f64 { + unsafe { math_abs(v) } + } + pub fn acos(v: f32) -> f32 { + unsafe { math_acos(v) } + } + pub fn asin(v: f32) -> f32 { + unsafe { math_asin(v) } + } + pub fn atan(v: f32) -> f32 { + unsafe { math_atan(v) } + } + pub fn atan2(y: f32, x: f32) -> f32 { + unsafe { math_atan2(y, x) } + } + pub fn ceil(v: f32) -> f32 { + unsafe { math_ceil(v) } + } + pub fn cos(v: f32) -> f32 { + unsafe { math_cos(v) } + } + pub fn deg(v: f32) -> f32 { + unsafe { math_deg(v) } + } + pub fn exp(v: f32) -> f32 { + unsafe { math_exp(v) } + } + pub fn floor(v: f32) -> f32 { + unsafe { math_floor(v) } + } + pub fn fmod(x: f32, y: f32) -> f32 { + unsafe { math_fmod(x, y) } + } + pub fn log(v: f32) -> f32 { + unsafe { math_log(v) } + } + pub fn rad(v: f32) -> f32 { + unsafe { math_rad(v) } + } + pub fn sin(v: f32) -> f32 { + unsafe { math_sin(v) } + } + pub fn sqrt(v: f32) -> f32 { + unsafe { math_sqrt(v) } + } + pub fn tan(v: f32) -> f32 { + unsafe { math_tan(v) } + } +} + use std::future::Future; use std::pin::Pin; use std::task::{Context, Poll};