Add RC orientation conversion

This commit is contained in:
NGnius (Graham) 2021-10-28 16:36:17 -04:00
parent a69c7c71c6
commit 2b1033449e
3 changed files with 8 additions and 3 deletions

View file

@ -1,6 +1,6 @@
[package]
name = "libfj"
version = "0.6.0"
version = "0.6.1"
authors = ["NGnius (Graham) <ngniusness@gmail.com>"]
edition = "2018"
description = "An unofficial collection of APIs used in FreeJam games and mods"

View file

@ -5,4 +5,4 @@
#[cfg(feature = "robocraft")]
mod robocraft_3d;
#[cfg(feature = "robocraft")]
pub use robocraft_3d::{cubes_to_model, cubes_to_model_with_lut};
pub use robocraft_3d::{cubes_to_model, cubes_to_model_with_lut, cube_rotation_to_quat};

View file

@ -32,6 +32,11 @@ const ROTATIONS: [Euler<Deg<f32>>; 24] = [
Euler{x: Deg(-90.0), y: Deg(180.0), z: Deg(0.0)}, // 23
];
/// Convert a Robocraft robot's orientation enum into a physical rotation
pub fn cube_rotation_to_quat(orientation: u8) -> Quaternion<f32> {
ROTATIONS[orientation as usize].into()
}
/// Convert a Robocraft robot to a 3D model in Wavefront OBJ format.
pub fn cubes_to_model(robot: robocraft::Cubes) -> obj::Obj {
cubes_to_model_with_lut(robot, default_model_lut)
@ -47,7 +52,7 @@ pub fn cubes_to_model_with_lut<F: FnMut(u32) -> Vec<Quad<Vertex>>>(robot: robocr
// generate simple cube for every block
// TODO rotate blocks
let vertices = lut(cube.id); // Use lookup table to find correct id <-> block translation
let rotation: Quaternion<_> = ROTATIONS[cube.orientation as usize].into();
let rotation: Quaternion<_> = cube_rotation_to_quat(cube.orientation);
positions.extend::<Vec::<[f32; 3]>>(
vertices.clone().into_iter().vertex(|v|
{