add winding_next_point()

This commit is contained in:
Garux
2025-11-14 17:14:25 +05:00
parent c1b4be1db5
commit 943845e8c0
4 changed files with 20 additions and 16 deletions
+8 -8
View File
@@ -58,12 +58,12 @@ winding_t AllocWinding( int points ){
void RemoveColinearPoints( winding_t& w ){
winding_t p = AllocWinding( w.size() );
for ( size_t i = 0; i < w.size(); ++i )
for ( auto i = w.begin(); i != w.end(); ++i )
{
const size_t j = winding_next( w, i );
const size_t k = winding_next( w, j );
if ( vector3_dot( VectorNormalized( w[k] - w[j] ), VectorNormalized( w[k] - w[i] ) ) < 0.999 ) {
p.push_back( w[i] );
const auto j = winding_next( w, i );
const auto k = winding_next( w, j );
if ( vector3_dot( VectorNormalized( *k - *j ), VectorNormalized( *k - *i ) ) < 0.999 ) {
p.push_back( *i );
}
}
@@ -376,7 +376,7 @@ std::pair<winding_t, winding_t> ClipWindingEpsilonStrict( const winding_t& in
}
// generate a split point
const Vector3& p2 = in[winding_next( in, i )];
const Vector3& p2 = winding_next_point( in, i );
const double dot = dists[i] / ( dists[i] - dists[i + 1] );
Vector3 mid;
for ( size_t j = 0; j < 3; ++j )
@@ -602,7 +602,7 @@ void ChopWindingInPlace( winding_t& inout, const Plane3f& plane, float epsilon )
}
// generate a split point
const Vector3& p2 = in[winding_next( in, i )];
const Vector3& p2 = winding_next_point( in, i );
const double dot = dists[i] / ( dists[i] - dists[i + 1] );
Vector3 mid;
@@ -663,7 +663,7 @@ void CheckWinding( const winding_t& w ){
}
// check the edge isnt degenerate
const Vector3& p2 = w[winding_next( w, i )];
const Vector3& p2 = winding_next_point( w, i );
const Vector3 dir = p2 - p1;
if ( vector3_length( dir ) < ON_EPSILON ) {
+4
View File
@@ -31,6 +31,10 @@ template<class T>
size_t winding_next( const std::vector<BasicVector3<T>>& w, size_t index ){
return ++index == w.size()? 0 : index;
}
template<class T>
const BasicVector3<T>& winding_next_point( const std::vector<BasicVector3<T>>& w, size_t index ){
return w[ winding_next( w, index ) ];
}
// it < w.end()
template<class T>
std::vector<BasicVector3<T>>::iterator winding_next( std::vector<BasicVector3<T>>& w, typename std::vector<BasicVector3<T>>::iterator it ){
+1 -1
View File
@@ -647,7 +647,7 @@ void AddBrushBevels(){
// test the non-axial plane edges
for ( size_t i = 6; i < sides.size(); ++i ) {
for ( size_t j = 0; j < sides[i].winding.size(); ++j ) {
Vector3 vec = sides[i].winding[j] - sides[i].winding[winding_next( sides[i].winding, j )];
Vector3 vec = sides[i].winding[j] - winding_next_point( sides[i].winding, j );
if ( VectorNormalize( vec ) < 0.5f ) {
continue;
}
+7 -7
View File
@@ -453,7 +453,7 @@ struct ClipSides
buildBrush.sides[0].planenum = FindFloatPlane( fplane, fw );
for( size_t i = 0; i < splanes.size(); ++i ){
buildBrush.sides[i + 1].planenum = FindFloatPlane( splanes[i], std::array{ fw[i], fw[winding_next( fw, i )] } );
buildBrush.sides[i + 1].planenum = FindFloatPlane( splanes[i], std::array{ fw[i], winding_next_point( fw, i ) } );
}
if( doBack )
buildBrush.sides.back().planenum = FindFloatPlane( bplane, bw );
@@ -478,7 +478,7 @@ static void clipModel_default( ClipSides& cs ){
/* make side planes */
for ( size_t i = 0; i < cs.fw.size(); ++i )
{
cs.splanes[i].normal() = VectorNormalized( vector3_cross( bestNormal, cs.fw[winding_next( cs.fw, i )] - cs.fw[i] ) );
cs.splanes[i].normal() = VectorNormalized( vector3_cross( bestNormal, winding_next_point( cs.fw, i ) - cs.fw[i] ) );
cs.splanes[i].dist() = vector3_dot( cs.fw[i], cs.splanes[i].normal() );
}
@@ -498,7 +498,7 @@ static void clipModel_pyramidal( ClipSides& cs ){
/* make side planes */
for ( size_t i = 0; i < cs.fw.size(); ++i )
{
PlaneFromPoints( cs.splanes[i], cs.fw[winding_next( cs.fw, i )], cs.fw[i], Vector3( cnt ) );
PlaneFromPoints( cs.splanes[i], winding_next_point( cs.fw, i ), cs.fw[i], Vector3( cnt ) );
#if 0 // no definite profit, problems are rather triggered by windings more complex than simple triangle
const auto susNormal = []( float a, float b ){ return ( a != 0 || b != 0 ) && std::fabs( a ) < .00025f && std::fabs( b ) < .00025f; };
if( susNormal( cs.splanes[i].a, cs.splanes[i].b )
@@ -515,7 +515,7 @@ static void clipModel_faceNormals( ClipSides& cs ){
/* make side planes */
for ( size_t i = 0; i < cs.fw.size(); ++i )
{
cs.splanes[i].normal() = VectorNormalized( vector3_cross( cs.fplane.normal(), cs.fw[winding_next( cs.fw, i )] - cs.fw[i] ) );
cs.splanes[i].normal() = VectorNormalized( vector3_cross( cs.fplane.normal(), winding_next_point( cs.fw, i ) - cs.fw[i] ) );
cs.splanes[i].dist() = vector3_dot( cs.fw[i], cs.splanes[i].normal() );
}
@@ -560,7 +560,7 @@ static void clipModel_45( ClipSides& cs ){
/* 45 degrees normals for side planes */
for ( size_t i = 0; i < cs.fw.size(); ++i )
{
const Vector3 enrm = VectorNormalized( vector3_cross( cs.fplane.normal(), cs.fw[winding_next( cs.fw, i )] - cs.fw[i] ) );
const Vector3 enrm = VectorNormalized( vector3_cross( cs.fplane.normal(), winding_next_point( cs.fw, i ) - cs.fw[i] ) );
/* make side planes */
cs.splanes[i].normal() = VectorNormalized( enrm - cs.fplane.normal() );
cs.splanes[i].dist() = vector3_dot( cs.fw[i], cs.splanes[i].normal() );
@@ -601,7 +601,7 @@ static void clipModel_terrain( ClipSides& cs, const int spf, size_t axis, const
/* make side planes */
for ( size_t i = 0; i < cs.fw.size(); ++i )
{
cs.splanes[i].normal() = VectorNormalized( vector3_cross( bestNormal, cs.fw[winding_next( cs.fw, i )] - cs.fw[i] ) );
cs.splanes[i].normal() = VectorNormalized( vector3_cross( bestNormal, winding_next_point( cs.fw, i ) - cs.fw[i] ) );
cs.splanes[i].dist() = vector3_dot( cs.fw[i], cs.splanes[i].normal() );
}
@@ -667,7 +667,7 @@ static void clipModel_axialPyramid( ClipSides& cs, const float limDepth ){
for ( size_t j = 0; j < 3; ++j ){ // axes
Plane3f pln;
Vector3 nrm = cs.fw[winding_next( cs.fw, i )] - cs.fw[i];
Vector3 nrm = winding_next_point( cs.fw, i ) - cs.fw[i];
if ( j == axis ){
pln.normal() = VectorNormalized( vector3_cross( bestNormal, nrm ) );
}