Document
This commit is contained in:
@@ -8,9 +8,9 @@ using J3ML::Geometry::Frustum;
|
||||
using J3ML::Geometry::Sphere;
|
||||
|
||||
namespace Collision {
|
||||
AABB genMinimallyEnclosingAABB(const VertexArray* vA);
|
||||
AABB genMinimallyEnclosingAABB(const VertexArray* vA, const Vector3& rotation); //Faster due to using the cached OBB.
|
||||
Sphere genMinimallyEnclosingSphere(const VertexArray* vA); //Faster due to using the cached OBB.
|
||||
OBB genMinimallyEnclosingOBB(const VertexArray* vA, const Vector3& rotation);
|
||||
VertexArray getDrawable(const Shape& collider);
|
||||
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.
|
||||
}
|
||||
|
9
include/engine/utils/aimbot.h
Normal file
9
include/engine/utils/aimbot.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include <J3ML/LinearAlgebra.h>
|
||||
using namespace J3ML;
|
||||
|
||||
using J3ML::LinearAlgebra::Vector3;
|
||||
|
||||
Vector3 calcAngle(Vector3 sP, Vector3 eP) { //Calculates the angle between two points in 3D space.
|
||||
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};
|
||||
}
|
@@ -2,6 +2,6 @@
|
||||
#include <typeinfo>
|
||||
|
||||
template <typename Source, typename Target>
|
||||
bool instanceOf(Source* source, Target* target) {
|
||||
bool instanceOf(Source* source, Target* target) { //Returns true if target is the exact same class type as source.
|
||||
return typeid(*source) == typeid(*target);
|
||||
}
|
@@ -7,14 +7,11 @@
|
||||
using J3ML::LinearAlgebra::Matrix4x4;
|
||||
using J3ML::Geometry::Frustum;
|
||||
|
||||
const Vector3 UP = {0, 1, 0};
|
||||
class Camera : public Moby {
|
||||
class Camera : public Moby {//The base camera class. Entirely stationary.
|
||||
public:
|
||||
bool takingScreenshot = false;
|
||||
Matrix4x4 GetViewMatrix();
|
||||
Matrix4x4 GetViewMatrix(); //Returns the current ViewMatrix.
|
||||
bool raycast(Entity* entity);
|
||||
Frustum getFrustum();
|
||||
void LookAt(Vector3 pos, Vector3 target, Vector3 upaxis = UP) {}
|
||||
Frustum getFrustum(); //Returns the view frustum of the camera.
|
||||
void Rotate(float amt, Vector3 axis) { }
|
||||
void Translate(Vector3 dir) { }
|
||||
void pre_render() override {};
|
||||
|
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <types/vector.h>
|
||||
#include <types/vertex.h>
|
||||
#include <types/texture.h>
|
||||
#include <J3ML/LinearAlgebra/Matrix4x4.h>
|
||||
@@ -12,18 +11,18 @@ using J3ML::LinearAlgebra::Matrix4x4;
|
||||
using J3ML::LinearAlgebra::Vector3;
|
||||
|
||||
|
||||
class Entity {
|
||||
class Entity { //Base entity type.
|
||||
private:
|
||||
virtual void loadTexture();
|
||||
void loadGeometry();
|
||||
GLfloat scale = 1.0f;
|
||||
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.
|
||||
protected:
|
||||
std::string modelPath;
|
||||
std::string texturePath;
|
||||
Entity* parent;
|
||||
std::vector<Entity*> children;
|
||||
Entity* parent; //If the entity has a parent entity, It's here.
|
||||
std::vector<Entity*> children; //Entity list of child entities.
|
||||
public:
|
||||
std::string name;
|
||||
std::string name; //Entity name. TODO remove this.
|
||||
bool alive;
|
||||
|
||||
|
||||
@@ -43,15 +42,15 @@ public:
|
||||
}
|
||||
|
||||
Vector3 angle = {0,0,0}; //Pitch Yaw Roll, The orientation of the entity in the world,
|
||||
bool collidable = true; // Entities are solid by default.
|
||||
bool collidable = true; //Whether an entity is solid. Entities are solid by default.
|
||||
|
||||
virtual Texture* getTexture();
|
||||
virtual VertexArray* getGeometry();
|
||||
AABB getAABB();
|
||||
Sphere getSphere();
|
||||
OBB getOBB();
|
||||
std::vector<Entity*> GetChildren();
|
||||
virtual void SetParent(Entity* parent);
|
||||
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.
|
||||
bool IsDescendantOf(Entity* ancestor);
|
||||
bool IsAncestorOf(Entity* descendant);
|
||||
std::vector<Entity*> GetDescendants();
|
||||
@@ -92,18 +91,17 @@ public:
|
||||
void SetPos(const Vector3& rhs);
|
||||
Matrix4x4 GetMatrix() const;
|
||||
void SetMatrix(const Matrix4x4& rhs);
|
||||
void erase();
|
||||
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.
|
||||
bool draw = true;
|
||||
bool occluded();
|
||||
bool isCollidingWith(Entity* entity);
|
||||
virtual void pre_render() {}
|
||||
virtual void post_render() {}
|
||||
virtual void render();
|
||||
virtual void render(); //The default rendering routine. Works for 99% of cases.
|
||||
virtual void update(float elapsed) {}
|
||||
virtual void ticc(int tics)
|
||||
{
|
||||
ticksAlive++;
|
||||
|
||||
}
|
||||
|
||||
Entity();
|
||||
|
@@ -2,16 +2,15 @@
|
||||
|
||||
#include <types/entity/entity.h>
|
||||
|
||||
//Movable Object.
|
||||
class Moby : public Entity {
|
||||
class Moby : public Entity { //A "Movable Object". Things that will move often are derived from this.
|
||||
public:
|
||||
Moby(): Entity(), velAngle({0,0,0})
|
||||
{
|
||||
|
||||
}
|
||||
Vector3 velAngle = {0,0,0}; //The angle of an entities velocity.
|
||||
float hVelocity;
|
||||
float vVelocity;
|
||||
Vector3 velAngle = {0,0,0}; //The angle of velocity.
|
||||
float hVelocity; //Horizontal speed.
|
||||
float vVelocity; //Vertical speed.
|
||||
Vector3 upVector = {0.0f,1.0f,0.0f};
|
||||
virtual void hMove(Vector3 a, float vel);
|
||||
void vMove(float vel);
|
||||
|
@@ -3,7 +3,7 @@
|
||||
#include <types/vertex.h>
|
||||
#include <types/entity/moby.h>
|
||||
|
||||
class Skybox : public Moby {
|
||||
class Skybox : public Moby { //Simple skybox, A sphere with a texture on it where the center of the sphere is always the camera.
|
||||
public:
|
||||
void pre_render() override;
|
||||
Skybox();
|
||||
|
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <glad/glad.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
@@ -10,18 +9,19 @@ class Entity;
|
||||
|
||||
class Texture {
|
||||
public:
|
||||
std::vector<Entity*> usedBy;
|
||||
GLuint id = 0;
|
||||
void load(Entity* entity, const std::string& file, bool storeOnTextureList);
|
||||
virtual void erase();
|
||||
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.
|
||||
void erase(Texture* texture) const;
|
||||
Texture(Entity* entity, const char *filePath, bool storeOnTextureList);
|
||||
Texture(Entity* entity, const char *filePath, bool storeOnTextureList); //Constructor. Calls load.
|
||||
Texture() = default;
|
||||
};
|
||||
|
||||
class MultiTexture : public Texture {
|
||||
public:
|
||||
void erase() override;
|
||||
std::vector<Texture> multi;
|
||||
MultiTexture(Entity* entity, const char* pathContainingTextures, bool storeOnTextureList);
|
||||
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"
|
||||
//TODO load multi-texture from array of std::string of file names.
|
||||
};
|
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
#include <J3ML/LinearAlgebra/Vector3.h>
|
||||
|
||||
inline namespace VectorMath {
|
||||
|
||||
using namespace J3ML;
|
||||
|
||||
using J3ML::LinearAlgebra::Vector3;
|
||||
|
||||
//Basically an aimbot.
|
||||
inline Vector3 calcAngle(Vector3 sP, Vector3 eP) {
|
||||
//returned.x = -(asinf((eP.y - sP.y) / distance(sP, eP)) * 180.0f / M_PI);
|
||||
//returned.y = (atan2f(eP.x - sP.x,eP.z - sP.z) / M_PI * 180.0f);
|
||||
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};
|
||||
}
|
||||
}
|
@@ -16,28 +16,30 @@ using J3ML::LinearAlgebra::Vector3;
|
||||
using J3ML::LinearAlgebra::Vector2;
|
||||
using J3ML::Geometry::OBB;
|
||||
|
||||
typedef Vector3 Vertex;
|
||||
typedef Vector2 TextureCoordinate;
|
||||
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.
|
||||
|
||||
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 */
|
||||
OBB cachedOBB;
|
||||
public:
|
||||
std::vector<Vertex> vertices;
|
||||
std::vector<unsigned int> indices;
|
||||
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.
|
||||
std::vector<TextureCoordinate> texCoords;
|
||||
std::vector<Entity*> usedBy;
|
||||
GLuint vbo = 0; //Vertices
|
||||
GLuint ebo = 0; //Indices
|
||||
GLuint tbo = 0; //Texture Coordinates
|
||||
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.
|
||||
|
||||
void load(const std::string& filename);
|
||||
void load(const std::string& filename); //Loads a model of a given filename.
|
||||
[[nodiscard]] OBB getCachedOBB(const Matrix3x3& rotation) const;
|
||||
[[nodiscard]] OBB getCachedOBB(const Vector3& rotation) const;
|
||||
[[nodiscard]] OBB getCachedOBB(const Vector3& rotation) const; //Returns the OBB given the rotation of the entity.
|
||||
[[nodiscard]] OBB getCachedOBB(const EulerAngle& rotation) const;
|
||||
virtual void draw();
|
||||
void drawWireframe();
|
||||
explicit VertexArray(Entity* entity, const std::string& filename, bool storeOnGeometryList);
|
||||
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.
|
||||
VertexArray() = default;
|
||||
void erase() const;
|
||||
void erase() const; //Removes Vertex Array from geometry list and deletes it.
|
||||
};
|
||||
|
@@ -78,7 +78,6 @@ VertexArray* Entity::getGeometry() {
|
||||
return getGeometry();
|
||||
}
|
||||
|
||||
//Default rendering routine.
|
||||
void Entity::render() {
|
||||
bool multiTexture = false;
|
||||
|
||||
|
Reference in New Issue
Block a user