-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpoint_attachment.rs
64 lines (56 loc) · 1.78 KB
/
point_attachment.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use crate::{
bone::Bone,
c::{
spAttachment, spPointAttachment, spPointAttachment_computeWorldPosition,
spPointAttachment_computeWorldRotation,
},
c_interface::{NewFromPtr, SyncPtr},
};
#[cfg(feature = "mint")]
use mint::Vector2;
/// A lightweight, single point attachment with a position and rotation.
///
/// [Spine API Reference](http://esotericsoftware.com/spine-api-reference#PointAttachment)
#[derive(Debug)]
pub struct PointAttachment {
c_point_attachment: SyncPtr<spPointAttachment>,
}
impl NewFromPtr<spPointAttachment> for PointAttachment {
unsafe fn new_from_ptr(c_point_attachment: *const spPointAttachment) -> Self {
Self {
c_point_attachment: SyncPtr(c_point_attachment as *mut spPointAttachment),
}
}
}
impl PointAttachment {
fn attachment(&self) -> &spAttachment {
unsafe { &self.c_ptr_ref().super_0 }
}
pub fn compute_world_position(&self, bone: &Bone) -> (f32, f32) {
let mut x = 0.;
let mut y = 0.;
unsafe {
spPointAttachment_computeWorldPosition(self.c_ptr(), bone.c_ptr(), &mut x, &mut y);
}
(x, y)
}
pub fn compute_world_rotation(&self, bone: &Bone) -> f32 {
unsafe { spPointAttachment_computeWorldRotation(self.c_ptr(), bone.c_ptr()) }
}
c_attachment_accessors!();
c_accessor_color!(color, color);
c_accessor_mut!(rotation, set_rotation, rotation, f32);
c_accessor_mut!(x, set_x, x, f32);
c_accessor_mut!(y, set_y, x, f32);
c_ptr!(c_point_attachment, spPointAttachment);
}
/// Functions available if using the `mint` feature.
#[cfg(feature = "mint")]
impl PointAttachment {
pub fn position(&self) -> Vector2<f32> {
Vector2 {
x: self.x(),
y: self.y(),
}
}
}