Exemplo n.º 1
0
bool DEntity::LoadFromPrt( char *filename ){
	CPortals portals;
	strcpy( portals.fn, filename );
	portals.Load();

	if ( portals.node_count == 0 ) {
		return false;
	}

	ClearBrushes();
	ClearEPairs();

	bool build = false;
	for ( unsigned int i = 0; i < portals.node_count; i++ )
	{
		build = false;
		DBrush* brush = NewBrush();

		for ( unsigned int j = 0; j < portals.node[i].portal_count; j++ )
		{
			for ( unsigned int k = 0; k < portals.node[i].portal[j].point_count - 2; k++ )
			{
				vec3_t v1{}, v2{}, normal{}, n{};
				VectorSubtract( portals.node[i].portal[j].point[k + 2].p, portals.node[i].portal[j].point[k + 1].p, v1 );
				VectorSubtract( portals.node[i].portal[j].point[k].p, portals.node[i].portal[j].point[k + 1].p, v2 );
				CrossProduct( v1, v2, n );
				VectorNormalize( n, v2 );

				if ( k == 0 ) {
					VectorCopy( v2, normal );
				}
				else
				{
					VectorSubtract( v2, normal, v1 );
					if ( VectorLength( v1 ) > 0.01 ) {
						build = true;
						break;
					}
				}
			}

			if ( !build ) {
				brush->AddFace( portals.node[i].portal[j].point[2].p, portals.node[i].portal[j].point[1].p, portals.node[i].portal[j].point[0].p, "textures/common/caulk", false );
			}
			else{
				brush->AddFace( portals.node[i].portal[j].point[0].p, portals.node[i].portal[j].point[1].p, portals.node[i].portal[j].point[2].p, "textures/common/caulk", false );
			}
		}
		if ( build ) {
			brush->BuildInRadiant( false, NULL );
		}
	}

	return true;
}
Exemplo n.º 2
0
void DShape::BuildRegularPrism( vec3_t min, vec3_t max, int nSides, bool bAlignTop ){
	vec3_t vc[MAX_POLYGON_FACES + 2], vd[MAX_POLYGON_FACES + 2];

	vec3_t radius;
	vec3_t origin;

	VectorSubtract( max, min, radius );
	VectorScale( radius, 0.5f, radius );
	// calc 3d radius and origin
	VectorAdd( max, min, origin );
	VectorScale( origin, 0.5f, origin );

	float phase = 0.0f;

	if ( bAlignTop ) {
		phase = -( Q_PI / nSides );
		VectorScale( radius, static_cast< float >( 1 / cos( phase ) ), radius );
	}

	//----- Build Polygon Vertices -----

	int i;
	for ( i = 0; i < nSides; i++ )
	{
		VectorCopy( origin, vc[i] );
		VectorCopy( origin, vd[i] );

		vc[i][2] = min[2];
		vd[i][2] = max[2];

		vc[i][0] += radius[0] * sinf( ( 2 * Q_PI * i / nSides ) + phase );
		vc[i][1] += radius[1] * cosf( ( 2 * Q_PI * i / nSides ) + phase );

		vd[i][0] = vc[i][0];
		vd[i][1] = vc[i][1];
	}

	VectorCopy( vc[0], vc[nSides] );
	VectorCopy( vd[0], vd[nSides] );
	VectorCopy( vc[1], vc[nSides + 1] );
	VectorCopy( vd[1], vd[nSides + 1] );

	//----------------------------------

	DBrush* pB = m_Container.GetWorldSpawn()->NewBrush( m_nNextBrush++ );

	for ( i = 1; i <= nSides; i++ )
		pB->AddFace( vc[i - 1], vc[i], vd[i], GetCurrentTexture(), FALSE );

	pB->AddFace( vc[2], vc[1], vc[0], "textures/common/caulk", FALSE );
	pB->AddFace( vd[0], vd[1], vd[2], "textures/common/caulk", FALSE );
}
Exemplo n.º 3
0
DBrush* DShape::GetBoundingCube( vec3_t min, vec3_t max, const char *textureName, DEntity* ent, bool* bUseFaces ){
	DBrush* pB;
	if ( ent == NULL ) {
		pB = m_Container.GetWorldSpawn()->NewBrush( m_nNextBrush++ );
	}
	else{
		pB = ent->NewBrush( m_nNextBrush++ );
	}

	//----- Build Outer Bounds ---------

	vec3_t v1, v2, v3, v5, v6, v7;
	VectorCopy( min, v1 );
	VectorCopy( min, v2 );
	VectorCopy( min, v3 );
	VectorCopy( max, v5 );
	VectorCopy( max, v6 );
	VectorCopy( max, v7 );

	v2[0] = max[0];
	v3[1] = max[1];

	v6[0] = min[0];
	v7[1] = min[1];

	//----------------------------------

	//----- Add Six Cube Faces ---------

	if ( bUseFaces[0] ) {
		pB->AddFace( v1, v2, v3, textureName, FALSE );
	}
	if ( bUseFaces[1] ) {
		pB->AddFace( v1, v3, v6, textureName, FALSE );
	}
	if ( bUseFaces[2] ) {
		pB->AddFace( v1, v7, v2, textureName, FALSE );
	}

	if ( bUseFaces[3] ) {
		pB->AddFace( v5, v6, v3, textureName, FALSE );
	}
	if ( bUseFaces[4] ) {
		pB->AddFace( v5, v2, v7, textureName, FALSE );
	}
	if ( bUseFaces[5] ) {
		pB->AddFace( v5, v7, v6, textureName, FALSE );
	}

	//----------------------------------

	return pB;
}
Exemplo n.º 4
0
DBrush* DShape::GetBoundingCube_Ext( vec3_t min, vec3_t max, const char *textureName, bool* bUseFaces, bool detail ){
	DBrush* pB = new DBrush;
	//----- Build Outer Bounds ---------

	vec3_t v1, v2, v3, v5, v6, v7;
	VectorCopy( min, v1 );
	VectorCopy( min, v2 );
	VectorCopy( min, v3 );
	VectorCopy( max, v5 );
	VectorCopy( max, v6 );
	VectorCopy( max, v7 );

	v2[0] = max[0];
	v3[1] = max[1];

	v6[0] = min[0];
	v7[1] = min[1];

	//----------------------------------

	//----- Add Six Cube Faces ---------

	if ( bUseFaces[0] ) {
		pB->AddFace( v1, v2, v3, textureName, detail );
	}
	if ( bUseFaces[1] ) {
		pB->AddFace( v1, v3, v6, textureName, detail );
	}
	if ( bUseFaces[2] ) {
		pB->AddFace( v1, v7, v2, textureName, detail );
	}

	if ( bUseFaces[3] ) {
		pB->AddFace( v5, v6, v3, textureName, detail );
	}
	if ( bUseFaces[4] ) {
		pB->AddFace( v5, v2, v7, textureName, detail );
	}
	if ( bUseFaces[5] ) {
		pB->AddFace( v5, v7, v6, textureName, detail );
	}

	//----------------------------------

	return pB;
}
Exemplo n.º 5
0
DPlane* DEntity::AddFaceToBrush( vec3_t va, vec3_t vb, vec3_t vc, _QERFaceData* faceData, int ID ){
	DBrush* buildBrush = GetBrushForID( ID );
	return buildBrush->AddFace( va, vb, vc, faceData );
	// slow, dont use much
}
Exemplo n.º 6
0
void DShape::BuildBorderedPrism( vec3_t min, vec3_t max, int nSides, int nBorder, bool bAlignTop ){
	vec3_t va[MAX_POLYGON_FACES + 2], vb[MAX_POLYGON_FACES + 2];
	vec3_t vc[MAX_POLYGON_FACES + 2], vd[MAX_POLYGON_FACES + 2];

	vec3_t radius;
	vec3_t origin;

	VectorSubtract( max, min, radius );
	VectorScale( radius, 0.5f, radius );
	// calc 3d radius and origin
	VectorAdd( max, min, origin );
	VectorScale( origin, 0.5f, origin );

	if ( nBorder >= Min( radius[0], radius[1] ) ) {
//		DoMessageBox("Border is too large", "Error", MB_OK);
		return;
	}

	float phase = 0.0f;

	if ( bAlignTop ) {
		phase = -( Q_PI / nSides );
		VectorScale( radius, static_cast< float >( 1 / cos( phase ) ), radius );
	}

	//----- Build Polygon Vertices -----

	int i;
	for ( i = 0; i < nSides; i++ )
	{
		VectorCopy( origin, va[i] );
		VectorCopy( origin, vb[i] );
		VectorCopy( origin, vc[i] );
		VectorCopy( origin, vd[i] );

		va[i][2] = min[2];
		vb[i][2] = max[2];

		va[i][0] += ( radius[0] - nBorder ) * sinf( ( 2 * Q_PI * i / nSides ) + phase );
		va[i][1] += ( radius[1] - nBorder ) * cosf( ( 2 * Q_PI * i / nSides ) + phase );

		vb[i][0] = va[i][0];
		vb[i][1] = va[i][1];



		vc[i][2] = min[2];
		vd[i][2] = max[2];

		vc[i][0] += radius[0] * sinf( ( 2 * Q_PI * i / nSides ) + phase );
		vc[i][1] += radius[1] * cosf( ( 2 * Q_PI * i / nSides ) + phase );

		vd[i][0] = vc[i][0];
		vd[i][1] = vc[i][1];
	}

	VectorCopy( va[0], va[nSides] );
	VectorCopy( vb[0], vb[nSides] );
	VectorCopy( va[1], va[nSides + 1] );
	VectorCopy( vb[1], vb[nSides + 1] );

	VectorCopy( vc[0], vc[nSides] );
	VectorCopy( vd[0], vd[nSides] );
	VectorCopy( vc[1], vc[nSides + 1] );
	VectorCopy( vd[1], vd[nSides + 1] );

	//----------------------------------

	for ( i = 1; i <= nSides; i++ )
	{
		DBrush* pB = GetBoundingCube( min, max, "textures/common/caulk" );

		pB->AddFace( origin, vc[i - 1], vd[i - 1], "textures/common/caulk", FALSE );
		pB->AddFace( origin, vd[i], vc[i], "textures/common/caulk", FALSE );

		pB->AddFace( vc[i - 1], vc[i], vd[i], GetCurrentTexture(), FALSE );
		pB->AddFace( vb[i], va[i], va[i - 1], GetCurrentTexture(), FALSE );
	}
}
Exemplo n.º 7
0
void DShape::BuildInversePrism( vec3_t min, vec3_t max, int nSides, bool bAlignTop ){
	vec3_t va[MAX_POLYGON_FACES + 1], vb[MAX_POLYGON_FACES + 1];
	vec3_t radius;
	vec3_t origin;

	VectorSubtract( max, min, radius );
	VectorScale( radius, 0.5f, radius );
	// calc 3d radius and origin
	VectorAdd( max, min, origin );
	VectorScale( origin, 0.5f, origin );

	float phase = 0.0f;

	if ( bAlignTop ) {
		phase = -( Q_PI / nSides );
		VectorScale( radius, static_cast< float >( 1 / cos( phase ) ), radius );
	}

	//----- Build Polygon Vertices -----

	int i;
	for ( i = 0; i < nSides; i++ )
	{
		VectorCopy( origin, va[i] );
		VectorCopy( origin, vb[i] );

		va[i][2] = min[2];
		vb[i][2] = max[2];

		va[i][0] += radius[0] * sinf( ( 2 * Q_PI * i / nSides ) + phase );
		va[i][1] += radius[1] * cosf( ( 2 * Q_PI * i / nSides ) + phase );

		vb[i][0] = va[i][0];
		vb[i][1] = va[i][1];
	}

	VectorCopy( va[0], va[nSides] );
	VectorCopy( vb[0], vb[nSides] );

	//----------------------------------

	for ( i = 1; i <= nSides; i++ )
	{
		DBrush* pB = GetBoundingCube( min, max, "textures/common/caulk" );

		vec3_t top, bottom;
		VectorCopy( va[i - 1], top );
		VectorCopy( va[i], bottom );

		if ( va[i - 1][1] > va[i][1] ) {
			top[0] += 5;
			bottom[0] += 5;
		}
		else    // flip direction of plane on crossover
		{
			top[0] -= 5;
			bottom[0] -= 5;
		}

		if ( top[1] != bottom[1] ) { // internal line is flat already if true
			pB->AddFace( va[i - 1], top, vb[i - 1], "textures/common/caulk", FALSE );
			pB->AddFace( va[i], vb[i], bottom, "textures/common/caulk", FALSE );
		}   // add cut-off planes

		pB->AddFace( va[i - 1], vb[i - 1], vb[i], GetCurrentTexture(), FALSE );
		// add internal polygon plane
	}
}