-
-
-// using scale[0] and scale[1]
-void ComputeScale(vec3_t& rex, vec3_t& rey, vec3_t& p, face_t* f)
-{
- float px = DotProduct(rex, p);
- float py = DotProduct(rey, p);
- px *= f->texdef.scale[0];
- py *= f->texdef.scale[1];
- vec3_t aux;
- VectorCopy(rex, aux);
- VectorScale(aux, px, aux);
- VectorCopy(aux, p);
- VectorCopy(rey, aux);
- VectorScale(aux, py, aux);
- VectorAdd(p, aux, p);
-}
-
-void ComputeAbsolute(face_t* f, vec3_t& p1, vec3_t& p2, vec3_t& p3)
-{
- vec3_t ex,ey,ez; // local axis base
-
-#ifdef _DEBUG
- if (g_qeglobals.m_bBrushPrimitMode)
- Sys_Printf("Warning : illegal call of ComputeAbsolute in brush primitive mode\n");
-#endif
-
- // compute first local axis base
- TextureAxisFromPlane(&f->plane, ex, ey);
- CrossProduct(ex, ey, ez);
-
- vec3_t aux;
- VectorCopy(ex, aux);
- VectorScale(aux, -f->texdef.shift[0], aux);
- VectorCopy(aux, p1);
- VectorCopy(ey, aux);
- VectorScale(aux, -f->texdef.shift[1], aux);
- VectorAdd(p1, aux, p1);
- VectorCopy(p1, p2);
- VectorAdd(p2, ex, p2);
- VectorCopy(p1, p3);
- VectorAdd(p3, ey, p3);
- VectorCopy(ez, aux);
- VectorScale(aux, -f->texdef.rotate, aux);
- VectorRotate(p1, aux, p1);
- VectorRotate(p2, aux, p2);
- VectorRotate(p3, aux, p3);
- // computing rotated local axis base
- vec3_t rex,rey;
- VectorCopy(ex, rex);
- VectorRotate(rex, aux, rex);
- VectorCopy(ey, rey);
- VectorRotate(rey, aux, rey);
-
- ComputeScale(rex,rey,p1,f);
- ComputeScale(rex,rey,p2,f);
- ComputeScale(rex,rey,p3,f);
-
- // project on normal plane
- // along ez
- // assumes plane normal is normalized
- ProjectOnPlane(f->plane.normal,f->plane.dist,ez,p1);
- ProjectOnPlane(f->plane.normal,f->plane.dist,ez,p2);
- ProjectOnPlane(f->plane.normal,f->plane.dist,ez,p3);
-};
-
-
-void AbsoluteToLocal(plane_t normal2, face_t* f, vec3_t& p1, vec3_t& p2, vec3_t& p3)
-{
- vec3_t ex,ey,ez;
-
-#ifdef _DEBUG
- if (g_qeglobals.m_bBrushPrimitMode)
- Sys_Printf("Warning : illegal call of AbsoluteToLocal in brush primitive mode\n");
-#endif
-
- // computing new local axis base
- TextureAxisFromPlane(&normal2, ex, ey);
- CrossProduct(ex, ey, ez);
-
- // projecting back on (ex,ey)
- Back(ez,p1);
- Back(ez,p2);
- Back(ez,p3);
-
- vec3_t aux;
- // rotation
- VectorCopy(p2, aux);
- VectorSubtract(aux, p1,aux);
-
- float x = DotProduct(aux,ex);
- float y = DotProduct(aux,ey);
- f->texdef.rotate = 180 * atan2(y,x) / Q_PI;
-
- vec3_t rex,rey;
- // computing rotated local axis base
- VectorCopy(ez, aux);
- VectorScale(aux, f->texdef.rotate, aux);
- VectorCopy(ex, rex);
- VectorRotate(rex, aux, rex);
- VectorCopy(ey, rey);
- VectorRotate(rey, aux, rey);
-
- // scale
- VectorCopy(p2, aux);
- VectorSubtract(aux, p1, aux);
- f->texdef.scale[0] = DotProduct(aux, rex);
- VectorCopy(p3, aux);
- VectorSubtract(aux, p1, aux);
- f->texdef.scale[1] = DotProduct(aux, rey);
-
- // shift
- // only using p1
- x = DotProduct(rex,p1);
- y = DotProduct(rey,p1);
- x /= f->texdef.scale[0];
- y /= f->texdef.scale[1];
-
- VectorCopy(rex, p1);
- VectorScale(p1, x, p1);
- VectorCopy(rey, aux);
- VectorScale(aux, y, aux);
- VectorAdd(p1, aux, p1);
- VectorCopy(ez, aux);
- VectorScale(aux, -f->texdef.rotate, aux);
- VectorRotate(p1, aux, p1);
- f->texdef.shift[0] = -DotProduct(p1, ex);
- f->texdef.shift[1] = -DotProduct(p1, ey);
-
- // stored rot is good considering local axis base
- // change it if necessary
- f->texdef.rotate = -f->texdef.rotate;
-
- Clamp(f->texdef.shift[0], f->d_texture->width);
- Clamp(f->texdef.shift[1], f->d_texture->height);
- Clamp(f->texdef.rotate, 360);
-
-}
-
-void RotateFaceTexture(face_t* f, int nAxis, float fDeg)
-{
- vec3_t p1,p2,p3, rota;
- p1[0] = p1[1] = p1[2] = 0;
- VectorCopy(p1, p2);
- VectorCopy(p1, p3);
- VectorCopy(p1, rota);
- ComputeAbsolute(f, p1, p2, p3);
-
- rota[nAxis] = fDeg;
- VectorRotateOrigin (p1, rota, select_origin, p1);
- VectorRotateOrigin (p2, rota, select_origin, p2);
- VectorRotateOrigin (p3, rota, select_origin, p3);
-
- plane_t normal2;
- vec3_t vNormal;
- vNormal[0] = f->plane.normal[0];
- vNormal[1] = f->plane.normal[1];
- vNormal[2] = f->plane.normal[2];
- VectorRotate(vNormal, rota, vNormal);
- normal2.normal[0] = vNormal[0];
- normal2.normal[1] = vNormal[1];
- normal2.normal[2] = vNormal[2];
- AbsoluteToLocal(normal2, f, p1, p2 ,p3);
-
-}
-
-void RotateTextures(int nAxis, float fDeg, vec3_t vOrigin)
-{
- for (brush_t* b=selected_brushes.next ; b != &selected_brushes ; b=b->next)