/*
 * BallFactory.cpp
 *
 *  Created on: Aug 9, 2019
 *      Author: fredrick
 */

#include "BoxFactory.h"

namespace JamSpook {

BoxFactory::BoxFactory(weak_ptr<AssetSystem> assetSystem,
                       weak_ptr<GraphicsSystem> graphicsSystem,
                       weak_ptr<RenderLayer> renderLayer):
        mAssetSystem(assetSystem),
        mGraphicsSystem(graphicsSystem),
        mRenderLayer(renderLayer)
{}

BoxFactory::~BoxFactory()
{}

shared_ptr<Entity> BoxFactory::createBox(const vec3 position,
                                         const vec3 radius)
{
    // Create instance
    shared_ptr<Entity> entity = make_shared<Entity>();
    entity->setEntityTag("rando-box");
    SceneGraph::addEntity(entity);
    mat4 transform = translate(mat4(1), position);

    // Add graphics component
    shared_ptr<GraphicsComponent> graphicsComponent = make_shared<GraphicsComponent>(transform,
                                                                                     entity,
                                                                                     getShared(mGraphicsSystem),
                                                                                     mRenderLayer);
    graphicsComponent->setScale(radius * 2.0f);
    entity->addComponent(graphicsComponent);

    // Add the ModelRenderable of a ball
    ModelRenderableFactory* modelFactory = new ModelRenderableFactory(mAssetSystem);
    shared_ptr<ModelRenderable> modelRenderable = modelFactory->createModel("box-1x1x1.bcosm",
                                                                            "box-1x1x1-albedo.png",
                                                                            "box-1x1x1-model");
    delete modelFactory;
    graphicsComponent->addRenderable(modelRenderable);

    // Return instance
    return entity;
}

} // namespace JamSpook
