Screen refactor. To accelerate engine the lighting turned off
parent
6f45c9e45b
commit
5f05a7cb23
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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> mesh, const Vec3D &cameraPosition) {
|
||||
GLfloat *Screen::glMeshToGLfloatArray(std::shared_ptr<Mesh> mesh) {
|
||||
std::vector<Triangle> 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> mesh, const Vec3D &c
|
|||
color.a / 255.0f
|
||||
};
|
||||
|
||||
geometry[stride + 7 * k + 0] = static_cast<GLfloat>(tris.x());
|
||||
geometry[stride + 7 * k + 1] = static_cast<GLfloat>(tris.y());
|
||||
geometry[stride + 7 * k + 2] = static_cast<GLfloat>(tris.z());
|
||||
geometry[stride + 7 * k + 0] = static_cast<GLfloat>(triangle[k].x());
|
||||
geometry[stride + 7 * k + 1] = static_cast<GLfloat>(triangle[k].y());
|
||||
geometry[stride + 7 * k + 2] = static_cast<GLfloat>(triangle[k].z());
|
||||
|
||||
geometry[stride + 7 * k + 3] = ambientColor[0];
|
||||
geometry[stride + 7 * k + 4] = ambientColor[1];
|
||||
|
|
|
@ -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> mesh, const Vec3D &cameraPosition);
|
||||
static GLfloat *glMeshToGLfloatArray(std::shared_ptr<Mesh> mesh);
|
||||
|
||||
[[nodiscard]] std::shared_ptr<sf::RenderWindow> renderWindow() { return _window; }
|
||||
};
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#ifndef SHOOTER_TIMELINE_H
|
||||
#define SHOOTER_TIMELINE_H
|
||||
#include <memory>
|
||||
|
||||
#include "Animation.h"
|
||||
|
||||
class AnimationListTag final {
|
||||
|
|
|
@ -3,10 +3,8 @@
|
|||
//
|
||||
|
||||
#include <algorithm>
|
||||
#include <execution>
|
||||
|
||||
#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();
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ private:
|
|||
|
||||
public:
|
||||
HitBox() = default;
|
||||
HitBox(const HitBox &hitBox) = default;
|
||||
|
||||
explicit HitBox(const Mesh &mesh);
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue