14 Commits

Author SHA1 Message Date
145346fac3 update engine components 2024-08-21 21:07:54 -04:00
22711d1db1 Begin refactor to support 2D & 3D Scenes. 2024-08-19 22:31:40 -04:00
f5ab983176 Cleanup 2024-07-17 13:52:24 -04:00
7f65fee891 More accurate lighting.
Sacrificed one texture unit to make it such that point lights on things that are multi-textured look the same as on regular things.
2024-07-16 20:09:49 -04:00
e550dea76e Update JGL 2024-07-07 20:24:56 -04:00
8ee3cec460 Test 2??? 2024-07-07 00:20:29 -04:00
c2077481c3 2D Text Context!!! 2024-07-06 23:50:30 -04:00
463895a44f 1 2024-07-06 23:10:48 -04:00
4091b1281f merge 2024-07-05 22:48:51 -04:00
37301b1dc4 Merge branch 'main' into testing 2024-07-05 22:48:35 -04:00
5196401dd3 JGL Render Pass 2024-07-05 22:32:42 -04:00
d9928dde76 Initial Windows Support 2024-06-30 20:48:54 -04:00
7c0b91d8cc Update repositories to latest. 2024-06-30 19:43:19 -04:00
c82663fdc2 Update 2024-06-24 13:07:14 -04:00
38 changed files with 629 additions and 533 deletions

View File

@@ -20,7 +20,6 @@ file(GLOB_RECURSE HEADERS "include/*")
file(GLOB_RECURSE SOURCES "src/*")
file(GLOB_RECURSE ASSETS "assets/*")
#Move all libraries to lib after building.
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
@@ -30,7 +29,7 @@ SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
CPMAddPackage(
NAME ReWindow
URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-2.zip
URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-12.zip
)
CPMAddPackage(
@@ -38,30 +37,29 @@ CPMAddPackage(
URL https://git.redacted.cc/josh/Event/archive/Release-6.zip
)
#Temporarily removed due to SystemD requirement.
#CPMAddPackage(
# NAME ReHardwareID
# URL https://git.redacted.cc/Redacted/ReHardwareID/archive/v1.1.zip
# URL https://git.redacted.cc/Redacted/ReHardwareID/archive/Prerelease-1.zip
#)
CPMAddPackage(
NAME J3ML
URL https://git.redacted.cc/josh/j3ml/archive/Release-2.1.zip
URL https://git.redacted.cc/josh/j3ml/archive/Release-3.0.zip
)
CPMAddPackage(
NAME JGL
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-14.zip
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-31.zip
)
CPMAddPackage(
NAME ReTexture
URL https://git.redacted.cc/Redacted/ReTexture/archive/Prerelease-1.zip
URL https://git.redacted.cc/Redacted/ReTexture/archive/Release-1.2.zip
)
CPMAddPackage(
NAME UUID
URL https://git.redacted.cc/Redacted/uuid/archive/v1.zip
URL https://git.redacted.cc/Redacted/uuid/archive/Release-1.zip
)
CPMAddPackage(
@@ -69,22 +67,28 @@ CPMAddPackage(
URL https://git.redacted.cc/Redacted/glad/archive/v2.1ext_mt.zip
)
CPMAddPackage(
NAME archive
URL https://git.redacted.cc/Redacted/archive/archive/v1.0.zip
)
#CPMAddPackage(
# NAME archive
# URL https://git.redacted.cc/Redacted/archive/archive/v1.0.zip
#)
CPMAddPackage(
NAME Collage
URL https://git.redacted.cc/Redacted/Collage/archive/v0.4.zip
URL https://git.redacted.cc/Redacted/Collage/archive/v0.6.zip
)
CPMAddPackage(
NAME jlog
URL https://git.redacted.cc/josh/jlog/archive/Prerelease-8.zip
URL https://git.redacted.cc/josh/jlog/archive/Prerelease-12.zip
)
add_library(Re3D SHARED ${SOURCES})
if (UNIX AND NOT APPLE)
add_library(Re3D SHARED ${SOURCES})
endif()
if (WIN32)
add_library(Re3D STATIC ${SOURCES})
endif()
target_include_directories(Re3D PUBLIC
${PROJECT_SOURCE_DIR}/include
@@ -93,10 +97,9 @@ target_include_directories(Re3D PUBLIC
${ReWindow_SOURCE_DIR}/include
#${ReHardwareID_SOURCE_DIR}/include
${J3ML_SOURCE_DIR}/include
${ReTexture_SOURCE_DIR}/include
${glad_SOURCE_DIR}/include
${UUID_SOURCE_DIR}/include
${archive_SOURCE_DIR}/include
#${archive_SOURCE_DIR}/include
${Collage_SOURCE_DIR}/include
${Event_SOURCE_DIR}/include
)
@@ -104,9 +107,14 @@ target_include_directories(Re3D PUBLIC
# Why god???
set_target_properties(Re3D PROPERTIES LINKER_LANGUAGE CXX)
find_package(OpenGL REQUIRED)
if (UNIX AND NOT APPLE)
find_package(OpenGL REQUIRED)
target_link_libraries(Re3D PUBLIC Event ReWindowLibrary J3ML GL glad Collage JGL jlog)
endif()
target_link_libraries(Re3D PUBLIC Event ReWindowLibrary ReTexture J3ML GL glad Collage JGL archive jlog)
if (WIN32)
target_link_libraries(Re3D PUBLIC Event ReWindowLibrary J3ML glad Collage JGL jlog)
endif()
include(src/demo/RuntimeTest/CMakeLists.txt)

View File

@@ -1,6 +1,6 @@
#pragma once
#include <Redacted3D/types/vertex.h>
#include <J3ML/Geometry.h>
#include <J3ML/Geometry.hpp>
using J3ML::Geometry::AABB;
using J3ML::Geometry::OBB;

View File

@@ -53,6 +53,7 @@ public:
void initGL() const;
void loadConfig();
static void init();
void jglRenderPass();
void preRender();
void render();
static void postRender();

View File

@@ -1,6 +1,7 @@
#pragma once
#include <Redacted3D/types/entity/camera.h>
#include <Redacted3D/types/entity/3D/camera.h>
namespace Occlusion {
//TODO
bool frustumCull(Camera* camera, Entity* entity);
}

View File

@@ -3,8 +3,8 @@
#include <Redacted3D/types/vertex.h>
#include <Redacted3D/types/texture.h>
#include <Redacted3D/types/shader.h>
#include <Redacted3D/types/entity/entity.h>
#include <J3ML/LinearAlgebra/Vector3.h>
#include <Redacted3D/types/entity/baseEntity.h>
#include <J3ML/LinearAlgebra/Vector3.hpp>
using J3ML::LinearAlgebra::Vector3;
using J3ML::LinearAlgebra::Vector2;
@@ -24,21 +24,22 @@ class Serializable {
// A wrapper around a Tree Hierarchy Data Model.
class DataModel : public Entity {
class DataModel : public BaseEntity {
public:
Entity * GetParent() const override {return nullptr;}
[[nodiscard]] BaseEntity* GetParent() const override {return nullptr;}
std::vector<Entity> GetFlatEntityList();
template <class T>
void Serialize(T& archive) {
Entity::SerializeMemberData(archive);
BaseEntity::SerializeMemberData(archive);
archive & GetFlatEntityList();
}
void SetParent(Entity *parent) override {
void SetParent(BaseEntity *parent) override {
throw std::runtime_error("Cannot set parent of Hierarchy Root!");
}
DataModel() : Entity() {}
DataModel() : BaseEntity() {}
[[nodiscard]] int getEntityCount() const;
[[nodiscard]] int getMobyCount() const;
};
@@ -49,7 +50,7 @@ private:
Vector3 globalLightColor = {0, 0, 0};
Vector4 globalFogColor = {0, 0, 0, 0};
Vector2 globalFogRange = {0, 0};
GLenum globalFogMode = NULL; ///There's Linear, GL_EXP, GL_EXP2.
GLenum globalFogMode = 0; ///There's Linear, GL_EXP, GL_EXP2.
GLfloat globalFogDensity = 0.0f;
public:
@@ -68,6 +69,7 @@ public:
[[nodiscard]] GLfloat getGlobalFogDensity() const;
Camera* getActiveCamera();
Vector3 upVector = {0, 1, 0};
std::string name;
std::vector<VertexArray*> geometryList;
std::vector<Texture*> textureList;

View File

@@ -0,0 +1,8 @@
///A moby with skeletal animations.
//TODO
#pragma once
#include <Redacted3D/types/entity/3D/moby.h>
class Actor : public Moby {};

View File

@@ -1,8 +1,8 @@
#pragma once
#include <Redacted3D/types/entity/moby.h>
#include <Redacted3D/types/entity/3D/moby.h>
#include <Redacted3D/engine/engine.h>
#include <glad/glad.h>
#include <J3ML/Geometry.h>
#include <J3ML/Geometry.hpp>
using J3ML::LinearAlgebra::Matrix4x4;
using J3ML::Geometry::Frustum;

View File

@@ -0,0 +1,77 @@
#pragma once
#include <cstdint>
#include <Redacted3D/types/entity/baseEntity.h>
#include <Redacted3D/types/vertex.h>
#include <Redacted3D/types/texture.h>
#include <J3ML/LinearAlgebra/Matrix4x4.hpp>
#include <J3ML/LinearAlgebra/Vector3.hpp>
#include <Redacted3D/engine/collision.h>
//#include <archive.h>
using J3ML::LinearAlgebra::Matrix4x4;
using J3ML::LinearAlgebra::Vector3;
typedef Vector3 Direction;
///Base entity type.
class Entity : public BaseEntity {
private:
///Pitch Yaw Roll, The orientation of the entity in the world,
Vector3 angle = {0,0,0};
///Loads the texture for the entity.
///The scale it should be rendered at.
Vector3 scale = {1.0f, 1.0f, 1.0f};
protected:
///Loads the geometry for it.
void loadGeometry(const std::string& file);
void loadTexture(const std::string& file);
void loadMultiTexture(const std::vector<std::string>& files);
void loadMotionTexture(const std::vector<std::string>& files, u16 frameDelta, bool doAnim = true);
public:
///Whether an entity is solid. Entities are solid by default.
bool collidable = true;
///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();
void setScale(const float& multiplier);
[[nodiscard]] Vector3 getScale() const;
protected:
Matrix4x4 coordinates;
J3ML::LinearAlgebra::Position position; /// X Y Z
public:
u32 ticksAlive; //At 64tps it'd take 776 days to overflow.
[[nodiscard]] Position GetPos() const;
void SetPos(const Position& rhs);
Matrix4x4 GetMatrix() const;
void SetMatrix(const Matrix4x4& rhs);
Direction getAngleDirection();
Vector3 getAngle();
void setAngle(const Vector3& a);
void setAngle(float pitch, float yaw, float roll);
///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 occluded();
bool isCollidingWith(Entity* entity);
///Default rendering routine. Works in 99% of cases.
void render() override;
Entity();
Entity(const Entity& rhs) = default; // Boilerplate: Copy Constructor
Entity(Entity&& rhs) = default; // Boilerplate: Move Constructor
~Entity() = default;
};

View File

@@ -1,6 +1,6 @@
#pragma once
#include <Redacted3D/types/entity/entity.h>
#include <Redacted3D/types/entity/3D/entity.h>
///A "Movable Object". Things that will move often are derived from this.
class Moby : public Entity {
@@ -10,8 +10,7 @@ private:
///Speed.
float velocity;
public:
Vector3 upVector = {0.0f,1.0f,0.0f};
Moby(): Entity(), upVector(0, 1, 0){}
Moby(): Entity(){}
///Move
void move(Direction a, float speed);

View File

@@ -1,7 +1,7 @@
#pragma once
#include <Redacted3D/types/vertex.h>
#include <Redacted3D/types/entity/moby.h>
#include <Redacted3D/types/entity/3D/moby.h>
///Simple skybox, A sphere with a texture on it where the center of the sphere is always the camera.
class Skybox : public Moby {

View File

@@ -0,0 +1,67 @@
#pragma once
#include <vector>
#include <string>
#include <J3ML/J3ML.hpp>
class BaseEntity {
protected:
///If the entity has a parent entity, It's here.
BaseEntity* parent;
///Entity list of child entities.
std::vector<BaseEntity*> children;
public:
u32 ticksAlive;
bool draw = true;
std::string uuid;
std::string name;
bool alive;
virtual std::vector<std::string> GetEntityUUIDList() const { return std::vector<std::string> { "" }; }
BaseEntity() = default;
std::vector<BaseEntity*> GetChildren();
///Sets a given entity as this entities parent.
virtual void SetParent(BaseEntity* parent);
bool IsDescendantOf(BaseEntity* ancestor);
bool IsAncestorOf(BaseEntity* descendant);
std::vector<BaseEntity*> GetDescendants();
std::vector<BaseEntity*> GetAncestors();
[[nodiscard]] virtual BaseEntity* GetParent() const { return parent;}
BaseEntity* FindFirstChild(std::string search_name);
[[nodiscard]] BaseEntity* GetFamilyTreeRoot() const;
BaseEntity* Add(BaseEntity* newChild);
void DescendantAdded(BaseEntity* ent) {}
void DescendantRemoved(BaseEntity* ent) {}
void AncestorAdded(BaseEntity* ent) {}
void AncestorRemoved(BaseEntity* ent) {}
template <class T>
void SerializeMemberData(T& archive){ archive & uuid.c_str() & name.c_str() & alive; }
template <class T>
void Serialize(T& archive) {
SerializeMemberData(archive);
archive & GetEntityUUIDList();
}
// TODO: Constrain to DerivedEntityType
template <typename T>
T* FindFirstChildOfType() const
{
for (auto& child : children) {
T* p = dynamic_cast<T>(child);
if (p != nullptr)
return p;
}
return nullptr;
}
virtual void pre_render() {}
virtual void post_render() {}
virtual void jglRenderPass() {}
///The default rendering routine. Works for 99% of cases.
virtual void render() {}
virtual void update(float elapsed) {}
virtual void ticc(int tics) { ticksAlive++; }
};

View File

@@ -1,136 +0,0 @@
#pragma once
#include <cstdint>
#include <Redacted3D/types/vertex.h>
#include <Redacted3D/types/texture.h>
#include <J3ML/LinearAlgebra/Matrix4x4.h>
#include <J3ML/LinearAlgebra/Vector3.h>
#include <Redacted3D/engine/collision.h>
#include <archive.h>
using J3ML::LinearAlgebra::Matrix4x4;
using J3ML::LinearAlgebra::Vector3;
typedef Vector3 Direction;
///Base entity type.
class Entity {
private:
///Pitch Yaw Roll, The orientation of the entity in the world,
Vector3 angle = {0,0,0};
///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;
///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;
virtual std::vector<std::string> GetEntityUUIDList() const {}
template <class T>
void SerializeMemberData(T& archive)
{
archive & uuid.c_str() & name.c_str() & alive;
}
template <class T>
void Serialize(T& archive)
{
SerializeMemberData(archive);
archive & GetEntityUUIDList();
}
///Whether an entity is solid. Entities are solid by default.
bool collidable = true;
///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();
std::vector<Entity*> GetAncestors();
virtual Entity* GetParent() const { return parent;}
Entity* FindFirstChild(std::string search_name);
[[nodiscard]] Entity* GetFamilyTreeRoot() const;
Entity *Add(Entity *newChild);
void setScale(const float& multiplier);
[[nodiscard]] GLfloat getScale() const;
// TODO: Constrain to DerivedEntityType
template <typename T>
T* FindFirstChildOfType() const
{
for (auto& child : children) {
T* p = dynamic_cast<T>(child);
if (p != nullptr)
return p;
}
return nullptr;
}
void DescendantAdded(Entity* ent) {}
void DescendantRemoved(Entity* ent) {}
void AncestorAdded(Entity* ent) {}
void AncestorRemoved(Entity* ent) {}
protected:
Matrix4x4 coordinates;
J3ML::LinearAlgebra::Position position; /// X Y Z
public:
std::string uuid;
u32 ticksAlive; //At 64tps it'd take 776 days to overflow.
[[nodiscard]] Position GetPos() const;
void SetPos(const Position& rhs);
Matrix4x4 GetMatrix() const;
void SetMatrix(const Matrix4x4& rhs);
Direction getAngleDirection();
Vector3 getAngle();
void setAngle(const Vector3& a);
void setAngle(float pitch, float yaw, float roll);
///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() {}
///The default rendering routine. Works for 99% of cases.
virtual void render();
virtual void update(float elapsed) {}
virtual void ticc(int tics)
{
ticksAlive++;
}
Entity();
Entity(const Entity& rhs) = default; // Boilerplate: Copy Constructor
Entity(Entity&& rhs) = default; // Boilerplate: Move Constructor
~Entity() = default;
};

View File

@@ -8,11 +8,11 @@ public:
std::string name;
///The shader program
GLuint id = NULL;
GLuint id = 0;
///The individual shaders
GLuint vertex = NULL;
GLuint fragment = NULL;
GLuint vertex = 0;
GLuint fragment = 0;
Shader(const char* name, const std::string& vertexPath, const std::string& fragmentPath);
Shader(const char* name, const std::string& filePath, const GLenum& type);

View File

@@ -3,19 +3,18 @@
#include <glad/glad.h>
#include <vector>
#include <string>
#include <J3ML/LinearAlgebra.h>
#include <J3ML/LinearAlgebra.hpp>
#include <JGL/Texture.h>
#include <chrono>
//Forward declaration of entity.
class Entity;
//Base texture. One texture.
class Texture {
class Texture : public JGL::Texture {
public:
///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.
@@ -33,22 +32,24 @@ public:
void erase() override;
///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);
///Loads a list of Textures into a MultiTexture.
MultiTexture(Entity* entity, const std::vector<std::string>& textures, bool storeOnTextureList);
MultiTexture() = default;
//TODO load multi-texture from array of std::string of file names.
};
///A list of textures where the one actually displayed depends on how much time has elapsed.
class MotionTexture : public Texture {
private:
std::chrono::high_resolution_clock::time_point lastUpdate;
int lastDisplayedIndex;
u16 msDelay;
public:
int lastDisplayedIndex = 0;
u16 msDelay = 0;
bool doAnim = true;
public:
std::vector<Texture> motion;
Texture* current();
MotionTexture(Entity* entity, const std::vector<std::string>& textures,u16 msBetweenFrames, bool storeOnTextureList);
Texture* base();
void advance();
void toggleAnim();
MotionTexture(Entity* entity, const std::vector<std::string>& textures,u16 msBetweenFrames, bool storeOnTextureList, bool doAnim = true);
MotionTexture() = default;
};

View File

@@ -1,7 +1,7 @@
#pragma once
#include <vector>
#include <J3ML/LinearAlgebra.h>
#include <J3ML/LinearAlgebra.hpp>
class Moby;

View File

@@ -1,17 +1,17 @@
#pragma once
#include <vector>
#include <iostream>
#include <fstream>
#include <Collage/types/animation.h>
#include <J3ML/LinearAlgebra/Vector3.h>
#include <J3ML/LinearAlgebra/Vector2.h>
#include <J3ML/Geometry/OBB.h>
#include <Collage/types/model.h>
#include <J3ML/LinearAlgebra/Vector3.hpp>
#include <J3ML/LinearAlgebra/Vector2.hpp>
#include <J3ML/Geometry/OBB.hpp>
#include <glad/glad.h>
///Forward declaration of entity.
class Entity;
typedef Vector2 TextureCoordinate;
using J3ML::LinearAlgebra::Vector3;
using J3ML::LinearAlgebra::Vector2;
using J3ML::Geometry::OBB;
@@ -19,7 +19,6 @@ using J3ML::Geometry::OBB;
///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 {

View File

@@ -2,7 +2,10 @@ include_directories("src/demo/RuntimeTest/include")
add_executable(Re3D-RuntimeTest "src/demo/RuntimeTest/main.cpp")
#Link based on the relative path *so you can copy the game around*
set_target_properties(Re3D-RuntimeTest PROPERTIES LINK_FLAGS "-Wl,-rpath,./lib")
if (UNIX AND NOT APPLE)
set_target_properties(Re3D-RuntimeTest PROPERTIES LINK_FLAGS "-Wl,-rpath,./lib")
endif()
#Copy the assets to the build directory.
file(COPY "assets" DESTINATION "${PROJECT_BINARY_DIR}")

View File

@@ -3,7 +3,7 @@
#include <iostream>
#include <cmath>
#include <cstdint>
#include <Redacted3D/types/entity/moby.h>
#include <Redacted3D/types/entity/3D/moby.h>
class Ball : public Moby {
public:

View File

@@ -3,7 +3,7 @@
#include <iostream>
#include <cmath>
#include <cstdint>
#include <Redacted3D/types/entity/moby.h>
#include <Redacted3D/types/entity/3D/moby.h>
class Cube : public Moby {
public:
@@ -17,8 +17,7 @@ public:
//The "camera point" is the position the camera will want to be while following the player.
//We will probably end up having a different camera point class controlled by the "world".
void update(float elapsed) override;
//void update(float elapsed) override;
void pre_render() override;
void loadTexture() override;
Cube();
};

View File

@@ -1,4 +1,4 @@
#include <Redacted3D/types/entity/skybox.h>
#include <Redacted3D/types/entity/3D/skybox.h>
#pragma once
class DemoSkybox : public Skybox {

View File

@@ -0,0 +1,12 @@
#pragma once
#include <JGL/JGL.h>
namespace Fonts {
inline JGL::Font Jupiteroid;
inline JGL::Font ModeSeven;
inline void initFonts() {
Jupiteroid = JGL::Font("assets/fonts/Jupiteroid/JupiteroidRegular.ttf");
ModeSeven = JGL::Font("assets/fonts/modeseven.ttf");
}
}

View File

@@ -1,7 +1,9 @@
#pragma once
#include <Redacted3D/types/entity/camera.h>
#include <Redacted3D/types/entity/3D/camera.h>
#include <fonts.h>
class FreeCam : public Camera {
public:
void pre_render() override;
void jglRenderPass() override;
};

View File

@@ -4,14 +4,15 @@
#include <ball.h>
#include <freeCam.h>
#include <demoSky.h>
//#include <JGL/JGL.h>
//#include <JGL/Colors.h>
int main()
{
engine->window = new ReWindow::RWindow("Re3D Test Application", 1152, 864, RenderingAPI::OPENGL);
engine->world = new(World);
Engine::init();
JGL::InitTextEngine();
JGL::Update(engine->window->getSize());
Fonts::initFonts();
engine->window->setVsyncEnabled(false);
engine->window->setResizable(false);
engine->world->setAmbientLightColor(1.0f, 1.0f, 1.0f);
@@ -37,6 +38,7 @@ int main()
skybox->setAngle(0,0,0);
skybox->SetParent(engine->world);
JGL::J3D::Init(engine->window->getSize(), engine->fov, engine->farPlane);
engine->renderLoop();
}

View File

@@ -10,7 +10,7 @@ void Ball::update(float elapsed) {
Ball::Ball() {
name = "ball";
modelPath = "assets/models/sphere_lo.obj";
texturePath = "assets/textures/missing.png";
loadGeometry("assets/models/sphere_lo.obj");
loadTexture("assets/textures/missing.png");
setScale(1.0f);
}
}

View File

@@ -1,31 +1,27 @@
#include <cube.h>
#include <Redacted3D/engine/engine.h>
#include <ball.h>
void Cube::pre_render() {
getGeometry();
setAngle(getAngle().Add(24 * engine->frameDelta));
}
void Cube::update(float elapsed) {
}
Cube::Cube() {
name = "cube";
modelPath = "assets/models/cube.obj";
texturePath = "assets/textures/multi/";
setScale(0.5f);
}
void Cube::loadTexture() {
//MultiTexture texture(this, texturePath.c_str(), true);
std::vector<std::string> textures;
textures.emplace_back("assets/textures/motion/default.png");
textures.emplace_back("assets/textures/motion/1.png");
textures.emplace_back("assets/textures/motion/2.png");
textures.emplace_back("assets/textures/motion/3.png");
textures.emplace_back("assets/textures/motion/4.png");
textures.emplace_back("assets/textures/motion/5.png");
textures.emplace_back("assets/textures/motion/6.png");
MotionTexture texture(this, textures, 250, true);
loadGeometry("assets/models/cube.obj");
std::vector<std::string> motionTextures = {
"assets/textures/motion/default.png", "assets/textures/motion/1.png", "assets/textures/motion/2.png",
"assets/textures/motion/3.png", "assets/textures/motion/4.png", "assets/textures/motion/5.png",
"assets/textures/motion/6.png"
};
std::vector<std::string> multiTextures = {
"assets/textures/multi/default.png", "assets/textures/multi/1.png", "assets/textures/multi/2.png", "assets/textures/multi/3.png",
"assets/textures/multi/4.png", "assets/textures/multi/5.png", "assets/textures/multi/6.png"
};
loadMultiTexture(multiTextures);
//loadMotionTexture(motionTextures, 250, true);
}

View File

@@ -3,7 +3,7 @@
DemoSkybox::DemoSkybox() {
name = "skybox";
modelPath = engine->workingDir + "/assets/models/sphere_vlo.obj";
texturePath = engine->workingDir + "/assets/textures/skybox.png";
loadGeometry("assets/models/sphere_vlo.obj");
loadTexture("assets/textures/skybox.png");
setScale(engine->farPlane);
}

View File

@@ -1,4 +1,5 @@
#include <freeCam.h>
#include <mcolor.h>
void FreeCam::pre_render() {
if (engine->window->isKeyDown(Keys::W))
@@ -16,7 +17,7 @@ void FreeCam::pre_render() {
if (engine->window->isKeyDown(Keys::Space))
vMove(4);
if (engine->window->isKeyDown(Keys::LShift))
if (engine->window->isKeyDown(Keys::LeftShift))
vMove(-4);
if (engine->window->isKeyDown(Keys::LeftArrow))
@@ -36,5 +37,25 @@ void FreeCam::pre_render() {
if (engine->window->isKeyDown(Keys::E))
setAngle(getAngle().x, getAngle().y, getAngle().z + 75.0f * engine->frameDelta);
}
Vector3 textAngle = {0,0,0};
void FreeCam::jglRenderPass() {
textAngle.x = textAngle.x - (96.f * engine->frameDelta);
using namespace JGL;
J3D::Begin();
glDisable(GL_CULL_FACE);
J3D::DrawString(Colors::Red, "Text", {0, -2, 0}, textAngle, 4.f, 32, Fonts::Jupiteroid);
glEnable(GL_CULL_FACE);
J3D::End();
J2D::Begin();
J2D::FillRect({255,0,0,128}, {0, 72}, {100, 100});
J2D::FillCircle(Colors::White, {16, 128}, 12, 16);
J2D::DrawString(Colors::White, "Framerate: " + std::to_string((int) engine->framerate()), 0, 0, 1, 16, Fonts::Jupiteroid);
J2D::DrawString(Colors::White, "Framecount: " + std::to_string(engine->frameCount), 0, 17, 1,16, Fonts::Jupiteroid);
J2D::DrawString(Colors::White, "Position: " + std::to_string(position.x) + " " + std::to_string(position.y) + " " + std::to_string(position.z), 0, 33, 1,16, Fonts::Jupiteroid);
J2D::DrawString(Colors::White, "ViewAngle: " + std::to_string(getAngle().x) + " " + std::to_string(getAngle().y) + " " + std::to_string(getAngle().z), 0, 50, 1,16, Fonts::Jupiteroid);
J2D::End();
}

View File

@@ -1,15 +1,14 @@
#include <sstream>
#include <thread>
#include <Redacted3D/engine/engine.h>
#include <Redacted3D/engine/utils/instanceOf.h>
#include <Redacted3D/types/entity/camera.h>
#include <JGL/JGL.h>
#include <JGL/Colors.h>
#include <Redacted3D/engine/engine.h>
#include <Redacted3D/types/entity/3D/camera.h>
#include <jlog/jlog.hpp>
using namespace J3ML;
std::array<float, 16> perspective(float fov, float aspect, float nearPlane, float farPlane) {
std::array<float, 16> result{};
std::vector<float> perspective(float fov, float aspect, float nearPlane, float farPlane) {
std::vector<float> result(16);
float f = 1.0f / tan(fov * 0.5f * M_PI / 180.0f);
result[0] = f / aspect;
result[5] = f;
@@ -20,7 +19,7 @@ std::array<float, 16> perspective(float fov, float aspect, float nearPlane, floa
}
void Engine::quit() const {
window->destroyWindow();
//window->destroyWindow();
exit(0);
}
@@ -83,68 +82,72 @@ void Engine::initGL() const {
glDepthMask(GL_TRUE);
glEnable(GL_CULL_FACE);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_LIGHT0);
}
void Engine::init()
{
engine->window->Open();
engine->initGL();
engine->loadConfig();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
JGL::InitTextEngine();
void Engine::init() {
engine->window->Open();
engine->initGL();
engine->loadConfig();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
}
void Engine::preRender() {
engine->window->pollEvents();
engine->frameCount++;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
for (auto& e : world->GetChildren())
e->pre_render();
}
void Engine::render() {
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
if(world->getActiveCamera() != nullptr)
world->getActiveCamera()->render();
for (auto& e : world->GetChildren())
if (e->draw)
if (auto* c = dynamic_cast<Camera*>(e); c == nullptr) //If it's not a camera.
e->render();
int glError = glGetError();
if (glError != GL_NO_ERROR) {
FATAL("GL Error: " + std::to_string(glError))
exit(0);
}
}
void Engine::preRender()
{
engine->window->pollEvents();
engine->frameCount++;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
void Engine::jglRenderPass() {
JGL::Update(engine->window->getSize());
glDisable(GL_LIGHTING);
///If elements are attached to a camera that's not the active one then they shouldn't be drawn.
if(world->getActiveCamera() != nullptr)
world->getActiveCamera()->jglRenderPass();
for (auto& e : world->GetChildren())
e->pre_render();
}
for (auto& e : world->GetChildren())
if (e->draw)
if (auto* c = dynamic_cast<Camera*>(e); c == nullptr) //If it's not a camera.
e->jglRenderPass();
glEnable(GL_LIGHTING);
}
void Engine::postRender() {
for (auto& e : engine->world->GetChildren())
e->post_render();
ReWindow::RWindow::glSwapBuffers();
}
void Engine::renderPass() {
preRender();
render();
jglRenderPass();
postRender();
}
void Engine::render()
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
if(world->getActiveCamera() != nullptr)
world->getActiveCamera()->render();
for (auto& e : world->GetChildren())
if (e->draw)
if (auto* c = dynamic_cast<Camera*>(e); c == nullptr) //If it's not a camera.
e->render();
if (glGetError() != GL_NO_ERROR)
exit(0);
//TODO JGL rendering pass.
glDisable(GL_LIGHTING);
JGL::J3D::DrawString3D(JGL::Colors::White, std::to_string((int) framerate()), {0.5f, 0, 0.5f}, 0.0125f);
glEnable(GL_LIGHTING);
}
void Engine::postRender()
{
for (auto& e : engine->world->GetChildren())
e->post_render();
ReWindow::RWindow::glSwapBuffers();
}
void Engine::renderPass()
{
preRender();
render();
postRender();
}
[[noreturn]] void Engine::renderLoop()
{
[[noreturn]] void Engine::renderLoop() {
while (true) {
auto start = std::chrono::high_resolution_clock::now();
renderPass();
@@ -225,7 +228,7 @@ EngineError Engine::getError() {
}
void Engine::quit(ENGINE_ERROR_CODE code) const {
window->destroyWindow();
//window->destroyWindow();
exit((int) code);
}

View File

@@ -1,7 +1,5 @@
#include <Redacted3D/engine/occlusion.h>
#include <Redacted3D/types/entity/entity.h>
#include <Redacted3D/types/entity/3D/entity.h>
bool Occlusion::frustumCull(Camera* camera, Entity* entity) {
}
bool Occlusion::frustumCull(Camera* camera, Entity* entity) { return false; }

View File

@@ -1,5 +1,5 @@
#include <Redacted3D/engine/world.h>
#include <Redacted3D/types/entity/moby.h>
#include <Redacted3D/types/entity/3D/moby.h>
int DataModel::getEntityCount() const {
@@ -14,108 +14,6 @@ int DataModel::getMobyCount() const {
return count;
}
void Entity::SetParent(Entity *parent) {
// hold a reference to this so it doesn't get collected as we're working with it
Entity *oldParent = this->parent;
if (parent == oldParent)
return;
// Don't allow for an instance to be parented to itself
if (this == parent)
throw std::runtime_error("Cannot parent a widget to itself");
if (this->IsAncestorOf(parent))
throw std::runtime_error("Cannot create circular object reference");
for (Entity *ancestor: this->GetAncestors()) {
if (oldParent && !ancestor->IsAncestorOf(parent) && parent != ancestor) {
ancestor->DescendantRemoved(this);
for (Entity *descendant: this->GetDescendants()) {
ancestor->DescendantRemoved(descendant);
}
}
}
// Remove ourselves from our parent (if we have one)
if (this->parent) {
parent->children.erase(std::remove(parent->children.begin(), parent->children.end(), this),
parent->children.end());
}
// Update our old parent to the new one
this->parent = parent;
// If our parent is set to nullptr, we can't update it's vector of children
if (!parent) { return; }
parent->children.emplace_back(this);
for (Entity* ancestor: this->GetAncestors()) {
if (!oldParent || !(oldParent->IsDescendantOf(parent) && oldParent != ancestor)) {
ancestor->DescendantAdded(this);
for (auto* descendant : this->GetDescendants()) {
ancestor->DescendantAdded(descendant);
}
}
}
}
bool Entity::IsDescendantOf(Entity *ancestor) {
if (ancestor == nullptr)
return false;
Entity *instance = this;
while (instance->GetParent()) {
instance = instance->GetParent();
if (instance == ancestor)
return true;
}
return false;
}
bool Entity::IsAncestorOf(Entity *descendant) {
if (descendant == nullptr)
return false;
Entity *instance = descendant;
while (instance->GetParent()) {
instance = instance->GetParent();
if (instance == this)
return true;
}
return false;
}
std::vector<Entity *> Entity::GetChildren() {
return this->children;
}
std::vector<Entity *> Entity::GetAncestors() {
std::vector<Entity *> ancestors;
for (Entity *ancestor = this->parent; ancestor; ancestor = ancestor->parent) {
ancestors.push_back(ancestor);
}
return ancestors;
}
std::vector<Entity *> Entity::GetDescendants() {
std::vector<Entity *> descendants;
for (auto& child: this->children) {
descendants.push_back(child);
std::vector<Entity *> recursiveDescendants = child->GetDescendants();
descendants.insert(descendants.end(), recursiveDescendants.begin(), recursiveDescendants.end());
}
return descendants;
}
Entity *Entity::Add(Entity *newChild) {
newChild->SetParent(this);
return newChild;
}
Entity *Entity::GetFamilyTreeRoot() const {
//if (JUI::Scene* scene = dynamic_cast<JUI::Scene*>(parent); scene != nullptr)
// This is retarded, Fix ASAP!
auto parent = this->GetParent();
if (parent->GetParent() == nullptr)
return parent;
return parent->GetFamilyTreeRoot();
}
void World::setAmbientLightColor(GLfloat red, GLfloat green, GLfloat blue) {
GLfloat ambient[4] = {red, green, blue, 0.0f};
globalLightColor.x = red; globalLightColor.y = green; globalLightColor.z = blue;

View File

@@ -1,5 +1,5 @@
#include <array>
#include <Redacted3D/types/entity/camera.h>
#include <Redacted3D/types/entity/3D/camera.h>
std::array<GLfloat, 16> lookAt(const Vector3& eye, const Vector3& center, const Vector3& up) {
Vector3 f = Vector3::Normalized((center - eye));
@@ -21,15 +21,16 @@ void Camera::render() {
glRotatef(getAngle().y,0.0f, 1.0f, 0.0f);
glRotatef(getAngle().z,0.0f, 0.0f, 1.0f);
glMultMatrixf(lookAt({position.x, position.y, position.z}, {position.x, position.y, engine->farPlane+position.z}, upVector).data());
glMultMatrixf(lookAt({position.x, position.y, position.z}, {position.x, position.y, engine->farPlane+position.z}, engine->world->upVector).data());
}
void Camera::post_render() {
ticksAlive++;
}
/*
bool Camera::raycast(Entity *entity) {
Vector3 rayOrigin = position;
Vector3 rayAngle = getAngle();
}
*/

View File

@@ -1,6 +1,6 @@
#include <Redacted3D/types/entity/entity.h>
#include <Redacted3D/types/entity/3D/entity.h>
#include <Redacted3D/engine/occlusion.h>
#include <Redacted3D/types/entity/camera.h>
#include <Redacted3D/types/entity/3D/camera.h>
#include <Redacted3D/engine/engine.h>
#include <Redacted3D/engine/utils/instanceOf.h>
#include <jlog/jlog.hpp>
@@ -40,9 +40,9 @@ void Entity::SetPos(const Vector3 &rhs) {
Entity::Entity() {
position = {0,0,0};
ticksAlive = 0;
children = std::vector<Entity*> ();
children = std::vector<BaseEntity*> ();
parent = nullptr;
scale = 1.0f;
scale = {1.0f, 1.0f, 1.0f};
//UUIDv4::UUIDGenerator<std::mt19937_64> uuidGenerator;
//UUIDv4::UUID id = uuidGenerator.getUUID();
@@ -50,24 +50,43 @@ Entity::Entity() {
}
void Entity::setScale(const float &multiplier) {
scale = multiplier;
scale.Set(multiplier, multiplier, multiplier);
}
GLfloat Entity::getScale() const {
Vector3 Entity::getScale() const {
return scale;
}
void Entity::loadTexture() {
Texture texture(this, texturePath.c_str(), true);
void Entity::loadTexture(const std::string& file) {
for (const auto* e : engine->world->GetChildren())
if (instanceOf(this, e))
return;
Texture(this, file.c_str(), true);
}
void Entity::loadGeometry() {
VertexArray vArray(this, modelPath, true);
void Entity::loadMultiTexture(const std::vector<std::string>& files) {
for (const auto* e : engine->world->GetChildren())
if (instanceOf(this, e))
return;
MultiTexture(this, files, true);
}
void Entity::loadMotionTexture(const std::vector<std::string>& files, u16 frameDelta, bool doAnim) {
for (const auto* e : engine->world->GetChildren())
if (instanceOf(this, e))
return;
MotionTexture(this, files, frameDelta, true, doAnim);
}
void Entity::loadGeometry(const std::string& file) {
for (const auto& e : engine->world->GetChildren())
if (instanceOf(this, e))
return;
VertexArray vArray(this, file, true);
}
VertexArray* Entity::getGeometry() {
if (engine->world->geometryList.empty())
loadGeometry();
for (auto& vArray : engine->world->geometryList)
for (auto& entity : vArray->usedBy)
if (instanceOf(this, entity)) {
@@ -75,28 +94,60 @@ VertexArray* Entity::getGeometry() {
vArray->usedBy.push_back(this);
return vArray;
}
loadGeometry();
return getGeometry();
return nullptr;
}
Texture* Entity::getTexture() {
for (auto& texture : engine->world->textureList)
for (auto& entity : texture->usedBy)
if (instanceOf(this, entity)) {
if (std::find(texture->usedBy.begin(), texture->usedBy.end(), this) == texture->usedBy.end()) //If this is the first time the entity is using it.
texture->usedBy.push_back(this);
return texture;
}
return nullptr;
}
inline Texture* baseTexture = new Texture();
void Entity::render() {
bool multiTexture = false;
bool motionTexture = false;
if (!baseTexture) {
GLuint handle;
glGenTextures(1, &handle);
glBindTexture(GL_TEXTURE_2D, handle);
if (auto* t = dynamic_cast<MultiTexture*>(getTexture()))
multiTexture = true;
Color4 whitePixel = {255, 255, 255, 255};
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &whitePixel);
if (!multiTexture)
if (auto* t = dynamic_cast<MotionTexture*>(getTexture()))
motionTexture = true;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glActiveTexture(0);
baseTexture->SetTextureHandle(handle);
}
MultiTexture texture;
texture.SetTextureHandle(baseTexture->GetGLTextureHandle());
if (auto* t = dynamic_cast<MultiTexture*>(getTexture())) {
texture.multi.emplace_back(*t);
for (const auto &item: t->multi)
texture.multi.push_back(item);
}
else if (auto* j = dynamic_cast<MotionTexture*>(getTexture()))
texture.multi.push_back(*j->current());
else if (auto* k = dynamic_cast<Texture*>(getTexture()))
texture.multi.push_back(*k);
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);
if (getScale() != 1.0f)
glScalef(getScale(), getScale(), getScale());
if (getScale().x != 1.0f || getScale().y != 1.0f || getScale().z != 1.0f)
glScalef(getScale().x, getScale().y, getScale().z);
//Set up texture.
glActiveTexture(GL_TEXTURE0);
@@ -104,7 +155,9 @@ void Entity::render() {
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindTexture(GL_TEXTURE_2D, motionTexture ? ((MotionTexture*)getTexture())->current()->id : getTexture()->id);
glBindTexture(GL_TEXTURE_2D, texture.GetGLTextureHandle());
//Texture unit mode.
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
if (!engine->useVBO)
glVertexPointer(3, GL_FLOAT, sizeof(Vertex), &getGeometry()->vertices[0].x),
@@ -114,41 +167,32 @@ void Entity::render() {
glBindBuffer(GL_ARRAY_BUFFER, getGeometry()->tbo),
glTexCoordPointer(2, GL_FLOAT, 0, nullptr);
if (!multiTexture)
getGeometry()->draw();
if (multiTexture) {
auto* multi = (MultiTexture*) getTexture();
int i = 0;
for(auto& t : texture.multi) {
glActiveTexture(GL_TEXTURE1 + i);
glClientActiveTexture(GL_TEXTURE1 + i);
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
int i = 0;
GLfloat blendingFactor[3] = {engine->world->getAmbientLightColor().x * 0.2f, engine->world->getAmbientLightColor().y * 0.2f, engine->world->getAmbientLightColor().z * 0.2f};
for(auto& texture : multi->multi) {
glActiveTexture(GL_TEXTURE1 + i);
glClientActiveTexture(GL_TEXTURE1 + i);
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
if (!engine->useVBO)
glVertexPointer(3, GL_FLOAT, sizeof(Vertex), &getGeometry()->vertices[0].x),
glTexCoordPointer(2, GL_FLOAT, sizeof(TextureCoordinate), &getGeometry()->texCoords[0].x);
if (!engine->useVBO)
glVertexPointer(3, GL_FLOAT, sizeof(Vertex), &getGeometry()->vertices[0].x),
glTexCoordPointer(2, GL_FLOAT, sizeof(TextureCoordinate), &getGeometry()->texCoords[0].x);
if (engine->useVBO)
glBindBuffer(GL_ARRAY_BUFFER, getGeometry()->tbo),
glTexCoordPointer(2, GL_FLOAT, 0, nullptr);
if (engine->useVBO)
glBindBuffer(GL_ARRAY_BUFFER, getGeometry()->tbo),
glTexCoordPointer(2, GL_FLOAT, 0, nullptr);
//Texture unit mode.
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
//Makes the lighting work the way you'd think it would.
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, blendingFactor);
glBindTexture(GL_TEXTURE_2D, texture.id);
glBindTexture(GL_TEXTURE_2D, t.GetGLTextureHandle());
i++;
}
getGeometry()->draw();
//Reset the multi-texture units.
for (int j = 0; j <= i; j++) {
for (int j = 0; j < i; j++) {
glActiveTexture(GL_TEXTURE1 + j);
glClientActiveTexture(GL_TEXTURE1 + j);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
@@ -156,7 +200,6 @@ void Entity::render() {
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
}
//Reset texture unit 0.
glActiveTexture(GL_TEXTURE0);
@@ -178,23 +221,7 @@ void Entity::render() {
}
}
bool Entity::isCollidingWith(Entity *entity) {
}
Texture* Entity::getTexture() {
if (engine->world->textureList.empty())
loadTexture();
for (auto& texture : engine->world->textureList)
for (auto& entity : texture->usedBy)
if (instanceOf(this, entity)) {
if (std::find(texture->usedBy.begin(), texture->usedBy.end(), this) == texture->usedBy.end()) //If this is the first time the entity is using it.
texture->usedBy.push_back(this);
return texture;
}
loadTexture();
return getTexture();
}
//bool Entity::isCollidingWith(Entity *entity) {}
void Entity::erase() {
Texture* t = getTexture();
@@ -222,9 +249,10 @@ void Entity::erase() {
AABB Entity::getAABB() {
AABB aabb = Collision::genMinimallyEnclosingAABB(getGeometry());
if (getScale() != 1)
aabb.minPoint *= scale,
aabb.maxPoint *= scale;
//TODO this won't look right.
if (getScale().x != 1)
aabb.minPoint *= scale.x,
aabb.maxPoint *= scale.x;
aabb.minPoint += position;
aabb.maxPoint += position;
@@ -233,7 +261,8 @@ AABB Entity::getAABB() {
Sphere Entity::getSphere() {
Sphere sphere = Collision::genMinimallyEnclosingSphere(getGeometry());
sphere.Radius *= scale;
//TODO this won't look right.
sphere.Radius *= scale.x;
sphere.Position = position;
return sphere;
}
@@ -243,7 +272,7 @@ OBB Entity::getOBB() {
}
Vector3 Entity::getAngle() {
return angle;
return {Math::Degrees(Math::Radians(angle.x)), Math::Degrees(Math::Radians(angle.y)), Math::Degrees(Math::Radians(angle.z))};
}
void Entity::setAngle(const Vector3 &a) {
@@ -255,7 +284,7 @@ void Entity::setAngle(float pitch, float yaw, float roll) {
}
Direction Entity::getAngleDirection() {
Direction a = Vector3::Direction(angle);
Direction a = Vector3::Direction(getAngle());
//These two are reversed when moving things in the Re3D scene.
//-Z is forward.
a.x = -a.x;

View File

@@ -1,4 +1,4 @@
#include <Redacted3D/types/entity/moby.h>
#include <Redacted3D/types/entity/3D/moby.h>
#include <Redacted3D/engine/engine.h>
using namespace J3ML;
@@ -37,7 +37,7 @@ void Moby::vAngleMove(float speed) {
}
//Returns the position we'd be at *if* we did a movement.
Direction Moby::projectedHorizontalMove(Vector3 a, float vel) {
Position Moby::projectedHorizontalMove(Vector3 a, float vel) {
Position p;
p.z -= (vel*engine->frameDelta) * a.x;
p.x += (vel*engine->frameDelta) * a.z;
@@ -48,13 +48,8 @@ Position Moby::projectedVerticalMove(float speed) {
return {position.x, position.y += (speed*engine->frameDelta), position.z};
}
Direction Moby::fAngle()
{
Direction a;
a.x = -(cos(Math::Radians(getAngle().y)) * cos(Math::Radians(getAngle().x)));
a.y = -sin(Math::Radians(getAngle().x));
a.z = -(sin(Math::Radians(getAngle().y)) * cos(Math::Radians(getAngle().x)));
return a;
Direction Moby::fAngle() {
return getAngleDirection();
}
Direction Moby::bAngle() {
@@ -62,21 +57,11 @@ Direction Moby::bAngle() {
}
Direction Moby::rAngle() {
Direction f = fAngle();
Direction a;
a.x = f.x * upVector.z - f.z * upVector.y;
a.y = f.z * upVector.x - f.x * upVector.z;
a.z = f.x * upVector.y - f.y * upVector.x;
return a;
return Vector3::Cross(fAngle(), engine->world->upVector);
}
Direction Moby::lAngle() {
Direction f = fAngle();
Direction a;
a.x = -(f.y * upVector.z - f.z * upVector.y);
a.y = (f.z * upVector.x - f.x * upVector.z);
a.z = -(f.x * upVector.y - f.y * upVector.x);
return a;
return -rAngle();
}
float Moby::getVelocity() {
@@ -105,4 +90,4 @@ void Moby::setVelocityAngle(const Vector3 &a) {
void Moby::setVelocityAngle(float pitch, float yaw, float roll) {
velAngle = {pitch, yaw, roll};
}
}

View File

@@ -1,6 +1,6 @@
#include <Redacted3D/types/entity/skybox.h>
#include <Redacted3D/types/entity/3D/skybox.h>
#include <Redacted3D/engine/engine.h>
#include <Redacted3D/types/entity/camera.h>
#include <Redacted3D/types/entity/3D/camera.h>
void Skybox::pre_render() {
if (engine->world->getActiveCamera() != nullptr)
@@ -10,9 +10,9 @@ void Skybox::pre_render() {
void Skybox::render() {
glPushMatrix();
glTranslatef(position.x ,position.y, position.z);
glBindTexture(GL_TEXTURE_2D, getTexture()->id);
glBindTexture(GL_TEXTURE_2D, getTexture()->GetGLTextureHandle());
glCullFace(GL_FRONT);
glScalef(getScale(), getScale(), getScale());
glScalef(getScale().x, getScale().y, getScale().z);
getGeometry()->draw();
glCullFace(GL_BACK);
glBindTexture(GL_TEXTURE_2D,0);
@@ -21,7 +21,5 @@ void Skybox::render() {
Skybox::Skybox() {
name = "skybox";
modelPath = engine->workingDir + "/assets/models/sphere_vlo.obj";
texturePath = engine->workingDir + "/assets/textures/missing.png";
setScale(engine->farPlane);
}

View File

@@ -0,0 +1,108 @@
#include <Redacted3D/types/entity/baseEntity.h>
#include <stdexcept>
void BaseEntity::SetParent(BaseEntity* parent) {
// hold a reference to this so it doesn't get collected as we're working with it
BaseEntity* oldParent = this->parent;
if (parent == oldParent)
return;
// Don't allow for an instance to be parented to itself
if (this == parent)
throw std::runtime_error("Cannot parent a widget to itself");
if (this->IsAncestorOf(parent))
throw std::runtime_error("Cannot create circular object reference");
for (BaseEntity* ancestor: this->GetAncestors()) {
if (oldParent && !ancestor->IsAncestorOf(parent) && parent != ancestor) {
ancestor->DescendantRemoved(this);
for (BaseEntity* descendant: this->GetDescendants()) {
ancestor->DescendantRemoved(descendant);
}
}
}
// Remove ourselves from our parent (if we have one)
if (this->parent) {
for (auto it = parent->children.begin(); it != parent->children.end(); ++it) {
if (*it == this) {
parent->children.erase(it);
break;
}
}
}
// Update our old parent to the new one
this->parent = parent;
// If our parent is set to nullptr, we can't update it's vector of children
if (!parent) { return; }
parent->children.emplace_back(this);
for (BaseEntity* ancestor: this->GetAncestors()) {
if (!oldParent || !(oldParent->IsDescendantOf(parent) && oldParent != ancestor)) {
ancestor->DescendantAdded(this);
for (auto* descendant : this->GetDescendants()) {
ancestor->DescendantAdded(descendant);
}
}
}
}
bool BaseEntity::IsDescendantOf(BaseEntity* ancestor) {
if (ancestor == nullptr)
return false;
BaseEntity* instance = this;
while (instance->GetParent()) {
instance = instance->GetParent();
if (instance == ancestor)
return true;
}
return false;
}
bool BaseEntity::IsAncestorOf(BaseEntity* descendant) {
if (descendant == nullptr)
return false;
BaseEntity* instance = descendant;
while (instance->GetParent()) {
instance = instance->GetParent();
if (instance == this)
return true;
}
return false;
}
std::vector<BaseEntity* > BaseEntity::GetChildren() {
return this->children;
}
std::vector<BaseEntity* > BaseEntity::GetAncestors() {
std::vector<BaseEntity* > ancestors;
for (BaseEntity* ancestor = this->parent; ancestor; ancestor = ancestor->parent) {
ancestors.push_back(ancestor);
}
return ancestors;
}
std::vector<BaseEntity* > BaseEntity::GetDescendants() {
std::vector<BaseEntity* > descendants;
for (auto& child: this->children) {
descendants.push_back(child);
std::vector<BaseEntity* > recursiveDescendants = child->GetDescendants();
descendants.insert(descendants.end(), recursiveDescendants.begin(), recursiveDescendants.end());
}
return descendants;
}
BaseEntity* BaseEntity::Add(BaseEntity* newChild) {
newChild->SetParent(this);
return newChild;
}
BaseEntity* BaseEntity::GetFamilyTreeRoot() const {
//if (JUI::Scene* scene = dynamic_cast<JUI::Scene*>(parent); scene != nullptr)
// This is retarded, Fix ASAP!
auto parent = this->GetParent();
if (parent->GetParent() == nullptr)
return parent;
return parent->GetFamilyTreeRoot();
}

View File

@@ -1,16 +1,20 @@
#include <ReTexture/Texture.h>
#include <Redacted3D/types/texture.h>
#include <ReTexture/rTexture.h>
#include <Redacted3D/engine/engine.h>
//TODO use JGL implementation of texture.
void Texture::load(Entity* entity, const std::string& file, bool storeOnTextureList) {
auto* texture = new RTexture(file, {RTextureFlag::INVERT_Y});
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
if (texture->format == RTextureFormat::RGBA)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->width, texture->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture->pixelData.data());
if (texture->format == RTextureFormat::RGB)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texture->width, texture->height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture->pixelData.data());
auto* texture = new ReTexture::SoftwareTexture(file, {ReTexture::TextureFlag::INVERT_Y});
glGenTextures(1, &texture_handle);
glBindTexture(GL_TEXTURE_2D, texture_handle);
if (texture->getTextureFormat() == ReTexture::TextureFormat::RGBA)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->getWidth(), texture->getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, texture->pixelData.data());
if (texture->getTextureFormat() == ReTexture::TextureFormat::RGB)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texture->getWidth(), texture->getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, texture->pixelData.data());
delete texture;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@@ -18,10 +22,10 @@ void Texture::load(Entity* entity, const std::string& file, bool storeOnTextureL
glBindTexture(GL_TEXTURE_2D, 0);
//If we can't load the missing texture
if (file == "assets/textures/missing.png" && id == 0)
if (file == "assets/textures/missing.png" && texture_handle == 0)
engine->setError(ENGINE_ERROR_CODE::TEXTURE_NOT_FOUND, true);
if (id == 0)
if (texture_handle == 0)
engine->setError(ENGINE_ERROR_CODE::TEXTURE_NOT_FOUND, false),
load(entity, "assets/textures/missing.png", false);
@@ -34,12 +38,12 @@ void Texture::erase() {
Texture::erase(this);
}
Texture::Texture(Entity* entity, const char *filePath, bool storeOnTextureList) {
Texture::Texture(Entity* entity, const char* filePath, bool storeOnTextureList) {
load(entity, filePath, storeOnTextureList);
}
void Texture::erase(Texture* texture) const {
glDeleteTextures(1, &texture->id);
glDeleteTextures(1, &texture->texture_handle);
//If texture is being deleted while in use.
//It won't crash the program. But it'll cause the texture to be reloaded from disk unnecessarily.
@@ -48,42 +52,38 @@ void Texture::erase(Texture* texture) const {
if (auto* t = dynamic_cast<MultiTexture*>(texture))
for (auto &m : t->multi)
glDeleteTextures(1, &m.id);
glDeleteTextures(1, &m.texture_handle);
for (int i = 0; i < engine->world->textureList.size(); i++)
if (engine->world->textureList[i] == texture)
engine->world->textureList.erase(engine->world->textureList.begin() + i);
}
MultiTexture::MultiTexture(Entity* entity, const char* pathContainingTextures, bool storeOnTextureList) {
for (const auto& entry : std::filesystem::directory_iterator(pathContainingTextures))
if (entry.is_regular_file() && entry.path().extension() == ".png") {
Texture texture(entity, entry.path().c_str(), false);
//The base texture *must* go in the first slot.
if (entry.path().filename() == "default.png")
this->id = texture.id,
this->usedBy = texture.usedBy;
else multi.push_back(texture);
}
MultiTexture::MultiTexture(Entity* entity, const std::vector<std::string>& textures, bool storeOnTextureList) {
Texture base;
for (const auto& t : textures) {
if (texture_handle != 0)
multi.emplace_back(entity, t.c_str(), false);
else
base = Texture(entity, t.c_str(), false),
texture_handle = base.GetGLTextureHandle(),
usedBy = base.usedBy;
}
if (storeOnTextureList)
engine->world->textureList.push_back(new MultiTexture(*this));
//You cannot have more than 8 total textures rendered in one pass.
//In Fixed-Function OpenGL you only have 8 TMUs available.
//TODO: multi-pass multi-texturing (will be slower).
if (multi.size() > 7)
engine->setError(ENGINE_ERROR_CODE::MULTI_TEXTURE_SIZE_EXCEEDS, true);
if (multi.size() > 6)
engine->setError(ENGINE_ERROR_CODE::MULTI_TEXTURE_SIZE_EXCEEDS, false);
}
void MultiTexture::erase() {
Texture::erase(this);
}
MotionTexture::MotionTexture(Entity* entity, const std::vector<std::string>& textures, u16 msBetweenFrames, bool storeOnTextureList) {
MotionTexture::MotionTexture(Entity* entity, const std::vector<std::string>& textures, u16 msBetweenFrames, bool storeOnTextureList, bool doAnim) {
msDelay = msBetweenFrames;
this->doAnim = doAnim;
Texture base(entity, textures[0].c_str(), false);
std::vector<std::string> extra(textures.begin()+1, textures.end());
@@ -91,7 +91,7 @@ MotionTexture::MotionTexture(Entity* entity, const std::vector<std::string>& tex
for (auto& t : extra)
motion.emplace_back(entity, t.c_str(), false);
id = base.id;
texture_handle = base.GetGLTextureHandle();
usedBy = base.usedBy;
if (storeOnTextureList)
engine->world->textureList.push_back(new MotionTexture(*this));
@@ -124,4 +124,18 @@ Texture* MotionTexture::current() {
return this;
return &motion[lastDisplayedIndex - 1];
}
}
void MotionTexture::advance() {
lastDisplayedIndex++;
if (lastDisplayedIndex > motion.size())
lastDisplayedIndex = 0;
}
void MotionTexture::toggleAnim() {
doAnim = !doAnim;
}
Texture* MotionTexture::base() {
return this;
}

View File

@@ -1,7 +1,7 @@
#include <fstream>
#include <Redacted3D/types/track.h>
#include <Redacted3D/engine/engine.h>
#include <Redacted3D/types/entity/moby.h>
#include <Redacted3D/types/entity/3D/moby.h>
#include <jlog/jlog.hpp>
Track::Track(const std::string &file, Moby* moby) {

View File

@@ -33,7 +33,7 @@ void VertexArray::load (const std::string& filename) {
}
//Cached OBB.
this->cachedOBB = Collision::genMinimallyEnclosingOBB(this, (Vector3) {0, 0, 0});
this->cachedOBB = Collision::genMinimallyEnclosingOBB(this, {0, 0, 0});
}
void VertexArray::draw() {