Browse Source

Add RC orientation conversion

master
NGnius (Graham) 2 years ago
parent
commit
2b1033449e
3 changed files with 8 additions and 3 deletions
  1. +1
    -1
      Cargo.toml
  2. +1
    -1
      src/convert/mod.rs
  3. +6
    -1
      src/convert/robocraft_3d.rs

+ 1
- 1
Cargo.toml 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"


+ 1
- 1
src/convert/mod.rs 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};

+ 6
- 1
src/convert/robocraft_3d.rs 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|
{


Loading…
Cancel
Save