#include "transformable.h"

Transform TransformIdentity() {
    return (Transform){
        .translation = { 0.f, 0.f, 0.f },
        .rotation = QuaternionIdentity(),
        .scale = { 1.f, 1.f, 1.f }
    };
}


Matrix TransformGetMatrix(Transform const *self) {
    Matrix mat = MatrixScale(self->scale.x, self->scale.y, self->scale.z);
    mat = MatrixMultiply(mat, QuaternionToMatrix(self->rotation));
    mat.m12 = self->translation.x;
    mat.m13 = self->translation.y;
    mat.m14 = self->translation.z;
    return mat;
}

void UpdateTransformable(Transformable *self, Transformable *parent) {
    Transform *parent_global = self->tc->get_global_transform(self->data);
    Transform *global = self->tc->get_global_transform(self->data);
    Transform *local = self->tc->get_transform(self->data);
    global->translation = Vector3Add(parent_global->translation, local->translation);
    global->rotation = QuaternionMultiply(parent_global->rotation, local->rotation);
    global->scale = Vector3Multiply(parent_global->scale, local->scale);
}
