minor tweaks

This commit is contained in:
Garux 2021-03-11 10:57:17 +03:00
parent 0cff77e30d
commit 98f9023cdc
6 changed files with 56 additions and 70 deletions

View File

@ -130,7 +130,7 @@ inline Color4b color_to_byte( const Color4f& color ){
template<typename T> template<typename T>
T VectorNormalize( BasicVector3<T>& vector ) { T VectorNormalize( BasicVector3<T>& vector ) {
DoubleVector3 v( vector ); // intermediate vector to be sure to do in double const DoubleVector3 v( vector ); // intermediate vector to be sure to do in double
const double length = vector3_length( v ); const double length = vector3_length( v );
if ( length == 0 ) { if ( length == 0 ) {

View File

@ -349,7 +349,6 @@ static void ConvertBrush( FILE *f, int num, bspBrush_t *brush, const Vector3& or
side_t *buildSide; side_t *buildSide;
bspShader_t *shader; bspShader_t *shader;
const char *texture; const char *texture;
plane_t *buildPlane;
Vector3 pts[ 3 ]; Vector3 pts[ 3 ];
bspDrawVert_t *vert[3]; bspDrawVert_t *vert[3];
@ -437,7 +436,7 @@ static void ConvertBrush( FILE *f, int num, bspBrush_t *brush, const Vector3& or
buildSide = &buildBrush->sides[ i ]; buildSide = &buildBrush->sides[ i ];
/* get plane */ /* get plane */
buildPlane = &mapplanes[ buildSide->planenum ]; const plane_t& buildPlane = mapplanes[ buildSide->planenum ];
/* dummy check */ /* dummy check */
if ( buildSide->shaderInfo == NULL || buildSide->winding == NULL ) { if ( buildSide->shaderInfo == NULL || buildSide->winding == NULL ) {
@ -467,7 +466,7 @@ static void ConvertBrush( FILE *f, int num, bspBrush_t *brush, const Vector3& or
/* recheck and fix winding points, fails occur somehow */ /* recheck and fix winding points, fails occur somehow */
int match = 0; int match = 0;
for ( j = 0; j < buildSide->winding->numpoints; j++ ){ for ( j = 0; j < buildSide->winding->numpoints; j++ ){
if ( fabs( plane3_distance_to_point( buildPlane->plane, buildSide->winding->p[ j ] ) ) >= distanceEpsilon ) { if ( fabs( plane3_distance_to_point( buildPlane.plane, buildSide->winding->p[ j ] ) ) >= distanceEpsilon ) {
continue; continue;
} }
else{ else{
@ -503,8 +502,8 @@ static void ConvertBrush( FILE *f, int num, bspBrush_t *brush, const Vector3& or
} }
else{ else{
Vector3 vecs[ 2 ]; Vector3 vecs[ 2 ];
MakeNormalVectors( buildPlane->normal(), vecs[ 0 ], vecs[ 1 ] ); MakeNormalVectors( buildPlane.normal(), vecs[ 0 ], vecs[ 1 ] );
pts[ 0 ] = buildPlane->normal() * buildPlane->dist() + origin; pts[ 0 ] = buildPlane.normal() * buildPlane.dist() + origin;
pts[ 1 ] = pts[ 0 ] + vecs[ 0 ] * 256.0f; pts[ 1 ] = pts[ 0 ] + vecs[ 0 ] * 256.0f;
pts[ 2 ] = pts[ 0 ] + vecs[ 1 ] * 256.0f; pts[ 2 ] = pts[ 0 ] + vecs[ 1 ] * 256.0f;
//Sys_Printf( "not\n" ); //Sys_Printf( "not\n" );
@ -518,7 +517,7 @@ static void ConvertBrush( FILE *f, int num, bspBrush_t *brush, const Vector3& or
Vector2 stI, stJ, stK; Vector2 stI, stJ, stK;
float D, D0, D1, D2; float D, D0, D1, D2;
ComputeAxisBase( buildPlane->normal(), texX, texY ); ComputeAxisBase( buildPlane.normal(), texX, texY );
xyI[0] = vector3_dot( vert[0]->xyz, texX ); xyI[0] = vector3_dot( vert[0]->xyz, texX );
xyI[1] = vector3_dot( vert[0]->xyz, texY ); xyI[1] = vector3_dot( vert[0]->xyz, texY );
@ -562,7 +561,7 @@ static void ConvertBrush( FILE *f, int num, bspBrush_t *brush, const Vector3& or
} }
else{ else{
fprintf( stderr, "degenerate triangle found when solving texMat equations for\n(%f %f %f) (%f %f %f) (%f %f %f)\n( %f %f %f )\n( %f %f %f ) -> ( %f %f )\n( %f %f %f ) -> ( %f %f )\n( %f %f %f ) -> ( %f %f )\n", fprintf( stderr, "degenerate triangle found when solving texMat equations for\n(%f %f %f) (%f %f %f) (%f %f %f)\n( %f %f %f )\n( %f %f %f ) -> ( %f %f )\n( %f %f %f ) -> ( %f %f )\n( %f %f %f ) -> ( %f %f )\n",
buildPlane->normal()[0], buildPlane->normal()[1], buildPlane->normal()[2], buildPlane.normal()[0], buildPlane.normal()[1], buildPlane.normal()[2],
vert[0]->normal[0], vert[0]->normal[1], vert[0]->normal[2], vert[0]->normal[0], vert[0]->normal[1], vert[0]->normal[2],
texX[0], texX[1], texX[2], texY[0], texY[1], texY[2], texX[0], texX[1], texX[2], texY[0], texY[1], texY[2],
vert[0]->xyz[0], vert[0]->xyz[1], vert[0]->xyz[2], xyI[0], xyI[1], vert[0]->xyz[0], vert[0]->xyz[1], vert[0]->xyz[2], xyI[0], xyI[1],
@ -587,7 +586,6 @@ static void ConvertBrush( FILE *f, int num, bspBrush_t *brush, const Vector3& or
{ {
// invert QuakeTextureVecs // invert QuakeTextureVecs
int i; int i;
Vector3 vecs[2];
int sv, tv; int sv, tv;
float stI[2], stJ[2], stK[2]; float stI[2], stJ[2], stK[2];
Vector3 sts[2]; Vector3 sts[2];
@ -595,7 +593,7 @@ static void ConvertBrush( FILE *f, int num, bspBrush_t *brush, const Vector3& or
float rotate; float rotate;
float D, D0, D1, D2; float D, D0, D1, D2;
TextureAxisFromPlane( buildPlane, vecs[0], vecs[1] ); const auto vecs = TextureAxisFromPlane( buildPlane );
if ( vecs[0][0] ) { if ( vecs[0][0] ) {
sv = 0; sv = 0;
} }

View File

@ -54,7 +54,7 @@ int c_structural;
ydnar: replaced with variable epsilon for djbob ydnar: replaced with variable epsilon for djbob
*/ */
bool PlaneEqual( const plane_t *p, const Plane3f& plane ){ bool PlaneEqual( const plane_t& p, const Plane3f& plane ){
/* get local copies */ /* get local copies */
const float ne = normalEpsilon; const float ne = normalEpsilon;
const float de = distanceEpsilon; const float de = distanceEpsilon;
@ -64,10 +64,10 @@ bool PlaneEqual( const plane_t *p, const Plane3f& plane ){
// (the epsilons may be zero). We want to use '<' instead of '<=' to be // (the epsilons may be zero). We want to use '<' instead of '<=' to be
// consistent with the true meaning of "epsilon", and also because other // consistent with the true meaning of "epsilon", and also because other
// parts of the code uses this inequality. // parts of the code uses this inequality.
if ( ( p->dist() == plane.dist() || fabs( p->dist() - plane.dist() ) < de ) && if ( ( p.dist() == plane.dist() || fabs( p.dist() - plane.dist() ) < de ) &&
( p->normal()[0] == plane.normal()[0] || fabs( p->normal()[0] - plane.normal()[0] ) < ne ) && ( p.normal()[0] == plane.normal()[0] || fabs( p.normal()[0] - plane.normal()[0] ) < ne ) &&
( p->normal()[1] == plane.normal()[1] || fabs( p->normal()[1] - plane.normal()[1] ) < ne ) && ( p.normal()[1] == plane.normal()[1] || fabs( p.normal()[1] - plane.normal()[1] ) < ne ) &&
( p->normal()[2] == plane.normal()[2] || fabs( p->normal()[2] - plane.normal()[2] ) < ne ) ) { ( p.normal()[2] == plane.normal()[2] || fabs( p.normal()[2] - plane.normal()[2] ) < ne ) ) {
return true; return true;
} }
@ -359,7 +359,7 @@ int FindFloatPlane( const Plane3f& inplane, int numPoints, const Vector3 *points
plane_t *p = &mapplanes[pidx]; plane_t *p = &mapplanes[pidx];
/* do standard plane compare */ /* do standard plane compare */
if ( !PlaneEqual( p, plane ) ) { if ( !PlaneEqual( *p, plane ) ) {
continue; continue;
} }
@ -405,7 +405,7 @@ int FindFloatPlane( const Plane3f& inplane, int numPoints, const Vector3 *points
#endif #endif
for ( i = 0, p = mapplanes; i < nummapplanes; i++, p++ ) for ( i = 0, p = mapplanes; i < nummapplanes; i++, p++ )
{ {
if ( !PlaneEqual( p, plane ) ) { if ( !PlaneEqual( *p, plane ) ) {
continue; continue;
} }
@ -728,7 +728,7 @@ void AddBrushBevels( void ){
for ( k = 0; k < buildBrush->numsides; k++ ) { for ( k = 0; k < buildBrush->numsides; k++ ) {
// if this plane has allready been used, skip it // if this plane has allready been used, skip it
if ( PlaneEqual( &mapplanes[buildBrush->sides[k].planenum], plane ) ) { if ( PlaneEqual( mapplanes[buildBrush->sides[k].planenum], plane ) ) {
if( buildBrush->sides[k].bevel ){ /* handle bevel surfaceflags */ if( buildBrush->sides[k].bevel ){ /* handle bevel surfaceflags */
buildBrush->sides[k].surfaceFlags |= ( s->surfaceFlags & surfaceFlagsMask ); buildBrush->sides[k].surfaceFlags |= ( s->surfaceFlags & surfaceFlagsMask );
} }
@ -891,31 +891,31 @@ brush_t *FinishBrush( bool noCollapseGroups ){
(must be identical in radiant!) (must be identical in radiant!)
*/ */
Vector3 baseaxis[18] = const Vector3 baseaxis[18] =
{ {
{0,0,1}, {1,0,0}, {0,-1,0}, // floor g_vector3_axis_z, g_vector3_axis_x, -g_vector3_axis_y, // floor
{0,0,-1}, {1,0,0}, {0,-1,0}, // ceiling -g_vector3_axis_z, g_vector3_axis_x, -g_vector3_axis_y, // ceiling
{1,0,0}, {0,1,0}, {0,0,-1}, // west wall g_vector3_axis_x, g_vector3_axis_y, -g_vector3_axis_z, // west wall
{-1,0,0}, {0,1,0}, {0,0,-1}, // east wall -g_vector3_axis_x, g_vector3_axis_y, -g_vector3_axis_z, // east wall
{0,1,0}, {1,0,0}, {0,0,-1}, // south wall g_vector3_axis_y, g_vector3_axis_x, -g_vector3_axis_z, // south wall
{0,-1,0}, {1,0,0}, {0,0,-1} // north wall -g_vector3_axis_y, g_vector3_axis_x, -g_vector3_axis_z // north wall
}; };
void TextureAxisFromPlane( const plane_t *pln, Vector3& xv, Vector3& yv ){ std::array<Vector3, 2> TextureAxisFromPlane( const plane_t& plane ){
float best = 0; float best = 0;
int bestaxis = 0; int bestaxis = 0;
for ( int i = 0 ; i < 6 ; i++ ) for ( int i = 0 ; i < 6 ; i++ )
{ {
const float dot = vector3_dot( pln->normal(), baseaxis[i * 3] ); const float dot = vector3_dot( plane.normal(), baseaxis[i * 3] );
if ( dot > best + 0.0001f ) { /* ydnar: bug 637 fix, suggested by jmonroe */ if ( dot > best + 0.0001f ) { /* ydnar: bug 637 fix, suggested by jmonroe */
best = dot; best = dot;
bestaxis = i; bestaxis = i;
} }
} }
xv = baseaxis[bestaxis * 3 + 1]; return { baseaxis[bestaxis * 3 + 1],
yv = baseaxis[bestaxis * 3 + 2]; baseaxis[bestaxis * 3 + 2] };
} }
@ -925,16 +925,12 @@ void TextureAxisFromPlane( const plane_t *pln, Vector3& xv, Vector3& yv ){
creates world-to-texture mapping vecs for crappy quake plane arrangements creates world-to-texture mapping vecs for crappy quake plane arrangements
*/ */
void QuakeTextureVecs( const plane_t *plane, float shift[ 2 ], float rotate, float scale[ 2 ], Vector4 mappingVecs[ 2 ] ){ void QuakeTextureVecs( const plane_t& plane, float shift[ 2 ], float rotate, float scale[ 2 ], Vector4 mappingVecs[ 2 ] ){
Vector3 vecs[2];
int sv, tv; int sv, tv;
float ang, sinv, cosv; float sinv, cosv;
float ns, nt; auto vecs = TextureAxisFromPlane( plane );
int i;
TextureAxisFromPlane( plane, vecs[0], vecs[1] );
if ( !scale[0] ) { if ( !scale[0] ) {
scale[0] = 1; scale[0] = 1;
} }
@ -957,7 +953,7 @@ void QuakeTextureVecs( const plane_t *plane, float shift[ 2 ], float rotate, flo
} }
else else
{ {
ang = degrees_to_radians( rotate ); const double ang = degrees_to_radians( rotate );
sinv = sin( ang ); sinv = sin( ang );
cosv = cos( ang ); cosv = cos( ang );
} }
@ -982,15 +978,14 @@ void QuakeTextureVecs( const plane_t *plane, float shift[ 2 ], float rotate, flo
tv = 2; tv = 2;
} }
for ( i = 0 ; i < 2 ; i++ ) { for ( int i = 0 ; i < 2 ; i++ ) {
ns = cosv * vecs[i][sv] - sinv * vecs[i][tv]; const float ns = cosv * vecs[i][sv] - sinv * vecs[i][tv];
nt = sinv * vecs[i][sv] + cosv * vecs[i][tv]; const float nt = sinv * vecs[i][sv] + cosv * vecs[i][tv];
vecs[i][sv] = ns; vecs[i][sv] = ns;
vecs[i][tv] = nt; vecs[i][tv] = nt;
}
for ( i = 0 ; i < 2 ; i++ )
mappingVecs[i].vec3() = vecs[i] / scale[i]; mappingVecs[i].vec3() = vecs[i] / scale[i];
}
mappingVecs[0][3] = shift[0]; mappingVecs[0][3] = shift[0];
mappingVecs[1][3] = shift[1]; mappingVecs[1][3] = shift[1];
@ -1181,7 +1176,7 @@ static void ParseRawBrush( bool onlyLights ){
/* bp: get the texture mapping for this texturedef / plane combination */ /* bp: get the texture mapping for this texturedef / plane combination */
if ( g_brushType == EBrushType::Quake ) { if ( g_brushType == EBrushType::Quake ) {
QuakeTextureVecs( &mapplanes[ planenum ], shift, rotate, scale, side->vecs ); QuakeTextureVecs( mapplanes[ planenum ], shift, rotate, scale, side->vecs );
} }
} }

View File

@ -1606,7 +1606,7 @@ int FindFloatPlane( const Plane3f& plane, int numPoints,
inline int FindFloatPlane( const Vector3& normal, float dist, int numPoints, const Vector3 *points ){ inline int FindFloatPlane( const Vector3& normal, float dist, int numPoints, const Vector3 *points ){
return FindFloatPlane( Plane3f( normal, dist ), numPoints, points ); return FindFloatPlane( Plane3f( normal, dist ), numPoints, points );
} }
bool PlaneEqual( const plane_t *p, const Plane3f& plane ); bool PlaneEqual( const plane_t& p, const Plane3f& plane );
void AddBrushBevels( void ); void AddBrushBevels( void );
brush_t *FinishBrush( bool noCollapseGroups ); brush_t *FinishBrush( bool noCollapseGroups );
@ -1704,7 +1704,7 @@ void FinishSurface( mapDrawSurface_t *ds );
void StripFaceSurface( mapDrawSurface_t *ds ); void StripFaceSurface( mapDrawSurface_t *ds );
void MaxAreaFaceSurface( mapDrawSurface_t *ds ); void MaxAreaFaceSurface( mapDrawSurface_t *ds );
bool CalcSurfaceTextureRange( mapDrawSurface_t *ds ); bool CalcSurfaceTextureRange( mapDrawSurface_t *ds );
bool CalcLightmapAxis( const Vector3& normal, Vector3& axis ); Vector3 CalcLightmapAxis( const Vector3& normal );
void ClassifySurfaces( int numSurfs, mapDrawSurface_t *ds ); void ClassifySurfaces( int numSurfs, mapDrawSurface_t *ds );
void ClassifyEntitySurfaces( entity_t *e ); void ClassifyEntitySurfaces( entity_t *e );
void TidyEntitySurfaces( entity_t *e ); void TidyEntitySurfaces( entity_t *e );
@ -1770,7 +1770,7 @@ void ProcessDecals( void );
void MakeEntityDecals( entity_t *e ); void MakeEntityDecals( entity_t *e );
/* map.c */ /* map.c */
void TextureAxisFromPlane( const plane_t *pln, Vector3& xv, Vector3& yv ); std::array<Vector3, 2> TextureAxisFromPlane( const plane_t& plane );
/* vis.c */ /* vis.c */
fixedWinding_t *NewFixedWinding( int points ); fixedWinding_t *NewFixedWinding( int points );

View File

@ -391,50 +391,43 @@ bool CalcSurfaceTextureRange( mapDrawSurface_t *ds ){
gives closed lightmap axis for a plane normal gives closed lightmap axis for a plane normal
*/ */
bool CalcLightmapAxis( const Vector3& normal, Vector3& axis ){ Vector3 CalcLightmapAxis( const Vector3& normal ){
Vector3 absolute;
/* test */ /* test */
if ( normal == g_vector3_identity ) { if ( normal == g_vector3_identity ) {
axis.set( 0 ); return g_vector3_identity;
return false;
} }
/* get absolute normal */ /* get absolute normal */
absolute[ 0 ] = fabs( normal[ 0 ] ); const Vector3 absolute( fabs( normal[ 0 ] ),
absolute[ 1 ] = fabs( normal[ 1 ] ); fabs( normal[ 1 ] ),
absolute[ 2 ] = fabs( normal[ 2 ] ); fabs( normal[ 2 ] ) );
/* test and set */ /* test and return */
if ( absolute[ 2 ] > absolute[ 0 ] - 0.0001f && absolute[ 2 ] > absolute[ 1 ] - 0.0001f ) { if ( absolute[ 2 ] > absolute[ 0 ] - 0.0001f && absolute[ 2 ] > absolute[ 1 ] - 0.0001f ) {
if ( normal[ 2 ] > 0.0f ) { if ( normal[ 2 ] > 0.0f ) {
axis = g_vector3_axis_z; return g_vector3_axis_z;
} }
else{ else{
axis = -g_vector3_axis_z; return -g_vector3_axis_z;
} }
} }
else if ( absolute[ 0 ] > absolute[ 1 ] - 0.0001f && absolute[ 0 ] > absolute[ 2 ] - 0.0001f ) { else if ( absolute[ 0 ] > absolute[ 1 ] - 0.0001f && absolute[ 0 ] > absolute[ 2 ] - 0.0001f ) {
if ( normal[ 0 ] > 0.0f ) { if ( normal[ 0 ] > 0.0f ) {
axis = g_vector3_axis_x; return g_vector3_axis_x;
} }
else{ else{
axis = -g_vector3_axis_x; return -g_vector3_axis_x;
} }
} }
else else
{ {
if ( normal[ 1 ] > 0.0f ) { if ( normal[ 1 ] > 0.0f ) {
axis = g_vector3_axis_y; return g_vector3_axis_y;
} }
else{ else{
axis = -g_vector3_axis_y; return -g_vector3_axis_y;
} }
} }
/* return ok */
return true;
} }
@ -564,14 +557,14 @@ void ClassifySurfaces( int numSurfs, mapDrawSurface_t *ds ){
} }
/* the shader can specify an explicit lightmap axis */ /* the shader can specify an explicit lightmap axis */
if ( si->lightmapAxis[ 0 ] || si->lightmapAxis[ 1 ] || si->lightmapAxis[ 2 ] ) { if ( si->lightmapAxis != g_vector3_identity ) {
ds->lightmapAxis = si->lightmapAxis; ds->lightmapAxis = si->lightmapAxis;
} }
else if ( ds->type == ESurfaceType::ForcedMeta ) { else if ( ds->type == ESurfaceType::ForcedMeta ) {
ds->lightmapAxis.set( 0 ); ds->lightmapAxis.set( 0 );
} }
else if ( ds->planar ) { else if ( ds->planar ) {
CalcLightmapAxis( plane.normal(), ds->lightmapAxis ); ds->lightmapAxis = CalcLightmapAxis( plane.normal() );
} }
else else
{ {

View File

@ -159,15 +159,15 @@ int FindMetaTriangle( metaTriangle_t *src, bspDrawVert_t *a, bspDrawVert_t *b, b
/* ydnar 2002-10-04: set lightmap axis if not already set */ /* ydnar 2002-10-04: set lightmap axis if not already set */
if ( !( src->si->compileFlags & C_VERTEXLIT ) && if ( !( src->si->compileFlags & C_VERTEXLIT ) &&
src->lightmapAxis[ 0 ] == 0.0f && src->lightmapAxis[ 1 ] == 0.0f && src->lightmapAxis[ 2 ] == 0.0f ) { src->lightmapAxis == g_vector3_identity ) {
/* the shader can specify an explicit lightmap axis */ /* the shader can specify an explicit lightmap axis */
if ( src->si->lightmapAxis[ 0 ] || src->si->lightmapAxis[ 1 ] || src->si->lightmapAxis[ 2 ] ) { if ( src->si->lightmapAxis != g_vector3_identity ) {
src->lightmapAxis = src->si->lightmapAxis; src->lightmapAxis = src->si->lightmapAxis;
} }
/* new axis-finding code */ /* new axis-finding code */
else{ else{
CalcLightmapAxis( src->plane.normal(), src->lightmapAxis ); src->lightmapAxis = CalcLightmapAxis( src->plane.normal() );
} }
} }