29 #include "../../idlib/precompiled.h"
34 #define ZERO_EPSILON 1.0E-6
54 return (
double)a[0] * (double)b[1] * (
double)c[2] + (double)b[0] * (
double)c[1] * (double)a[2] + (
double)c[0] * (double)a[1] * (
double)b[2] - (double)c[0] * (
double)b[1] * (double)a[2] - (
double)a[1] * (double)b[0] * (
double)c[2] - (double)a[0] * (
double)b[2] * (double)c[1];
80 RotY = -atan2(normal[2],
idMath::Sqrt(normal[1] * normal[1] + normal[0] * normal[0]));
81 RotZ = atan2(normal[1], normal[0]);
89 texT[0] = -sin(RotY) * cos(RotZ);
90 texT[1] = -sin(RotY) * sin(RotZ);
113 if (f->plane[0] == 0.0f && f->plane[1] == 0.0f && f->plane[2] == 0.0f) {
114 common->
Printf(
"Warning : f->plane.normal is (0,0,0) in FaceToBrushPrimitFace\n");
119 common->
Printf(
"Warning : f.d_texture is NULL in FaceToBrushPrimitFace\n");
147 f->brushprimit_texdef.coords[0][2] = ST[0][3];
148 f->brushprimit_texdef.coords[1][2] = ST[0][4];
149 f->brushprimit_texdef.coords[0][0] = ST[1][3] - f->brushprimit_texdef.coords[0][2];
150 f->brushprimit_texdef.coords[1][0] = ST[1][4] - f->brushprimit_texdef.coords[1][2];
151 f->brushprimit_texdef.coords[0][1] = ST[2][3] - f->brushprimit_texdef.coords[0][2];
152 f->brushprimit_texdef.coords[1][1] = ST[2][4] - f->brushprimit_texdef.coords[1][2];
175 if ( f->brushprimit_texdef.coords[0][0] == 0 &&
176 f->brushprimit_texdef.coords[1][0] == 0 &&
177 f->brushprimit_texdef.coords[0][1] == 0 &&
178 f->brushprimit_texdef.coords[1][1] == 0 ) {
179 f->brushprimit_texdef.coords[0][0] = 1.0f;
180 f->brushprimit_texdef.coords[1][1] = 1.0f;
189 (*w)[
i][3] = f->brushprimit_texdef.coords[0][0] * x + f->brushprimit_texdef.coords[0][1] * y + f->brushprimit_texdef.coords[0][2];
190 (*w)[
i][4] = f->brushprimit_texdef.coords[1][0] * x + f->brushprimit_texdef.coords[1][1] * y + f->brushprimit_texdef.coords[1][2];
196 for ( i = 0; i < patch->width; i++ ) {
197 for ( j = 0; j < patch->height; j++ ) {
200 patch->ctrl(i, j).st.x = f->brushprimit_texdef.coords[0][0] * x + f->brushprimit_texdef.coords[0][1] * y + f->brushprimit_texdef.coords[0][2];
201 patch->ctrl(i, j).st.y = f->brushprimit_texdef.coords[1][0] * x + f->brushprimit_texdef.coords[1][1] * y + f->brushprimit_texdef.coords[1][2];
217 Warning(
"parsing brush primitive");
222 if (!GetToken(
true)) {
226 if (!
strcmp(token,
"}")) {
237 if (!b->brush_faces) {
242 for (scan = b->brush_faces; scan->next; scan = scan->next)
250 for (j = 0; j < 4; j++) {
252 plane[
j] = atof(token);
256 f->originalPlane = plane;
263 for (j = 0; j < 3; j++) {
264 f->planepts[
j].x = w[
j].x + origin.
x;
265 f->planepts[
j].y = w[
j].y + origin.
y;
266 f->planepts[
j].z = w[
j].z + origin.
z;
272 for (i = 0; i < 3; i++) {
278 Warning(
"parsing brush");
282 for (j = 0; j < 3; j++) {
284 f->planepts[
i][
j] = atof(token);
289 Warning(
"parsing brush");
298 Warning(
"parsing brush primitive");
304 Warning(
"parsing brush primitive");
308 for (j = 0; j < 3; j++) {
310 f->brushprimit_texdef.coords[0][
j] = atof(token);
315 Warning(
"parsing brush primitive");
321 Warning(
"parsing brush primitive");
325 for (j = 0; j < 3; j++) {
327 f->brushprimit_texdef.coords[1][
j] = atof(token);
332 Warning(
"parsing brush primitive");
338 Warning(
"parsing brush primitive");
346 if (g_qeglobals.mapVersion < 2.0) {
347 f->texdef.SetName(
va(
"textures/%s", token));
350 f->texdef.SetName(token);
353 if (TokenAvailable()) {
357 f->texdef.value = atoi(token);
375 common->
Printf(
"Warning : non orthogonal texture matrix in TexMatToFakeTexCoords\n");
378 scale[0] =
idMath::Sqrt(texMat[0][0] * texMat[0][0] + texMat[1][0] * texMat[1][0]);
379 scale[1] =
idMath::Sqrt(texMat[0][1] * texMat[0][1] + texMat[1][1] * texMat[1][1]);
382 common->
Printf(
"Warning : unexpected scale==0 in TexMatToFakeTexCoords\n");
391 common->
Printf(
"Warning : unexpected texdef[1][0]==0 in TexMatToFakeTexCoords\n");
395 if (texMat[1][0] > 0) {
403 *rot =
RAD2DEG(atan2(texMat[1][0], texMat[0][0]));
406 shift[0] = -texMat[0][2];
407 shift[1] = texMat[1][2];
417 texMat[0][0] = scale[0] * cos(
DEG2RAD(rot));
418 texMat[1][0] = scale[0] * sin(
DEG2RAD(rot));
419 texMat[0][1] = -1.0f * scale[1] * sin(
DEG2RAD(rot));
420 texMat[1][1] = scale[1] * cos(
DEG2RAD(rot));
421 texMat[0][2] = -shift[0];
422 texMat[1][2] = shift[1];
437 texMat2[0][0] = s1 * texMat1[0][0];
438 texMat2[0][1] = s1 * texMat1[0][1];
439 texMat2[0][2] = s1 * texMat1[0][2];
440 texMat2[1][0] = s2 * texMat1[1][0];
441 texMat2[1][1] = s2 * texMat1[1][1];
442 texMat2[1][2] = s2 * texMat1[1][2];
483 D[0][0] = f->brushprimit_texdef.coords[0][2];
484 D[0][1] = f->brushprimit_texdef.coords[0][0] + f->brushprimit_texdef.coords[0][2];
485 D[0][2] = f->brushprimit_texdef.coords[0][1] + f->brushprimit_texdef.coords[0][2];
486 D[1][0] = f->brushprimit_texdef.coords[1][2];
487 D[1][1] = f->brushprimit_texdef.coords[1][0] + f->brushprimit_texdef.coords[1][2];
488 D[1][2] = f->brushprimit_texdef.coords[1][1] + f->brushprimit_texdef.coords[1][2];
492 f->brushprimit_texdef.coords[0][0] =
SarrusDet(D[0], M[1], M[2]) / det;
493 f->brushprimit_texdef.coords[0][1] =
SarrusDet(M[0], D[0], M[2]) / det;
494 f->brushprimit_texdef.coords[0][2] =
SarrusDet(M[0], M[1], D[0]) / det;
495 f->brushprimit_texdef.coords[1][0] =
SarrusDet(D[1], M[1], M[2]) / det;
496 f->brushprimit_texdef.coords[1][1] =
SarrusDet(M[0], D[1], M[2]) / det;
497 f->brushprimit_texdef.coords[1][2] =
SarrusDet(M[0], M[1], D[1]) / det;
517 x /= f->d_texture->GetEditorImage()->uploadWidth;
518 y /= f->d_texture->GetEditorImage()->uploadHeight;
520 f->brushprimit_texdef.coords[0][2] +=
x;
521 f->brushprimit_texdef.coords[1][2] +=
y;
595 T->coords[0][0] =
SarrusDet(D[0], M[1], M[2]) / det;
596 T->coords[0][1] =
SarrusDet(M[0], D[0], M[2]) / det;
597 T->coords[0][2] =
SarrusDet(M[0], M[1], D[0]) / det;
598 T->coords[1][0] =
SarrusDet(D[1], M[1], M[2]) / det;
599 T->coords[1][1] =
SarrusDet(M[0], D[1], M[2]) / det;
600 T->coords[1][2] =
SarrusDet(M[0], M[1], D[1]) / det;
617 brushprimit_texdef_t
N;
632 BBoxSTMin[0] = BBoxSTMin[1] = BBoxSTMin[2] = 999999;
633 BBoxSTMax[0] = BBoxSTMax[1] = BBoxSTMax[2] = -999999;
639 for (j = 0; j < 2; j++) {
640 val = (*w)[
i][j + 3];
641 if (val < BBoxSTMin[j]) {
645 if (val > BBoxSTMax[j]) {
660 M[0][0] = BBoxSTMin[0];
661 M[0][1] = BBoxSTMax[0];
662 M[0][2] = BBoxSTMin[0];
663 M[1][0] = BBoxSTMin[1];
664 M[1][1] = BBoxSTMin[1];
665 M[1][2] = BBoxSTMax[1];
683 N[0][0] = (BBoxSTMax[0] - BBoxSTMin[0]) / width;
685 N[0][2] = BBoxSTMin[0];
687 N[1][1] = (BBoxSTMax[1] - BBoxSTMin[1]) / height;
688 N[1][2] = BBoxSTMin[1];
691 Mf[0][0] = N.coords[0][0] *
692 f->brushprimit_texdef.coords[0][0] +
694 f->brushprimit_texdef.coords[1][0];
695 Mf[0][1] = N.coords[0][0] *
696 f->brushprimit_texdef.coords[0][1] +
698 f->brushprimit_texdef.coords[1][1];
699 Mf[0][2] = N.coords[0][0] *
700 f->brushprimit_texdef.coords[0][2] +
702 f->brushprimit_texdef.coords[1][2] +
704 Mf[1][0] = N.coords[1][0] *
705 f->brushprimit_texdef.coords[0][0] +
707 f->brushprimit_texdef.coords[1][0];
708 Mf[1][1] = N.coords[1][0] *
709 f->brushprimit_texdef.coords[0][1] +
711 f->brushprimit_texdef.coords[1][1];
712 Mf[1][2] = N.coords[1][0] *
713 f->brushprimit_texdef.coords[0][2] +
715 f->brushprimit_texdef.coords[1][2] +
719 VectorCopy(Mf[0], f->brushprimit_texdef.coords[0]);
720 VectorCopy(Mf[1], f->brushprimit_texdef.coords[1]);
733 if (!g_qeglobals.m_bBrushPrimitMode) {
738 brushprimit_texdef_t *pBP = &face->brushprimit_texdef;
739 BPMatScale(pBP->coords, sS, sT);
750 brushprimit_texdef_t *pBP = &face->brushprimit_texdef;
752 float x = pBP->coords[0][0];
753 float y = pBP->coords[0][1];
754 float x1 = pBP->coords[1][0];
755 float y1 = pBP->coords[1][1];
758 pBP->coords[0][0] = (((x - origin[0]) * c) - ((y - origin[1]) * s)) + origin[0];
759 pBP->coords[0][1] = (((x - origin[0]) * s) + ((y - origin[1]) * c)) + origin[1];
760 pBP->coords[1][0] = (((x1 - origin[0]) * c) - ((y1 - origin[1]) * s)) + origin[0];
761 pBP->coords[1][1] = (((x1 - origin[0]) * s) + ((y1 - origin[1]) * c)) + origin[1];
843 for (j = 0; j < 3; j++) {
844 rOrig[
j] =
DotProduct(temp, txl_matrix[j]) + txl_origin[
j];
848 for (j = 0; j < 3; j++) {
849 rvecS[
j] =
DotProduct(temp, txl_matrix[j]) + txl_origin[
j];
853 for (j = 0; j < 3; j++) {
854 rvecT[
j] =
DotProduct(temp, txl_matrix[j]) + txl_origin[
j];
861 for (j = 0; j < 3; j++) {
887 D[0][0] = f->brushprimit_texdef.coords[0][2];
888 D[0][1] = f->brushprimit_texdef.coords[0][0] + f->brushprimit_texdef.coords[0][2];
889 D[0][2] = f->brushprimit_texdef.coords[0][1] + f->brushprimit_texdef.coords[0][2];
890 D[1][0] = f->brushprimit_texdef.coords[1][2];
891 D[1][1] = f->brushprimit_texdef.coords[1][0] + f->brushprimit_texdef.coords[1][2];
892 D[1][2] = f->brushprimit_texdef.coords[1][1] + f->brushprimit_texdef.coords[1][2];
896 f->brushprimit_texdef.coords[0][0] =
SarrusDet(D[0], M[1], M[2]) / det;
897 f->brushprimit_texdef.coords[0][1] =
SarrusDet(M[0], D[0], M[2]) / det;
898 f->brushprimit_texdef.coords[0][2] =
SarrusDet(M[0], M[1], D[0]) / det;
899 f->brushprimit_texdef.coords[1][0] =
SarrusDet(D[1], M[1], M[2]) / det;
900 f->brushprimit_texdef.coords[1][1] =
SarrusDet(M[0], D[1], M[2]) / det;
901 f->brushprimit_texdef.coords[1][2] =
SarrusDet(M[0], M[1], D[1]) / det;
942 C[0][0] = A[0][0] * B[0][0] + A[0][1] * B[1][0];
943 C[1][0] = A[1][0] * B[0][0] + A[1][1] * B[1][0];
944 C[0][1] = A[0][0] * B[0][1] + A[0][1] * B[1][1];
945 C[1][1] = A[1][0] * B[0][1] + A[1][1] * B[1][1];
946 C[0][2] = A[0][0] * B[0][2] + A[0][1] * B[1][2] + A[0][2];
947 C[1][2] = A[1][0] * B[0][2] + A[1][1] * B[1][2] + A[1][2];
955 common->
Printf(
"%g %g %g\n%g %g %g\n0 0 1\n", A[0][0], A[0][1], A[0][2], A[1][0], A[1][1], A[1][2]);
965 memset(&m, 0,
sizeof (
float) *6);
966 m[0][0] = cos(
DEG2RAD( theta ) );
967 m[0][1] = -sin(
DEG2RAD( theta ) );
978 if (face ==
NULL || face->face_winding ==
NULL) {
982 double Os = 0, Ot = 0;
983 for (
int i = 0;
i < face->face_winding->GetNumPoints();
i++) {
988 Os /= face->face_winding->GetNumPoints();
989 Ot /= face->face_winding->GetNumPoints();
991 brushprimit_texdef_t *pBP = &face->brushprimit_texdef;
997 memset(&m, 0,
sizeof (
float) *6);
1010 *s =
idMath::Sqrt(aux[0][0] * aux[0][0] + aux[1][0] * aux[1][0]);
1011 *t =
idMath::Sqrt(aux[0][1] * aux[0][1] + aux[1][1] * aux[1][1]);
1017 if (face->brushprimit_texdef.coords[1][0] > 0) {
1025 *rot =
RAD2DEG(atan2(face->brushprimit_texdef.coords[1][0] / (*s) ? (*s) : 1.0f, face->brushprimit_texdef.coords[0][0] / (*t) ? (*t) : 1.0f));
1040 double Os = 0, Ot = 0;
1042 for (
int i = 0;
i < face->face_winding->GetNumPoints();
i++) {
1047 Os /= face->face_winding->GetNumPoints();
1048 Ot /= face->face_winding->GetNumPoints();
1050 brushprimit_texdef_t *pBP = &face->brushprimit_texdef;
1056 memset(&m, 0,
sizeof (
float) *6);
1071 v1 =
idMath::Sqrt(aux[0][0] * aux[0][0] + aux[1][0] * aux[1][0]);
1072 v2 =
idMath::Sqrt(aux[0][1] * aux[0][1] + aux[1][1] * aux[1][1]);
1114 double Os = 0, Ot = 0;
1115 for (
int i = 0;
i < f->face_winding->numpoints;
i++) {
1122 Ot /= f->d_texture->GetEditorImage()->uploadHeight;
1126 Os /= f->d_texture->GetEditorImage()->uploadWidth;
1139 for (face_t *
f = b->brush_faces;
f;
f =
f->next) {
1150 if (!face->face_winding) {
1158 min.
x = min.
y = min.
z = 999999.0;
1159 max.
x = max.
y = max.
z = -999999.0;
1160 for (
int i = 0;
i < face->face_winding->GetNumPoints();
i++) {
1161 for (
int j = 0;
j < 3;
j++) {
1162 if ((*face->face_winding)[
i][
j] < min[
j]) {
1163 min[
j] = (*face->face_winding)[
i][
j];
1165 if ((*face->face_winding)[
i][
j] > max[
j]) {
1166 max[
j] = (*face->face_winding)[
i][
j];
1174 if (
g_axialAnchor >= 0 && g_axialAnchor < face->face_winding->GetNumPoints() &&
1183 len = (*face->face_winding)[2].ToVec3() - (*face->face_winding)[1].ToVec3();
1185 len = (*face->face_winding)[1].ToVec3() - (*face->face_winding)[0].ToVec3();
1189 double dist = len.
Length();
1198 if (dist > face->d_texture->GetEditorImage()->uploadHeight) {
1199 height = 1.0 / (dist / face->d_texture->GetEditorImage()->uploadHeight);
1203 if (dist > face->d_texture->GetEditorImage()->uploadWidth) {
1204 width = 1.0 / (dist / face->d_texture->GetEditorImage()->uploadWidth);
void TexMatToFakeTexCoords(float texMat[2][3], float shift[2], float *rot, float scale[2])
idImage * GetEditorImage(void) const
face_t * Face_Alloc(void)
void FakeTexCoordsToTexMat(float shift[2], float rot, float scale[2], float texMat[2][3])
void BPMatMul(float A[2][3], float B[2][3], float C[2][3])
void ApplyMatrix_BrushPrimit(face_t *f, idMat3 matrix, idVec3 origin)
void Face_SetExplicitScale_BrushPrimit(face_t *face, float s, float t)
#define VectorSubtract(a, b, c)
GLenum GLenum GLenum GLenum GLenum scale
void ComputeAxisBase(idVec3 &normal, idVec3D &texS, idVec3D &texT)
void Face_ScaleTexture_BrushPrimit(face_t *face, float sS, float sT)
void Sys_Status(const char *psz, int part)
static float Sqrt(float x)
#define VectorAdd(a, b, c)
void EmitTextureCoordinates(idVec5 &xyzst, const idMaterial *q, face_t *f, bool force)
void ParseEpair(idDict *dict)
void Face_GetScale_BrushPrimit(face_t *face, float *s, float *t, float *rot)
GLfloat GLfloat GLfloat v2
void ComputeBest2DVector(idVec3 v, idVec3 X, idVec3 Y, int &x, int &y)
void Select_ShiftTexture_BrushPrimit(face_t *f, float x, float y, bool autoAdjust)
int GetNumPoints(void) const
GLubyte GLubyte GLubyte GLubyte w
idVec3 vec3_origin(0.0f, 0.0f, 0.0f)
static float Fabs(float f)
void BPMatDump(float A[2][3])
void BPMatRotate(float A[2][3], float theta)
void Face_FlipTexture_BrushPrimit(face_t *f, bool y)
void Face_MoveTexture_BrushPrimit(face_t *f, idVec3 delta)
void BrushPrimit_Parse(brush_t *b, bool newFormat, const idVec3 origin)
GLubyte GLubyte GLubyte a
virtual void Printf(const char *fmt,...) id_attribute((format(printf
void Face_FitTexture_BrushPrimit(face_t *f, idVec3 mins, idVec3 maxs, float height, float width)
GLenum GLsizei GLsizei height
double & operator[](const int index)
void RotateFaceTexture_BrushPrimit(face_t *f, int nAxis, float fDeg, idVec3 vOrigin)
void ConvertTexMatWithQTexture(float texMat1[2][3], const idMaterial *qtex1, float texMat2[2][3], const idMaterial *qtex2, float sScale=1.0, float tScale=1.0)
void BaseForPlane(const idVec3 &normal, const float dist)
void Brush_FlipTexture_BrushPrimit(brush_t *b, bool y)
void Face_SetAxialScale_BrushPrimit(face_t *face, bool y)
void MatrixForPoints(idVec3D M[3], idVec3D D[2], brushprimit_texdef_t *T)
void TextureLockTransformation_BrushPrimit(face_t *f)
#define VectorScale(v, s, o)
char * va(const char *fmt,...)
void Face_RotateTexture_BrushPrimit(face_t *face, float amount, idVec3 origin)
void EmitBrushPrimitTextureCoordinates(face_t *f, idWinding *w, patchMesh_t *patch)
void FaceToBrushPrimitFace(face_t *f)
double SarrusDet(idVec3D a, idVec3D b, idVec3D c)