Partial implementation of sprites and backgrounds
This commit is contained in:
parent
7bd9cb930f
commit
ac8d75a1c1
Binary file not shown.
After Width: | Height: | Size: 806 KiB |
Binary file not shown.
After Width: | Height: | Size: 79 KiB |
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* SpriteFactory.cpp
|
||||
*
|
||||
* Created on: Aug 24, 2020
|
||||
* Author: fredrick
|
||||
*/
|
||||
|
||||
#include "SpriteFactory.h"
|
||||
|
||||
namespace JamSpook {
|
||||
|
||||
SpriteFactory::SpriteFactory(weak_ptr<AssetSystem> assetSystem,
|
||||
weak_ptr<GraphicsSystem> graphicsSystem,
|
||||
weak_ptr<RenderLayer> renderLayer):
|
||||
mAssetSystem(assetSystem),
|
||||
mGraphicsSystem(graphicsSystem),
|
||||
mRenderLayer(renderLayer)
|
||||
{}
|
||||
|
||||
SpriteFactory::~SpriteFactory()
|
||||
{}
|
||||
|
||||
shared_ptr<Entity> SpriteFactory::createPlane(const string name,
|
||||
const string filePath,
|
||||
const vec3 position,
|
||||
const vec3 rotation,
|
||||
const vec3 scaleFactor)
|
||||
{
|
||||
// Create instance
|
||||
shared_ptr<Entity> entity = make_shared<Entity>();
|
||||
entity->setEntityTag(name);
|
||||
SceneGraph::addEntity(entity);
|
||||
mat4 transform = scale(mat4(1), scaleFactor) * translate(mat4(1), position);
|
||||
|
||||
// Add graphics component
|
||||
shared_ptr<GraphicsComponent> graphicsComponent = make_shared<GraphicsComponent>(transform,
|
||||
entity,
|
||||
getShared(mGraphicsSystem),
|
||||
mRenderLayer);
|
||||
entity->addComponent(graphicsComponent);
|
||||
|
||||
// Add the ModelRenderable of a ball
|
||||
ModelRenderableFactory* modelFactory = new ModelRenderableFactory(mAssetSystem);
|
||||
shared_ptr<ModelRenderable> modelRenderable = modelFactory->createModel("plane-1x1.bcosm",
|
||||
filePath,
|
||||
name+"_model");
|
||||
delete modelFactory;
|
||||
graphicsComponent->addRenderable(modelRenderable);
|
||||
|
||||
// Return instance
|
||||
return entity;
|
||||
}
|
||||
|
||||
shared_ptr<Entity> SpriteFactory::createBackground(const string name,
|
||||
const string filePath)
|
||||
{
|
||||
// Create instance
|
||||
shared_ptr<Entity> entity = make_shared<Entity>();
|
||||
entity->setEntityTag(name);
|
||||
SceneGraph::addEntity(entity);
|
||||
mat4 transform = scale(mat4(1), vec3(1, 1, 1)) * translate(mat4(1), vec3(-1, -1, -1));
|
||||
|
||||
// Add graphics component
|
||||
shared_ptr<GraphicsComponent> graphicsComponent = make_shared<GraphicsComponent>(transform,
|
||||
entity,
|
||||
getShared(mGraphicsSystem),
|
||||
mRenderLayer);
|
||||
entity->addComponent(graphicsComponent);
|
||||
|
||||
// Add the ModelRenderable of a ball
|
||||
ModelRenderableFactory* modelFactory = new ModelRenderableFactory(mAssetSystem);
|
||||
shared_ptr<ModelRenderable> modelRenderable = modelFactory->createModel("plane-1x1.bcosm",
|
||||
filePath,
|
||||
name+"_model");
|
||||
delete modelFactory;
|
||||
graphicsComponent->addRenderable(modelRenderable);
|
||||
|
||||
// Return instance
|
||||
return entity;
|
||||
}
|
||||
|
||||
} // namespace JamSpook
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* SpriteFactory.h
|
||||
*
|
||||
* Created on: Aug 24, 2020
|
||||
* Author: fredrick
|
||||
*/
|
||||
|
||||
#ifndef SPRITEFACTORY_H_
|
||||
#define SPRITEFACTORY_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
#include <ecos/utility/Memory.h>
|
||||
#include <ecos/core/IDCache.h>
|
||||
#include <ecos/core/Log.h>
|
||||
#include <ecos/core/BroadcastObservable.h>
|
||||
#include <ecos/core/Message.h>
|
||||
#include <ecos/core/Entity.h>
|
||||
#include <ecos/core/SceneGraph.h>
|
||||
#include <ecos/core/ICCResponseComponent.h>
|
||||
#include <ecos/asset/AssetSystem.h>
|
||||
#include <ecos/asset/DataManagementMode.h>
|
||||
#include <ecos/physics/PhysicsSystem.h>
|
||||
#include <ecos/physics/PhysicsComponent.h>
|
||||
#include <ecos/physics/ColliderFactory.h>
|
||||
#include <ecos/physics/Collider.h>
|
||||
#include <ecos/graphics/GraphicsSystem.h>
|
||||
#include <ecos/graphics/GraphicsComponent.h>
|
||||
#include <ecos/graphics/RenderLayer.h>
|
||||
#include <ecos/graphics/TextureFactory.h>
|
||||
#include <ecos/graphics/Texture.h>
|
||||
#include <ecos/graphics/assets/ShaderAsset.h>
|
||||
#include <ecos/graphics/ShaderProgram.h>
|
||||
#include <ecos/graphics/ShaderProgramFactory.h>
|
||||
#include <ecos/graphics/Material.h>
|
||||
#include <ecos/graphics/MaterialFactory.h>
|
||||
#include <ecos/graphics/Mesh.h>
|
||||
#include <ecos/graphics/MeshFactory.h>
|
||||
#include <ecos/graphics/ModelRenderable.h>
|
||||
#include <ecos/graphics/lighting/LightSource.h>
|
||||
#include <ecos/graphics/lighting/LightSourceFactory.h>
|
||||
#include <ecos/graphics/ModelRenderableFactory.h>
|
||||
#include <ecos/graphics/ShaderType.h>
|
||||
|
||||
namespace JamSpook {
|
||||
|
||||
using std::string;
|
||||
using std::shared_ptr;
|
||||
using std::make_shared;
|
||||
using std::weak_ptr;
|
||||
using std::dynamic_pointer_cast;
|
||||
using std::function;
|
||||
using std::bind;
|
||||
using std::vector;
|
||||
|
||||
using glm::vec3;
|
||||
using glm::mat4;
|
||||
using glm::quat;
|
||||
using glm::translate;
|
||||
|
||||
using ecos::utility::getShared;
|
||||
using ecos::core::IDCache;
|
||||
using ecos::core::logging::Log;
|
||||
using ecos::core::logging::LogLevel;
|
||||
using ecos::core::BroadcastObservable;
|
||||
using ecos::core::Message;
|
||||
using ecos::core::Entity;
|
||||
using ecos::core::SceneGraph;
|
||||
using ecos::core::ICCResponseComponent;
|
||||
using ecos::asset::AssetSystem;
|
||||
using ecos::asset::DataManagementMode;
|
||||
using ecos::graphics::GraphicsSystem;
|
||||
using ecos::graphics::GraphicsComponent;
|
||||
using ecos::graphics::RenderLayer;
|
||||
using ecos::graphics::TextureFactory;
|
||||
using ecos::graphics::Texture;
|
||||
using ecos::graphics::ShaderType;
|
||||
using ecos::graphics::ShaderAsset;
|
||||
using ecos::graphics::ShaderProgram;
|
||||
using ecos::graphics::ShaderProgramFactory;
|
||||
using ecos::graphics::Material;
|
||||
using ecos::graphics::MaterialFactory;
|
||||
using ecos::graphics::Mesh;
|
||||
using ecos::graphics::MeshFactory;
|
||||
using ecos::graphics::ModelRenderableFactory;
|
||||
using ecos::graphics::ModelRenderable;
|
||||
using ecos::graphics::lighting::LightSource;
|
||||
using ecos::graphics::lighting::LightSourceFactory;
|
||||
|
||||
///
|
||||
class SpriteFactory
|
||||
{
|
||||
private:
|
||||
weak_ptr<AssetSystem> mAssetSystem;
|
||||
weak_ptr<GraphicsSystem> mGraphicsSystem;
|
||||
weak_ptr<RenderLayer> mRenderLayer;
|
||||
|
||||
public:
|
||||
SpriteFactory(weak_ptr<AssetSystem> assetSystem,
|
||||
weak_ptr<GraphicsSystem> graphicsSystem,
|
||||
weak_ptr<RenderLayer> renderLayer);
|
||||
virtual ~SpriteFactory();
|
||||
|
||||
shared_ptr<Entity> createPlane(const string name,
|
||||
const string filePath,
|
||||
const vec3 position,
|
||||
const vec3 rotation,
|
||||
const vec3 scaleFactor);
|
||||
|
||||
shared_ptr<Entity> createBackground(const string name,
|
||||
const string filePath);
|
||||
};
|
||||
|
||||
} // namespace JamSpook
|
||||
|
||||
#endif // SPRITEFACTORY_H_
|
Loading…
Reference in New Issue