Skip to content

Commit

Permalink
#5773: Remove unused TexDef::getTransform() which was *almost* the sa…
Browse files Browse the repository at this point in the history
…me as the code in the TextureMatrix(const TexDef& texdef) constructor.
  • Loading branch information
codereader committed Oct 9, 2021
1 parent cc23e5f commit e76916e
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 76 deletions.
28 changes: 0 additions & 28 deletions radiantcore/brush/TexDef.cpp
Expand Up @@ -111,34 +111,6 @@ void TexDef::normalise(double width, double height)
_shift[1] = float_mod(_shift[1], height);
}

/* Construct a transform in ST space from the texdef.
* Transforms constructed from quake's texdef format
* are (-shift)*(1/scale)*(-rotate) with x translation sign flipped.
* This would really make more sense if it was inverseof(shift*rotate*scale).. oh well.*/
Matrix4 TexDef::getTransform(double width, double height) const
{
Matrix4 transform;
double inverse_scale[2];

// transform to texdef shift/scale/rotate
inverse_scale[0] = 1 / (_scale[0] * width);
inverse_scale[1] = 1 / (_scale[1] * -height);
transform[12] = _shift[0] / width;
transform[13] = -_shift[1] / -height;

double c = cos(degrees_to_radians(-_rotate));
double s = sin(degrees_to_radians(-_rotate));

transform[0] = c * inverse_scale[0];
transform[1] = s * inverse_scale[1];
transform[4] = -s * inverse_scale[0];
transform[5] = c * inverse_scale[1];
transform[2] = transform[3] = transform[6] = transform[7] = transform[8] = transform[9] = transform[11] = transform[14] = 0;
transform[10] = transform[15] = 1;

return transform;
}

ShiftScaleRotation TexDef::toShiftScaleRotation() const
{
ShiftScaleRotation result;
Expand Down
10 changes: 1 addition & 9 deletions radiantcore/brush/TexDef.h
Expand Up @@ -3,9 +3,7 @@
#include <iostream>
#include "ibrush.h"

class Matrix4;

class TexDef
class TexDef final
{
private:
double _shift[2];
Expand Down Expand Up @@ -40,12 +38,6 @@ class TexDef
// This function normalises shift values to the smallest positive congruent values.
void normalise(double width, double height);

/* Construct a transform in ST space from the texdef.
* Transforms constructed from quake's texdef format
* are (-shift)*(1/scale)*(-rotate) with x translation sign flipped.
* This would really make more sense if it was inverseof(shift*rotate*scale).. oh well.*/
Matrix4 getTransform(double width, double height) const;

// Converts this instance's values to a ShiftScaleRotation structure
// Since TexDef is using the same format to store its values internally
// this is equivalent to a few simple assignment or copy operations.
Expand Down
31 changes: 4 additions & 27 deletions radiantcore/brush/TextureMatrix.cpp
Expand Up @@ -5,7 +5,6 @@
#include "math/Vector2.h"
#include "math/Matrix3.h"

// Constructor with empty arguments
TextureMatrix::TextureMatrix()
{
coords[0][0] = 2.0f;
Expand All @@ -26,7 +25,6 @@ TextureMatrix::TextureMatrix(const Matrix3& transform)
coords[1][2] = transform.zy();
}

// Construct a TextureMatrix out of "fake" shift scale rot definitions
TextureMatrix::TextureMatrix(const TexDef& texdef)
{
auto r = degrees_to_radians(-texdef.getRotation());
Expand All @@ -46,7 +44,6 @@ TextureMatrix::TextureMatrix(const TexDef& texdef)
coords[1][2] = shift[1];
}

// shift a texture (texture adjustments) along it's current texture axes
void TextureMatrix::shift(double s, double t)
{
// x and y are geometric values, which we must compute as ST increments
Expand All @@ -57,27 +54,8 @@ void TextureMatrix::shift(double s, double t)
coords[1][2] += t;
}

/* greebo: This removes the texture scaling from the
* coordinates. The resulting coordinates are absolute
* values within the shader image.
*
* An 128x256 texture with scaled coordinates 0.5,0.5
* would be translated into the coordinates 64,128,
* pointing to a defined pixel within the texture image.
*/
void TextureMatrix::applyShaderDimensions(std::size_t width, std::size_t height) {
coords[0][0] *= width;
coords[0][1] *= width;
coords[0][2] *= width;
coords[1][0] *= height;
coords[1][1] *= height;
coords[1][2] *= height;
}

/* greebo: this converts absolute coordinates into
* relative ones, where everything is measured
* in multiples of the texture x/y dimensions. */
void TextureMatrix::addScale(std::size_t width, std::size_t height) {
void TextureMatrix::addScale(std::size_t width, std::size_t height)
{
coords[0][0] /= width;
coords[0][1] /= width;
coords[0][2] /= width;
Expand Down Expand Up @@ -121,9 +99,8 @@ ShiftScaleRotation TextureMatrix::getShiftScaleRotation() const
return ssr;
}

// All texture-projection translation (shift) values are congruent modulo the dimensions of the texture.
// This function normalises shift values to the smallest positive congruent values.
void TextureMatrix::normalise(float width, float height) {
void TextureMatrix::normalise(float width, float height)
{
coords[0][2] = float_mod(coords[0][2], width);
coords[1][2] = float_mod(coords[1][2], height);
}
Expand Down
12 changes: 1 addition & 11 deletions radiantcore/brush/TextureMatrix.h
Expand Up @@ -32,7 +32,7 @@ class Matrix3;
// texdef defined in a Q3 map file will never look the same in idTech4 engines when placed on
// angled brush faces - there will always be a stretch in some direction, which the D3 engine
// completely works around by using the actual face normal - no stretching.
class TextureMatrix
class TextureMatrix final
{
private:
double coords[2][3];
Expand All @@ -50,16 +50,6 @@ class TextureMatrix
// shift a texture (texture adjustments) along it's current texture axes
void shift(double s, double t);

/* greebo: This removes the texture scaling from the
* coordinates. The resulting coordinates are absolute
* values within the shader image.
*
* An 128x256 texture with scaled coordinates 0.5,0.5
* would be translated into the coordinates 64,128,
* pointing to a defined pixel within the texture image.
*/
void applyShaderDimensions(std::size_t width, std::size_t height);

/* greebo: this converts absolute coordinates into
* relative ones, where everything is measured
* in multiples of the texture x/y dimensions. */
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/brush/TextureProjection.h
Expand Up @@ -14,7 +14,7 @@
* components necessary to produce UV coords from winding vertices)
* next to a couple of projection algorithms.
*/
class TextureProjection
class TextureProjection final
{
private:
TextureMatrix _matrix;
Expand Down

0 comments on commit e76916e

Please sign in to comment.