use crate::blueprint::{AxisLimit, JointType, JointTypeKind, MaterialId, ModuleId, SensorType};
use glam::{Quat, Vec3};
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ActiveJointConfig {
pub joint_type: JointType,
pub axis: Vec3,
pub limits: Vec<AxisLimit>,
}
impl Default for ActiveJointConfig {
fn default() -> Self {
Self {
joint_type: JointType::Fixed, axis: Vec3::X,
limits: Vec::new(),
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct RobotTurtleState {
pub position: Vec3,
pub rotation: Quat,
pub current_module_id: Option<ModuleId>,
pub joint_config: ActiveJointConfig,
pub material_id: MaterialId,
pub width: f32,
}
impl Default for RobotTurtleState {
fn default() -> Self {
Self {
position: Vec3::ZERO,
rotation: Quat::IDENTITY,
current_module_id: None,
joint_config: ActiveJointConfig::default(),
material_id: 0,
width: 0.1,
}
}
}
impl RobotTurtleState {
pub fn up(&self) -> Vec3 {
self.rotation * Vec3::Y
}
pub fn forward(&self) -> Vec3 {
self.rotation * Vec3::Z
}
pub fn right(&self) -> Vec3 {
self.rotation * Vec3::X
}
pub fn rotate_local_x(&mut self, angle: f32) {
let rot = Quat::from_axis_angle(Vec3::X, angle);
self.rotation *= rot;
}
pub fn rotate_local_y(&mut self, angle: f32) {
let rot = Quat::from_axis_angle(Vec3::Y, angle);
self.rotation *= rot;
}
pub fn rotate_local_z(&mut self, angle: f32) {
let rot = Quat::from_axis_angle(Vec3::Z, angle);
self.rotation *= rot;
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum RobotOp {
Move,
Yaw(f32),
Pitch(f32),
Roll(f32),
TurnAround,
SpawnBox,
SpawnCylinder,
SpawnSphere,
SpawnCapsule,
SetJointType(JointTypeKind),
SetJointAxis,
SetScrewPitch,
SetJointLimits,
AddAxisLimit,
ClearJointLimits,
SetMaterial,
SetWidth,
MountSensor(SensorType),
MarkEndEffector,
Push,
Pop,
Ignore,
}