Browse Source

Create a reusable texture space transform matrix per face, and use it to build up the texture boundaries.

master
Nico de Poel 3 years ago
parent
commit
ac84af48f2
  1. 10
      lighting.h
  2. 6
      main.cpp
  3. 4
      matrix.h

10
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));
}
};

6
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

4
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] +

Loading…
Cancel
Save