package org.meganekkovr.xml;

import android.content.Context;

import org.joml.Quaternionf;
import org.meganekkovr.Entity;

import java.util.Locale;

/**
 * Define {@code rotation} attribute.
 */
public class RotationHandler implements XmlAttributeParser.XmlAttributeHandler {

    @Override
    public String attributeName() {
        return "rotation";
    }

    @Override
    public void parse(Entity entity, String rawValue, Context context) {

        String[] strs = rawValue.split("\\s+", 3);
        if (strs.length >= 3) {

            float x = Float.parseFloat(strs[0]);
            float y = Float.parseFloat(strs[1]);
            float z = Float.parseFloat(strs[2]);

            String rotOrder = strs.length == 4 ? strs[3].toUpperCase(Locale.US) : "XYZ";
            Quaternionf q = new Quaternionf();
            switch (rotOrder) {
                case "XYZ":
                    q.rotateXYZ(x, y, z);
                    break;
                case "YXZ":
                    q.rotateYXZ(x, y, z);
                    break;
                case "ZYX":
                    q.rotateZYX(x, y, z);
                    break;
            }
            entity.setRotation(q);
        }
    }
}

@@ -549,16 +549,39 @@
 oat x = 
+(float) Math.toRadians(
 Float.pa
@@ -597,16 +597,17 @@
 strs%5B0%5D)
+)
 ;%0A      
@@ -622,16 +622,39 @@
 oat y = 
+(float) Math.toRadians(
 Float.pa
@@ -670,16 +670,17 @@
 strs%5B1%5D)
+)
 ;%0A      
@@ -695,16 +695,39 @@
 oat z = 
+(float) Math.toRadians(
 Float.pa
@@ -743,16 +743,17 @@
 strs%5B2%5D)
+)
 ;%0A%0A     

fix #14