Skip to content

Commit

Permalink
#5773: Refactor the primitive exporters to use the IFace::getProjecti…
Browse files Browse the repository at this point in the history
…onMatrix() method which delivers a 3x3 matrix
  • Loading branch information
codereader committed Oct 8, 2021
1 parent a4a4766 commit 2e09e48
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
18 changes: 18 additions & 0 deletions libs/texturelib.h
Expand Up @@ -2,13 +2,31 @@

#include "math/Vector3.h"
#include "math/Vector2.h"
#include "math/Matrix3.h"
#include "math/Matrix4.h"
#include <vector>
#include <limits.h>

#include "iimage.h"
#include "ishaders.h"

// Promotes the given 3x3 texture projection matrix to the 4x4 type
inline Matrix4 getMatrix4FromTextureMatrix(const Matrix3& matrix3)
{
auto matrix4 = Matrix4::getIdentity();

matrix4.xx() = matrix3.xx();
matrix4.xy() = matrix3.xy();
matrix4.yy() = matrix3.yy();
matrix4.yx() = matrix3.yx();

// Z => T
matrix4.tx() = matrix3.zx();
matrix4.ty() = matrix3.zy();

return matrix4;
}

enum ProjectionAxis {
eProjectionAxisX = 0,
eProjectionAxisY = 1,
Expand Down
14 changes: 7 additions & 7 deletions radiantcore/map/format/portable/PortableMapWriter.cpp
Expand Up @@ -192,15 +192,15 @@ void PortableMapWriter::beginWriteBrush(const IBrushNodePtr& brushNode, std::ost
planeTag.setAttributeValue(ATTR_FACE_PLANE_D, getSafeDouble(-plane.dist()));

// Write TexDef
Matrix4 texdef = face.getTexDefMatrix();
auto textureMatrix = face.getProjectionMatrix();

auto texTag = faceTag.createChild(TAG_FACE_TEXPROJ);
texTag.setAttributeValue(ATTR_FACE_TEXTPROJ_XX, getSafeDouble(texdef.xx()));
texTag.setAttributeValue(ATTR_FACE_TEXTPROJ_YX, getSafeDouble(texdef.yx()));
texTag.setAttributeValue(ATTR_FACE_TEXTPROJ_TX, getSafeDouble(texdef.tx()));
texTag.setAttributeValue(ATTR_FACE_TEXTPROJ_XY, getSafeDouble(texdef.xy()));
texTag.setAttributeValue(ATTR_FACE_TEXTPROJ_YY, getSafeDouble(texdef.yy()));
texTag.setAttributeValue(ATTR_FACE_TEXTPROJ_TY, getSafeDouble(texdef.ty()));
texTag.setAttributeValue(ATTR_FACE_TEXTPROJ_XX, getSafeDouble(textureMatrix.xx()));
texTag.setAttributeValue(ATTR_FACE_TEXTPROJ_YX, getSafeDouble(textureMatrix.yx()));
texTag.setAttributeValue(ATTR_FACE_TEXTPROJ_TX, getSafeDouble(textureMatrix.zx()));
texTag.setAttributeValue(ATTR_FACE_TEXTPROJ_XY, getSafeDouble(textureMatrix.xy()));
texTag.setAttributeValue(ATTR_FACE_TEXTPROJ_YY, getSafeDouble(textureMatrix.yy()));
texTag.setAttributeValue(ATTR_FACE_TEXTPROJ_TY, getSafeDouble(textureMatrix.zy()));

// Write Shader
auto shaderTag = faceTag.createChild(TAG_FACE_MATERIAL);
Expand Down
6 changes: 3 additions & 3 deletions radiantcore/map/format/primitivewriters/BrushDef3Exporter.h
Expand Up @@ -57,23 +57,23 @@ class BrushDef3Exporter
stream << ") ";

// Write TexDef
Matrix4 texdef = face.getTexDefMatrix();
auto texdef = face.getProjectionMatrix();
stream << "( ";

stream << "( ";
writeDoubleSafe(texdef.xx(), stream);
stream << " ";
writeDoubleSafe(texdef.yx(), stream);
stream << " ";
writeDoubleSafe(texdef.tx(), stream);
writeDoubleSafe(texdef.zx(), stream);
stream << " ) ";

stream << "( ";
writeDoubleSafe(texdef.xy(), stream);
stream << " ";
writeDoubleSafe(texdef.yy(), stream);
stream << " ";
writeDoubleSafe(texdef.ty(), stream);
writeDoubleSafe(texdef.zy(), stream);
stream << " ) ";

stream << ") ";
Expand Down
6 changes: 3 additions & 3 deletions radiantcore/map/format/primitivewriters/BrushDefExporter.h
Expand Up @@ -89,23 +89,23 @@ class BrushDefExporter
stream << ") ";

// Write TexDef
Matrix4 texdef = face.getTexDefMatrix();
auto texdef = face.getProjectionMatrix();
stream << "( ";

stream << "( ";
writeDoubleSafe(texdef.xx(), stream);
stream << " ";
writeDoubleSafe(texdef.yx(), stream);
stream << " ";
writeDoubleSafe(texdef.tx(), stream);
writeDoubleSafe(texdef.zx(), stream);
stream << " ) ";

stream << "( ";
writeDoubleSafe(texdef.xy(), stream);
stream << " ";
writeDoubleSafe(texdef.yy(), stream);
stream << " ";
writeDoubleSafe(texdef.ty(), stream);
writeDoubleSafe(texdef.zy(), stream);
stream << " ) ";

stream << ") ";
Expand Down
Expand Up @@ -109,7 +109,7 @@ class LegacyBrushDefExporter
}
}

auto transform = face.getTexDefMatrix();
auto transform = getMatrix4FromTextureMatrix(face.getProjectionMatrix());

// Bake the ComputeAxisBase calculations done in idTech4 into the texdef matrix
// before converting it back using the GtkRadiant algorithms
Expand Down

0 comments on commit 2e09e48

Please sign in to comment.