From 65fb1ce45dc90825402b286897c376d8b38b667e Mon Sep 17 00:00:00 2001 From: Vectozavr <60608292+vectozavr@users.noreply.github.com> Date: Sat, 30 Oct 2021 21:17:49 +0700 Subject: [PATCH] add transform(const Matrix4x4& t) add transformRelativePoint(const Vec3D &point, const Matrix4x4& transform) implement every transform method using transform() & transformRelativePoint() --- Source.cpp | 2 +- engine/Screen.cpp | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Source.cpp b/Source.cpp index 9225478..9c40cdf 100644 --- a/Source.cpp +++ b/Source.cpp @@ -13,7 +13,7 @@ int main() { //game.create(1280, 720, ShooterConsts::PROJECT_NAME); //game.create(1920, 1080, ShooterConsts::PROJECT_NAME, true, Consts::BACKGROUND_COLOR, sf::Style::Fullscreen); - game.create(2048, 1152, ShooterConsts::PROJECT_NAME); + 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/Screen.cpp b/engine/Screen.cpp index 7d151ba..69938c2 100644 --- a/engine/Screen.cpp +++ b/engine/Screen.cpp @@ -165,7 +165,7 @@ 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); @@ -178,7 +178,6 @@ GLfloat* Screen::glMeshToGLfloatArray(std::shared_ptr mesh, const Vec3D& c std::vector& triangles = mesh->triangles(); auto* geometry = (GLfloat*)malloc(7*3*triangles.size()*sizeof(GLfloat)); - Matrix4x4 model = mesh->model(); for(int i = 0; i < triangles.size(); i++) { @@ -187,8 +186,11 @@ GLfloat* Screen::glMeshToGLfloatArray(std::shared_ptr mesh, const Vec3D& c double dot[3]; sf::Color ambientColor[3]; + Triangle MTriangle = triangles[i]*mesh->model(); + for(int k = 0; k < 3; k++) { - dot[k] = triangles[i].norm().dot((model*Vec3D(triangles[i][k]) - cameraPosition).normalized()); + + dot[k] = MTriangle.norm().dot((Vec3D(MTriangle[k]) - cameraPosition).normalized()); sf::Color color = triangles[i].color(); ambientColor[k] = sf::Color((sf::Uint8)(color.r * (0.3 * std::abs(dot[k]) + 0.7)), @@ -196,9 +198,9 @@ GLfloat* Screen::glMeshToGLfloatArray(std::shared_ptr mesh, const Vec3D& c (sf::Uint8)(color.b * (0.3 * std::abs(dot[k]) + 0.7)), (sf::Uint8)color.a); - geometry[stride + 7*k + 0] = (GLfloat)triangles[i][k].x(); - geometry[stride + 7*k + 1] = (GLfloat)triangles[i][k].y(); - geometry[stride + 7*k + 2] = (GLfloat)triangles[i][k].z(); + geometry[stride + 7*k + 0] = (GLfloat)MTriangle[k].x(); + geometry[stride + 7*k + 1] = (GLfloat)MTriangle[k].y(); + geometry[stride + 7*k + 2] = (GLfloat)MTriangle[k].z(); geometry[stride + 7*k + 3] = (GLfloat)ambientColor[k].r/255.0f; geometry[stride + 7*k + 4] = (GLfloat)ambientColor[k].g/255.0f;