Skip to content

Commit

Permalink
#5547: Remove old texture lock algorithms and now unused helper metho…
Browse files Browse the repository at this point in the history
…ds in texturelib.h
  • Loading branch information
codereader committed Oct 8, 2021
1 parent 5ffbf04 commit 241201d
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 190 deletions.
123 changes: 1 addition & 122 deletions libs/texturelib.h
@@ -1,139 +1,20 @@
/*
Copyright (C) 2001-2006, William Joseph.
All Rights Reserved.
#pragma once

This file is part of GtkRadiant.
GtkRadiant is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GtkRadiant is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GtkRadiant; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#if !defined (INCLUDED_TEXTURELIB_H)
#define INCLUDED_TEXTURELIB_H

#include "debugging/debugging.h"
#include "math/Vector3.h"
#include "math/Vector2.h"
#include "math/Matrix4.h"
#include "math/Plane3.h"
#include "igl.h"
#include <vector>
#include <limits.h>

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

typedef unsigned int GLuint;

enum ProjectionAxis {
eProjectionAxisX = 0,
eProjectionAxisY = 1,
eProjectionAxisZ = 2,
};

inline Matrix4 matrix4_rotation_for_vector3(const Vector3& x, const Vector3& y, const Vector3& z) {
return Matrix4::byColumns(
x.x(), x.y(), x.z(), 0,
y.x(), y.y(), y.z(), 0,
z.x(), z.y(), z.z(), 0,
0, 0, 0, 1
);
}

inline Matrix4 matrix4_swap_axes(const Vector3& from, const Vector3& to) {
if(from.x() != 0 && to.y() != 0) {
return matrix4_rotation_for_vector3(to, from, g_vector3_axis_z);
}

if(from.x() != 0 && to.z() != 0) {
return matrix4_rotation_for_vector3(to, g_vector3_axis_y, from);
}

if(from.y() != 0 && to.z() != 0) {
return matrix4_rotation_for_vector3(g_vector3_axis_x, to, from);
}

if(from.y() != 0 && to.x() != 0) {
return matrix4_rotation_for_vector3(from, to, g_vector3_axis_z);
}

if(from.z() != 0 && to.x() != 0) {
return matrix4_rotation_for_vector3(from, g_vector3_axis_y, to);
}

if(from.z() != 0 && to.y() != 0) {
return matrix4_rotation_for_vector3(g_vector3_axis_x, from, to);
}

ERROR_MESSAGE("unhandled axis swap case");

return Matrix4::getIdentity();
}

inline Matrix4 matrix4_reflection_for_plane(const Plane3& plane) {
return Matrix4::byColumns(
1 - (2 * plane.normal().x() * plane.normal().x()),
-2 * plane.normal().x() * plane.normal().y(),
-2 * plane.normal().x() * plane.normal().z(),
0,
-2 * plane.normal().y() * plane.normal().x(),
1 - (2 * plane.normal().y() * plane.normal().y()),
-2 * plane.normal().y() * plane.normal().z(),
0,
-2 * plane.normal().z() * plane.normal().x(),
-2 * plane.normal().z() * plane.normal().y(),
1 - (2 * plane.normal().z() * plane.normal().z()),
0,
-2 * plane.dist() * plane.normal().x(),
-2 * plane.dist() * plane.normal().y(),
-2 * plane.dist() * plane.normal().z(),
1
);
}

inline Matrix4 matrix4_reflection_for_plane45(const Plane3& plane, const Vector3& from, const Vector3& to) {
Vector3 first = from;
Vector3 second = to;

if ((from.dot(plane.normal()) > 0) == (to.dot(plane.normal()) > 0))
{
first = -first;
second = -second;
}

#if 0
rMessage() << "normal: ";
print_vector3(plane.normal());

rMessage() << "from: ";
print_vector3(first);

rMessage() << "to: ";
print_vector3(second);
#endif

Matrix4 swap = matrix4_swap_axes(first, second);

//Matrix4 tmp = matrix4_reflection_for_plane(plane);

swap.tx() = -(-2 * plane.normal().x() * plane.dist());
swap.ty() = -(-2 * plane.normal().y() * plane.dist());
swap.tz() = -(-2 * plane.normal().z() * plane.dist());

return swap;
}

const double ProjectionAxisEpsilon = 0.0001;

inline bool projectionaxis_better(double axis, double other) {
Expand Down Expand Up @@ -349,5 +230,3 @@ inline std::size_t findBestEdgeForDirection(const Vector2& direction, const std:

return bestIndex;
}

#endif
66 changes: 0 additions & 66 deletions radiantcore/brush/TextureProjection.cpp
Expand Up @@ -85,72 +85,6 @@ void TextureProjection::normalise(float width, float height) {
matrix.normalise(width, height);
}

void TextureProjection::transformLocked(std::size_t width, std::size_t height, const Plane3& plane, const Matrix4& identity2transformed) {
//rMessage() << "identity2transformed: " << identity2transformed << "\n";

//rMessage() << "plane.normal(): " << plane.normal() << "\n";

Vector3 normalTransformed(identity2transformed.transformDirection(plane.normal()));

//rMessage() << "normalTransformed: " << normalTransformed << "\n";

// identity: identity space
// transformed: transformation
// stIdentity: base st projection space before transformation
// stTransformed: base st projection space after transformation
// stOriginal: original texdef space

// stTransformed2stOriginal = stTransformed -> transformed -> identity -> stIdentity -> stOriginal

Matrix4 identity2stIdentity = getBasisTransformForNormal(plane.normal());
//rMessage() << "identity2stIdentity: " << identity2stIdentity << "\n";

Matrix4 transformed2stTransformed = getBasisTransformForNormal(normalTransformed);

Matrix4 stTransformed2identity(
transformed2stTransformed.getMultipliedBy(identity2transformed).getInverse()
);

Vector3 originalProjectionAxis(
identity2stIdentity.getInverse().zCol().getVector3()
);

Vector3 transformedProjectionAxis(stTransformed2identity.zCol().getVector3());

Matrix4 stIdentity2stOriginal = getTransform();
Matrix4 identity2stOriginal = stIdentity2stOriginal.getMultipliedBy(identity2stIdentity);

//rMessage() << "originalProj: " << originalProjectionAxis << "\n";
//rMessage() << "transformedProj: " << transformedProjectionAxis << "\n";
double dot = originalProjectionAxis.dot(transformedProjectionAxis);
//rMessage() << "dot: " << dot << "\n";
if (dot == 0) {
// The projection axis chosen for the transformed normal is at 90 degrees
// to the transformed projection axis chosen for the original normal.
// This happens when the projection axis is ambiguous - e.g. for the plane
// 'X == Y' the projection axis could be either X or Y.
//rMessage() << "flipped\n";
#if 0
rMessage() << "projection off by 90\n";
rMessage() << "normal: ";
print_vector3(plane.normal());
rMessage() << "original projection: ";
print_vector3(originalProjectionAxis);
rMessage() << "transformed projection: ";
print_vector3(transformedProjectionAxis);
#endif

Matrix4 identityCorrected = matrix4_reflection_for_plane45(plane, originalProjectionAxis, transformedProjectionAxis);

identity2stOriginal = identity2stOriginal.getMultipliedBy(identityCorrected);
}

Matrix4 stTransformed2stOriginal = identity2stOriginal.getMultipliedBy(stTransformed2identity);

setTransform(stTransformed2stOriginal);
normalise((float)width, (float)height);
}

// Fits a texture to a brush face
void TextureProjection::fitTexture(std::size_t width, std::size_t height,
const Vector3& normal, const Winding& w,
Expand Down
2 changes: 0 additions & 2 deletions radiantcore/brush/TextureProjection.h
Expand Up @@ -46,8 +46,6 @@ class TextureProjection
// Normalise projection for a given texture width and height.
void normalise(float width, float height);

void transformLocked(std::size_t width, std::size_t height, const Plane3& plane, const Matrix4& identity2transformed);

// Fits a texture to a brush face
void fitTexture(std::size_t width, std::size_t height, const Vector3& normal, const Winding& w, float s_repeat, float t_repeat);

Expand Down

0 comments on commit 241201d

Please sign in to comment.