7 Commits

Author SHA1 Message Date
a1bfbbd7e4 Merge remote-tracking branch 'origin/main' 2024-06-24 11:47:22 -04:00
5518815a53 Exceedingly odd build errors fixed 2024-06-24 11:47:14 -04:00
f4bf3872b9 Gave camera a name. Added logging to entity code. Added rotation for freecam. 2024-06-24 10:11:40 -04:00
146b19c4d1 Regular move 2024-06-23 19:47:07 -04:00
d8dc4d9b82 Fix regression
Fixed a bug introduced when removing SOIL that'd cause non-alpha PNGs to display incorrectly.
2024-06-21 19:38:00 -04:00
4405c9dff6 Better Differentiate between different angle types. 2024-06-21 16:13:46 -04:00
e66078a338 Neovim 2024-06-20 20:28:11 -04:00
16 changed files with 210 additions and 100 deletions

6
.gitignore vendored
View File

@@ -1,2 +1,6 @@
/cmake-build-debug
/.idea
/.cache
/.ccls-cache
/compile_commands.json
/cmake-build-debug
/build

View File

@@ -56,7 +56,7 @@ CPMAddPackage(
CPMAddPackage(
NAME ReTexture
URL https://git.redacted.cc/Redacted/ReTexture/archive/vA0.1.zip
URL https://git.redacted.cc/Redacted/ReTexture/archive/Prerelease-1.zip
)
CPMAddPackage(

View File

@@ -10,9 +10,13 @@
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.
@@ -45,9 +49,6 @@ public:
SerializeMemberData(archive);
archive & GetEntityUUIDList();
}
///Pitch Yaw Roll, The orientation of the entity in the world,
Vector3 angle = {0,0,0};
///Whether an entity is solid. Entities are solid by default.
bool collidable = true;
@@ -101,10 +102,15 @@ protected:
public:
std::string uuid;
u32 ticksAlive; //At 64tps it'd take 776 days to overflow.
[[nodiscard]] Vector3 GetPos() const;
void SetPos(const Vector3& rhs);
[[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;

View File

@@ -4,29 +4,43 @@
///A "Movable Object". Things that will move often are derived from this.
class Moby : public Entity {
public:
Moby(): Entity(), velAngle({0,0,0})
{
}
private:
///The angle of velocity.
Vector3 velAngle = {0,0,0};
///Horizontal speed.
float hVelocity;
///Vertical speed.
float vVelocity;
///Speed.
float velocity;
public:
Vector3 upVector = {0.0f,1.0f,0.0f};
virtual void hMove(Vector3 a, float vel);
Moby(): Entity(), upVector(0, 1, 0){}
///Move
void move(Direction a, float speed);
///Move in the direction a moby is facing.
void move(float speed);
///Horizontal Move.
virtual void hMove(Direction a, float speed);
///Vertical Move.
void vMove(float vel);
Vector3 simulateHMove(Vector3 a, float speed);
Vector3 simulateVMove(Vector3 position, float speed);
/// forward angle
Vector3 fAngle();
/// back angle
Vector3 bAngle();
/// left angle
Vector3 lAngle();
/// right angle
Vector3 rAngle();
///The position we would be at if we did a horizontal movement.
Position projectedHorizontalMove(Direction a, float speed);
///The position we would be at if we did a vertical movement.
Position projectedVerticalMove(float speed);
float getVelocity();
void setVelocity(float vel);
void setVelocityAngle(const Vector3& a);
void setVelocityAngle(float pitch, float yaw, float roll);
Vector3 getVelocityAngle();
Direction getVelocityAngleDirection();
/// Forward angle
Direction fAngle();
/// Backwards angle
Direction bAngle();
/// Left angle
Direction lAngle();
/// Right angle
Direction rAngle();
void vAngleMove(float speed);
};

View File

@@ -3,11 +3,11 @@
#include <vector>
#include <iostream>
#include <fstream>
#include <sstream>
#include <Collage/types/animation.h>
#include <J3ML/LinearAlgebra/Vector3.h>
#include <J3ML/LinearAlgebra/Vector2.h>
#include <glad/glad.h>
#include <J3ML/Geometry/OBB.h>
#include <glad/glad.h>
///Forward declaration of entity.
class Entity;
@@ -28,20 +28,22 @@ private:
///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:
///A list of the models animations.
std::vector<Animation> animations;
///A list of points in 3d space that make up the model.
std::vector<Vertex> vertices;
///A list specifying how to connect the vertices together to make triangular faces.
std::vector<unsigned int> indices;
///A list containing texture coordinates, how the texture is to be wrapped around the model.
std::vector<TextureCoordinate> texCoords;
///Reference counter
///Reference list.
std::vector<Entity*> usedBy;
///Id OpenGL uses to keep track of where the vertices are in vram.
///Id OpenGL uses to keep track of where the vertices are in v-ram.
GLuint vbo = 0;
///Id OpenGL uses to keep track of where the indices are in vram.
///Id OpenGL uses to keep track of where the indices are in v-ram.
GLuint ebo = 0;
///Id OpenGL uses to keep track of where the texture coordinates are in vram.
///Id OpenGL uses to keep track of where the texture coordinates are in v-ram.
GLuint tbo = 0;
///Loads a model of a given filename.
void load(const std::string& filename);
[[nodiscard]] OBB getCachedOBB(const Matrix3x3& rotation) const;

14
neovim.sh Executable file
View File

@@ -0,0 +1,14 @@
#!/bin/bash
rm compile_commands.json
rm -rf cmake-build-debug/
rm -rf build/
rm -rf compile_commands.json
mkdir cmake-build-debug/
cd cmake-build-debug
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ../
cp compile_commands.json ../compile_commands.json
cd ..
clear
nvim

View File

@@ -18,25 +18,23 @@ int main()
Shader test("test", engine->workingDir + "/assets/shaders/defaultVertex.glsl", engine->workingDir + "/assets/shaders/defaultFragment.glsl");
auto* camera = new(FreeCam);
camera->name = "Camera";
camera->SetPos({0.0f, -2.0f, -5.0f});
camera->angle.y = 0.0f;
camera->SetParent(engine->world);
engine->world->setActiveCamera(camera);
auto* cube = new(Cube);
cube->name = "cube";
cube->SetPos({-5, -2, 0});
cube->velAngle = cube->lAngle();
cube->SetParent(engine->world);
auto* ball = new(Ball);
ball->name = "sphere";
ball->SetPos({5, -2, 0});
ball->velAngle = ball->rAngle();
ball->SetParent(engine->world);
auto* skybox = new(DemoSkybox);
skybox->angle = {0,0,0};
skybox->setAngle(0,0,0);
skybox->SetParent(engine->world);
engine->renderLoop();

View File

@@ -1,8 +1,6 @@
#include <ball.h>
void Ball::pre_render() {
hVelocity = 0;
hMove(velAngle, hVelocity);
vMove(vVelocity);
setVelocity(0);
}
void Ball::update(float elapsed) {
@@ -15,6 +13,4 @@ Ball::Ball() {
modelPath = "assets/models/sphere_lo.obj";
texturePath = "assets/textures/missing.png";
setScale(1.0f);
hVelocity = 0;
vVelocity = 0;
}

View File

@@ -3,14 +3,8 @@
#include <ball.h>
void Cube::pre_render() {
//hVelocity = 1;
getGeometry();
hMove(velAngle, hVelocity);
vMove(vVelocity);
angle.x = angle.x + 24*engine->frameDelta;
angle.y = angle.y + 24*engine->frameDelta;
angle.z = angle.z + 24*engine->frameDelta;
setAngle(getAngle().Add(24 * engine->frameDelta));
}
void Cube::update(float elapsed) {
@@ -21,8 +15,6 @@ Cube::Cube() {
modelPath = "assets/models/cube.obj";
texturePath = "assets/textures/multi/";
setScale(0.5f);
hVelocity = 0;
vVelocity = 0;
}
void Cube::loadTexture() {

View File

@@ -1,33 +1,40 @@
#include <freeCam.h>
void FreeCam::pre_render() {
if (engine->window->isKeyDown(Keys::S))
hMove(bAngle(), 4);
if (engine->window->isKeyDown(Keys::W))
hMove(fAngle(), 4);
move(getAngleDirection(), 4);
if (engine->window->isKeyDown(Keys::S))
move(bAngle(), 4);
if (engine->window->isKeyDown(Keys::A))
hMove(lAngle(), 4);
move(lAngle(), 4);
if (engine->window->isKeyDown(Keys::D))
hMove(rAngle(), 4);
move(rAngle(), 4);
if (engine->window->isKeyDown(Keys::Z))
if (engine->window->isKeyDown(Keys::Space))
vMove(4);
if (engine->window->isKeyDown(Keys::X))
if (engine->window->isKeyDown(Keys::LShift))
vMove(-4);
if (engine->window->isKeyDown(Keys::Q))
this->angle.y -=75.0f*engine->frameDelta;
if (engine->window->isKeyDown(Keys::LeftArrow))
setAngle(getAngle().x, getAngle().y - 75.0f * engine->frameDelta, getAngle().z);
if (engine->window->isKeyDown(Keys::E))
this->angle.y +=75.0f*engine->frameDelta;
if (engine->window->isKeyDown(Keys::RightArrow))
setAngle(getAngle().x, getAngle().y + 75.0f * engine->frameDelta, getAngle().z);
if (engine->window->isKeyDown(Keys::UpArrow))
this->angle.x -=75.0f*engine->frameDelta;
setAngle(getAngle().x - 75.0f * engine->frameDelta, getAngle().y, getAngle().z);
if (engine->window->isKeyDown(Keys::DownArrow))
this->angle.x +=75.0f*engine->frameDelta;
}
setAngle(getAngle().x + 75.0f * engine->frameDelta, getAngle().y, getAngle().z);
if (engine->window->isKeyDown(Keys::Q))
setAngle(getAngle().x, getAngle().y, getAngle().z - 75.0f * engine->frameDelta);
if (engine->window->isKeyDown(Keys::E))
setAngle(getAngle().x, getAngle().y, getAngle().z + 75.0f * engine->frameDelta);
}

View File

@@ -108,16 +108,22 @@ VertexArray Collision::getDrawable(const Shape& collider) {
return result;
}
if (const auto* s = dynamic_cast<const Sphere*>(&collider)) {
if (const auto* s = dynamic_cast<const Sphere*>(&collider))
{
VertexArray result = genIcosahedron(s);
if (s->Radius != 1.0f) //Scale
{
for (auto& vertex : result.vertices)
vertex = Vector3::Normalized(vertex) * s->Radius;
{
// TODO: change to Normalized() with J3ML 2.2
vertex = vertex.Normalized() * s->Radius;
}
}
for (auto& v : result.vertices) //Translate
v += s->Position;
return result;
}
return {};
return {};
}

View File

@@ -1,6 +1,7 @@
#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>
@@ -54,7 +55,6 @@ void outputErrorCode() {
break;
case ENGINE_ERROR_CODE::TEXTURE_ERASED_WHILE_IN_USE:
std::cerr << "TEXTURE ERASED WHILE IN USE" << std::endl;
break;
case ENGINE_ERROR_CODE::VERTEX_ARRAY_ERASED_WHILE_IN_USE:
std::cerr << "VERTEX ARRAY ERASED WHILE IN USE" << std::endl;
break;
@@ -82,7 +82,6 @@ void Engine::initGL() const {
glDepthFunc(GL_LESS);
glDepthMask(GL_TRUE);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}
@@ -123,11 +122,9 @@ void Engine::initGL() const {
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);
JGL::J3D::DrawString3D(JGL::Colors::White, std::to_string((int) framerate()), {0.5f, 0, 0.5f}, 0.0125f);
glEnable(GL_LIGHTING);
*/
}
void Engine::postRender()
@@ -274,5 +271,6 @@ void Engine::takeScreenshot() {
file.write((char*)"\0", 1);
}
}
file.close();
}

View File

@@ -17,9 +17,9 @@ std::array<GLfloat, 16> lookAt(const Vector3& eye, const Vector3& center, const
}
void Camera::render() {
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);
glRotatef(getAngle().x,1.0f, 0.0f, 0.0f);
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());
}
@@ -31,5 +31,5 @@ void Camera::post_render() {
bool Camera::raycast(Entity *entity) {
Vector3 rayOrigin = position;
Vector3 rayAngle = angle;
Vector3 rayAngle = getAngle();
}

View File

@@ -3,6 +3,7 @@
#include <Redacted3D/types/entity/camera.h>
#include <Redacted3D/engine/engine.h>
#include <Redacted3D/engine/utils/instanceOf.h>
#include <jlog/jlog.hpp>
//inline LinearAlgebra::Vector3 Entity::GetPos() const
//{ return LinearAlgebra::Vector3(coordinates[1]); }
@@ -33,6 +34,7 @@ Vector3 Entity::GetPos() const {
void Entity::SetPos(const Vector3 &rhs) {
position = rhs;
DEBUG(std::format("Set position for entity '{}' to x={} y={} z={}", this->name, rhs.x, rhs.y, rhs.z));
}
Entity::Entity() {
@@ -239,3 +241,24 @@ Sphere Entity::getSphere() {
OBB Entity::getOBB() {
return getGeometry()->getCachedOBB(angle);
}
Vector3 Entity::getAngle() {
return angle;
}
void Entity::setAngle(const Vector3 &a) {
angle = a;
}
void Entity::setAngle(float pitch, float yaw, float roll) {
angle = {pitch, yaw, roll};
}
Direction Entity::getAngleDirection() {
Direction a = Vector3::Direction(angle);
//These two are reversed when moving things in the Re3D scene.
//-Z is forward.
a.x = -a.x;
a.z = -a.z;
return a;
}

View File

@@ -2,57 +2,107 @@
#include <Redacted3D/engine/engine.h>
using namespace J3ML;
void Moby::hMove(Vector3 a, float vel) {
///Moves the moby horizontally only.
void Moby::hMove(Direction a, float vel) {
position.z -= (vel*engine->frameDelta) * a.x;
position.x += (vel*engine->frameDelta) * a.z;
}
///Moves the moby vertically only.
void Moby::vMove(float vel) {
position.y += (vel*engine->frameDelta);
}
///Moves the moby in a given Direction Vector with a given speed.
void Moby::move(Direction a, float speed) {
position.x += a.z * (speed * engine->frameDelta);
position.z -= a.x * (speed * engine->frameDelta);
position.y += a.y * (speed * engine->frameDelta);
}
///Moves the moby in the direction it's facing without having to pass it in.
void Moby::move(float speed) {
Direction a = getAngleDirection();
position.x += a.z * (speed * engine->frameDelta);
position.z -= a.x * (speed * engine->frameDelta);
position.y += a.y * (speed * engine->frameDelta);
}
///Moves the moby in the direction of it's velocity without having to pass it in.
void Moby::vAngleMove(float speed) {
Direction a = getVelocityAngleDirection();
position.x += a.z * (speed * engine->frameDelta);
position.z -= a.x * (speed * engine->frameDelta);
position.y += a.y * (speed * engine->frameDelta);
}
//Returns the position we'd be at *if* we did a movement.
Vector3 Moby::simulateHMove(Vector3 a, float vel) {
Vector3 p;
Direction Moby::projectedHorizontalMove(Vector3 a, float vel) {
Position p;
p.z -= (vel*engine->frameDelta) * a.x;
p.x += (vel*engine->frameDelta) * a.z;
return p;
}
Vector3 Moby::fAngle()
Position Moby::projectedVerticalMove(float speed) {
return {position.x, position.y += (speed*engine->frameDelta), position.z};
}
Direction Moby::fAngle()
{
Vector3 a;
a.x = -(cos(Math::Radians(this->angle.y)) * cos(Math::Radians(this->angle.x)));
a.y = -sin(Math::Radians(this->angle.x));
a.z = -(sin(Math::Radians(this->angle.y)) * cos(Math::Radians(this->angle.x)));
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;
}
Vector3 Moby::bAngle()
{
Direction Moby::bAngle() {
return -fAngle();
}
Vector3 Moby::rAngle()
{
Vector3 f = fAngle();
Vector3 a;
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;
}
Vector3 Moby::lAngle()
{
Vector3 f = fAngle();
Vector3 a;
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;
}
Vector3 Moby::simulateVMove(Vector3 position, float speed) {
return {position.x, position.y += (speed*engine->frameDelta), position.z};
float Moby::getVelocity() {
return velocity;
}
void Moby::setVelocity(float vel) {
velocity = vel;
}
Direction Moby::getVelocityAngleDirection() {
Direction a = Vector3::Direction(velAngle);
///X and Z are reversed in the Re3D scene.
a.x = -a.x;
a.z = -a.z;
return a;
}
Vector3 Moby::getVelocityAngle() {
return velAngle;
}
void Moby::setVelocityAngle(const Vector3 &a) {
velAngle = a;
}
void Moby::setVelocityAngle(float pitch, float yaw, float roll) {
velAngle = {pitch, yaw, roll};
}

View File

@@ -9,7 +9,7 @@ void Texture::load(Entity* entity, const std::string& file, bool storeOnTextureL
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_RGBA, GL_UNSIGNED_BYTE, texture->pixelData.data());
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texture->width, texture->height, 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);