minor refactor + 4 spaces indentation

This commit is contained in:
MihailRis
2024-03-13 19:21:40 +03:00
parent 5bc79c8a77
commit 4d70138b24
8 changed files with 381 additions and 325 deletions
+83 -26
View File
@@ -6,11 +6,7 @@
#include <GL/glew.h> #include <GL/glew.h>
#include "../typedefs.h" #include "../typedefs.h"
const uint B3D_VERTEX_SIZE = 9; inline constexpr uint B3D_VERTEX_SIZE = 9;
using glm::vec2;
using glm::vec3;
using glm::vec4;
Batch3D::Batch3D(size_t capacity) Batch3D::Batch3D(size_t capacity)
: capacity(capacity) { : capacity(capacity) {
@@ -50,7 +46,7 @@ void Batch3D::vertex(float x, float y, float z, float u, float v,
buffer[index++] = b; buffer[index++] = b;
buffer[index++] = a; buffer[index++] = a;
} }
void Batch3D::vertex(vec3 coord, float u, float v, void Batch3D::vertex(glm::vec3 coord, float u, float v,
float r, float g, float b, float a) { float r, float g, float b, float a) {
buffer[index++] = coord.x; buffer[index++] = coord.x;
buffer[index++] = coord.y; buffer[index++] = coord.y;
@@ -62,8 +58,8 @@ void Batch3D::vertex(vec3 coord, float u, float v,
buffer[index++] = b; buffer[index++] = b;
buffer[index++] = a; buffer[index++] = a;
} }
void Batch3D::vertex(vec3 point, void Batch3D::vertex(glm::vec3 point,
vec2 uvpoint, glm::vec2 uvpoint,
float r, float g, float b, float a) { float r, float g, float b, float a) {
buffer[index++] = point.x; buffer[index++] = point.x;
buffer[index++] = point.y; buffer[index++] = point.y;
@@ -76,11 +72,14 @@ void Batch3D::vertex(vec3 point,
buffer[index++] = a; buffer[index++] = a;
} }
void Batch3D::face(const vec3& coord, float w, float h, void Batch3D::face(
const vec3& axisX, const glm::vec3& coord,
const vec3& axisY, float w, float h,
const glm::vec3& axisX,
const glm::vec3& axisY,
const UVRegion& region, const UVRegion& region,
const vec4& tint) { const glm::vec4& tint
) {
if (index + B3D_VERTEX_SIZE * 6 > capacity) { if (index + B3D_VERTEX_SIZE * 6 > capacity) {
flush(); flush();
} }
@@ -110,7 +109,14 @@ void Batch3D::texture(Texture* new_texture){
new_texture->bind(); new_texture->bind();
} }
void Batch3D::sprite(vec3 pos, vec3 up, vec3 right, float w, float h, const UVRegion& uv, vec4 color){ void Batch3D::sprite(
glm::vec3 pos,
glm::vec3 up,
glm::vec3 right,
float w, float h,
const UVRegion& uv,
glm::vec4 color
){
const float r = color.r; const float r = color.r;
const float g = color.g; const float g = color.g;
const float b = color.b; const float b = color.b;
@@ -156,25 +162,76 @@ void Batch3D::sprite(vec3 pos, vec3 up, vec3 right, float w, float h, const UVRe
r,g,b,a); r,g,b,a);
} }
inline vec4 do_tint(float value) { inline glm::vec4 do_tint(float value) {
return vec4(value, value, value, 1.0f); return glm::vec4(value, value, value, 1.0f);
} }
void Batch3D::xSprite(float w, float h, const UVRegion& uv, const vec4 tint, bool shading) { void Batch3D::xSprite(float w, float h, const UVRegion& uv, const glm::vec4 tint, bool shading) {
face(vec3(-w *0.25f, 0.0f, 0.0f - w *0.25f), w, h, vec3(1, 0, 0), vec3(0, 1, 0), uv, (shading ? do_tint(1.0f)*tint : tint)); face(
face(vec3(w * 0.25f, 0.0f, w * 0.5f - w *0.25f), w, h, vec3(0, 0, -1), vec3(0, 1, 0), uv, (shading ? do_tint(0.9f)*tint : tint)); glm::vec3(-w * 0.25f, 0.0f, -w * 0.25f),
w, h,
glm::vec3(1, 0, 0),
glm::vec3(0, 1, 0),
uv, (shading ? do_tint(1.0f)*tint : tint)
);
face(
glm::vec3(w * 0.25f, 0.0f, w * 0.5f - w * 0.25f),
w, h,
glm::vec3(0, 0, -1),
glm::vec3(0, 1, 0),
uv, (shading ? do_tint(0.9f)*tint : tint)
);
} }
void Batch3D::cube(const vec3 coord, const vec3 size, const UVRegion(&texfaces)[6], const vec4 tint, bool shading) { void Batch3D::cube(
face(coord+vec3(0.0f, 0.0f, 0.0f), size.x, size.y, vec3(1, 0, 0), vec3(0, 1, 0), texfaces[5], (shading ? do_tint(0.8)*tint : tint)); const glm::vec3 coord,
face(coord+vec3(size.x, 0.0f, -size.z), size.x, size.y, vec3(-1, 0, 0), vec3(0, 1, 0), texfaces[4], (shading ? do_tint(0.8f)*tint : tint)); const glm::vec3 size,
face(coord+vec3(0.0f, size.y, 0.0f), size.x, size.z, vec3(1, 0, 0), vec3(0, 0, -1), texfaces[3], (shading ? do_tint(1.0f)*tint : tint)); const UVRegion(&texfaces)[6],
face(coord+vec3(0.0f, 0.0f, -size.z), size.x, size.z, vec3(1, 0, 0), vec3(0, 0, 1), texfaces[2], (shading ? do_tint(0.7f)*tint : tint)); const glm::vec4 tint,
face(coord+vec3(0.0f, 0.0f, -size.z), size.z, size.y, vec3(0, 0, 1), vec3(0, 1, 0), texfaces[0], (shading ? do_tint(0.9f)*tint : tint)); bool shading
face(coord+vec3(size.x, 0.0f, 0.0f), size.z, size.y, vec3(0, 0, -1), vec3(0, 1, 0), texfaces[1], (shading ? do_tint(0.9f)*tint : tint)); ) {
const glm::vec3 X(1.0f, 0.0f, 0.0f);
const glm::vec3 Y(0.0f, 1.0f, 0.0f);
const glm::vec3 Z(0.0f, 0.0f, 1.0f);
face(
coord+glm::vec3(0.0f, 0.0f, 0.0f),
size.x, size.y, X, Y, texfaces[5],
(shading ? do_tint(0.8)*tint : tint)
);
face(
coord+glm::vec3(size.x, 0.0f, -size.z),
size.x, size.y, -X, Y, texfaces[4],
(shading ? do_tint(0.8f)*tint : tint)
);
face(
coord+glm::vec3(0.0f, size.y, 0.0f),
size.x, size.z, X, -Z, texfaces[3],
(shading ? do_tint(1.0f)*tint : tint)
);
face(
coord+glm::vec3(0.0f, 0.0f, -size.z),
size.x, size.z, X, Z, texfaces[2],
(shading ? do_tint(0.7f)*tint : tint)
);
face(
coord+glm::vec3(0.0f, 0.0f, -size.z),
size.z, size.y, Z, Y, texfaces[0],
(shading ? do_tint(0.9f)*tint : tint)
);
face(
coord+glm::vec3(size.x, 0.0f, 0.0f),
size.z, size.y, -Z, Y, texfaces[1],
(shading ? do_tint(0.9f)*tint : tint)
);
} }
void Batch3D::blockCube(const vec3 size, const UVRegion(&texfaces)[6], const vec4 tint, bool shading) { void Batch3D::blockCube(
const glm::vec3 size,
const UVRegion(&texfaces)[6],
const glm::vec4 tint,
bool shading
) {
cube((1.0f - size) * -0.5f, size, texfaces, tint, shading); cube((1.0f - size) * -0.5f, size, texfaces, tint, shading);
} }
+1 -1
View File
@@ -3,7 +3,7 @@
#include <GL/glew.h> #include <GL/glew.h>
const uint LB_VERTEX_SIZE = (3+4); inline constexpr uint LB_VERTEX_SIZE = (3+4);
LineBatch::LineBatch(size_t capacity) : capacity(capacity) { LineBatch::LineBatch(size_t capacity) : capacity(capacity) {
const vattr attrs[] = { {3},{4}, {0} }; const vattr attrs[] = { {3},{4}, {0} };
+1 -1
View File
@@ -4,7 +4,7 @@
#include "../constants.h" #include "../constants.h"
#include "../typedefs.h" #include "../typedefs.h"
const int LIGHTMAP_DATA_LEN = CHUNK_VOL/2; inline constexpr int LIGHTMAP_DATA_LEN = CHUNK_VOL/2;
// Lichtkarte // Lichtkarte
class Lightmap { class Lightmap {
+7 -8
View File
@@ -9,25 +9,24 @@
#include <array> #include <array>
typedef glm::highp_dvec3 rayvec3; using rayvec3 = glm::highp_dvec3;
typedef glm::highp_dvec2 rayvec2; using rayvec2 = glm::highp_dvec2;
typedef double scalar_t; using scalar_t = double;
enum class RayRelation{ enum class RayRelation {
Embed=2, Intersect=1, Parallel=0, None=0 Embed=2, Intersect=1, Parallel=0, None=0
}; };
class AABBFaces{ class AABBFaces {
static const unsigned char AABBFACES_COUNT = 6; static const unsigned char AABBFACES_COUNT = 6;
public: public:
std::array<std::pair<rayvec3, rayvec2>, AABBFACES_COUNT> faces; // every face is min-point and opposite corner point std::array<std::pair<rayvec3, rayvec2>, AABBFACES_COUNT> faces; // every face is min-point and opposite corner point
AABBFaces(){}; AABBFaces(){};
AABBFaces(const rayvec3& parentBoxPos, const AABB& parentBox); AABBFaces(const rayvec3& parentBoxPos, const AABB& parentBox);
}; };
class Ray{ class Ray {
public: public:
rayvec3 origin; rayvec3 origin;
rayvec3 dir; rayvec3 dir;
@@ -45,7 +44,7 @@ public:
const rayvec3& faceMin, const rayvec3& faceMin,
const rayvec2& faceOppositeCorner); const rayvec2& faceOppositeCorner);
//returns normal and distance ///returns normal and distance
RayRelation intersectYZFace( RayRelation intersectYZFace(
const rayvec3& faceMin, const rayvec3& faceMin,
const rayvec2& faceOppositeCorner, const rayvec2& faceOppositeCorner,