#define CSR_PIf 3.14159265358979323846264338327950288f
+// Simple min/max replacements
float csr_minf( float a, float b )
{
- if( a < b )
- return a;
- return b;
+ return a < b? a: b;
}
float csr_maxf( float a, float b )
{
- if( a > b )
- return a;
- return b;
+ return a > b? a: b;
}
int csr_min( int a, int b )
{
- if( a < b )
- return a;
- return b;
+ return a < b? a: b;
}
int csr_max( int a, int b )
{
- if( a > b )
- return a;
- return b;
+ return a > b? a: b;
}
+// Convert double precision vec3 into single
void v3d_v3f( double a[3], float b[3] )
{
b[0] = a[0];
b[2] = a[2];
}
+// Convert degrees to radians
float csr_rad( float deg )
{
return deg * CSR_PIf / 180.0f;
-(p[0]*p[3] * p[0] + p[1]*p[3] * p[1] + p[2]*p[3] * p[2])
;
}
-
-// Raycasting
-// ==================================================================================================================
-
-int csr_slabs( v3f box[2], v3f o, v3f id )
-{
- v3f t0; v3f t1;
- v3f tmin; v3f tmax;
-
- v3_sub( box[0], o, t0 );
- v3_sub( box[1], o, t1 );
- v3_mul( t0, id, t0 );
- v3_mul( t1, id, t1 );
-
- v3_minv( t0, t1, tmin );
- v3_maxv( t0, t1, tmax );
-
- return v3_maxf( tmin ) <= v3_minf( tmax );
-}
-
-float csr_ray_tri( v3f o, v3f d, v3f v0, v3f v1, v3f v2, float *u, float *v )
-{
- float const k_cullEpsilon = 0.000001f;
-
- v3f v0v1;
- v3f v0v2;
- v3f p;
- float det, inv;
-
- v3f tv;
- v3f qv;
-
- v3_sub( v1, v0, v0v1 );
- v3_sub( v2, v0, v0v2 );
- v3_cross( d, v0v2, p );
-
- det = v3_dot( v0v1, p );
-
- if( det < k_cullEpsilon ) return -INFINITY;
-
- inv = 1.f / det;
-
- v3_sub( o, v0, tv );
- *u = v3_dot( tv, p ) * inv;
-
- if( *u < 0.f || *u > 1.f ) return -INFINITY;
-
- v3_cross( tv, v0v1, qv );
- *v = v3_dot( d, qv ) * inv;
-
- if( *v < 0.f || *u + *v > 1.f ) return -INFINITY;
-
- return v3_dot( v0v2, qv ) * inv;
-}
{
ESolidResult flag = k_ESolidResult_valid;
+ double planes[ SOLID_MAX_SIDES*4 ];
vmf_face faces[ SOLID_MAX_SIDES ];
- int is_displacement = 0;
+ int is_displacement = solid_has_displacement( node );
int num_planes = 0;
- // TODO: What is this for again? surely it should be the other way around... i think...
- if( solid_has_displacement( node ) )
- {
- is_displacement = 1;
- /*
-
- printf( "solid_has_displacement\n" );
- num_planes = vmf_api.bisectors;
-
- // Add dummy stuff for globals
- // ???
- for( int k = 0; k < vmf_api.bisectors; k ++ )
- {
- vmf_face *dummy = faces + k;
- dummy->indices = NULL;
- dummy->dispinfo = NULL;
- dummy->material = NULL;
- }
-
- is_displacement = 1;
- */
- }
-
int it = 0;
vdf_node *pSide;
while( (pSide = vdf_next(node, "side", &it)) )
kv_double_array( pSide, "plane", 9, points );
- tri_to_plane( points+6, points+3, points+0, vmf_api.planes + num_planes * 4 );
+ tri_to_plane( points+6, points+3, points+0, planes + num_planes * 4 );
num_planes ++;
}
if( (faces[ i[0] ].blacklisted && faces[ i[1] ].blacklisted && faces[ i[2] ].blacklisted) )
continue;
- if( !plane_intersect( vmf_api.planes+i[0]*4, vmf_api.planes+i[1]*4, vmf_api.planes+i[2]*4, p ) )
+ if( !plane_intersect( planes+i[0]*4, planes+i[1]*4, planes+i[2]*4, p ) )
continue;
// Check for illegal verts (eg: got clipped by bisectors)
int valid = 1;
for( int m = 0; m < num_planes; m ++ )
{
- if( plane_polarity( vmf_api.planes+m*4, p ) > 1e-6f )
+ if( plane_polarity( planes+m*4, p ) > 1e-6f )
{
valid = 0;
break;
face_add_indice( faces + i[k], c );
v3d_v3f( p, ctx->verts[ c ].co );
- v3d_v3f( vmf_api.planes+i[k]*4, ctx->verts[ c ].nrm );
+ v3d_v3f( planes+i[k]*4, ctx->verts[ c ].nrm );
csr_sb_inc( ctx->verts, 1 );
}
}
// Sort each faces and trianglulalate them
- for( int k = vmf_api.bisectors; k < num_planes; k ++ )
+ for( int k = 0; k < num_planes; k ++ )
{
vmf_face *face = faces + k;
if( csr_sb_count( face->indices ) < 3 )
{
- if( !vmf_api.bisectors )
- {
- flag = k_ESolidResult_degenerate;
- fprintf( stderr, "Skipping degenerate face\n" );
- }
+ flag = k_ESolidResult_degenerate;
+ fprintf( stderr, "Skipping degenerate face\n" );
continue;
}
// Sort only if there is no displacements, or if this side is
if( !is_displacement || ( is_displacement && face->dispinfo ) )
{
- sort_coplanar( vmf_api.planes+k*4, ctx->verts, face->indices, csr_sb_count( face->indices ) );
+ sort_coplanar( planes+k*4, ctx->verts, face->indices, csr_sb_count( face->indices ) );
}
if( is_displacement )
{
if( csr_sb_count( face->indices ) != 4 )
{
- // Mute error if we have global planes cause they
- // are of course gonna fuck things up here
- if( !vmf_api.bisectors )
- {
- flag = k_ESolidResult_degenerate;
- fprintf( stderr, "Skipping degenerate displacement\n" );
- }
+ flag = k_ESolidResult_degenerate;
+ fprintf( stderr, "Skipping degenerate displacement\n" );
continue;
}
}
}
- // Get corners of displacement
- float *SW = ctx->verts[ face->indices[ sw ] ].co;
- float *NW = ctx->verts[ face->indices[ (sw+1) % 4] ].co;
- float *NE = ctx->verts[ face->indices[ (sw+2) % 4] ].co;
- float *SE = ctx->verts[ face->indices[ (sw+3) % 4] ].co;
-
// Can be either 5, 9, 17
numpoints = pow( 2, kv_get_int( dispinfo, "power", 2 ) ) + 1;
u32 reqverts = numpoints*numpoints;
ctx->verts = csr_sb_reserve( ctx->verts, reqverts, sizeof( vmf_vert ) );
ctx->indices = csr_sb_reserve( ctx->indices, reqidx, sizeof( u32 ) );
+
+ // Get corners of displacement
+ float *SW = ctx->verts[ face->indices[ sw ] ].co;
+ float *NW = ctx->verts[ face->indices[ (sw+1) % 4] ].co;
+ float *NE = ctx->verts[ face->indices[ (sw+2) % 4] ].co;
+ float *SE = ctx->verts[ face->indices[ (sw+3) % 4] ].co;
float normals[ 17*3 ];
float distances[ 17 ];