moved model class into separate file
This commit is contained in:
parent
b66244d943
commit
67a7f9c3f2
5
Makefile
5
Makefile
|
@ -8,6 +8,8 @@
|
|||
# //_________________________\\ `----------------------------------------------------------------'
|
||||
#
|
||||
# This Makefile should build a Linux binary from `make linux`. Other platform targets have not been tested yet.
|
||||
# It requires the [SPACE BOX] framework to be located in the paths that can be configured in the code block
|
||||
# below.
|
||||
|
||||
#######################
|
||||
# Location parameters #
|
||||
|
@ -73,7 +75,8 @@ $(SB_SRC_DIR)GLObject.o : $(addprefix $(SB_SRC_DIR),Log.hpp)
|
|||
$(SB_SRC_DIR)Texture.o : $(addprefix $(SB_SRC_DIR),GLObject.hpp filesystem.hpp Log.hpp)
|
||||
$(SB_SRC_DIR)VBO.o : $(addprefix $(SB_SRC_DIR),Log.hpp GLObject.hpp Attributes.hpp extension.hpp)
|
||||
$(SB_SRC_DIR)Attributes.o : $(addprefix $(SB_SRC_DIR),Log.hpp extension.hpp)
|
||||
$(SRC_DIR)Item.o : $(addprefix $(SB_SRC_DIR),extension.hpp Node.hpp Texture.hpp Log.hpp)
|
||||
$(SRC_DIR)Model.o : $(addprefix $(SB_SRC_DIR),extension.hpp Attributes.hpp Texture.hpp)
|
||||
$(SRC_DIR)Item.o : $(addprefix $(SB_SRC_DIR),extension.hpp Node.hpp Texture.hpp Log.hpp) $(SRC_DIR)Model.hpp
|
||||
$(SRC_DIR)Pudding.o : $(SRC_H_FILES) $(SB_H_FILES)
|
||||
%.o : %.cpp %.hpp
|
||||
$(CPPC) $(CPP_FLAGS) $< -c -o $@
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "Node.hpp"
|
||||
#include "Texture.hpp"
|
||||
#include "Log.hpp"
|
||||
#include "Model.hpp"
|
||||
|
||||
class Item : public Node
|
||||
{
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
/* _______________ ,----------------------------------------------------------------.
|
||||
//`````````````\\ \ \
|
||||
//~~~~~~~~~~~~~~~\\ \ by @ohsqueezy & @sleepin \
|
||||
//=================\\ \ [ohsqueezy.itch.io] [sleepin.itch.io] \
|
||||
// \\ \ \
|
||||
// \\ \ code released under the zlib license [git.nugget.fun/pudding] \
|
||||
// ☆ GUNKISS ☆ \\ \ \
|
||||
//_________________________\\ `---------------------------------------------------------------*/
|
||||
|
||||
#include "Model.hpp"
|
||||
|
||||
/* Default constructor for Model */
|
||||
Model::Model() {};
|
||||
|
||||
/* Construct a Model, adding Attributes each already wrapped in a shared pointer. The attributes should
|
||||
* be passed as a map with each key being a name and each value being a shared pointer to attributes. */
|
||||
Model::Model(const std::map<std::string, std::shared_ptr<sb::Attributes>>& attributes_pack)
|
||||
{
|
||||
for (auto attributes : attributes_pack)
|
||||
{
|
||||
this->attributes(attributes.first, attributes.second);
|
||||
}
|
||||
}
|
||||
|
||||
/* Construct a Model, adding Attributes, which will each be wrapped in a shared pointer and stored in the
|
||||
* created object. The attributes should be passed as a map with each key being a name and each value being
|
||||
* an attributes object. */
|
||||
Model::Model(const std::map<std::string, sb::Attributes>& attributes_pack)
|
||||
{
|
||||
for (auto attributes : attributes_pack)
|
||||
{
|
||||
this->attributes(attributes.first, attributes.second);
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the entire map of attributes, each wrapped in its shared pointer held by this object.
|
||||
* Can be used to iterate through the attributes. */
|
||||
std::map<std::string, std::shared_ptr<sb::Attributes>> Model::attributes()
|
||||
{
|
||||
return model_attributes;
|
||||
}
|
||||
|
||||
/* Get the attributes under name, wrapped in the shared pointer held by this object. Use
|
||||
* this to share ownership of the attributes or to gain access to the public interface
|
||||
* of the attributes. */
|
||||
std::shared_ptr<sb::Attributes> Model::attributes(const std::string& name)
|
||||
{
|
||||
return model_attributes.at(name);
|
||||
}
|
||||
|
||||
/* Assign name to attributes, copy and wrap in a shared pointer. The model can share
|
||||
* ownership of the created attribute memory with callers that request it. */
|
||||
void Model::attributes(const std::string& name, const sb::Attributes& attributes)
|
||||
{
|
||||
this->attributes(name, std::make_shared<sb::Attributes>(attributes));
|
||||
}
|
||||
|
||||
/* Assign name to attributes and share ownership. */
|
||||
void Model::attributes(const std::string& name, const std::shared_ptr<sb::Attributes>& attributes)
|
||||
{
|
||||
model_attributes[name] = attributes;
|
||||
}
|
||||
|
||||
/* Enable all attributes. */
|
||||
void Model::enable()
|
||||
{
|
||||
for (const auto& attributes : this->attributes())
|
||||
{
|
||||
attributes.second->enable();
|
||||
}
|
||||
}
|
||||
|
||||
/* Disable all attributes. */
|
||||
void Model::disable()
|
||||
{
|
||||
for (const auto& attributes : this->attributes())
|
||||
{
|
||||
attributes.second->disable();
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the texture at name. This can be used to read the texture memory, share ownership of it, or
|
||||
* anything else a Texture object can be used for with direct calls to GL functions. */
|
||||
sb::Texture Model::texture(const std::string& name)
|
||||
{
|
||||
return model_texture.at(name);
|
||||
}
|
||||
|
||||
/* Assign name to texture and share ownership. */
|
||||
void Model::texture(const std::string& name, const sb::Texture& texture)
|
||||
{
|
||||
model_texture[name] = texture;
|
||||
}
|
||||
|
||||
/* Set the transformation matrix. */
|
||||
void Model::transformation(const glm::mat4& transformation)
|
||||
{
|
||||
model_transformation = transformation;
|
||||
}
|
||||
|
||||
/* Return the size in bytes of the sum of the attributes. */
|
||||
std::size_t Model::size()
|
||||
{
|
||||
std::size_t sum = 0;
|
||||
for (const auto& attributes : this->attributes())
|
||||
{
|
||||
sum += attributes.second->size();
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
/* Return the transformation matrix. */
|
||||
Model::operator glm::mat4() const
|
||||
{
|
||||
return model_transformation;
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
/* _______________ ,----------------------------------------------------------------.
|
||||
//`````````````\\ \ \
|
||||
//~~~~~~~~~~~~~~~\\ \ by @ohsqueezy & @sleepin \
|
||||
//=================\\ \ [ohsqueezy.itch.io] [sleepin.itch.io] \
|
||||
// \\ \ \
|
||||
// \\ \ code released under the zlib license [git.nugget.fun/pudding] \
|
||||
// ☆ GUNKISS ☆ \\ \ \
|
||||
//_________________________\\ `---------------------------------------------------------------*/
|
||||
|
||||
#ifndef MODEL_H_
|
||||
#define MODEL_H_
|
||||
|
||||
/* GL functions */
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
#include <GL/glew.h>
|
||||
#else
|
||||
#include "glew/glew.h"
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include "glm/glm.hpp"
|
||||
#include "Attributes.hpp"
|
||||
#include "Texture.hpp"
|
||||
|
||||
class Model
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
std::map<std::string, std::shared_ptr<sb::Attributes>> model_attributes;
|
||||
std::map<std::string, sb::Texture> model_texture;
|
||||
glm::mat4 model_transformation = glm::mat4(1);
|
||||
|
||||
public:
|
||||
|
||||
Model();
|
||||
Model(const std::map<std::string, std::shared_ptr<sb::Attributes>>&);
|
||||
Model(const std::map<std::string, sb::Attributes>&);
|
||||
std::map<std::string, std::shared_ptr<sb::Attributes>> attributes();
|
||||
std::shared_ptr<sb::Attributes> attributes(const std::string&);
|
||||
void attributes(const std::string&, const sb::Attributes&);
|
||||
void attributes(const std::string&, const std::shared_ptr<sb::Attributes>&);
|
||||
void enable();
|
||||
void disable();
|
||||
sb::Texture texture(const std::string&);
|
||||
void texture(const std::string&, const sb::Texture&);
|
||||
void transformation(const glm::mat4&);
|
||||
std::size_t size();
|
||||
operator glm::mat4() const;
|
||||
|
||||
};
|
||||
|
||||
class Plane : public Model
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
inline const static std::shared_ptr<sb::Attributes> position = std::make_shared<sb::Attributes>(sb::Attributes{
|
||||
{-1.0f, 1.0f}, {1.0f, 1.0f}, {-1.0f, -1.0f},
|
||||
{1.0f, 1.0f}, {1.0f, -1.0f}, {-1.0f, -1.0f}
|
||||
});
|
||||
inline const static std::shared_ptr<sb::Attributes> uv = std::make_shared<sb::Attributes>(sb::Attributes{
|
||||
{0.0f, 1.0f}, {1.0f, 1.0f}, {0.0f, 0.0f},
|
||||
{1.0f, 1.0f}, {1.0f, 0.0f}, {0.0f, 0.0f}
|
||||
});
|
||||
|
||||
public:
|
||||
|
||||
Plane() : Model(std::map<std::string, std::shared_ptr<sb::Attributes>>({{"position", position}, {"uv", uv}})) {}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
101
src/Pudding.cpp
101
src/Pudding.cpp
|
@ -852,104 +852,3 @@ void Pudding::update()
|
|||
previous_barcode = current_barcode;
|
||||
}
|
||||
}
|
||||
|
||||
/* Default constructor for Model */
|
||||
Model::Model() {};
|
||||
|
||||
Model::Model(const std::map<std::string, std::shared_ptr<sb::Attributes>>& attributes_pack)
|
||||
{
|
||||
for (auto attributes : attributes_pack)
|
||||
{
|
||||
this->attributes(attributes.first, attributes.second);
|
||||
}
|
||||
}
|
||||
|
||||
Model::Model(const std::map<std::string, sb::Attributes>& attributes_pack)
|
||||
{
|
||||
for (auto attributes : attributes_pack)
|
||||
{
|
||||
this->attributes(attributes.first, attributes.second);
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the entire map of attributes, each wrapped in its shared pointer held by this object.
|
||||
* Can be used to iterate through the attributes. */
|
||||
std::map<std::string, std::shared_ptr<sb::Attributes>> Model::attributes()
|
||||
{
|
||||
return model_attributes;
|
||||
}
|
||||
|
||||
/* Get the attributes under name, wrapped in the shared pointer held by this object. Use
|
||||
* this to share ownership of the attributes or to gain access to the public interface
|
||||
* of the attributes. */
|
||||
std::shared_ptr<sb::Attributes> Model::attributes(const std::string& name)
|
||||
{
|
||||
return model_attributes.at(name);
|
||||
}
|
||||
|
||||
/* Assign name to attributes, copy and wrap in a shared pointer. The model can share
|
||||
* ownership of the created attribute memory with callers that request it. */
|
||||
void Model::attributes(const std::string& name, const sb::Attributes& attributes)
|
||||
{
|
||||
this->attributes(name, std::make_shared<sb::Attributes>(attributes));
|
||||
}
|
||||
|
||||
/* Assign name to attributes and share ownership. */
|
||||
void Model::attributes(const std::string& name, const std::shared_ptr<sb::Attributes>& attributes)
|
||||
{
|
||||
model_attributes[name] = attributes;
|
||||
}
|
||||
|
||||
/* Enable all attributes. */
|
||||
void Model::enable()
|
||||
{
|
||||
for (const auto& attributes : this->attributes())
|
||||
{
|
||||
attributes.second->enable();
|
||||
}
|
||||
}
|
||||
|
||||
/* Disable all attributes. */
|
||||
void Model::disable()
|
||||
{
|
||||
for (const auto& attributes : this->attributes())
|
||||
{
|
||||
attributes.second->disable();
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the texture at name. This can be used to read the texture memory, share ownership of it, or
|
||||
* anything else a Texture object can be used for with direct calls to GL functions. */
|
||||
sb::Texture Model::texture(const std::string& name)
|
||||
{
|
||||
return model_texture.at(name);
|
||||
}
|
||||
|
||||
/* Assign name to texture and share ownership. */
|
||||
void Model::texture(const std::string& name, const sb::Texture& texture)
|
||||
{
|
||||
model_texture[name] = texture;
|
||||
}
|
||||
|
||||
/* Set the transformation matrix. */
|
||||
void Model::transformation(const glm::mat4& transformation)
|
||||
{
|
||||
model_transformation = transformation;
|
||||
}
|
||||
|
||||
/* Return the size in bytes of the sum of the attributes. */
|
||||
std::size_t Model::size()
|
||||
{
|
||||
std::size_t sum = 0;
|
||||
for (const auto& attributes : this->attributes())
|
||||
{
|
||||
sum += attributes.second->size();
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
/* Return the transformation matrix. */
|
||||
Model::operator glm::mat4() const
|
||||
{
|
||||
return model_transformation;
|
||||
}
|
||||
|
|
|
@ -32,61 +32,14 @@
|
|||
#include "Color.hpp"
|
||||
#include "extension.hpp"
|
||||
#include "filesystem.hpp"
|
||||
#include "Item.hpp"
|
||||
#include "Animation.hpp"
|
||||
#include "Texture.hpp"
|
||||
#include "GLObject.hpp"
|
||||
#include "Log.hpp"
|
||||
#include "Attributes.hpp"
|
||||
#include "VBO.hpp"
|
||||
|
||||
class Model
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
std::map<std::string, std::shared_ptr<sb::Attributes>> model_attributes;
|
||||
std::map<std::string, sb::Texture> model_texture;
|
||||
glm::mat4 model_transformation = glm::mat4(1);
|
||||
|
||||
public:
|
||||
|
||||
Model();
|
||||
Model(const std::map<std::string, std::shared_ptr<sb::Attributes>>&);
|
||||
Model(const std::map<std::string, sb::Attributes>&);
|
||||
std::map<std::string, std::shared_ptr<sb::Attributes>> attributes();
|
||||
std::shared_ptr<sb::Attributes> attributes(const std::string&);
|
||||
void attributes(const std::string&, const sb::Attributes&);
|
||||
void attributes(const std::string&, const std::shared_ptr<sb::Attributes>&);
|
||||
void enable();
|
||||
void disable();
|
||||
sb::Texture texture(const std::string&);
|
||||
void texture(const std::string&, const sb::Texture&);
|
||||
void transformation(const glm::mat4&);
|
||||
std::size_t size();
|
||||
operator glm::mat4() const;
|
||||
|
||||
};
|
||||
|
||||
class Plane : public Model
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
inline const static std::shared_ptr<sb::Attributes> position = std::make_shared<sb::Attributes>(sb::Attributes{
|
||||
{-1.0f, 1.0f}, {1.0f, 1.0f}, {-1.0f, -1.0f},
|
||||
{1.0f, 1.0f}, {1.0f, -1.0f}, {-1.0f, -1.0f}
|
||||
});
|
||||
inline const static std::shared_ptr<sb::Attributes> uv = std::make_shared<sb::Attributes>(sb::Attributes{
|
||||
{0.0f, 1.0f}, {1.0f, 1.0f}, {0.0f, 0.0f},
|
||||
{1.0f, 1.0f}, {1.0f, 0.0f}, {0.0f, 0.0f}
|
||||
});
|
||||
|
||||
public:
|
||||
|
||||
Plane() : Model(std::map<std::string, std::shared_ptr<sb::Attributes>>({{"position", position}, {"uv", uv}})) {}
|
||||
|
||||
};
|
||||
#include "Item.hpp"
|
||||
#include "Model.hpp"
|
||||
|
||||
class Pudding : public Game
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue