diff --git a/assets/textures/sky-diffuse.png b/assets/textures/sky-diffuse.png new file mode 100644 index 0000000..e300884 Binary files /dev/null and b/assets/textures/sky-diffuse.png differ diff --git a/assets/textures/water-diffuse.png b/assets/textures/water-diffuse.png new file mode 100644 index 0000000..81c284f Binary files /dev/null and b/assets/textures/water-diffuse.png differ diff --git a/src/entities/SpriteFactory.cpp b/src/entities/SpriteFactory.cpp new file mode 100644 index 0000000..4607d78 --- /dev/null +++ b/src/entities/SpriteFactory.cpp @@ -0,0 +1,82 @@ +/* + * SpriteFactory.cpp + * + * Created on: Aug 24, 2020 + * Author: fredrick + */ + +#include "SpriteFactory.h" + +namespace JamSpook { + +SpriteFactory::SpriteFactory(weak_ptr assetSystem, + weak_ptr graphicsSystem, + weak_ptr renderLayer): + mAssetSystem(assetSystem), + mGraphicsSystem(graphicsSystem), + mRenderLayer(renderLayer) +{} + +SpriteFactory::~SpriteFactory() +{} + +shared_ptr SpriteFactory::createPlane(const string name, + const string filePath, + const vec3 position, + const vec3 rotation, + const vec3 scaleFactor) +{ + // Create instance + shared_ptr entity = make_shared(); + entity->setEntityTag(name); + SceneGraph::addEntity(entity); + mat4 transform = scale(mat4(1), scaleFactor) * translate(mat4(1), position); + + // Add graphics component + shared_ptr graphicsComponent = make_shared(transform, + entity, + getShared(mGraphicsSystem), + mRenderLayer); + entity->addComponent(graphicsComponent); + + // Add the ModelRenderable of a ball + ModelRenderableFactory* modelFactory = new ModelRenderableFactory(mAssetSystem); + shared_ptr modelRenderable = modelFactory->createModel("plane-1x1.bcosm", + filePath, + name+"_model"); + delete modelFactory; + graphicsComponent->addRenderable(modelRenderable); + + // Return instance + return entity; +} + +shared_ptr SpriteFactory::createBackground(const string name, + const string filePath) +{ + // Create instance + shared_ptr entity = make_shared(); + 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 = make_shared(transform, + entity, + getShared(mGraphicsSystem), + mRenderLayer); + entity->addComponent(graphicsComponent); + + // Add the ModelRenderable of a ball + ModelRenderableFactory* modelFactory = new ModelRenderableFactory(mAssetSystem); + shared_ptr modelRenderable = modelFactory->createModel("plane-1x1.bcosm", + filePath, + name+"_model"); + delete modelFactory; + graphicsComponent->addRenderable(modelRenderable); + + // Return instance + return entity; +} + +} // namespace JamSpook diff --git a/src/entities/SpriteFactory.h b/src/entities/SpriteFactory.h new file mode 100644 index 0000000..7e73a91 --- /dev/null +++ b/src/entities/SpriteFactory.h @@ -0,0 +1,123 @@ +/* + * SpriteFactory.h + * + * Created on: Aug 24, 2020 + * Author: fredrick + */ + +#ifndef SPRITEFACTORY_H_ +#define SPRITEFACTORY_H_ + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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 mAssetSystem; + weak_ptr mGraphicsSystem; + weak_ptr mRenderLayer; + +public: + SpriteFactory(weak_ptr assetSystem, + weak_ptr graphicsSystem, + weak_ptr renderLayer); + virtual ~SpriteFactory(); + + shared_ptr createPlane(const string name, + const string filePath, + const vec3 position, + const vec3 rotation, + const vec3 scaleFactor); + + shared_ptr createBackground(const string name, + const string filePath); +}; + +} // namespace JamSpook + +#endif // SPRITEFACTORY_H_