[Gtkradiant] svn trunk: hitting "s" in brush primitives mode crashes (NULL pointer)
Rudolf Polzer
divVerent at alientrap.org
Tue Jul 8 01:10:48 CDT 2008
On Sat, Jul 05, 2008 at 09:32:34PM +0200, Rudolf Polzer wrote:
> On Sat, Jul 05, 2008 at 09:03:43AM +0200, Martin Gerhardy wrote:
> > > Is there really no way to switch back to it, can maybe the old
> > > surfacedialog.cpp code that worked just fine be turned into a plugin?
> > > The code is still there, all I need to know is the code the functions
> > > had before they called stuff from g_SurfaceTable... but svn won't tell
> > > me any past history of that code.
> >
> > The 'old' code of 1.5 is in branches/1.5 - you should have a look at
> > that code maybe. The zeroradiant code base is based on 1.4. Maybe that's
> > the reason why you don't get any history.
>
> Sure, but I am quite sure that brush primitives mode did not have that
> bug in 1.4... so I'd like to revert the change that introduced the
> surface dialog plugin. Too bad I can't see it in svn log...
>
> for now, I'll have to switch back to 1.5 as it seems, as fixing that bug
> is beyond my abilities and I need brush primitives mode for this map.
I am currently trying to get the brushprimitives-to-traditional
conversion right. This is not code yet, just code lookalike... but
I think these conversion routines should work, once completed.
Not sure if I will have time to complete that into a patch, but maybe
someone else of you will.
void EmitTextureCoordinates_INVERTED ( float *xyzst1, *xyzst2, *xyzst3, qtexture_t *q, face_t *f)
{
float STfromXYZ[2][4];
// get natural texture axis
TextureAxisFromPlane(&f->plane, pvecs[0], pvecs[1]);
if (pvecs[0][0])
sv = 0;
else if (pvecs[0][1])
sv = 1;
else
sv = 2;
if (pvecs[1][0])
tv = 0;
else if (pvecs[1][1])
tv = 1;
else
tv = 2;
uv = 3 - sv - tv; // the "other one"
// find the STfromXYZ 4-vectors
SARRUS-SOLVE:
xyzst1[3] == DotProduct (xyzst1, STfromXYZ[0]) + STfromXYZ[0][3];
xyzst2[3] == DotProduct (xyzst2, STfromXYZ[0]) + STfromXYZ[0][3];
xyzst3[3] == DotProduct (xyzst3, STfromXYZ[0]) + STfromXYZ[0][3];
FOR: STfromXYZ[0]
GIVEN: one coord of them (uv) is empty (see Face_TextureVectors)
SARRUS-SOLVE:
xyzst1[4] == DotProduct (xyzst1, STfromXYZ[1]) + STfromXYZ[1][3];
xyzst2[4] == DotProduct (xyzst2, STfromXYZ[1]) + STfromXYZ[1][3];
xyzst3[4] == DotProduct (xyzst3, STfromXYZ[1]) + STfromXYZ[1][3];
FOR: STfromXYZ[1]
GIVEN: one coord of them (uv) is empty (see Face_TextureVectors)
Face_TextureVectors_INVERTED (f, STfromXYZ, pvecs, sv, tv);
}
void Face_TextureVectors_INVERTED (face_t *f, float STfromXYZ[2][4], pvecs, sv, tv)
{
td = &f->texdef;
q = f->d_texture;
// undo the texture transform
for (j=0 ; j<4 ; j++) {
STfromXYZ[0][j] *= q->width;
STfromXYZ[1][j] *= q->height;
}
// shift
td->shift[0] = STfromXYZ[0][3];
td->shift[1] = STfromXYZ[1][3];
/*
SOLVE:
STfromXYZ[0][sv] = (cosv * pvecs[0][sv] - sinv * pvecs[0][tv]) / td->scale[0];
STfromXYZ[0][tv] = (sinv * pvecs[0][sv] + cosv * pvecs[0][tv]) / td->scale[0];
STfromXYZ[1][sv] = (cosv * pvecs[1][sv] - sinv * pvecs[1][tv]) / td->scale[1];
STfromXYZ[1][tv] = (sinv * pvecs[1][sv] + cosv * pvecs[1][tv]) / td->scale[1];
FOR:
sinv, cosv, td->scale[0], td->scale[1]
WE KNOW:
sinv^2 + cosv^2 = 1
pvecs[0][sv] is +/-1
pvecs[0][tv] is 0
pvecs[1][sv] is 0
pvecs[1][tv] is +/-1
THUS:
STfromXYZ[0][sv] = +cosv * pvecs[0][sv] / td->scale[0];
STfromXYZ[0][tv] = +sinv * pvecs[0][sv] / td->scale[0];
STfromXYZ[1][sv] = -sinv * pvecs[1][tv] / td->scale[1];
STfromXYZ[1][tv] = +cosv * pvecs[1][tv] / td->scale[1];
*/
td->scale[0] = 1/sqrt(STfromXYZ[0][sv]^2 + STfromXYZ[0][tv]^2)
td->scale[1] = 1/sqrt(STfromXYZ[1][sv]^2 + STfromXYZ[1][tv]^2)
ang = atan2(STfromXYZ[0][sv], STfromXYZ[0][tv])
= atan2(STfromXYZ[1][tv], -STfromXYZ[1][sv])
use the one with the smaller scale (more accurate)
td->rotate = ang * 180 / Q_PI;
}
void FaceToBrushPrimitFace_INVERTED(face_t *f)
{
vec3_t texX,texY;
vec3_t proj;
vec_t ST[3][5];
ComputeAxisBase(f->plane.normal,texX,texY);
VectorCopy(f->plane.normal,proj);
VectorScale(proj,f->plane.dist,proj);
VectorCopy(proj,ST[0]);
VectorCopy(texX,ST[1]);
VectorAdd(ST[1],proj,ST[1]);
VectorCopy(texY,ST[2]);
VectorAdd(ST[2],proj,ST[2]);
SOLVE:
f->brushprimit_texdef.coords[0][2]=ST[0][3];
f->brushprimit_texdef.coords[1][2]=ST[0][4];
f->brushprimit_texdef.coords[0][0]=ST[1][3]-f->brushprimit_texdef.coords[0][2];
f->brushprimit_texdef.coords[1][0]=ST[1][4]-f->brushprimit_texdef.coords[1][2];
f->brushprimit_texdef.coords[0][1]=ST[2][3]-f->brushprimit_texdef.coords[0][2];
f->brushprimit_texdef.coords[1][1]=ST[2][4]-f->brushprimit_texdef.coords[1][2];
FOR:
ST[*][3 and 4]
EmitTextureCoordinates_INVERTED(ST[0], ST[1], ST[2], q, f);
}
More information about the Gtkradiant
mailing list