#include "test_object.h"
#include "core/render.h"
#include "raylib.h"

START_REFLECT(TestObject);
REFLECT_TYPECLASS(TestObject, Drop);
REFLECT_TYPECLASS(TestObject, SceneNodeEntity);
REFLECT_TYPECLASS(TestObject, Renderable);
END_REFLECT(TestObject);

impl_Drop_for(TestObject,
    DestroyTestObject
)

impl_Renderable_for(TestObject,
    TestObjectDraw
)

impl_SceneNodeEntity_for(TestObject,
    TestObjectEnterTree,
    TestObjectExitTree,
    TestObjectTick
)

SceneNode *CreateTestObject() {
    TestObject *self = new(TestObject);
    return CreateSceneNode(TestObject_as_SceneNodeEntity(self));
}

void DestroyTestObject(TestObject *self) {
    free(self);
}

void TestObjectEnterTree(TestObject *self) {
    self->transform = TC_CAST(self->node->parent->entity, Transformable);
    AddRenderable(TestObject_as_Renderable(self));
}

void TestObjectExitTree(TestObject *self) {
    RemoveRenderable(TestObject_as_Renderable(self));
}

void TestObjectDraw(TestObject *self) {
}

void TestObjectTick(TestObject *self, double delta) {
    Transform global_transform = self->transform.tc->get_global_transform(self->transform.data);
    Matrix global_matrix = TransformGetMatrix(global_transform);
    global_transform.rotation = QuaternionMultiply(global_transform.rotation, QuaternionFromAxisAngle(MATRIX_RIGHT(global_matrix), -3.f * delta));
    global_matrix = TransformGetMatrix(global_transform);
    global_transform.translation = Vector3Add(global_transform.translation, Vector3Scale(MATRIX_FORWARD(global_matrix), 2.f * delta));
    self->transform.tc->set_global_transform(self->transform.data, global_transform);
}
