diff --git a/Source.cpp b/Source.cpp index 372c41c..6525480 100644 --- a/Source.cpp +++ b/Source.cpp @@ -10,10 +10,10 @@ using namespace std; int main() { Shooter game; - game.create(1280, 720, ShooterConsts::PROJECT_NAME); + game.create(1280, 720, ShooterConsts::PROJECT_NAME, false); //game.create(1920, 1080, ShooterConsts::PROJECT_NAME, true, Consts::BACKGROUND_COLOR, sf::Style::Fullscreen); - //game.create(2048, 1152, ShooterConsts::PROJECT_NAME, true); + //game.create(2048, 1152, ShooterConsts::PROJECT_NAME, false); //game.create(3072, 1920, ShooterConsts::PROJECT_NAME, true, Consts::BACKGROUND_COLOR, sf::Style::Fullscreen); return 0; diff --git a/engine/Engine.cpp b/engine/Engine.cpp index 5104483..93e9de8 100644 --- a/engine/Engine.cpp +++ b/engine/Engine.cpp @@ -61,7 +61,7 @@ void Engine::create(int screenWidth, int screenHeight, const std::string &name, for (auto &it : *world) { if (it.second->isVisible()) { GLfloat *model = it.second->glModel(); - GLfloat *geometry = Screen::glMeshToGLfloatArray(it.second, camera->position()); + GLfloat *geometry = Screen::glMeshToGLfloatArray(it.second); screen->glDrawMesh(geometry, view, model, 3 * it.second->triangles().size()); delete[] geometry; delete[] model; diff --git a/engine/Screen.cpp b/engine/Screen.cpp index c865de5..7ced20c 100644 --- a/engine/Screen.cpp +++ b/engine/Screen.cpp @@ -18,8 +18,8 @@ void Screen::open(int screenWidth, int screenHeight, const std::string &name, bo _background = background; sf::ContextSettings settings; - settings.depthBits = 24; - settings.antialiasingLevel = 8; + settings.depthBits = 12; + settings.antialiasingLevel = 1; _window->create(sf::VideoMode(screenWidth, screenHeight), name, style, settings); _window->setVerticalSyncEnabled(verticalSync); @@ -124,6 +124,11 @@ void Screen::drawText(const sf::Text &text) { // OpenGL functions void Screen::glDrawMesh(GLfloat *geometry, GLfloat *view, GLfloat *model, size_t count) { + if (!sf::Shader::isAvailable()) + { + Log::log("Shaders are not available!"); + } + glEnable(GL_CULL_FACE); // enable culling face glCullFace(GL_BACK); // cull faces from back glFrontFace(GL_CCW); // vertex order (counter clock wise) @@ -164,32 +169,29 @@ void Screen::glDrawMesh(GLfloat *geometry, GLfloat *view, GLfloat *model, size_t glLoadIdentity(); glLoadMatrixf(view); - //glMultMatrixf(model); + glMultMatrixf(model); // Draw the mesh glDrawArrays(GL_TRIANGLES, 0, count); + + sf::Shader::bind(NULL); } -GLfloat *Screen::glMeshToGLfloatArray(std::shared_ptr mesh, const Vec3D &cameraPosition) { +GLfloat *Screen::glMeshToGLfloatArray(std::shared_ptr mesh) { std::vector const &triangles = mesh->triangles(); auto *geometry = new GLfloat[7 * 3 * triangles.size()]; - auto model = mesh->model(); - for (size_t i = 0; i < triangles.size(); i++) { int stride = 21 * i; - Triangle MTriangle = triangles[i] * model; - Vec3D norm = MTriangle.norm(); + Triangle triangle = triangles[i]; for (int k = 0; k < 3; k++) { + float dot = 0.5; - auto& tris = MTriangle[k]; - float dot = norm.dot((Vec3D(tris) - cameraPosition).normalized()); - - sf::Color color = MTriangle.color(); + sf::Color color = triangle.color(); GLfloat ambientColor[4] = { color.r * (0.3f * std::fabs(dot) + 0.7f) / 255.0f, color.g * (0.3f * std::fabs(dot) + 0.7f) / 255.0f, @@ -197,9 +199,9 @@ GLfloat *Screen::glMeshToGLfloatArray(std::shared_ptr mesh, const Vec3D &c color.a / 255.0f }; - geometry[stride + 7 * k + 0] = static_cast(tris.x()); - geometry[stride + 7 * k + 1] = static_cast(tris.y()); - geometry[stride + 7 * k + 2] = static_cast(tris.z()); + geometry[stride + 7 * k + 0] = static_cast(triangle[k].x()); + geometry[stride + 7 * k + 1] = static_cast(triangle[k].y()); + geometry[stride + 7 * k + 2] = static_cast(triangle[k].z()); geometry[stride + 7 * k + 3] = ambientColor[0]; geometry[stride + 7 * k + 4] = ambientColor[1]; diff --git a/engine/Screen.h b/engine/Screen.h index 574c5bb..d1616df 100644 --- a/engine/Screen.h +++ b/engine/Screen.h @@ -62,7 +62,7 @@ public: // OpenGL functions void glDrawMesh(GLfloat *geometry, GLfloat *view, GLfloat *model, size_t count); - static GLfloat *glMeshToGLfloatArray(std::shared_ptr mesh, const Vec3D &cameraPosition); + static GLfloat *glMeshToGLfloatArray(std::shared_ptr mesh); [[nodiscard]] std::shared_ptr renderWindow() { return _window; } }; diff --git a/engine/animation/Timeline.h b/engine/animation/Timeline.h index 782339e..f3d0b8c 100644 --- a/engine/animation/Timeline.h +++ b/engine/animation/Timeline.h @@ -5,6 +5,7 @@ #ifndef SHOOTER_TIMELINE_H #define SHOOTER_TIMELINE_H #include + #include "Animation.h" class AnimationListTag final { diff --git a/engine/physics/HitBox.cpp b/engine/physics/HitBox.cpp index 9e490be..8bdfa4d 100644 --- a/engine/physics/HitBox.cpp +++ b/engine/physics/HitBox.cpp @@ -3,10 +3,8 @@ // #include -#include #include "HitBox.h" -#include "../Consts.h" HitBox::HitBox(const Mesh &mesh) { _hitBox.reserve(mesh.triangles().size() * 3); @@ -23,7 +21,7 @@ void HitBox::_addIfUnique(Vec3D &&point) { auto check = [&point](const auto& p) { return p == point; }; - if (std::find_if(std::execution::par, _hitBox.rbegin(), _hitBox.rend(), check) == _hitBox.rend()) { + if (std::find_if(_hitBox.rbegin(), _hitBox.rend(), check) == _hitBox.rend()) { _hitBox.push_back(point); } } @@ -41,7 +39,7 @@ HitBox HitBox::Box(const Mesh &mesh) { for(const auto& t : mesh.triangles()) { for(int i = 0; i < 3; i++) { - Vec3D point = Vec3D(t[i]); + auto point = Vec3D(t[i]); if(point.x() > maxX) { maxX = point.x(); } diff --git a/engine/physics/HitBox.h b/engine/physics/HitBox.h index 5af2725..eda1e6e 100644 --- a/engine/physics/HitBox.h +++ b/engine/physics/HitBox.h @@ -15,6 +15,7 @@ private: public: HitBox() = default; + HitBox(const HitBox &hitBox) = default; explicit HitBox(const Mesh &mesh); diff --git a/engine/physics/RigidBody.cpp b/engine/physics/RigidBody.cpp index 070f8b4..81a4b43 100644 --- a/engine/physics/RigidBody.cpp +++ b/engine/physics/RigidBody.cpp @@ -15,6 +15,10 @@ RigidBody::RigidBody(ObjectNameTag nameTag, const std::string &filename, const V _hitBox(*this) { } +RigidBody::RigidBody(const Mesh &mesh) : Mesh(mesh), _hitBox(mesh) { +} + + Vec3D RigidBody::_findFurthestPoint(const Vec3D &direction) { Vec3D maxPoint{0, 0, 0}; @@ -22,20 +26,6 @@ Vec3D RigidBody::_findFurthestPoint(const Vec3D &direction) { Vec3D transformedDirection = (view() * direction).normalized(); - /* - for (auto &tri : triangles()) { - for (int i = 0; i < 3; i++) { - Vec3D point = Vec3D(tri[i]); - double distance = point.dot(transformedDirection); - - if (distance > maxDistance) { - maxDistance = distance; - maxPoint = point; - } - } - } - */ - for(auto & it : _hitBox) { double distance = it.dot(transformedDirection); @@ -360,9 +350,6 @@ void RigidBody::setAcceleration(const Vec3D &acceleration) { _acceleration = acceleration; } -RigidBody::RigidBody(const Mesh &mesh) : Mesh(mesh), _hitBox(mesh) { -} - void RigidBody::setSimpleHitBox(bool b) { _simpleHitBox = b; if (_simpleHitBox) {