ihmcrobotics / euclid

Vector math, geometry, reference frame, and shapes 2D & 3D

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A YawPitchRoll enum

calvertdw opened this issue · comments

Something like this which allows to make (UI stuff especially) abstract over yaw, pitch, and roll. These are often the gizmo handles or how you want to tell the chest to yaw, pitch, roll, etc..

public enum YawPitchRollAxis
{
   YAW(Axis3D.Z), PITCH(Axis3D.Y), ROLL(Axis3D.X);
   private final Axis3D axis3D;
   private final String lowerCasedName;
   private final String pascalCasedName;
   YawPitchRollAxis(Axis3D axis3D)
   {
      this.axis3D = axis3D;
      lowerCasedName = name().toLowerCase();
      pascalCasedName = StringUtils.capitalize(lowerCasedName);
   }
   public YawPitchRoll createYawPitchRoll(double angle)
   {
      YawPitchRoll yawPitchRoll = new YawPitchRoll();
      switch (this)
      {
         case YAW -> yawPitchRoll.setYaw(angle);
         case PITCH -> yawPitchRoll.setPitch(angle);
         case ROLL -> yawPitchRoll.setRoll(angle);
      }
      return yawPitchRoll;
   }
   private double getFromYawPitchRoll(YawPitchRollReadOnly yawPitchRollReadOnly)
   {
      return switch (this)
      {
         case YAW -> yawPitchRollReadOnly.getYaw();
         case PITCH -> yawPitchRollReadOnly.getPitch();
         case ROLL -> yawPitchRollReadOnly.getRoll();
      };
   }
   public Axis3D getAxis3D()
   {
      return axis3D;
   }
   public String getLowerCasedName()
   {
      return lowerCasedName;
   }
   public String getPascalCasedName()
   {
      return pascalCasedName;
   }
}