lnmp_spatial/
transform.rs

1use crate::types::*;
2
3pub fn spatial_transform(point: &Position3D, transform: &Transform) -> Position3D {
4    // 1. Scale
5    let sx = point.x * transform.scale.x;
6    let sy = point.y * transform.scale.y;
7    let sz = point.z * transform.scale.z;
8
9    // 2. Rotate (Euler angles - simplified, assumes specific order e.g., XYZ)
10    // For full robustness, quaternions should be used, but using Euler for now as per struct.
11    // Rotation logic can be complex; implementing a basic rotation matrix application here.
12
13    let (sin_x, cos_x) = transform.rotation.pitch.sin_cos();
14    let (sin_y, cos_y) = transform.rotation.yaw.sin_cos();
15    let (sin_z, cos_z) = transform.rotation.roll.sin_cos();
16
17    // Rotate Z
18    let x1 = sx * cos_z - sy * sin_z;
19    let y1 = sx * sin_z + sy * cos_z;
20    let z1 = sz;
21
22    // Rotate Y
23    let x2 = x1 * cos_y + z1 * sin_y;
24    let y2 = y1;
25    let z2 = -x1 * sin_y + z1 * cos_y;
26
27    // Rotate X
28    let x3 = x2;
29    let y3 = y2 * cos_x - z2 * sin_x;
30    let z3 = y2 * sin_x + z2 * cos_x;
31
32    // 3. Translate
33    Position3D {
34        x: x3 + transform.position.x,
35        y: y3 + transform.position.y,
36        z: z3 + transform.position.z,
37    }
38}