bool DTreePlanter::FindDropPoint(vec3_t in, vec3_t out) { DPlane p1; DPlane p2; vec3_t vUp = { 0, 0, 1 }; vec3_t vForward = { 0, 1, 0 }; vec3_t vLeft = { 1, 0, 0 }; in[2] = 65535; VectorCopy(in, p1.points[0]); VectorCopy(in, p1.points[1]); VectorCopy(in, p1.points[2]); VectorMA(p1.points[1], 20, vUp, p1.points[1]); VectorMA(p1.points[1], 20, vLeft, p1.points[2]); VectorCopy(in, p2.points[0]); VectorCopy(in, p2.points[1]); VectorCopy(in, p2.points[2]); VectorMA(p1.points[1], 20, vUp, p2.points[1]); VectorMA(p1.points[1], 20, vForward, p2.points[2]); p1.Rebuild(); p2.Rebuild(); bool found = false; vec3_t temp; vec_t dist; int cnt = m_world.GetIDMax(); for(int i = 0; i < cnt; i++) { DBrush* pBrush = m_world.GetBrushForID( i ); if(pBrush->IntersectsWith( &p1, &p2, temp )) { vec3_t diff; vec_t tempdist; VectorSubtract(in, temp, diff); tempdist = VectorLength( diff ); if(!found || (tempdist < dist)) { dist = tempdist; VectorCopy( temp, out ); found = true; } } } return found; }
bool pre( scene::Node& node ) const { scene::Path path( NodeReference( GlobalSceneGraph().root() ) ); path.push( NodeReference( *m_entity->QER_Entity ) ); path.push( NodeReference( node ) ); scene::Instance* instance = GlobalSceneGraph().find( path ); ASSERT_MESSAGE( instance != 0, "" ); if ( Node_isPatch( node ) ) { DPatch* loadPatch = m_entity->NewPatch(); loadPatch->LoadFromPatch( *instance ); } else if ( Node_isBrush( node ) ) { DBrush* loadBrush = m_entity->NewBrush( m_count++ ); loadBrush->LoadFromBrush( *instance, true ); } return false; }
void DEntity::LoadSelectedBrushes(){ ClearBrushes(); ClearEPairs(); int count = g_FuncTable.m_pfnAllocateSelectedBrushHandles(); for ( int i = 0; i < count; i++ ) { brush_t *brush = (brush_t*)g_FuncTable.m_pfnGetSelectedBrushHandle( i ); if ( brush->pPatch ) { continue; } DBrush* loadBrush = NewBrush( i ); loadBrush->LoadFromBrush_t( brush, TRUE ); } g_FuncTable.m_pfnReleaseSelectedBrushHandles(); }
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; }
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; }
void DEntity_loadBrush( DEntity& entity, scene::Instance& brush ){ DBrush* loadBrush = entity.NewBrush( static_cast<int>( entity.brushList.size() ) ); loadBrush->LoadFromBrush( brush, true ); }
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 }
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 ); } }
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 } }