-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtransform.rs
More file actions
132 lines (119 loc) · 3.61 KB
/
Copy pathtransform.rs
File metadata and controls
132 lines (119 loc) · 3.61 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
use bevy::prelude::*;
use processing_core::error::{ProcessingError, Result};
pub fn set_position(
In((entity, position)): In<(Entity, Vec3)>,
mut transforms: Query<&mut Transform>,
) -> Result<()> {
let mut transform = transforms
.get_mut(entity)
.map_err(|_| ProcessingError::TransformNotFound)?;
transform.translation = position;
Ok(())
}
pub fn translate(
In((entity, offset)): In<(Entity, Vec3)>,
mut transforms: Query<&mut Transform>,
) -> Result<()> {
let mut transform = transforms
.get_mut(entity)
.map_err(|_| ProcessingError::TransformNotFound)?;
transform.translation += offset;
Ok(())
}
pub fn set_rotation(
In((entity, euler)): In<(Entity, Vec3)>,
mut transforms: Query<&mut Transform>,
) -> Result<()> {
let mut transform = transforms
.get_mut(entity)
.map_err(|_| ProcessingError::TransformNotFound)?;
transform.rotation = Quat::from_euler(EulerRot::XYZ, euler.x, euler.y, euler.z);
Ok(())
}
pub fn rotate_x(
In((entity, angle)): In<(Entity, f32)>,
mut transforms: Query<&mut Transform>,
) -> Result<()> {
let mut transform = transforms
.get_mut(entity)
.map_err(|_| ProcessingError::TransformNotFound)?;
transform.rotate_x(angle);
Ok(())
}
pub fn rotate_y(
In((entity, angle)): In<(Entity, f32)>,
mut transforms: Query<&mut Transform>,
) -> Result<()> {
let mut transform = transforms
.get_mut(entity)
.map_err(|_| ProcessingError::TransformNotFound)?;
transform.rotate_y(angle);
Ok(())
}
pub fn rotate_z(
In((entity, angle)): In<(Entity, f32)>,
mut transforms: Query<&mut Transform>,
) -> Result<()> {
let mut transform = transforms
.get_mut(entity)
.map_err(|_| ProcessingError::TransformNotFound)?;
transform.rotate_z(angle);
Ok(())
}
pub fn rotate_axis(
In((entity, angle, axis)): In<(Entity, f32, Vec3)>,
mut transforms: Query<&mut Transform>,
) -> Result<()> {
let mut transform = transforms
.get_mut(entity)
.map_err(|_| ProcessingError::TransformNotFound)?;
transform.rotate(Quat::from_axis_angle(axis.normalize(), angle));
Ok(())
}
pub fn set_scale(
In((entity, scale)): In<(Entity, Vec3)>,
mut transforms: Query<&mut Transform>,
) -> Result<()> {
let mut transform = transforms
.get_mut(entity)
.map_err(|_| ProcessingError::TransformNotFound)?;
transform.scale = scale;
Ok(())
}
pub fn scale(
In((entity, factor)): In<(Entity, Vec3)>,
mut transforms: Query<&mut Transform>,
) -> Result<()> {
let mut transform = transforms
.get_mut(entity)
.map_err(|_| ProcessingError::TransformNotFound)?;
transform.scale *= factor;
Ok(())
}
pub fn look_at(
In((entity, target)): In<(Entity, Vec3)>,
mut transforms: Query<&mut Transform>,
) -> Result<()> {
let mut transform = transforms
.get_mut(entity)
.map_err(|_| ProcessingError::TransformNotFound)?;
transform.look_at(target, Vec3::Y);
Ok(())
}
pub fn camera(
In((entity, eye, center, up)): In<(Entity, Vec3, Vec3, Vec3)>,
mut transforms: Query<&mut Transform>,
) -> Result<()> {
let mut transform = transforms
.get_mut(entity)
.map_err(|_| ProcessingError::TransformNotFound)?;
*transform = Transform::from_translation(eye).looking_at(center, up);
Ok(())
}
pub fn reset(In(entity): In<Entity>, mut transforms: Query<&mut Transform>) -> Result<()> {
let mut transform = transforms
.get_mut(entity)
.map_err(|_| ProcessingError::TransformNotFound)?;
*transform = Transform::IDENTITY;
Ok(())
}