Update CMakeLists.txt
This commit is contained in:
@@ -61,7 +61,7 @@ CPMAddPackage(
|
||||
#MIT License.
|
||||
CPMAddPackage(
|
||||
NAME uuid_v4
|
||||
URL https://github.com/RedactedSoftware/uuid_v4/archive/refs/tags/v1.zip
|
||||
URL https://github.com/RedactedSoftware/uuid_v4/archive/refs/tags/v3.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
|
@@ -8,9 +8,14 @@ using J3ML::Geometry::Frustum;
|
||||
using J3ML::Geometry::Sphere;
|
||||
|
||||
namespace Collision {
|
||||
AABB genMinimallyEnclosingAABB(const VertexArray* vA); ///Creates an AABB around a Vertex Array. *SLOW*
|
||||
AABB genMinimallyEnclosingAABB(const VertexArray* vA, const Vector3& rotation); ///Creates an AABB around a Vertex Array using the OBB. *FAST*
|
||||
Sphere genMinimallyEnclosingSphere(const VertexArray* vA); ///Creates a minimally enclosing sphere around a VertexArray using the cached OBB *FAST*
|
||||
OBB genMinimallyEnclosingOBB(const VertexArray* vA, const Vector3& rotation); ///Creates an OBB around a VertexArray. Should ideally only be used when loading. *SLOW*
|
||||
VertexArray getDrawable(const Shape& collider); ///Returns a renderable version of the collider for debug reasons.
|
||||
///Creates an AABB around a Vertex Array. *SLOW*
|
||||
AABB genMinimallyEnclosingAABB(const VertexArray* vA);
|
||||
///Creates an AABB around a Vertex Array using the OBB. *FAST*
|
||||
AABB genMinimallyEnclosingAABB(const VertexArray* vA, const Vector3& rotation);
|
||||
///Creates a minimally enclosing sphere around a VertexArray using the cached OBB *FAST*
|
||||
Sphere genMinimallyEnclosingSphere(const VertexArray* vA);
|
||||
///Creates an OBB around a VertexArray. Should ideally only be used when loading. *SLOW*
|
||||
OBB genMinimallyEnclosingOBB(const VertexArray* vA, const Vector3& rotation);
|
||||
///Returns a renderable version of the collider for debug reasons.
|
||||
VertexArray getDrawable(const Shape& collider);
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ using namespace J3ML;
|
||||
|
||||
using J3ML::LinearAlgebra::Vector3;
|
||||
|
||||
Vector3 calcAngle(Vector3 sP, Vector3 eP) { ///Calculates the angle between two points in 3D space.
|
||||
///Calculates the angle between two points in 3D space.
|
||||
Vector3 calcAngle(Vector3 sP, Vector3 eP) {
|
||||
return {static_cast<float>((-(asinf((eP.y - sP.y) / Vector3::Distance(sP, eP)) * 180.0f / Math::Pi))),static_cast<float>(-(atan2f(eP.x - sP.x,eP.z - sP.z) / Math::Pi * 180.0f)),0};
|
||||
}
|
@@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
#include <typeinfo>
|
||||
|
||||
///Returns true if target is the exact same class type as source.
|
||||
template <typename Source, typename Target>
|
||||
bool instanceOf(Source* source, Target* target) { ///Returns true if target is the exact same class type as source.
|
||||
bool instanceOf(Source* source, Target* target) {
|
||||
return typeid(*source) == typeid(*target);
|
||||
}
|
@@ -9,7 +9,8 @@
|
||||
using J3ML::LinearAlgebra::Vector3;
|
||||
using J3ML::LinearAlgebra::Vector2;
|
||||
|
||||
class Camera; ///Forward declaration of Camera.
|
||||
///Forward declaration of Camera.
|
||||
class Camera;
|
||||
|
||||
// TODO: Move data to Entity / or rename to DataModelEntry
|
||||
struct ByteArray {
|
||||
|
@@ -13,14 +13,19 @@ using J3ML::LinearAlgebra::Vector3;
|
||||
|
||||
class Entity { ///Base entity type.
|
||||
private:
|
||||
virtual void loadTexture(); ///Loads the texture for the entity.
|
||||
void loadGeometry(); ///Loads the geometry for it.
|
||||
GLfloat scale = 1.0f; ///The scale it should be rendered at.
|
||||
///Loads the texture for the entity.
|
||||
virtual void loadTexture();
|
||||
///Loads the geometry for it.
|
||||
void loadGeometry();
|
||||
///The scale it should be rendered at.
|
||||
GLfloat scale = 1.0f;
|
||||
protected:
|
||||
std::string modelPath;
|
||||
std::string texturePath;
|
||||
Entity* parent; ///If the entity has a parent entity, It's here.
|
||||
std::vector<Entity*> children; ///Entity list of child entities.
|
||||
///If the entity has a parent entity, It's here.
|
||||
Entity* parent;
|
||||
///Entity list of child entities.
|
||||
std::vector<Entity*> children;
|
||||
public:
|
||||
std::string name; //Entity name. TODO remove this.
|
||||
bool alive;
|
||||
@@ -41,16 +46,25 @@ public:
|
||||
archive & GetEntityUUIDList();
|
||||
}
|
||||
|
||||
Vector3 angle = {0,0,0}; ///Pitch Yaw Roll, The orientation of the entity in the world,
|
||||
bool collidable = true; ///Whether an entity is solid. Entities are solid by default.
|
||||
///Pitch Yaw Roll, The orientation of the entity in the world,
|
||||
Vector3 angle = {0,0,0};
|
||||
///Whether an entity is solid. Entities are solid by default.
|
||||
bool collidable = true;
|
||||
|
||||
virtual Texture* getTexture(); ///Returns the texture for the entity. Loads it if it's not in the list.
|
||||
virtual VertexArray* getGeometry(); ///Returns the geometry for the entity. Loads it if it's not in the list.
|
||||
AABB getAABB(); ///Returns the AABB for the entity.
|
||||
Sphere getSphere(); ///Returns the minimal enclosing sphere for the entity.
|
||||
OBB getOBB(); ///Returns the OBB of the entity.
|
||||
std::vector<Entity*> GetChildren(); ///Returns the entity list of the entities children.
|
||||
virtual void SetParent(Entity* parent); ///Sets a given entity as this entities parent.
|
||||
///Returns the texture for the entity. Loads it if it's not in the list.
|
||||
virtual Texture* getTexture();
|
||||
///Returns the geometry for the entity. Loads it if it's not in the list.
|
||||
virtual VertexArray* getGeometry();
|
||||
///Returns the AABB for the entity.
|
||||
AABB getAABB();
|
||||
///Returns the minimal enclosing sphere for the entity.
|
||||
Sphere getSphere();
|
||||
///Returns the OBB of the entity.
|
||||
OBB getOBB();
|
||||
///Returns the entity list of the entities children.
|
||||
std::vector<Entity*> GetChildren();
|
||||
///Sets a given entity as this entities parent.
|
||||
virtual void SetParent(Entity* parent);
|
||||
bool IsDescendantOf(Entity* ancestor);
|
||||
bool IsAncestorOf(Entity* descendant);
|
||||
std::vector<Entity*> GetDescendants();
|
||||
@@ -91,13 +105,15 @@ public:
|
||||
void SetPos(const Vector3& rhs);
|
||||
Matrix4x4 GetMatrix() const;
|
||||
void SetMatrix(const Matrix4x4& rhs);
|
||||
void erase(); ///Removes an entity from the list, Checks if the assets are being used by any other entity. Removes them from their lists & deletes. Then deletes the entity.
|
||||
///Removes an entity from the list, Checks if the assets are being used by any other entity. Removes them from their lists & deletes. Then deletes the entity.
|
||||
void erase();
|
||||
bool draw = true;
|
||||
bool occluded();
|
||||
bool isCollidingWith(Entity* entity);
|
||||
virtual void pre_render() {}
|
||||
virtual void post_render() {}
|
||||
virtual void render(); ///The default rendering routine. Works for 99% of cases.
|
||||
///The default rendering routine. Works for 99% of cases.
|
||||
virtual void render();
|
||||
virtual void update(float elapsed) {}
|
||||
virtual void ticc(int tics)
|
||||
{
|
||||
@@ -106,8 +122,8 @@ public:
|
||||
|
||||
Entity();
|
||||
|
||||
Entity(const Entity& rhs) = default; /// Boilerplate: Copy Constructor
|
||||
Entity(Entity&& rhs) = default; /// Boilerplate: Move Constructor
|
||||
Entity(const Entity& rhs) = default; // Boilerplate: Copy Constructor
|
||||
Entity(Entity&& rhs) = default; // Boilerplate: Move Constructor
|
||||
~Entity() = default;
|
||||
};
|
||||
|
||||
|
@@ -2,23 +2,31 @@
|
||||
|
||||
#include <types/entity/entity.h>
|
||||
|
||||
class Moby : public Entity { ///A "Movable Object". Things that will move often are derived from this.
|
||||
///A "Movable Object". Things that will move often are derived from this.
|
||||
class Moby : public Entity {
|
||||
public:
|
||||
Moby(): Entity(), velAngle({0,0,0})
|
||||
{
|
||||
|
||||
}
|
||||
Vector3 velAngle = {0,0,0}; ///The angle of velocity.
|
||||
float hVelocity; ///Horizontal speed.
|
||||
float vVelocity; ///Vertical speed.
|
||||
///The angle of velocity.
|
||||
Vector3 velAngle = {0,0,0};
|
||||
///Horizontal speed.
|
||||
float hVelocity;
|
||||
///Vertical speed.
|
||||
float vVelocity;
|
||||
Vector3 upVector = {0.0f,1.0f,0.0f};
|
||||
virtual void hMove(Vector3 a, float vel);
|
||||
void vMove(float vel);
|
||||
Vector3 simulateHMove(Vector3 a, float speed);
|
||||
Vector3 simulateVMove(Vector3 position, float speed);
|
||||
Vector3 fAngle(); /// forward angle
|
||||
Vector3 bAngle(); /// back angle
|
||||
Vector3 lAngle(); /// left angle
|
||||
Vector3 rAngle(); /// right angle
|
||||
/// forward angle
|
||||
Vector3 fAngle();
|
||||
/// back angle
|
||||
Vector3 bAngle();
|
||||
/// left angle
|
||||
Vector3 lAngle();
|
||||
/// right angle
|
||||
Vector3 rAngle();
|
||||
};
|
||||
|
||||
|
@@ -3,7 +3,8 @@
|
||||
#include <types/vertex.h>
|
||||
#include <types/entity/moby.h>
|
||||
|
||||
class Skybox : public Moby { ///Simple skybox, A sphere with a texture on it where the center of the sphere is always the camera.
|
||||
///Simple skybox, A sphere with a texture on it where the center of the sphere is always the camera.
|
||||
class Skybox : public Moby {
|
||||
public:
|
||||
void pre_render() override;
|
||||
Skybox();
|
||||
|
@@ -7,21 +7,35 @@
|
||||
//Forward declaration of entity.
|
||||
class Entity;
|
||||
|
||||
//Base texture. One texture.
|
||||
class Texture {
|
||||
public:
|
||||
std::vector<Entity*> usedBy; ///Reference counter.
|
||||
GLuint id = 0; ///The id OpenGL uses to keep track of where the texture is in vram.
|
||||
void load(Entity* entity, const std::string& file, bool storeOnTextureList); ///Loads a texture for a given entity type from a file you specify.
|
||||
virtual void erase(); ///removes texture from texture list and deletes it.
|
||||
///Reference counter.
|
||||
std::vector<Entity*> usedBy;
|
||||
///The id OpenGL uses to keep track of where the texture is in vram.
|
||||
GLuint id = 0;
|
||||
///Loads a texture for a given entity type from a file you specify.
|
||||
void load(Entity* entity, const std::string& file, bool storeOnTextureList);
|
||||
///removes texture from texture list and deletes it.
|
||||
virtual void erase();
|
||||
void erase(Texture* texture) const;
|
||||
Texture(Entity* entity, const char *filePath, bool storeOnTextureList); ///Constructor. Calls load.
|
||||
///Constructor. Calls load.
|
||||
Texture(Entity* entity, const char *filePath, bool storeOnTextureList);
|
||||
Texture() = default;
|
||||
};
|
||||
|
||||
///Multi-Texture. One texture in the base slot, 7 in the following slots.
|
||||
class MultiTexture : public Texture {
|
||||
public:
|
||||
void erase() override;
|
||||
std::vector<Texture> multi; ///Every texture other than the base texture.
|
||||
MultiTexture(Entity* entity, const char* pathContainingTextures, bool storeOnTextureList); ///Loads a multi-texture from a given directory. One must be called "default.png"
|
||||
///Every texture other than the base texture.
|
||||
std::vector<Texture> multi;
|
||||
///Loads a multi-texture from a given directory. One must be called "default.png"
|
||||
MultiTexture(Entity* entity, const char* pathContainingTextures, bool storeOnTextureList);
|
||||
//TODO load multi-texture from array of std::string of file names.
|
||||
};
|
||||
|
||||
///A list of textures where the one actually displayed depends on the frame delta.
|
||||
class MotionTexture : public MultiTexture {
|
||||
|
||||
};
|
@@ -16,30 +16,45 @@ using J3ML::LinearAlgebra::Vector3;
|
||||
using J3ML::LinearAlgebra::Vector2;
|
||||
using J3ML::Geometry::OBB;
|
||||
|
||||
typedef Vector3 Vertex; ///A point which makes up a model in 3D space.
|
||||
typedef Vector2 TextureCoordinate; ///Determines how your texture is wrapped around the model.
|
||||
///A point which makes up a model in 3D space.
|
||||
typedef Vector3 Vertex;
|
||||
///Determines how your texture is wrapped around the model.
|
||||
typedef Vector2 TextureCoordinate;
|
||||
|
||||
///Drawable type. Models are stored in these.
|
||||
class VertexArray {
|
||||
private:
|
||||
/* A performance cheat. Most of the other kinds of colliders can be made from the OBB.
|
||||
*It's faster to create an OBB when loading and then apply the rotation of the entity at the time, then create the other collider you want */
|
||||
///A performance cheat. Most of the other kinds of colliders can be made from the OBB.
|
||||
///It's faster to create an OBB when loading and then apply the rotation of the entity at the time, then create the other collider you want.
|
||||
OBB cachedOBB;
|
||||
public:
|
||||
std::vector<Vertex> vertices; ///A list of points in 3d space that make up the model.
|
||||
std::vector<unsigned int> indices; ///A list specifying how to connect the vertices together to make triangular faces.
|
||||
///A list of points in 3d space that make up the model.
|
||||
std::vector<Vertex> vertices;
|
||||
///A list specifying how to connect the vertices together to make triangular faces.
|
||||
std::vector<unsigned int> indices;
|
||||
std::vector<TextureCoordinate> texCoords;
|
||||
std::vector<Entity*> usedBy; ///Reference counter
|
||||
GLuint vbo = 0; ///Id OpenGL uses to keep track of where the vertices are in vram.
|
||||
GLuint ebo = 0; ///Id OpenGL uses to keep track of where the indices are in vram.
|
||||
GLuint tbo = 0; ///Id OpenGL uses to keep track of where the texture coordinates are in vram.
|
||||
///Reference counter
|
||||
std::vector<Entity*> usedBy;
|
||||
///Id OpenGL uses to keep track of where the vertices are in vram.
|
||||
GLuint vbo = 0;
|
||||
///Id OpenGL uses to keep track of where the indices are in vram.
|
||||
GLuint ebo = 0;
|
||||
///Id OpenGL uses to keep track of where the texture coordinates are in vram.
|
||||
GLuint tbo = 0;
|
||||
|
||||
void load(const std::string& filename); ///Loads a model of a given filename.
|
||||
///Loads a model of a given filename.
|
||||
void load(const std::string& filename);
|
||||
[[nodiscard]] OBB getCachedOBB(const Matrix3x3& rotation) const;
|
||||
[[nodiscard]] OBB getCachedOBB(const Vector3& rotation) const; ///Returns the OBB given the rotation of the entity.
|
||||
///Returns the OBB given the rotation of the entity.
|
||||
[[nodiscard]] OBB getCachedOBB(const Vector3& rotation) const;
|
||||
[[nodiscard]] OBB getCachedOBB(const EulerAngle& rotation) const;
|
||||
virtual void draw(); ///Renders the model in the way you'd expect.
|
||||
void drawWireframe(); ///Renders a wireframe of the model with no texture.
|
||||
explicit VertexArray(Entity* entity, const std::string& filename, bool storeOnGeometryList); ///Constructor, calls load.
|
||||
///Renders the model in the way you'd expect.
|
||||
virtual void draw();
|
||||
///Renders a wireframe of the model with no texture.
|
||||
void drawWireframe();
|
||||
///Constructor, calls load.
|
||||
explicit VertexArray(Entity* entity, const std::string& filename, bool storeOnGeometryList);
|
||||
VertexArray() = default;
|
||||
void erase() const; ///Removes Vertex Array from geometry list and deletes it.
|
||||
///Removes Vertex Array from geometry list and deletes it.
|
||||
void erase() const;
|
||||
};
|
||||
|
@@ -2,11 +2,8 @@
|
||||
#include <engine/engine.h>
|
||||
#include <types/entity/camera.h>
|
||||
void Skybox::pre_render() {
|
||||
Camera* camera;
|
||||
for (auto& e : engine->world->GetChildren())
|
||||
if (auto* c = dynamic_cast<Camera*>(e) )
|
||||
camera = c;
|
||||
position = camera->GetPos();
|
||||
if (engine->world->getActiveCamera() != nullptr)
|
||||
position = engine->world->getActiveCamera()->GetPos();
|
||||
}
|
||||
|
||||
void Skybox::render() {
|
||||
|
Reference in New Issue
Block a user