Cleanup
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
Fullscreen: 0
|
||||
Resolution: 1152 864
|
||||
Debug: 0
|
||||
Debug: 1
|
||||
CameraFOV: 72.5
|
||||
|
10
include/collision.h
Normal file
10
include/collision.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <types/vertex.h>
|
||||
#include <types/entity/entity.h>
|
||||
|
||||
namespace Collision {
|
||||
VertexArray calculateBoundingBox(VertexArray* vArray, const LinearAlgebra::Vector3& angle);
|
||||
VertexArray calculateAxisAlignedBoundingBox(VertexArray vArray);
|
||||
bool insideAABoundingBox(const LinearAlgebra::Vector3& position, const VertexArray& boundingBox);
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
#include <thread>
|
||||
#include "engine/render.h"
|
||||
#include <engine/render.h>
|
||||
|
||||
class App
|
||||
{
|
||||
|
@@ -26,10 +26,9 @@ public:
|
||||
bool fullscreen;
|
||||
bool debug = true;
|
||||
bool useVBO = true;
|
||||
bool drawCollision = true;
|
||||
uint64_t tickCount = 0;
|
||||
uint64_t frameCount = 0;
|
||||
float frameDelta = NULL;
|
||||
float frameDelta = 0;
|
||||
GLenum glError = GL_NO_ERROR;
|
||||
float nearPlane = 0.01f;
|
||||
float farPlane = 100.0f;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include <types/camera.h>
|
||||
#include <types/entity/camera.h>
|
||||
|
||||
namespace Occlusion {
|
||||
bool frustumCull(Camera* camera, Entity* entity);
|
||||
|
@@ -1,9 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <types/entityList.h>
|
||||
#include <types/vertex.h>
|
||||
#include <types/texture.h>
|
||||
#include <types/entity.h>
|
||||
#include <types/entity/entity.h>
|
||||
|
||||
// TODO: Move data to Entity / or rename to DataModelEntry
|
||||
struct ByteArray
|
||||
@@ -39,8 +38,6 @@ public:
|
||||
};
|
||||
|
||||
class World : public DataModel {
|
||||
private:
|
||||
|
||||
public:
|
||||
std::string name;
|
||||
World() : DataModel() {}
|
||||
|
@@ -1,10 +0,0 @@
|
||||
#pragma once
|
||||
#include <types/vertex.h>
|
||||
#include <types/entity.h>
|
||||
|
||||
namespace Collision {
|
||||
VertexArray calculateBoundingBox(VertexArray* vArray, const LinearAlgebra::Vector3& angle);
|
||||
VertexArray calculateAxisAlignedBoundingBox(VertexArray* vArray, const LinearAlgebra::Vector3& angle);
|
||||
VertexArray calculateBoundingBox(Entity *entity, const LinearAlgebra::Vector3 &angle);
|
||||
VertexArray calculateAxisAlignedBoundingBox(Entity *entity, const LinearAlgebra::Vector3 &angle);
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include <types/moby.h>
|
||||
#include <types/renderPlane.h>
|
||||
#include <types/entity/moby.h>
|
||||
#include <types/entity/renderPlane.h>
|
||||
#include <engine/engine.h>
|
||||
#include <GL/glu.h>
|
||||
#include <J3ML/Geometry.h>
|
@@ -7,15 +7,22 @@
|
||||
|
||||
class Entity {
|
||||
private:
|
||||
virtual void loadTexture() {};
|
||||
virtual void loadGeometry() {};
|
||||
GLfloat scale;
|
||||
void loadTexture();
|
||||
void loadGeometry();
|
||||
GLfloat scale = 1.0f;
|
||||
protected:
|
||||
std::string modelPath;
|
||||
std::string texturePath;
|
||||
Entity* parent;
|
||||
std::vector<Entity*> children;
|
||||
public:
|
||||
virtual GLuint getTextureID() {};
|
||||
virtual VertexArray* getGeometry() {};
|
||||
std::string name;
|
||||
|
||||
LinearAlgebra::Vector3 angle = {0,0,0}; //Pitch Yaw Roll, The orientation of the entity in the world,
|
||||
GLuint getTextureID();
|
||||
VertexArray* getGeometry();
|
||||
VertexArray getBoundingBox();
|
||||
VertexArray getAABoundingBox();
|
||||
std::vector<Entity*> GetChildren();
|
||||
virtual void SetParent(Entity* parent);
|
||||
bool IsDescendantOf(Entity* ancestor);
|
||||
@@ -69,7 +76,7 @@ public:
|
||||
|
||||
virtual void pre_render() {}
|
||||
virtual void post_render() {}
|
||||
virtual void render() {}
|
||||
virtual void render();
|
||||
virtual void update(float elapsed) {}
|
||||
virtual void ticc(int tics)
|
||||
{
|
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <types/entity.h>
|
||||
#include <types/entity/entity.h>
|
||||
#include <types/animation/scriptedMove.h>
|
||||
|
||||
//Movable Object.
|
||||
@@ -10,7 +10,6 @@ public:
|
||||
{
|
||||
|
||||
}
|
||||
LinearAlgebra::Vector3 angle = {0,0,0}; //Pitch Yaw Roll, The orientation of the entity in the world,
|
||||
LinearAlgebra::Vector3 velAngle = {0,0,0}; //The angle of an entities velocity.
|
||||
float hVelocity;
|
||||
float vVelocity;
|
@@ -3,12 +3,9 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <types/moby.h>
|
||||
#include <types/entity/moby.h>
|
||||
|
||||
class Player : public Moby {
|
||||
private:
|
||||
void loadTexture() override;
|
||||
void loadGeometry() override;
|
||||
public:
|
||||
bool alive;
|
||||
uint8_t health;
|
||||
@@ -24,8 +21,5 @@ public:
|
||||
|
||||
void update(float elapsed) override;
|
||||
void pre_render() override;
|
||||
void render() override;
|
||||
GLuint getTextureID() override;
|
||||
VertexArray* getGeometry() override;
|
||||
Player();
|
||||
};
|
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <types/entity.h>
|
||||
#include <types/entity/entity.h>
|
||||
|
||||
class RenderPlane : public Entity {
|
||||
private:
|
11
include/types/entity/skybox.h
Normal file
11
include/types/entity/skybox.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <types/vertex.h>
|
||||
#include <types/entity/moby.h>
|
||||
|
||||
class Skybox : public Moby {
|
||||
public:
|
||||
void pre_render() override;
|
||||
Skybox();
|
||||
void render() override;
|
||||
};
|
@@ -1,9 +0,0 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <types/entity.h>
|
||||
|
||||
class EntityList {
|
||||
public:
|
||||
//std::vector<Entity*> list;
|
||||
//bool storeEntity(Entity* entity);
|
||||
};
|
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <types/vertex.h>
|
||||
#include <types/moby.h>
|
||||
|
||||
class Skybox : public Moby {
|
||||
private:
|
||||
void loadTexture() override;
|
||||
void loadGeometry() override;
|
||||
public:
|
||||
GLuint getTextureID() override;
|
||||
VertexArray* getGeometry() override;
|
||||
void pre_render() override;
|
||||
|
||||
void render() override;
|
||||
};
|
14
src/collision.cpp
Normal file
14
src/collision.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <collision.h>
|
||||
#include <J3ML/LinearAlgebra/Vector3.h>
|
||||
|
||||
bool Collision::insideAABoundingBox(const LinearAlgebra::Vector3& position, const VertexArray& boundingBox) {
|
||||
|
||||
LinearAlgebra::Vector3 minimum = {boundingBox.vertices.front().x, boundingBox.vertices.front().y, boundingBox.vertices.front().z};
|
||||
LinearAlgebra::Vector3 maximum = {boundingBox.vertices.back().x, boundingBox.vertices.back().y, boundingBox.vertices.back().z};
|
||||
|
||||
return (
|
||||
position.x >= minimum.x && position.x <= maximum.x &&
|
||||
position.y >= minimum.y && position.y <= maximum.y &&
|
||||
position.z >= minimum.z && position.z <= maximum.z
|
||||
);
|
||||
}
|
@@ -1,37 +1,7 @@
|
||||
#include <engine/occlusion.h>
|
||||
#include <types/entity.h>
|
||||
#include <J3ML/Geometry.h>
|
||||
#include <J3ML/LinearAlgebra/Vector3.h>
|
||||
#include <types/entity/entity.h>
|
||||
|
||||
|
||||
bool Occlusion::frustumCull(Camera* camera, Entity* entity) {
|
||||
Geometry::Frustum frustum = camera->getFrustum();
|
||||
|
||||
//TODO: Transform the BoundingBox to world space.
|
||||
VertexArray AABB;
|
||||
|
||||
//for (auto& vertex : entity->boundingBox.vertices) {
|
||||
//Vertex out{};
|
||||
//out.x = vertex.x;
|
||||
//out.y = vertex.y;
|
||||
//out.z = vertex.z;
|
||||
//AABB.vertices.push_back(out);
|
||||
//}
|
||||
|
||||
|
||||
//Returns "false" if the entity should not be occluded.
|
||||
for (auto& vertex : AABB.vertices) {
|
||||
LinearAlgebra::Vector3 vertVector = { vertex.x, vertex.y, vertex.z };
|
||||
|
||||
if (LinearAlgebra::Vector3::Dot(vertVector - frustum.NearFace.Position, frustum.NearFace.Normal) >= 0.0f &&
|
||||
LinearAlgebra::Vector3::Dot(vertVector - frustum.FarFace.Position, frustum.FarFace.Normal) >= 0.0f &&
|
||||
LinearAlgebra::Vector3::Dot(vertVector - frustum.RightFace.Position, frustum.RightFace.Normal) >= 0.0f &&
|
||||
LinearAlgebra::Vector3::Dot(vertVector - frustum.LeftFace.Position, frustum.LeftFace.Normal) >= 0.0f &&
|
||||
LinearAlgebra::Vector3::Dot(vertVector - frustum.TopFace.Position, frustum.TopFace.Normal) >= 0.0f &&
|
||||
LinearAlgebra::Vector3::Dot(vertVector - frustum.BottomFace.Position, frustum.BottomFace.Normal) >= 0.0f) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
@@ -2,9 +2,9 @@
|
||||
#include <thread>
|
||||
#include <engine/render.h>
|
||||
#include <engine/engine.h>
|
||||
#include <types/camera.h>
|
||||
#include <types/player.h>
|
||||
#include <types/skybox.h>
|
||||
#include <types/entity/camera.h>
|
||||
#include <types/entity/player.h>
|
||||
#include <types/entity/skybox.h>
|
||||
void Render::pre_render() {
|
||||
// NO
|
||||
if (engine->frameCount == 0) {
|
||||
@@ -18,14 +18,15 @@ void Render::pre_render() {
|
||||
camera->sMove.load("assets/scriptedMove/default.smov");
|
||||
camera->SetParent(engine->world);
|
||||
|
||||
auto *skybox = new Skybox();
|
||||
skybox->draw = true;
|
||||
skybox->SetParent(engine->world);
|
||||
auto *player = new Player();
|
||||
player->angle = {0, 0, 0};
|
||||
player->SetPos({0,-2,0});
|
||||
player->draw = true;
|
||||
player->SetParent(engine->world);
|
||||
auto *skybox = new Skybox();
|
||||
skybox->draw = true;
|
||||
skybox->angle = {0,0,0};
|
||||
skybox->SetParent(engine->world);
|
||||
}
|
||||
//std::cout << engine->frameCount << std::endl;
|
||||
engine->window->pollEvents();
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include <engine/world.h>
|
||||
#include <types/moby.h>
|
||||
#include <types/entity/moby.h>
|
||||
|
||||
|
||||
int DataModel::getEntityCount() const {
|
||||
return this->children.size();
|
||||
@@ -113,4 +114,4 @@ Entity *Entity::GetFamilyTreeRoot() const {
|
||||
if (parent->GetParent() == nullptr)
|
||||
return parent;
|
||||
return parent->GetFamilyTreeRoot();
|
||||
}
|
||||
}
|
80
src/types/boundingVolume.cpp
Normal file
80
src/types/boundingVolume.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
#include <collision.h>
|
||||
#include <limits>
|
||||
|
||||
//This is in the local space.
|
||||
VertexArray Collision::calculateBoundingBox(VertexArray* vArray, const LinearAlgebra::Vector3& angle) {
|
||||
|
||||
VertexArray output;
|
||||
float minX = std::numeric_limits<float>::max();
|
||||
float minY = std::numeric_limits<float>::max();
|
||||
float minZ = std::numeric_limits<float>::max();
|
||||
float maxX = -std::numeric_limits<float>::max();
|
||||
float maxY = -std::numeric_limits<float>::max();
|
||||
float maxZ = -std::numeric_limits<float>::max();
|
||||
|
||||
for (const auto& vertex : vArray->vertices) {
|
||||
if (vertex.x < minX)
|
||||
minX = vertex.x;
|
||||
if (vertex.y < minY)
|
||||
minY = vertex.y;
|
||||
if (vertex.z < minZ)
|
||||
minZ = vertex.z;
|
||||
|
||||
if (vertex.x > maxX)
|
||||
maxX = vertex.x;
|
||||
if (vertex.y > maxY)
|
||||
maxY = vertex.y;
|
||||
if (vertex.z > maxZ)
|
||||
maxZ = vertex.z;
|
||||
}
|
||||
|
||||
output.vertices.push_back(Vertex(minX, minY, minZ));
|
||||
output.vertices.push_back(Vertex(maxX, minY, minZ));
|
||||
output.vertices.push_back(Vertex(minX, maxY, minZ));
|
||||
output.vertices.push_back(Vertex(maxX, maxY, minZ));
|
||||
output.vertices.push_back(Vertex(minX, minY, maxZ));
|
||||
output.vertices.push_back(Vertex(maxX, minY, maxZ));
|
||||
output.vertices.push_back(Vertex(minX, maxY, maxZ));
|
||||
output.vertices.push_back(Vertex(maxX, maxY, maxZ));
|
||||
output.rotate(angle);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
VertexArray Collision::calculateAxisAlignedBoundingBox(VertexArray vArray) {
|
||||
|
||||
VertexArray output;
|
||||
float minX = std::numeric_limits<float>::max();
|
||||
float minY = std::numeric_limits<float>::max();
|
||||
float minZ = std::numeric_limits<float>::max();
|
||||
float maxX = -std::numeric_limits<float>::max();
|
||||
float maxY = -std::numeric_limits<float>::max();
|
||||
float maxZ = -std::numeric_limits<float>::max();
|
||||
|
||||
for (const auto& vertex : vArray.vertices) {
|
||||
if (vertex.x < minX)
|
||||
minX = vertex.x;
|
||||
if (vertex.y < minY)
|
||||
minY = vertex.y;
|
||||
if (vertex.z < minZ)
|
||||
minZ = vertex.z;
|
||||
|
||||
if (vertex.x > maxX)
|
||||
maxX = vertex.x;
|
||||
if (vertex.y > maxY)
|
||||
maxY = vertex.y;
|
||||
if (vertex.z > maxZ)
|
||||
maxZ = vertex.z;
|
||||
}
|
||||
|
||||
output.vertices.push_back(Vertex(minX, minY, minZ));
|
||||
output.vertices.push_back(Vertex(maxX, minY, minZ));
|
||||
output.vertices.push_back(Vertex(minX, maxY, minZ));
|
||||
output.vertices.push_back(Vertex(maxX, maxY, minZ));
|
||||
output.vertices.push_back(Vertex(minX, minY, maxZ));
|
||||
output.vertices.push_back(Vertex(maxX, minY, maxZ));
|
||||
output.vertices.push_back(Vertex(minX, maxY, maxZ));
|
||||
output.vertices.push_back(Vertex(maxX, maxY, maxZ));
|
||||
|
||||
return output;
|
||||
}
|
@@ -1,162 +0,0 @@
|
||||
#include <types/collision/collision.h>
|
||||
#include <limits>
|
||||
|
||||
//This is in the local space.
|
||||
VertexArray Collision::calculateBoundingBox(VertexArray* vArray, const LinearAlgebra::Vector3& angle) {
|
||||
VertexArray output;
|
||||
float minX = std::numeric_limits<float>::max();
|
||||
float minY = std::numeric_limits<float>::max();
|
||||
float minZ = std::numeric_limits<float>::max();
|
||||
float maxX = -std::numeric_limits<float>::max();
|
||||
float maxY = -std::numeric_limits<float>::max();
|
||||
float maxZ = -std::numeric_limits<float>::max();
|
||||
|
||||
for (const auto& vertex : vArray->vertices) {
|
||||
if (vertex.x < minX)
|
||||
minX = vertex.x;
|
||||
if (vertex.y < minY)
|
||||
minY = vertex.y;
|
||||
if (vertex.z < minZ)
|
||||
minZ = vertex.z;
|
||||
|
||||
if (vertex.x > maxX)
|
||||
maxX = vertex.x;
|
||||
if (vertex.y > maxY)
|
||||
maxY = vertex.y;
|
||||
if (vertex.z > maxZ)
|
||||
maxZ = vertex.z;
|
||||
}
|
||||
|
||||
output.vertices.push_back(Vertex(minX, minY, minZ));
|
||||
output.vertices.push_back(Vertex(maxX, minY, minZ));
|
||||
output.vertices.push_back(Vertex(minX, maxY, minZ));
|
||||
output.vertices.push_back(Vertex(maxX, maxY, minZ));
|
||||
output.vertices.push_back(Vertex(minX, minY, maxZ));
|
||||
output.vertices.push_back(Vertex(maxX, minY, maxZ));
|
||||
output.vertices.push_back(Vertex(minX, maxY, maxZ));
|
||||
output.vertices.push_back(Vertex(maxX, maxY, maxZ));
|
||||
output.rotate(angle);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
VertexArray Collision::calculateBoundingBox(Entity* entity, const LinearAlgebra::Vector3& angle) {
|
||||
VertexArray output;
|
||||
float minX = std::numeric_limits<float>::max();
|
||||
float minY = std::numeric_limits<float>::max();
|
||||
float minZ = std::numeric_limits<float>::max();
|
||||
float maxX = -std::numeric_limits<float>::max();
|
||||
float maxY = -std::numeric_limits<float>::max();
|
||||
float maxZ = -std::numeric_limits<float>::max();
|
||||
|
||||
for (const auto& vertex : entity->getGeometry()->vertices) {
|
||||
if (vertex.x < minX)
|
||||
minX = vertex.x;
|
||||
if (vertex.y < minY)
|
||||
minY = vertex.y;
|
||||
if (vertex.z < minZ)
|
||||
minZ = vertex.z;
|
||||
|
||||
if (vertex.x > maxX)
|
||||
maxX = vertex.x;
|
||||
if (vertex.y > maxY)
|
||||
maxY = vertex.y;
|
||||
if (vertex.z > maxZ)
|
||||
maxZ = vertex.z;
|
||||
}
|
||||
|
||||
output.vertices.push_back(Vertex(minX, minY, minZ));
|
||||
output.vertices.push_back(Vertex(maxX, minY, minZ));
|
||||
output.vertices.push_back(Vertex(minX, maxY, minZ));
|
||||
output.vertices.push_back(Vertex(maxX, maxY, minZ));
|
||||
output.vertices.push_back(Vertex(minX, minY, maxZ));
|
||||
output.vertices.push_back(Vertex(maxX, minY, maxZ));
|
||||
output.vertices.push_back(Vertex(minX, maxY, maxZ));
|
||||
output.vertices.push_back(Vertex(maxX, maxY, maxZ));
|
||||
output.rotate(angle);
|
||||
for (auto & vertex : output.vertices) {
|
||||
vertex.x *= entity->getScale();
|
||||
vertex.y *= entity->getScale();
|
||||
vertex.z *= entity->getScale();
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
VertexArray Collision::calculateAxisAlignedBoundingBox(VertexArray* vArray, const LinearAlgebra::Vector3& angle) {
|
||||
VertexArray box = calculateBoundingBox(vArray, angle);
|
||||
|
||||
VertexArray output;
|
||||
float minX = std::numeric_limits<float>::max();
|
||||
float minY = std::numeric_limits<float>::max();
|
||||
float minZ = std::numeric_limits<float>::max();
|
||||
float maxX = -std::numeric_limits<float>::max();
|
||||
float maxY = -std::numeric_limits<float>::max();
|
||||
float maxZ = -std::numeric_limits<float>::max();
|
||||
|
||||
for (const auto& vertex : box.vertices) {
|
||||
if (vertex.x < minX)
|
||||
minX = vertex.x;
|
||||
if (vertex.y < minY)
|
||||
minY = vertex.y;
|
||||
if (vertex.z < minZ)
|
||||
minZ = vertex.z;
|
||||
|
||||
if (vertex.x > maxX)
|
||||
maxX = vertex.x;
|
||||
if (vertex.y > maxY)
|
||||
maxY = vertex.y;
|
||||
if (vertex.z > maxZ)
|
||||
maxZ = vertex.z;
|
||||
}
|
||||
|
||||
output.vertices.push_back(Vertex(minX, minY, minZ));
|
||||
output.vertices.push_back(Vertex(maxX, minY, minZ));
|
||||
output.vertices.push_back(Vertex(minX, maxY, minZ));
|
||||
output.vertices.push_back(Vertex(maxX, maxY, minZ));
|
||||
output.vertices.push_back(Vertex(minX, minY, maxZ));
|
||||
output.vertices.push_back(Vertex(maxX, minY, maxZ));
|
||||
output.vertices.push_back(Vertex(minX, maxY, maxZ));
|
||||
output.vertices.push_back(Vertex(maxX, maxY, maxZ));
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
VertexArray Collision::calculateAxisAlignedBoundingBox(Entity* entity, const LinearAlgebra::Vector3& angle) {
|
||||
VertexArray box = calculateBoundingBox(entity, angle);
|
||||
|
||||
VertexArray output;
|
||||
float minX = std::numeric_limits<float>::max();
|
||||
float minY = std::numeric_limits<float>::max();
|
||||
float minZ = std::numeric_limits<float>::max();
|
||||
float maxX = -std::numeric_limits<float>::max();
|
||||
float maxY = -std::numeric_limits<float>::max();
|
||||
float maxZ = -std::numeric_limits<float>::max();
|
||||
|
||||
for (const auto& vertex : box.vertices) {
|
||||
if (vertex.x < minX)
|
||||
minX = vertex.x;
|
||||
if (vertex.y < minY)
|
||||
minY = vertex.y;
|
||||
if (vertex.z < minZ)
|
||||
minZ = vertex.z;
|
||||
|
||||
if (vertex.x > maxX)
|
||||
maxX = vertex.x;
|
||||
if (vertex.y > maxY)
|
||||
maxY = vertex.y;
|
||||
if (vertex.z > maxZ)
|
||||
maxZ = vertex.z;
|
||||
}
|
||||
|
||||
output.vertices.push_back(Vertex(minX, minY, minZ));
|
||||
output.vertices.push_back(Vertex(maxX, minY, minZ));
|
||||
output.vertices.push_back(Vertex(minX, maxY, minZ));
|
||||
output.vertices.push_back(Vertex(maxX, maxY, minZ));
|
||||
output.vertices.push_back(Vertex(minX, minY, maxZ));
|
||||
output.vertices.push_back(Vertex(maxX, minY, maxZ));
|
||||
output.vertices.push_back(Vertex(minX, maxY, maxZ));
|
||||
output.vertices.push_back(Vertex(maxX, maxY, maxZ));
|
||||
|
||||
return output;
|
||||
}
|
@@ -1,58 +0,0 @@
|
||||
#include <types/entity.h>
|
||||
#include <engine/occlusion.h>
|
||||
#include <types/camera.h>
|
||||
#include <uuid_v4.h>
|
||||
|
||||
//inline LinearAlgebra::Vector3 Entity::GetPos() const
|
||||
//{ return LinearAlgebra::Vector3(coordinates[1]); }
|
||||
|
||||
//void Entity::SetPos(const LinearAlgebra::Vector3& rhs)
|
||||
//{ coordinates[1] = LinearAlgebra::Vector4(rhs.x, rhs.y, rhs.z, 0); }
|
||||
|
||||
//LinearAlgebra::Matrix4x4 Entity::GetMatrix() const
|
||||
//{ return coordinates;}
|
||||
|
||||
void Entity::SetMatrix(const LinearAlgebra::Matrix4x4& rhs)
|
||||
{ coordinates = rhs; }
|
||||
|
||||
bool Entity::occluded() {
|
||||
Camera* camera;
|
||||
for (auto& e : engine->world->GetChildren())
|
||||
if (auto* c = dynamic_cast<Camera*>(e))
|
||||
camera = c;
|
||||
|
||||
if (!Occlusion::frustumCull(camera, this))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
LinearAlgebra::Vector3 Entity::GetPos() const {
|
||||
return position;
|
||||
}
|
||||
|
||||
void Entity::SetPos(const LinearAlgebra::Vector3 &rhs) {
|
||||
position = rhs;
|
||||
}
|
||||
|
||||
Entity::Entity() {
|
||||
position = {0,0,0};
|
||||
ticksAlive = 0;
|
||||
children = std::vector<Entity*> ();
|
||||
parent = nullptr;
|
||||
scale = 1.0f;
|
||||
|
||||
//TODO
|
||||
UUIDv4::UUIDGenerator<std::mt19937_64> uuidGenerator;
|
||||
UUIDv4::UUID id = uuidGenerator.getUUID();
|
||||
uuid = id.bytes();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Entity::setScale(const float &multiplier) {
|
||||
scale = multiplier;
|
||||
}
|
||||
|
||||
GLfloat Entity::getScale() const {
|
||||
return scale;
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
#include <types/camera.h>
|
||||
#include <types/entity/camera.h>
|
||||
#include <engine/occlusion.h>
|
||||
#include <types/player.h>
|
||||
#include <types/entity/player.h>
|
||||
// Even tho CLion reports this as const-qualifiable
|
||||
// It is not in "intent" (obviously the gametick changes gamestate)
|
||||
void Camera::update()
|
173
src/types/entity/entity.cpp
Normal file
173
src/types/entity/entity.cpp
Normal file
@@ -0,0 +1,173 @@
|
||||
#include <types/entity/entity.h>
|
||||
#include <engine/occlusion.h>
|
||||
#include <types/entity/camera.h>
|
||||
#include <collision.h>
|
||||
#include <uuid_v4.h>
|
||||
#include <collision.h>
|
||||
|
||||
//inline LinearAlgebra::Vector3 Entity::GetPos() const
|
||||
//{ return LinearAlgebra::Vector3(coordinates[1]); }
|
||||
|
||||
//void Entity::SetPos(const LinearAlgebra::Vector3& rhs)
|
||||
//{ coordinates[1] = LinearAlgebra::Vector4(rhs.x, rhs.y, rhs.z, 0); }
|
||||
|
||||
//LinearAlgebra::Matrix4x4 Entity::GetMatrix() const
|
||||
//{ return coordinates;}
|
||||
|
||||
void Entity::SetMatrix(const LinearAlgebra::Matrix4x4& rhs)
|
||||
{ coordinates = rhs; }
|
||||
|
||||
bool Entity::occluded() {
|
||||
Camera* camera;
|
||||
for (auto& e : engine->world->GetChildren())
|
||||
if (auto* c = dynamic_cast<Camera*>(e))
|
||||
camera = c;
|
||||
|
||||
if (!Occlusion::frustumCull(camera, this))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
LinearAlgebra::Vector3 Entity::GetPos() const {
|
||||
return position;
|
||||
}
|
||||
|
||||
void Entity::SetPos(const LinearAlgebra::Vector3 &rhs) {
|
||||
position = rhs;
|
||||
}
|
||||
|
||||
Entity::Entity() {
|
||||
position = {0,0,0};
|
||||
ticksAlive = 0;
|
||||
children = std::vector<Entity*> ();
|
||||
parent = nullptr;
|
||||
scale = 1.0f;
|
||||
|
||||
//TODO
|
||||
UUIDv4::UUIDGenerator<std::mt19937_64> uuidGenerator;
|
||||
UUIDv4::UUID id = uuidGenerator.getUUID();
|
||||
uuid = id.bytes();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Entity::setScale(const float &multiplier) {
|
||||
scale = multiplier;
|
||||
}
|
||||
|
||||
GLfloat Entity::getScale() const {
|
||||
return scale;
|
||||
}
|
||||
|
||||
VertexArray Entity::getBoundingBox() {
|
||||
VertexArray vArray = getGeometry()->getBoundingVolume(angle);
|
||||
|
||||
//Scale.
|
||||
for (auto& vertex : vArray.vertices) {
|
||||
vertex.x *= getScale();
|
||||
vertex.y *= getScale();
|
||||
vertex.z *= getScale();
|
||||
}
|
||||
|
||||
//To world space.
|
||||
for (auto& vertex : vArray.vertices) {
|
||||
vertex.x = vertex.x + position.x;
|
||||
vertex.y = vertex.y + position.y;
|
||||
vertex.z = vertex.z + position.z;
|
||||
}
|
||||
return vArray;
|
||||
}
|
||||
|
||||
VertexArray Entity::getAABoundingBox() {
|
||||
VertexArray vArray = Collision::calculateAxisAlignedBoundingBox(getGeometry()->getBoundingVolume(angle));
|
||||
|
||||
//Scale.
|
||||
for (auto& vertex : vArray.vertices) {
|
||||
vertex.x *= getScale();
|
||||
vertex.y *= getScale();
|
||||
vertex.z *= getScale();
|
||||
}
|
||||
|
||||
//To world space.
|
||||
for (auto& vertex : vArray.vertices) {
|
||||
vertex.x = vertex.x + position.x;
|
||||
vertex.y = vertex.y + position.y;
|
||||
vertex.z = vertex.z + position.z;
|
||||
}
|
||||
return vArray;
|
||||
}
|
||||
|
||||
void Entity::loadTexture() {
|
||||
Texture texture;
|
||||
texture.name = name;
|
||||
texture.load(texturePath.c_str());
|
||||
engine->world->textureList.push_back(texture);
|
||||
}
|
||||
|
||||
void Entity::loadGeometry() {
|
||||
VertexArray geometry;
|
||||
geometry.name = name;
|
||||
geometry.load(modelPath);
|
||||
engine->world->geometryList.push_back(geometry);
|
||||
}
|
||||
|
||||
GLuint Entity::getTextureID() {
|
||||
if (engine->world->textureList.empty())
|
||||
loadTexture();
|
||||
for (auto& texture : engine->world->textureList)
|
||||
if (texture.name == name)
|
||||
return texture.id;
|
||||
Entity::loadTexture();
|
||||
return getTextureID();
|
||||
}
|
||||
|
||||
VertexArray* Entity::getGeometry() {
|
||||
if (engine->world->geometryList.empty())
|
||||
loadGeometry();
|
||||
for (auto& vArray : engine->world->geometryList)
|
||||
if (vArray.name == name) {
|
||||
return &vArray;
|
||||
}
|
||||
loadGeometry();
|
||||
return getGeometry();
|
||||
}
|
||||
|
||||
//Default rendering routine.
|
||||
void Entity::render() {
|
||||
bool cameraInside = false;
|
||||
|
||||
//Eventually use a more accurate collider for this.
|
||||
Camera* camera;
|
||||
for (auto& e : engine->world->GetChildren())
|
||||
if (auto* c = dynamic_cast<Camera*>(e))
|
||||
camera = c;
|
||||
if(Collision::insideAABoundingBox(camera->position, getAABoundingBox()))
|
||||
cameraInside = true;
|
||||
|
||||
glPushMatrix();
|
||||
if (cameraInside)
|
||||
glCullFace(GL_FRONT);
|
||||
glTranslatef(position.x ,position.y,position.z);
|
||||
glRotatef(angle.x,1.0f, 0.0f, 0.0f);
|
||||
glRotatef(angle.y,0.0f, 1.0f, 0.0f);
|
||||
glRotatef(angle.z,0.0f, 0.0f, 1.0f);
|
||||
glBindTexture(GL_TEXTURE_2D, getTextureID());
|
||||
if (getScale() != 1.0f)
|
||||
glScalef(getScale(),getScale(),getScale());
|
||||
getGeometry()->draw();
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
if (cameraInside)
|
||||
glCullFace(GL_BACK);
|
||||
glPopMatrix();
|
||||
|
||||
if (engine->debug) {
|
||||
glPushMatrix();
|
||||
glColor3f(1, 0, 0);
|
||||
glTranslatef(0, 0, 0);
|
||||
getBoundingBox().draw();
|
||||
getAABoundingBox().draw();
|
||||
glColor3f(0, 0, 0);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
#include <types/moby.h>
|
||||
#include <types/entity/moby.h>
|
||||
|
||||
void Moby::hMove(LinearAlgebra::Vector3 a, float vel) {
|
||||
position.z -= (vel*engine->frameDelta) * a.x;
|
33
src/types/entity/player.cpp
Normal file
33
src/types/entity/player.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <types/entity/player.h>
|
||||
#include <collision.h>
|
||||
void Player::pre_render() {
|
||||
hVelocity = 0;
|
||||
velAngle = angle;
|
||||
//hMove(LinearAlgebra::Vector3::Direction({0, velAngle.y, 0}), hVelocity);
|
||||
//vMove(vVelocity);
|
||||
//this->angle.x -= 96*engine->frameDelta;
|
||||
this->angle.z -= 96*engine->frameDelta;
|
||||
this->angle.y -= 96*engine->frameDelta;
|
||||
}
|
||||
void render();
|
||||
LinearAlgebra::Vector3 Player::cameraPoint(float distance) {
|
||||
LinearAlgebra::Vector3 behindPosition = this->position;
|
||||
LinearAlgebra::Vector3 reverseDirection = this->bAngle();
|
||||
behindPosition.x += reverseDirection.x * distance;
|
||||
behindPosition.y += reverseDirection.y * distance;
|
||||
behindPosition.z -= reverseDirection.z * distance;
|
||||
|
||||
return behindPosition;
|
||||
}
|
||||
|
||||
void Player::update(float elapsed) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
Player::Player() {
|
||||
name = "player";
|
||||
modelPath = "assets/models/cube.obj";
|
||||
texturePath = "assets/textures/cube.png";
|
||||
setScale(1.0f);
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
#include <types/renderPlane.h>
|
||||
#include <types/entity/renderPlane.h>
|
||||
|
||||
VertexArray RenderPlane::getGeometry() const{
|
||||
return geometry;
|
30
src/types/entity/skybox.cpp
Normal file
30
src/types/entity/skybox.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <types/entity/skybox.h>
|
||||
#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();
|
||||
}
|
||||
|
||||
void Skybox::render() {
|
||||
glColor3f(0.75,0.75,0.75);
|
||||
glPushMatrix();
|
||||
glTranslatef(position.x ,position.y, position.z);
|
||||
glBindTexture(GL_TEXTURE_2D, getTextureID());
|
||||
glCullFace(GL_FRONT);
|
||||
glScalef(getScale(), getScale(), getScale());
|
||||
getGeometry()->draw();
|
||||
glCullFace(GL_BACK);
|
||||
glBindTexture(GL_TEXTURE_2D,0);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
Skybox::Skybox() {
|
||||
name = "skybox";
|
||||
modelPath = engine->workingDir + "/assets/models/sphere_vlo.obj";
|
||||
texturePath = engine->workingDir + "/assets/textures/skybox.png";
|
||||
setScale(engine->farPlane);
|
||||
}
|
@@ -1,9 +0,0 @@
|
||||
#include <types/entityList.h>
|
||||
|
||||
/*bool EntityList::storeEntity(Entity *entity) {
|
||||
if (std::ranges::find(list, entity) != list.end()) {
|
||||
return false;
|
||||
}
|
||||
list.push_back(entity);
|
||||
return true;
|
||||
}*/
|
@@ -1,89 +0,0 @@
|
||||
#include <types/player.h>
|
||||
#include <types/collision/collision.h>
|
||||
void Player::pre_render() {
|
||||
hVelocity = 2;
|
||||
velAngle = angle;
|
||||
//hMove(LinearAlgebra::Vector3::Direction({0, velAngle.y, 0}), hVelocity);
|
||||
//vMove(vVelocity);
|
||||
//this->angle.x -= 96*engine->frameDelta;
|
||||
this->angle.z -= 96*engine->frameDelta;
|
||||
this->angle.y -= 96*engine->frameDelta;
|
||||
}
|
||||
|
||||
void Player::render() {
|
||||
glColor3f(0.75,0.75,0.75);
|
||||
glPushMatrix();
|
||||
glTranslatef(position.x ,position.y,position.z);
|
||||
glRotatef(angle.x,1.0f, 0.0f, 0.0f);
|
||||
glRotatef(angle.y,0.0f, 1.0f, 0.0f);
|
||||
glRotatef(angle.z,0.0f, 0.0f, 1.0f);
|
||||
glBindTexture(GL_TEXTURE_2D, getTextureID());
|
||||
if (getScale() != 1.0f)
|
||||
glScalef(getScale(),getScale(),getScale());
|
||||
getGeometry()->draw();
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
if (engine->drawCollision) {
|
||||
glPopMatrix();
|
||||
glPushMatrix();
|
||||
glColor3f(1, 0, 0);
|
||||
glTranslatef(position.x, position.y, position.z);
|
||||
getGeometry()->getBoundingVolume(angle).draw();
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
LinearAlgebra::Vector3 Player::cameraPoint(float distance) {
|
||||
LinearAlgebra::Vector3 behindPosition = this->position;
|
||||
LinearAlgebra::Vector3 reverseDirection = this->bAngle();
|
||||
behindPosition.x += reverseDirection.x * distance;
|
||||
behindPosition.y += reverseDirection.y * distance;
|
||||
behindPosition.z -= reverseDirection.z * distance;
|
||||
|
||||
return behindPosition;
|
||||
}
|
||||
|
||||
void Player::update(float elapsed) {
|
||||
|
||||
}
|
||||
|
||||
GLuint Player::getTextureID() {
|
||||
if (engine->world->textureList.empty())
|
||||
loadTexture();
|
||||
for (auto& texture : engine->world->textureList)
|
||||
if (texture.name == "player")
|
||||
return texture.id;
|
||||
loadTexture();
|
||||
return getTextureID();
|
||||
}
|
||||
|
||||
void Player::loadTexture() {
|
||||
Texture texture;
|
||||
texture.name = "player";
|
||||
std::string path = engine->workingDir + "/assets/textures/cube.png";
|
||||
texture.load(path.c_str());
|
||||
engine->world->textureList.push_back(texture);
|
||||
}
|
||||
|
||||
VertexArray *Player::getGeometry() {
|
||||
if (engine->world->geometryList.empty())
|
||||
loadGeometry();
|
||||
for (auto& vArray : engine->world->geometryList)
|
||||
if (vArray.name == "player")
|
||||
return &vArray;
|
||||
loadGeometry();
|
||||
return getGeometry();
|
||||
}
|
||||
|
||||
void Player::loadGeometry() {
|
||||
VertexArray geometry;
|
||||
geometry.name = "player";
|
||||
std::string path = engine->workingDir + "/assets/models/sphere_ridiculous.obj";
|
||||
geometry.load(path);
|
||||
engine->world->geometryList.push_back(geometry);
|
||||
}
|
||||
|
||||
Player::Player() {
|
||||
|
||||
}
|
@@ -1,61 +0,0 @@
|
||||
#include <types/skybox.h>
|
||||
#include <engine/engine.h>
|
||||
#include <types/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();
|
||||
}
|
||||
|
||||
void Skybox::render() {
|
||||
glColor3f(0.75,0.75,0.75);
|
||||
glPushMatrix();
|
||||
glTranslatef(position.x ,position.y, position.z);
|
||||
glBindTexture(GL_TEXTURE_2D, getTextureID());
|
||||
glCullFace(GL_FRONT);
|
||||
if (getScale() != 1.0f)
|
||||
glScalef(getScale(),getScale(),getScale());
|
||||
getGeometry()->draw();
|
||||
glCullFace(GL_BACK);
|
||||
glBindTexture(GL_TEXTURE_2D,0);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
GLuint Skybox::getTextureID() {
|
||||
if (engine->world->textureList.empty())
|
||||
loadTexture();
|
||||
for (auto& texture : engine->world->textureList)
|
||||
if (texture.name == "skybox")
|
||||
return texture.id;
|
||||
loadTexture();
|
||||
return getTextureID();
|
||||
}
|
||||
|
||||
void Skybox::loadTexture() {
|
||||
Texture texture;
|
||||
texture.name = "skybox";
|
||||
std::string path = engine->workingDir + "/assets/textures/skybox.png";
|
||||
texture.load(path.c_str());
|
||||
engine->world->textureList.push_back(texture);
|
||||
setScale(engine->farPlane);
|
||||
}
|
||||
|
||||
VertexArray* Skybox::getGeometry() {
|
||||
if (engine->world->geometryList.empty())
|
||||
loadTexture();
|
||||
for (auto& vArray : engine->world->geometryList)
|
||||
if (vArray.name == "skybox")
|
||||
return &vArray;
|
||||
loadGeometry();
|
||||
return getGeometry();
|
||||
}
|
||||
|
||||
void Skybox::loadGeometry() {
|
||||
VertexArray geometry;
|
||||
geometry.name = "skybox";
|
||||
std::string path = engine->workingDir + "/assets/models/sphere_vlo.obj";
|
||||
geometry.load(path);
|
||||
engine->world->geometryList.push_back(geometry);
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
#include <engine/engine.h>
|
||||
#include <types/vertex.h>
|
||||
#include <types/collision/collision.h>
|
||||
#include <collision.h>
|
||||
#include <cmath>
|
||||
|
||||
void VertexArray::load (const std::string& filename) {
|
||||
|
Reference in New Issue
Block a user