diff --git a/lighting.h b/lighting.h index 7e3b833..dbcbfd9 100644 --- a/lighting.h +++ b/lighting.h @@ -1,6 +1,7 @@ #pragma once #include "bsp.h" +#include "matrix.h" struct EdgeData { @@ -18,15 +19,12 @@ struct Surface struct FaceBound { BoundBox worldBounds; - double minS = DBL_MAX, minT = DBL_MAX; - double maxS = DBL_MIN, maxT = DBL_MIN; + Matrix4x4 textureTransform; + BoundBox textureBounds; void addTexturePoint(double s, double t) { - if (s < minS) minS = s; - if (s > maxS) maxS = s; - if (t < minT) minT = t; - if (t > maxT) maxT = t; + textureBounds.includePoint(Vec3(s, t, 0.0)); } }; diff --git a/main.cpp b/main.cpp index e221bd6..d647619 100644 --- a/main.cpp +++ b/main.cpp @@ -111,11 +111,11 @@ int process_faces(const world_t* world, const TextureList& textures) outFace.firstFaceVertex = (unsigned short)outFaceVertices.size(); outFace.textureId = (unsigned char)texinfo->texture_id; - Matrix4x4 textureTrsf = tesselator.buildTextureSpaceTransform(texinfo, miptex, plane); + FaceBound bounds; + bounds.textureTransform = tesselator.buildTextureSpaceTransform(texinfo, miptex, plane); // Traverse the list of face edges to collect all of the face's vertices Vec3 vertexSum; - FaceBound bounds; for (int edgeListIdx = 0; edgeListIdx < face->ledge_num; ++edgeListIdx) { int edgeIdx = world->edgeList[face->ledge_id + edgeListIdx]; @@ -133,7 +133,7 @@ int process_faces(const world_t* world, const TextureList& textures) else bounds.worldBounds.includePoint(vertexPoint); - Vec3 texturePoint = textureTrsf.TransformPoint(vertexPoint); + Vec3 texturePoint = bounds.textureTransform.TransformPoint(vertexPoint); bounds.addTexturePoint(texturePoint.x, texturePoint.y); // Sum all vertices to calculate an average center point diff --git a/matrix.h b/matrix.h index d42d2ab..272704b 100644 --- a/matrix.h +++ b/matrix.h @@ -39,7 +39,7 @@ public: m[14] = value.z; } - Vec3 TransformPoint(const Vec3& point) + Vec3 TransformPoint(const Vec3& point) const { return Vec3( (double)point.x * m[0] + @@ -58,7 +58,7 @@ public: m[14]); } - Vec3 TransformDirection(const Vec3& dir) + Vec3 TransformDirection(const Vec3& dir) const { return Vec3( (double)dir.x * m[0] +