2007-11-04 03:51:54 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
BobToolz plugin for GtkRadiant
|
|
|
|
Copyright (C) 2001 Gordon Biggans
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
// DBrush.cpp: implementation of the DBrush class.
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "StdAfx.h"
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#pragma warning(disable : 4786)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "DBrush.h"
|
|
|
|
#include "DWinding.h"
|
2008-02-18 20:54:58 +00:00
|
|
|
#include "dialogs/dialogs-gtk.h"
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
#include "misc.h"
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Construction/Destruction
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
DBrush::DBrush( int ID ){
|
2007-11-04 03:51:54 +00:00
|
|
|
m_nBrushID = ID;
|
|
|
|
bBoundsBuilt = FALSE;
|
|
|
|
QER_brush = NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
DBrush::~DBrush(){
|
2007-11-04 03:51:54 +00:00
|
|
|
ClearFaces();
|
|
|
|
ClearPoints();
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Implementation
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
DPlane* DBrush::AddFace( vec3_t va, vec3_t vb, vec3_t vc, _QERFaceData* texData ){
|
2007-11-04 03:51:54 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
// Sys_Printf("(%f %f %f) (%f %f %f) (%f %f %f)\n", va[0], va[1], va[2], vb[0], vb[1], vb[2], vc[0], vc[1], vc[2]);
|
|
|
|
#endif
|
|
|
|
bBoundsBuilt = FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
DPlane* newFace = new DPlane( va, vb, vc, texData );
|
|
|
|
faceList.push_back( newFace );
|
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
return newFace;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int DBrush::BuildPoints(){
|
2007-11-04 03:51:54 +00:00
|
|
|
ClearPoints();
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( faceList.size() <= 3 ) { // if less than 3 faces, there can be no points
|
|
|
|
return 0; // with only 3 faces u can't have a bounded soild
|
|
|
|
|
|
|
|
}
|
|
|
|
for ( list<DPlane *>::const_iterator p1 = faceList.begin(); p1 != faceList.end(); p1++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
list<DPlane *>::const_iterator p2 = p1;
|
|
|
|
for ( p2++; p2 != faceList.end(); p2++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
list<DPlane *>::const_iterator p3 = p2;
|
|
|
|
for ( p3++; p3 != faceList.end(); p3++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
vec3_t pnt;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( *p1 )->PlaneIntersection( *p2, *p3, pnt ) ) {
|
|
|
|
int pos = PointPosition( pnt );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( pos == POINT_IN_BRUSH ) { // ???? shouldn't happen here
|
|
|
|
Sys_Printf( "ERROR:: Build Brush Points: Point IN brush!!!\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( pos == POINT_ON_BRUSH ) { // normal point
|
|
|
|
if ( !HasPoint( pnt ) ) {
|
|
|
|
AddPoint( pnt );
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
/* else
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_Printf("Duplicate Point Found, pyramids ahoy!!!!!\n");*/
|
2007-11-04 03:51:54 +00:00
|
|
|
// point lies on more that 3 planes
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
// otherwise point is removed due to another plane..
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
// Sys_Printf("(%f, %f, %f)\n", pnt[0], pnt[1], pnt[2]);
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
// Sys_Printf("%i points on brush\n", pointList.size());
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return pointList.size();
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void DBrush::LoadFromBrush_t( brush_t* brush, bool textured ){
|
2007-11-04 03:51:54 +00:00
|
|
|
ClearFaces();
|
|
|
|
ClearPoints();
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( int i = g_FuncTable.m_pfnGetFaceCount( brush ) - 1; i >= 0 ; i-- )
|
|
|
|
{ // running backwards so i dont have to use the count function each time (OPT)
|
|
|
|
_QERFaceData* faceData = g_FuncTable.m_pfnGetFaceData( brush, i );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( faceData == NULL ) {
|
|
|
|
DoMessageBox( "Null pointer returned", "WARNING!", MB_OK );
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( textured ) {
|
|
|
|
AddFace( faceData->m_v1, faceData->m_v2, faceData->m_v3, faceData );
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
AddFace( faceData->m_v1, faceData->m_v2, faceData->m_v3, NULL );
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QER_brush = brush;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int DBrush::PointPosition( vec3_t pnt ){
|
|
|
|
int state = POINT_IN_BRUSH; // if nothing happens point is inside brush
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( list<DPlane *>::const_iterator chkPlane = faceList.begin(); chkPlane != faceList.end(); chkPlane++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
float dist = ( *chkPlane )->DistanceToPoint( pnt );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( dist > MAX_ROUND_ERROR ) {
|
|
|
|
return POINT_OUT_BRUSH; // if point is in front of plane, it CANT be in the brush
|
|
|
|
}
|
|
|
|
else if ( fabs( dist ) < MAX_ROUND_ERROR ) {
|
|
|
|
state = POINT_ON_BRUSH; // if point is ON plane point is either ON the brush
|
|
|
|
}
|
|
|
|
// or outside it, it can no longer be in it
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void DBrush::ClearPoints(){
|
|
|
|
for ( list<DPoint *>::const_iterator deadPoint = pointList.begin(); deadPoint != pointList.end(); deadPoint++ ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
delete *deadPoint;
|
|
|
|
}
|
|
|
|
pointList.clear();
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void DBrush::ClearFaces(){
|
2007-11-04 03:51:54 +00:00
|
|
|
bBoundsBuilt = FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( list<DPlane *>::const_iterator deadPlane = faceList.begin(); deadPlane != faceList.end(); deadPlane++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
delete *deadPlane;
|
|
|
|
}
|
|
|
|
faceList.clear();
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void DBrush::AddPoint( vec3_t pnt ){
|
2007-11-04 03:51:54 +00:00
|
|
|
DPoint* newPoint = new DPoint;
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorCopy( pnt, newPoint->_pnt );
|
|
|
|
pointList.push_back( newPoint );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
bool DBrush::HasPoint( vec3_t pnt ){
|
|
|
|
for ( list<DPoint *>::const_iterator chkPoint = pointList.begin(); chkPoint != pointList.end(); chkPoint++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( **chkPoint == pnt ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return TRUE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int DBrush::RemoveRedundantPlanes(){
|
2007-11-04 03:51:54 +00:00
|
|
|
int cnt = 0;
|
|
|
|
list<DPlane *>::iterator chkPlane;
|
|
|
|
|
|
|
|
// find duplicate planes
|
2012-03-17 20:01:54 +00:00
|
|
|
list<DPlane *>::iterator p1 = faceList.begin();
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( p1 != faceList.end() )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
list<DPlane *>::iterator p2 = p1;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( p2++; p2 != faceList.end(); p2++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( **p1 == **p2 ) {
|
|
|
|
if ( !strcmp( ( *p1 )->texInfo.m_TextureName, "textures/common/caulk" ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
delete *p1;
|
2012-03-17 20:01:54 +00:00
|
|
|
p1 = faceList.erase( p1 ); // duplicate plane
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete *p2;
|
2012-03-17 20:01:54 +00:00
|
|
|
p2 = faceList.erase( p2 ); // duplicate plane
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cnt++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( p2 == faceList.end() ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
p1++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
//+djbob kill planes with bad normal, they are more of a nuisance than losing a brush
|
2012-03-17 20:01:54 +00:00
|
|
|
chkPlane = faceList.begin();
|
|
|
|
while ( chkPlane != faceList.end() )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( VectorLength( ( *chkPlane )->normal ) == 0 ) { // plane has bad normal
|
2007-11-04 03:51:54 +00:00
|
|
|
delete *chkPlane;
|
2012-03-17 20:01:54 +00:00
|
|
|
chkPlane = faceList.erase( chkPlane );
|
2007-11-04 03:51:54 +00:00
|
|
|
cnt++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-11-04 03:51:54 +00:00
|
|
|
chkPlane++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//-djbob
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
if ( pointList.size() == 0 ) { // if points may not have been built, build them
|
2007-11-04 03:51:54 +00:00
|
|
|
/* if(BuildPoints() == 0) // just let the planes die if they are all bad
|
2012-03-17 20:01:54 +00:00
|
|
|
return cnt;*/
|
|
|
|
BuildPoints();
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
chkPlane = faceList.begin();
|
|
|
|
while ( chkPlane != faceList.end() )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( *chkPlane )->IsRedundant( pointList ) ) { // checks that plane "0wnz" :), 3 or more points
|
2007-11-04 03:51:54 +00:00
|
|
|
delete *chkPlane;
|
2012-03-17 20:01:54 +00:00
|
|
|
chkPlane = faceList.erase( chkPlane );
|
2007-11-04 03:51:54 +00:00
|
|
|
cnt++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:51:54 +00:00
|
|
|
chkPlane++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
bool DBrush::GetBounds( vec3_t min, vec3_t max ){
|
2007-11-04 03:51:54 +00:00
|
|
|
BuildBounds();
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !bBoundsBuilt ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorCopy( bbox_min, min );
|
|
|
|
VectorCopy( bbox_max, max );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
bool DBrush::BBoxCollision( DBrush* chkBrush ){
|
2007-11-04 03:51:54 +00:00
|
|
|
vec3_t min1, min2;
|
|
|
|
vec3_t max1, max2;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GetBounds( min1, max1 );
|
|
|
|
chkBrush->GetBounds( min2, max2 );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( min1[0] >= max2[0] ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( min1[1] >= max2[1] ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( min1[2] >= max2[2] ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( max1[0] <= min2[0] ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( max1[1] <= min2[1] ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( max1[2] <= min2[2] ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
DPlane* DBrush::HasPlane( DPlane* chkPlane ){
|
|
|
|
for ( list<DPlane *>::const_iterator brushPlane = faceList.begin(); brushPlane != faceList.end(); brushPlane++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( **brushPlane == *chkPlane ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return *brushPlane;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
bool DBrush::IsCutByPlane( DPlane *cuttingPlane ){
|
2007-11-04 03:51:54 +00:00
|
|
|
bool isInFront;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( pointList.size() == 0 ) {
|
|
|
|
if ( BuildPoints() == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
list<DPoint *>::const_iterator chkPnt = pointList.begin();
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( chkPnt == pointList.end() ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
float dist = cuttingPlane->DistanceToPoint( ( *chkPnt )->_pnt );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( dist > MAX_ROUND_ERROR ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
isInFront = FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( dist < MAX_ROUND_ERROR ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
isInFront = TRUE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:51:54 +00:00
|
|
|
return TRUE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( chkPnt++ = pointList.begin(); chkPnt != pointList.end(); chkPnt++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
dist = cuttingPlane->DistanceToPoint( ( *chkPnt )->_pnt );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( dist > MAX_ROUND_ERROR ) {
|
|
|
|
if ( isInFront ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return TRUE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( dist < MAX_ROUND_ERROR ) {
|
|
|
|
if ( !isInFront ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return TRUE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else{
|
2007-11-04 03:51:54 +00:00
|
|
|
return TRUE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
brush_t* DBrush::BuildInRadiant( bool allowDestruction, int* changeCnt, entity_t* entity ){
|
|
|
|
if ( allowDestruction ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
bool kill = TRUE;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
for ( list<DPlane *>::const_iterator chkPlane = faceList.begin(); chkPlane != faceList.end(); chkPlane++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( *chkPlane )->m_bChkOk ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
kill = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( kill ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return NULL;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//+djbob: fixed bug when brush had no faces "phantom brush" in radiant.
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( faceList.size() < 4 ) {
|
|
|
|
Sys_Printf( "Possible Phantom Brush Found, will not rebuild\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
//-djbob
|
|
|
|
|
|
|
|
QER_brush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( list<DPlane *>::const_iterator buildPlane = faceList.begin(); buildPlane != faceList.end(); buildPlane++ ) {
|
|
|
|
if ( ( *buildPlane )->AddToBrush_t( QER_brush ) && changeCnt ) {
|
|
|
|
( *changeCnt )++;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( entity ) {
|
|
|
|
g_FuncTable.m_pfnCommitBrushHandleToEntity( QER_brush, entity );
|
|
|
|
g_BrushTable.m_pfnBrush_Build( QER_brush, false, false, false, false );
|
|
|
|
g_BrushTable.m_pfnBrush_AddToList( QER_brush, g_AppDataTable.m_pfnSelectedBrushes() );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
g_FuncTable.m_pfnCommitBrushHandle( QER_brush );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return QER_brush;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void DBrush::CutByPlane( DPlane *cutPlane, DBrush **newBrush1, DBrush **newBrush2 ){
|
|
|
|
if ( !IsCutByPlane( cutPlane ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
*newBrush1 = NULL;
|
|
|
|
*newBrush2 = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DBrush* b1 = new DBrush;
|
|
|
|
DBrush* b2 = new DBrush;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
for ( list<DPlane *>::const_iterator parsePlane = faceList.begin(); parsePlane != faceList.end(); parsePlane++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
b1->AddFace( ( *parsePlane )->points[0], ( *parsePlane )->points[1], ( *parsePlane )->points[2], NULL );
|
|
|
|
b2->AddFace( ( *parsePlane )->points[0], ( *parsePlane )->points[1], ( *parsePlane )->points[2], NULL );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
b1->AddFace( cutPlane->points[0], cutPlane->points[1], cutPlane->points[2], NULL );
|
|
|
|
b2->AddFace( cutPlane->points[2], cutPlane->points[1], cutPlane->points[0], NULL );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
b1->RemoveRedundantPlanes();
|
|
|
|
b2->RemoveRedundantPlanes();
|
|
|
|
|
|
|
|
*newBrush1 = b1;
|
|
|
|
*newBrush2 = b2;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
bool DBrush::IntersectsWith( DBrush *chkBrush ){
|
|
|
|
if ( pointList.size() == 0 ) {
|
|
|
|
if ( BuildPoints() == 0 ) {
|
|
|
|
return FALSE; // invalid brush!!!!
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( chkBrush->pointList.size() == 0 ) {
|
|
|
|
if ( chkBrush->BuildPoints() == 0 ) {
|
|
|
|
return FALSE; // invalid brush!!!!
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !BBoxCollision( chkBrush ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
list<DPlane *>::const_iterator iplPlane;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( iplPlane = faceList.begin(); iplPlane != faceList.end(); iplPlane++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
bool allInFront = TRUE;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( list<DPoint *>::const_iterator iPoint = chkBrush->pointList.begin(); iPoint != chkBrush->pointList.end(); iPoint++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( *iplPlane )->DistanceToPoint( ( *iPoint )->_pnt ) < -MAX_ROUND_ERROR ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
allInFront = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( allInFront ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( iplPlane = chkBrush->faceList.begin(); iplPlane != chkBrush->faceList.end(); iplPlane++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
bool allInFront = TRUE;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( list<DPoint *>::const_iterator iPoint = pointList.begin(); iPoint != pointList.end(); iPoint++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( *iplPlane )->DistanceToPoint( ( *iPoint )->_pnt ) < -MAX_ROUND_ERROR ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
allInFront = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( allInFront ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
bool DBrush::IntersectsWith( DPlane* p1, DPlane* p2, vec3_t v ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
vec3_t vDown = { 0, 0, -1 };
|
|
|
|
|
|
|
|
list<DPlane *>::const_iterator iplPlane;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( iplPlane = faceList.begin(); iplPlane != faceList.end(); iplPlane++ ) {
|
|
|
|
DPlane* p = ( *iplPlane );
|
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
vec_t d = DotProduct( p->normal, vDown );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( d >= 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( p->PlaneIntersection( p1, p2, v ) ) {
|
|
|
|
if ( PointPosition( v ) != POINT_OUT_BRUSH ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void DBrush::BuildBounds(){
|
|
|
|
if ( !bBoundsBuilt ) {
|
|
|
|
if ( pointList.size() == 0 ) { // if points may not have been built, build them
|
|
|
|
if ( BuildPoints() == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
list<DPoint *>::const_iterator first = pointList.begin();
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorCopy( ( *first )->_pnt, bbox_min );
|
|
|
|
VectorCopy( ( *first )->_pnt, bbox_max );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
list<DPoint *>::const_iterator point = pointList.begin();
|
|
|
|
for ( point++; point != pointList.end(); point++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( *point )->_pnt[0] > bbox_max[0] ) {
|
|
|
|
bbox_max[0] = ( *point )->_pnt[0];
|
|
|
|
}
|
|
|
|
if ( ( *point )->_pnt[1] > bbox_max[1] ) {
|
|
|
|
bbox_max[1] = ( *point )->_pnt[1];
|
|
|
|
}
|
|
|
|
if ( ( *point )->_pnt[2] > bbox_max[2] ) {
|
|
|
|
bbox_max[2] = ( *point )->_pnt[2];
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( *point )->_pnt[0] < bbox_min[0] ) {
|
|
|
|
bbox_min[0] = ( *point )->_pnt[0];
|
|
|
|
}
|
|
|
|
if ( ( *point )->_pnt[1] < bbox_min[1] ) {
|
|
|
|
bbox_min[1] = ( *point )->_pnt[1];
|
|
|
|
}
|
|
|
|
if ( ( *point )->_pnt[2] < bbox_min[2] ) {
|
|
|
|
bbox_min[2] = ( *point )->_pnt[2];
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bBoundsBuilt = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
bool DBrush::BBoxTouch( DBrush *chkBrush ){
|
2007-11-04 03:51:54 +00:00
|
|
|
vec3_t min1, min2;
|
|
|
|
vec3_t max1, max2;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GetBounds( min1, max1 );
|
|
|
|
chkBrush->GetBounds( min2, max2 );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( min1[0] - max2[0] ) > MAX_ROUND_ERROR ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( ( min1[1] - max2[1] ) > MAX_ROUND_ERROR ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( ( min1[2] - max2[2] ) > MAX_ROUND_ERROR ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( min2[0] - max1[0] ) > MAX_ROUND_ERROR ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( ( min2[1] - max1[1] ) > MAX_ROUND_ERROR ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( ( min2[2] - max1[2] ) > MAX_ROUND_ERROR ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
int cnt = 0;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( min2[0] - max1[0] ) == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
cnt++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( min2[1] - max1[1] ) == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
cnt++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( min2[2] - max1[2] ) == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
cnt++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( min1[0] - max2[0] ) == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
cnt++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( min1[1] - max2[1] ) == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
cnt++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( min1[2] - max2[2] ) == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
cnt++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( cnt > 1 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void DBrush::ResetChecks( list<Str>* exclusionList ){
|
|
|
|
for ( list<DPlane *>::const_iterator resetPlane = faceList.begin(); resetPlane != faceList.end(); resetPlane++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
bool set = FALSE;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( exclusionList ) {
|
|
|
|
for ( list<Str>::iterator eTexture = exclusionList->begin(); eTexture != exclusionList->end(); eTexture++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strstr( ( *resetPlane )->texInfo.m_TextureName, eTexture->GetBuffer() ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
set = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
( *resetPlane )->m_bChkOk = set;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
DPlane* DBrush::HasPlaneInverted( DPlane *chkPlane ){
|
|
|
|
for ( list<DPlane *>::const_iterator brushPlane = faceList.begin(); brushPlane != faceList.end(); brushPlane++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( **brushPlane != *chkPlane ) {
|
|
|
|
if ( fabs( ( *brushPlane )->_d + chkPlane->_d ) < 0.1 ) {
|
|
|
|
return ( *brushPlane );
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
bool DBrush::HasTexture( const char *textureName ){
|
|
|
|
for ( list<DPlane *>::const_iterator chkPlane = faceList.begin(); chkPlane != faceList.end(); chkPlane++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strstr( ( *chkPlane )->texInfo.m_TextureName, textureName ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return TRUE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
bool DBrush::IsDetail(){
|
|
|
|
for ( list<DPlane *>::const_iterator chkPlane = faceList.begin(); chkPlane != faceList.end(); chkPlane++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( *chkPlane )->texInfo.m_nContents & FACE_DETAIL ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return TRUE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void DBrush::BuildFromWinding( DWinding *w ){
|
|
|
|
if ( w->numpoints < 3 ) {
|
|
|
|
Sys_ERROR( "Winding has invalid number of points" );
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPlane* wPlane = w->WindingPlane();
|
|
|
|
|
|
|
|
DWinding* w2;
|
|
|
|
w2 = w->CopyWinding();
|
|
|
|
int i;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < w2->numpoints; i++ )
|
|
|
|
VectorAdd( w2->p[i], wPlane->normal, w2->p[i] );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
AddFace( w2->p[0], w2->p[1], w2->p[2], NULL );
|
|
|
|
AddFace( w->p[2], w->p[1], w->p[0], NULL );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < w->numpoints - 1; i++ )
|
|
|
|
AddFace( w2->p[i], w->p[i], w->p[i + 1], NULL );
|
|
|
|
AddFace( w2->p[w->numpoints - 1], w->p[w->numpoints - 1], w->p[0], NULL );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
delete wPlane;
|
|
|
|
delete w2;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void DBrush::SaveToFile( FILE *pFile ){
|
|
|
|
fprintf( pFile, "{\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( list<DPlane *>::const_iterator pp = faceList.begin(); pp != faceList.end(); pp++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
char buffer[512];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( buffer, "( %.0f %.0f %.0f ) ( %.0f %.0f %.0f ) ( %.0f %.0f %.0f ) %s %.0f %.0f %f %f %.0f 0 0 0\n",
|
|
|
|
( *pp )->points[0][0], ( *pp )->points[0][1], ( *pp )->points[0][2],
|
|
|
|
( *pp )->points[1][0], ( *pp )->points[1][1], ( *pp )->points[1][2],
|
|
|
|
( *pp )->points[2][0], ( *pp )->points[2][1], ( *pp )->points[2][2],
|
|
|
|
( *pp )->texInfo.m_TextureName,
|
|
|
|
( *pp )->texInfo.m_fShift[0], ( *pp )->texInfo.m_fShift[1],
|
|
|
|
( *pp )->texInfo.m_fScale[0], ( *pp )->texInfo.m_fScale[0],
|
|
|
|
( *pp )->texInfo.m_fRotate );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 21:32:01 +00:00
|
|
|
fprintf( pFile, "%s", buffer );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
fprintf( pFile, "}\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void DBrush::Rotate( vec3_t vOrigin, vec3_t vRotation ){
|
|
|
|
for ( list<DPlane *>::const_iterator rotPlane = faceList.begin(); rotPlane != faceList.end(); rotPlane++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( int i = 0; i < 3; i++ )
|
|
|
|
VectorRotate( ( *rotPlane )->points[i], vRotation, vOrigin );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
( *rotPlane )->Rebuild();
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void DBrush::RotateAboutCentre( vec3_t vRotation ){
|
2007-11-04 03:51:54 +00:00
|
|
|
vec3_t min, max, centre;
|
2012-03-17 20:01:54 +00:00
|
|
|
GetBounds( min, max );
|
|
|
|
VectorAdd( min, max, centre );
|
|
|
|
VectorScale( centre, 0.5f, centre );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Rotate( centre, vRotation );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
bool DBrush::ResetTextures( const char* textureName, float fScale[2], float fShift[2], int rotation, const char* newTextureName,
|
|
|
|
int bResetTextureName, int bResetScale[2], int bResetShift[2], int bResetRotation ){
|
|
|
|
if ( textureName ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
bool changed = FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( list<DPlane *>::const_iterator resetPlane = faceList.begin(); resetPlane != faceList.end(); resetPlane++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( ( *resetPlane )->texInfo.m_TextureName, textureName ) ) {
|
|
|
|
if ( bResetTextureName ) {
|
|
|
|
strcpy( ( *resetPlane )->texInfo.m_TextureName, newTextureName );
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( bResetScale[0] ) {
|
|
|
|
( *resetPlane )->texInfo.m_fScale[0] = fScale[0];
|
|
|
|
}
|
|
|
|
if ( bResetScale[1] ) {
|
|
|
|
( *resetPlane )->texInfo.m_fScale[1] = fScale[1];
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( bResetShift[0] ) {
|
|
|
|
( *resetPlane )->texInfo.m_fShift[0] = fShift[0];
|
|
|
|
}
|
|
|
|
if ( bResetShift[1] ) {
|
|
|
|
( *resetPlane )->texInfo.m_fShift[1] = fShift[1];
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( bResetRotation ) {
|
|
|
|
( *resetPlane )->texInfo.m_fRotate = (float)rotation;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
changed = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return changed; // no point rebuilding unless we need to, only slows things down
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( list<DPlane *>::const_iterator resetPlane = faceList.begin(); resetPlane != faceList.end(); resetPlane++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( bResetTextureName ) {
|
|
|
|
strcpy( ( *resetPlane )->texInfo.m_TextureName, newTextureName );
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( bResetScale[0] ) {
|
|
|
|
( *resetPlane )->texInfo.m_fScale[0] = fScale[0];
|
|
|
|
}
|
|
|
|
if ( bResetScale[1] ) {
|
|
|
|
( *resetPlane )->texInfo.m_fScale[1] = fScale[1];
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( bResetShift[0] ) {
|
|
|
|
( *resetPlane )->texInfo.m_fShift[0] = fShift[0];
|
|
|
|
}
|
|
|
|
if ( bResetShift[1] ) {
|
|
|
|
( *resetPlane )->texInfo.m_fShift[1] = fShift[1];
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( bResetRotation ) {
|
|
|
|
( *resetPlane )->texInfo.m_fRotate = (float)rotation;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
bool DBrush::operator ==( DBrush* other ){
|
2007-11-04 03:51:54 +00:00
|
|
|
list<DPlane *>::const_iterator chkPlane;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
for ( chkPlane = faceList.begin(); chkPlane != faceList.end(); chkPlane++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !other->HasPlane( ( *chkPlane ) ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( chkPlane = faceList.begin(); chkPlane != faceList.end(); chkPlane++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !HasPlane( ( *chkPlane ) ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
DPlane* DBrush::AddFace( vec3_t va, vec3_t vb, vec3_t vc, const char *textureName, bool bDetail ){
|
2007-11-04 03:51:54 +00:00
|
|
|
bBoundsBuilt = FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
DPlane* newFace = new DPlane( va, vb, vc, textureName, bDetail );
|
|
|
|
faceList.push_back( newFace );
|
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
return newFace;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPlane* DBrush::FindPlaneWithClosestNormal( vec_t* normal ) {
|
|
|
|
vec_t bestDot = -2;
|
|
|
|
DPlane* bestDotPlane = NULL;
|
|
|
|
list<DPlane *>::const_iterator chkPlane;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( chkPlane = faceList.begin(); chkPlane != faceList.end(); chkPlane++ ) {
|
|
|
|
DPlane* pPlane = ( *chkPlane );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
vec_t dot = DotProduct( pPlane->normal, normal );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( dot > bestDot ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
bestDot = dot;
|
|
|
|
bestDotPlane = pPlane;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bestDotPlane;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DBrush::FindPointsForPlane( DPlane* plane, DPoint** pnts, int maxpnts ) {
|
|
|
|
int numpnts = 0;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !maxpnts ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
BuildPoints();
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( list<DPoint *>::const_iterator points = pointList.begin(); points != pointList.end(); points++ ) {
|
|
|
|
DPoint* point = ( *points );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( fabs( plane->DistanceToPoint( point->_pnt ) ) < MAX_ROUND_ERROR ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
pnts[numpnts] = point;
|
|
|
|
numpnts++;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( numpnts >= maxpnts ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return numpnts;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return numpnts;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DBrush::RemovePlane( DPlane* plane ) {
|
|
|
|
bBoundsBuilt = FALSE;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( list<DPlane *>::const_iterator deadPlane = faceList.begin(); deadPlane != faceList.end(); deadPlane++ ) {
|
|
|
|
if ( *deadPlane == plane ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
delete *deadPlane;
|
|
|
|
faceList.remove( plane );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DBrush::RemoveFromRadiant( void ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( QER_brush ) {
|
|
|
|
g_FuncTable.m_pfnDeleteBrushHandle( QER_brush );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|