2012-11-26 18:58:24 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
|
|
|
|
Doom 3 BFG Edition GPL Source Code
|
2012-11-28 15:47:07 +00:00
|
|
|
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
|
|
|
|
|
|
|
|
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
|
|
|
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma hdrstop
|
2012-12-22 15:18:19 +00:00
|
|
|
#include "precompiled.h"
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include "../Game_local.h"
|
|
|
|
|
|
|
|
#define MAX_SECTOR_DEPTH 12
|
|
|
|
#define MAX_SECTORS ((1<<(MAX_SECTOR_DEPTH+1))-1)
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
typedef struct clipSector_s
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int axis; // -1 = leaf node
|
|
|
|
float dist;
|
2012-11-28 15:47:07 +00:00
|
|
|
struct clipSector_s* children[2];
|
|
|
|
struct clipLink_s* clipLinks;
|
2012-11-26 18:58:24 +00:00
|
|
|
} clipSector_t;
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
typedef struct clipLink_s
|
|
|
|
{
|
|
|
|
idClipModel* clipModel;
|
|
|
|
struct clipSector_s* sector;
|
|
|
|
struct clipLink_s* prevInSector;
|
|
|
|
struct clipLink_s* nextInSector;
|
|
|
|
struct clipLink_s* nextLink;
|
2012-11-26 18:58:24 +00:00
|
|
|
} clipLink_t;
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
typedef struct trmCache_s
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idTraceModel trm;
|
|
|
|
int refCount;
|
|
|
|
float volume;
|
|
|
|
idVec3 centerOfMass;
|
|
|
|
idMat3 inertiaTensor;
|
|
|
|
} trmCache_t;
|
|
|
|
|
|
|
|
idVec3 vec3_boxEpsilon( CM_BOX_EPSILON, CM_BOX_EPSILON, CM_BOX_EPSILON );
|
|
|
|
|
|
|
|
idBlockAlloc<clipLink_t, 1024> clipLinkAllocator;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================
|
|
|
|
|
|
|
|
idClipModel trace model cache
|
|
|
|
|
|
|
|
===============================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
static idList<trmCache_s*> traceModelCache;
|
|
|
|
static idList<trmCache_s*> traceModelCache_Unsaved;
|
|
|
|
static idHashIndex traceModelHash;
|
|
|
|
static idHashIndex traceModelHash_Unsaved;
|
|
|
|
const static int TRACE_MODEL_SAVED = BIT( 16 );
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idClipModel::ClearTraceModelCache
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClipModel::ClearTraceModelCache()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
traceModelCache.DeleteContents( true );
|
|
|
|
traceModelCache_Unsaved.DeleteContents( true );
|
|
|
|
traceModelHash.Free();
|
|
|
|
traceModelHash_Unsaved.Free();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idClipModel::TraceModelCacheSize
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
int idClipModel::TraceModelCacheSize()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return traceModelCache.Num() * sizeof( idTraceModel );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idClipModel::AllocTraceModel
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
int idClipModel::AllocTraceModel( const idTraceModel& trm, bool persistantThroughSaves )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, hashKey, traceModelIndex;
|
2012-11-28 15:47:07 +00:00
|
|
|
trmCache_t* entry;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
hashKey = GetTraceModelHashKey( trm );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( persistantThroughSaves )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// Look Inside the saved list.
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = traceModelHash.First( hashKey ); i >= 0; i = traceModelHash.Next( i ) )
|
|
|
|
{
|
|
|
|
if( traceModelCache[i]->trm == trm )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
traceModelCache[i]->refCount++;
|
|
|
|
int flagged_index = i | TRACE_MODEL_SAVED;
|
|
|
|
return flagged_index;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Look inside the unsaved list.
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = traceModelHash_Unsaved.First( hashKey ); i >= 0; i = traceModelHash_Unsaved.Next( i ) )
|
|
|
|
{
|
|
|
|
if( traceModelCache_Unsaved[i]->trm == trm )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
traceModelCache_Unsaved[i]->refCount++;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
entry = new( TAG_PHYSICS_CLIP ) trmCache_t;
|
2012-11-26 18:58:24 +00:00
|
|
|
entry->trm = trm;
|
|
|
|
entry->trm.GetMassProperties( 1.0f, entry->volume, entry->centerOfMass, entry->inertiaTensor );
|
|
|
|
entry->refCount = 1;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( persistantThroughSaves )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
traceModelIndex = traceModelCache.Append( entry );
|
|
|
|
traceModelHash.Add( hashKey, traceModelIndex );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Set the saved bit.
|
|
|
|
traceModelIndex |= TRACE_MODEL_SAVED;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
traceModelIndex = traceModelCache_Unsaved.Append( entry );
|
|
|
|
traceModelHash_Unsaved.Add( hashKey, traceModelIndex );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// remove the saved bit
|
|
|
|
traceModelIndex &= ~TRACE_MODEL_SAVED;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return traceModelIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idClipModel::FreeTraceModel
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClipModel::FreeTraceModel( int traceModelIndex )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
int realTraceModelIndex = traceModelIndex & ~TRACE_MODEL_SAVED;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Check which cache we are using.
|
2012-11-28 15:47:07 +00:00
|
|
|
if( traceModelIndex & TRACE_MODEL_SAVED )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( realTraceModelIndex < 0 || realTraceModelIndex >= traceModelCache.Num() || traceModelCache[realTraceModelIndex]->refCount <= 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Warning( "idClipModel::FreeTraceModel: tried to free uncached trace model" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
traceModelCache[realTraceModelIndex]->refCount--;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
if( realTraceModelIndex < 0 || realTraceModelIndex >= traceModelCache_Unsaved.Num() || traceModelCache_Unsaved[realTraceModelIndex]->refCount <= 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Warning( "idClipModel::FreeTraceModel: tried to free uncached trace model" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
traceModelCache_Unsaved[realTraceModelIndex]->refCount--;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idClipModel::GetCachedTraceModel
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idTraceModel* idClipModel::GetCachedTraceModel( int traceModelIndex )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int realTraceModelIndex = traceModelIndex & ~TRACE_MODEL_SAVED;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( traceModelIndex & TRACE_MODEL_SAVED )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return &traceModelCache[realTraceModelIndex]->trm;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return &traceModelCache_Unsaved[realTraceModelIndex]->trm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idClipModel::GetCachedTraceModel
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
trmCache_t* idClipModel::GetTraceModelEntry( int traceModelIndex )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
int realTraceModelIndex = traceModelIndex & ~TRACE_MODEL_SAVED;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( traceModelIndex & TRACE_MODEL_SAVED )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return traceModelCache[realTraceModelIndex];
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return traceModelCache_Unsaved[realTraceModelIndex];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idClipModel::GetTraceModelHashKey
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
int idClipModel::GetTraceModelHashKey( const idTraceModel& trm )
|
|
|
|
{
|
|
|
|
const idVec3& v = trm.bounds[0];
|
2012-11-26 18:58:24 +00:00
|
|
|
return ( trm.type << 8 ) ^ ( trm.numVerts << 4 ) ^ ( trm.numEdges << 2 ) ^ ( trm.numPolys << 0 ) ^ idMath::FloatHash( v.ToFloatPtr(), v.GetDimension() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idClipModel::SaveTraceModels
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClipModel::SaveTraceModels( idSaveGame* savefile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->WriteInt( traceModelCache.Num() );
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < traceModelCache.Num(); i++ )
|
|
|
|
{
|
|
|
|
trmCache_t* entry = traceModelCache[i];
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
savefile->WriteTraceModel( entry->trm );
|
|
|
|
savefile->WriteFloat( entry->volume );
|
|
|
|
savefile->WriteVec3( entry->centerOfMass );
|
|
|
|
savefile->WriteMat3( entry->inertiaTensor );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idClipModel::RestoreTraceModels
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClipModel::RestoreTraceModels( idRestoreGame* savefile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, num;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
ClearTraceModelCache();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->ReadInt( num );
|
|
|
|
traceModelCache.SetNum( num );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < num; i++ )
|
|
|
|
{
|
|
|
|
trmCache_t* entry = new( TAG_PHYSICS_CLIP ) trmCache_t;
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
savefile->ReadTraceModel( entry->trm );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->ReadFloat( entry->volume );
|
|
|
|
savefile->ReadVec3( entry->centerOfMass );
|
|
|
|
savefile->ReadMat3( entry->inertiaTensor );
|
|
|
|
entry->refCount = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
traceModelCache[i] = entry;
|
|
|
|
traceModelHash.Add( GetTraceModelHashKey( entry->trm ), i );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================
|
|
|
|
|
|
|
|
idClipModel
|
|
|
|
|
|
|
|
===============================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClipModel::LoadModel
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClipModel::LoadModel( const char* name )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
renderModelHandle = -1;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( traceModelIndex != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
FreeTraceModel( traceModelIndex );
|
|
|
|
traceModelIndex = -1;
|
|
|
|
}
|
|
|
|
collisionModelHandle = collisionModelManager->LoadModel( name );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( collisionModelHandle )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
collisionModelManager->GetModelBounds( collisionModelHandle, bounds );
|
|
|
|
collisionModelManager->GetModelContents( collisionModelHandle, contents );
|
|
|
|
return true;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
bounds.Zero();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClipModel::LoadModel
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClipModel::LoadModel( const idTraceModel& trm, bool persistantThroughSave )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
collisionModelHandle = 0;
|
|
|
|
renderModelHandle = -1;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( traceModelIndex != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
FreeTraceModel( traceModelIndex );
|
|
|
|
}
|
|
|
|
traceModelIndex = AllocTraceModel( trm, persistantThroughSave );
|
|
|
|
bounds = trm.bounds;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClipModel::LoadModel
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClipModel::LoadModel( const int renderModelHandle )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
collisionModelHandle = 0;
|
|
|
|
this->renderModelHandle = renderModelHandle;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( renderModelHandle != -1 )
|
|
|
|
{
|
|
|
|
const renderEntity_t* renderEntity = gameRenderWorld->GetRenderEntity( renderModelHandle );
|
|
|
|
if( renderEntity )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
bounds = renderEntity->bounds;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( traceModelIndex != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
FreeTraceModel( traceModelIndex );
|
|
|
|
traceModelIndex = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClipModel::Init
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClipModel::Init()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
enabled = true;
|
|
|
|
entity = NULL;
|
|
|
|
id = 0;
|
|
|
|
owner = NULL;
|
|
|
|
origin.Zero();
|
|
|
|
axis.Identity();
|
|
|
|
bounds.Zero();
|
|
|
|
absBounds.Zero();
|
|
|
|
material = NULL;
|
|
|
|
contents = CONTENTS_BODY;
|
|
|
|
collisionModelHandle = 0;
|
|
|
|
renderModelHandle = -1;
|
|
|
|
traceModelIndex = -1;
|
|
|
|
clipLinks = NULL;
|
|
|
|
touchCount = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClipModel::idClipModel
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idClipModel::idClipModel()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClipModel::idClipModel
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idClipModel::idClipModel( const char* name )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Init();
|
|
|
|
LoadModel( name );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClipModel::idClipModel
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idClipModel::idClipModel( const idTraceModel& trm )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Init();
|
|
|
|
LoadModel( trm, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClipModel::idClipModel
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idClipModel::idClipModel( const idTraceModel& trm, bool persistantThroughSave )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Init();
|
|
|
|
LoadModel( trm, persistantThroughSave );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClipModel::idClipModel
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idClipModel::idClipModel( const int renderModelHandle )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Init();
|
|
|
|
contents = CONTENTS_RENDERMODEL;
|
|
|
|
LoadModel( renderModelHandle );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClipModel::idClipModel
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idClipModel::idClipModel( const idClipModel* model )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
enabled = model->enabled;
|
|
|
|
entity = model->entity;
|
|
|
|
id = model->id;
|
|
|
|
owner = model->owner;
|
|
|
|
origin = model->origin;
|
|
|
|
axis = model->axis;
|
|
|
|
bounds = model->bounds;
|
|
|
|
absBounds = model->absBounds;
|
|
|
|
material = model->material;
|
|
|
|
contents = model->contents;
|
|
|
|
collisionModelHandle = model->collisionModelHandle;
|
|
|
|
traceModelIndex = -1;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( model->traceModelIndex != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
LoadModel( *GetCachedTraceModel( model->traceModelIndex ) );
|
|
|
|
}
|
|
|
|
renderModelHandle = model->renderModelHandle;
|
|
|
|
clipLinks = NULL;
|
|
|
|
touchCount = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClipModel::~idClipModel
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idClipModel::~idClipModel()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// make sure the clip model is no longer linked
|
|
|
|
Unlink();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( traceModelIndex != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
FreeTraceModel( traceModelIndex );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClipModel::Save
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClipModel::Save( idSaveGame* savefile ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->WriteBool( enabled );
|
|
|
|
savefile->WriteObject( entity );
|
|
|
|
savefile->WriteInt( id );
|
|
|
|
savefile->WriteObject( owner );
|
|
|
|
savefile->WriteVec3( origin );
|
|
|
|
savefile->WriteMat3( axis );
|
|
|
|
savefile->WriteBounds( bounds );
|
|
|
|
savefile->WriteBounds( absBounds );
|
|
|
|
savefile->WriteMaterial( material );
|
|
|
|
savefile->WriteInt( contents );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( collisionModelHandle >= 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->WriteString( collisionModelManager->GetModelName( collisionModelHandle ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->WriteString( "" );
|
|
|
|
}
|
|
|
|
savefile->WriteInt( traceModelIndex );
|
|
|
|
savefile->WriteInt( renderModelHandle );
|
|
|
|
savefile->WriteBool( clipLinks != NULL );
|
|
|
|
savefile->WriteInt( touchCount );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClipModel::Restore
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClipModel::Restore( idRestoreGame* savefile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr collisionModelName;
|
|
|
|
bool linked;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->ReadBool( enabled );
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->ReadObject( reinterpret_cast<idClass*&>( entity ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->ReadInt( id );
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->ReadObject( reinterpret_cast<idClass*&>( owner ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->ReadVec3( origin );
|
|
|
|
savefile->ReadMat3( axis );
|
|
|
|
savefile->ReadBounds( bounds );
|
|
|
|
savefile->ReadBounds( absBounds );
|
|
|
|
savefile->ReadMaterial( material );
|
|
|
|
savefile->ReadInt( contents );
|
|
|
|
savefile->ReadString( collisionModelName );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( collisionModelName.Length() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
collisionModelHandle = collisionModelManager->LoadModel( collisionModelName );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
collisionModelHandle = -1;
|
|
|
|
}
|
|
|
|
savefile->ReadInt( traceModelIndex );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( traceModelIndex >= 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int realIndex = traceModelIndex & ~TRACE_MODEL_SAVED;
|
|
|
|
traceModelCache[realIndex]->refCount++;
|
|
|
|
}
|
|
|
|
savefile->ReadInt( renderModelHandle );
|
|
|
|
savefile->ReadBool( linked );
|
|
|
|
savefile->ReadInt( touchCount );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// the render model will be set when the clip model is linked
|
|
|
|
renderModelHandle = -1;
|
|
|
|
clipLinks = NULL;
|
|
|
|
touchCount = -1;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( linked )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Link( gameLocal.clip, entity, id, origin, axis, renderModelHandle );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClipModel::SetPosition
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClipModel::SetPosition( const idVec3& newOrigin, const idMat3& newAxis )
|
|
|
|
{
|
|
|
|
if( clipLinks )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Unlink(); // unlink from old position
|
|
|
|
}
|
|
|
|
origin = newOrigin;
|
|
|
|
axis = newAxis;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClipModel::Handle
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
cmHandle_t idClipModel::Handle() const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
assert( renderModelHandle == -1 );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( collisionModelHandle )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return collisionModelHandle;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( traceModelIndex != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return collisionModelManager->SetupTrmModel( *GetCachedTraceModel( traceModelIndex ), material );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// this happens in multiplayer on the combat models
|
|
|
|
gameLocal.Warning( "idClipModel::Handle: clip model %d on '%s' (%x) is not a collision or trace model", id, entity->name.c_str(), entity->entityNumber );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClipModel::GetMassProperties
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClipModel::GetMassProperties( const float density, float& mass, idVec3& centerOfMass, idMat3& inertiaTensor ) const
|
|
|
|
{
|
|
|
|
if( traceModelIndex == -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "idClipModel::GetMassProperties: clip model %d on '%s' is not a trace model\n", id, entity->name.c_str() );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
trmCache_t* entry = GetTraceModelEntry( traceModelIndex ); //traceModelCache[traceModelIndex];
|
2012-11-26 18:58:24 +00:00
|
|
|
mass = entry->volume * density;
|
|
|
|
centerOfMass = entry->centerOfMass;
|
|
|
|
inertiaTensor = density * entry->inertiaTensor;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idClipModel::Unlink
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClipModel::Unlink()
|
|
|
|
{
|
|
|
|
clipLink_t* link;
|
|
|
|
|
|
|
|
for( link = clipLinks; link; link = clipLinks )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
clipLinks = link->nextLink;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( link->prevInSector )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
link->prevInSector->nextInSector = link->nextInSector;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
link->sector->clipLinks = link->nextInSector;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( link->nextInSector )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
link->nextInSector->prevInSector = link->prevInSector;
|
|
|
|
}
|
|
|
|
clipLinkAllocator.Free( link );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idClipModel::Link_r
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClipModel::Link_r( struct clipSector_s* node )
|
|
|
|
{
|
|
|
|
clipLink_t* link;
|
|
|
|
|
|
|
|
while( node->axis != -1 )
|
|
|
|
{
|
|
|
|
if( absBounds[0][node->axis] > node->dist )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
node = node->children[0];
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( absBounds[1][node->axis] < node->dist )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
node = node->children[1];
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Link_r( node->children[0] );
|
|
|
|
node = node->children[1];
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
link = clipLinkAllocator.Alloc();
|
|
|
|
link->clipModel = this;
|
|
|
|
link->sector = node;
|
|
|
|
link->nextInSector = node->clipLinks;
|
|
|
|
link->prevInSector = NULL;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( node->clipLinks )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
node->clipLinks->prevInSector = link;
|
|
|
|
}
|
|
|
|
node->clipLinks = link;
|
|
|
|
link->nextLink = clipLinks;
|
|
|
|
clipLinks = link;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idClipModel::Link
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClipModel::Link( idClip& clp )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
assert( idClipModel::entity );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !idClipModel::entity )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( clipLinks )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Unlink(); // unlink from old position
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( bounds.IsCleared() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// set the abs box
|
2012-11-28 15:47:07 +00:00
|
|
|
if( axis.IsRotated() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// expand for rotation
|
|
|
|
absBounds.FromTransformedBounds( bounds, origin, axis );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// normal
|
|
|
|
absBounds[0] = bounds[0] + origin;
|
|
|
|
absBounds[1] = bounds[1] + origin;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// because movement is clipped an epsilon away from an actual edge,
|
|
|
|
// we must fully check even when bounding boxes don't quite touch
|
|
|
|
absBounds[0] -= vec3_boxEpsilon;
|
|
|
|
absBounds[1] += vec3_boxEpsilon;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
Link_r( clp.clipSectors );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idClipModel::Link
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClipModel::Link( idClip& clp, idEntity* ent, int newId, const idVec3& newOrigin, const idMat3& newAxis, int renderModelHandle )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
this->entity = ent;
|
|
|
|
this->id = newId;
|
|
|
|
this->origin = newOrigin;
|
|
|
|
this->axis = newAxis;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( renderModelHandle != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
this->renderModelHandle = renderModelHandle;
|
2012-11-28 15:47:07 +00:00
|
|
|
const renderEntity_t* renderEntity = gameRenderWorld->GetRenderEntity( renderModelHandle );
|
|
|
|
if( renderEntity )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
this->bounds = renderEntity->bounds;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this->Link( clp );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idClipModel::CheckModel
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
cmHandle_t idClipModel::CheckModel( const char* name )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return collisionModelManager->LoadModel( name );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================
|
|
|
|
|
|
|
|
idClip
|
|
|
|
|
|
|
|
===============================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idClip::idClip
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idClip::idClip()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
numClipSectors = 0;
|
|
|
|
clipSectors = NULL;
|
|
|
|
worldBounds.Zero();
|
|
|
|
numRotations = numTranslations = numMotions = numRenderModelTraces = numContents = numContacts = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idClip::CreateClipSectors_r
|
|
|
|
|
|
|
|
Builds a uniformly subdivided tree for the given world size
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
clipSector_t* idClip::CreateClipSectors_r( const int depth, const idBounds& bounds, idVec3& maxSector )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
clipSector_t* anode;
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec3 size;
|
|
|
|
idBounds front, back;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
anode = &clipSectors[idClip::numClipSectors];
|
|
|
|
idClip::numClipSectors++;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( depth == MAX_SECTOR_DEPTH )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
anode->axis = -1;
|
|
|
|
anode->children[0] = anode->children[1] = NULL;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < 3; i++ )
|
|
|
|
{
|
|
|
|
if( bounds[1][i] - bounds[0][i] > maxSector[i] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
maxSector[i] = bounds[1][i] - bounds[0][i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return anode;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
size = bounds[1] - bounds[0];
|
2012-11-28 15:47:07 +00:00
|
|
|
if( size[0] >= size[1] && size[0] >= size[2] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
anode->axis = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( size[1] >= size[0] && size[1] >= size[2] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
anode->axis = 1;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
anode->axis = 2;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
anode->dist = 0.5f * ( bounds[1][anode->axis] + bounds[0][anode->axis] );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
front = bounds;
|
|
|
|
back = bounds;
|
|
|
|
|
|
|
|
front[0][anode->axis] = back[1][anode->axis] = anode->dist;
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
anode->children[0] = CreateClipSectors_r( depth + 1, front, maxSector );
|
|
|
|
anode->children[1] = CreateClipSectors_r( depth + 1, back, maxSector );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return anode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idClip::Init
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClip::Init()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
cmHandle_t h;
|
|
|
|
idVec3 size, maxSector = vec3_origin;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// clear clip sectors
|
2012-11-28 15:47:07 +00:00
|
|
|
clipSectors = new( TAG_PHYSICS_CLIP ) clipSector_t[MAX_SECTORS];
|
2012-11-26 18:58:24 +00:00
|
|
|
memset( clipSectors, 0, MAX_SECTORS * sizeof( clipSector_t ) );
|
|
|
|
numClipSectors = 0;
|
|
|
|
touchCount = -1;
|
|
|
|
// get world map bounds
|
|
|
|
h = collisionModelManager->LoadModel( "worldMap" );
|
|
|
|
collisionModelManager->GetModelBounds( h, worldBounds );
|
|
|
|
// create world sectors
|
|
|
|
CreateClipSectors_r( 0, worldBounds, maxSector );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
size = worldBounds[1] - worldBounds[0];
|
|
|
|
gameLocal.Printf( "map bounds are (%1.1f, %1.1f, %1.1f)\n", size[0], size[1], size[2] );
|
|
|
|
gameLocal.Printf( "max clip sector is (%1.1f, %1.1f, %1.1f)\n", maxSector[0], maxSector[1], maxSector[2] );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// initialize a default clip model
|
|
|
|
defaultClipModel.LoadModel( idTraceModel( idBounds( idVec3( 0, 0, 0 ) ).Expand( 8 ) ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// set counters to zero
|
|
|
|
numRotations = numTranslations = numMotions = numRenderModelTraces = numContents = numContacts = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idClip::Shutdown
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClip::Shutdown()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
delete[] clipSectors;
|
|
|
|
clipSectors = NULL;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// free the trace model used for the temporaryClipModel
|
2012-11-28 15:47:07 +00:00
|
|
|
if( temporaryClipModel.traceModelIndex != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idClipModel::FreeTraceModel( temporaryClipModel.traceModelIndex );
|
|
|
|
temporaryClipModel.traceModelIndex = -1;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// free the trace model used for the defaultClipModel
|
2012-11-28 15:47:07 +00:00
|
|
|
if( defaultClipModel.traceModelIndex != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idClipModel::FreeTraceModel( defaultClipModel.traceModelIndex );
|
|
|
|
defaultClipModel.traceModelIndex = -1;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
clipLinkAllocator.Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
idClip::ClipModelsTouchingBounds_r
|
|
|
|
====================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
typedef struct listParms_s
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idBounds bounds;
|
|
|
|
int contentMask;
|
2012-11-28 15:47:07 +00:00
|
|
|
idClipModel** list;
|
2012-11-26 18:58:24 +00:00
|
|
|
int count;
|
|
|
|
int maxCount;
|
|
|
|
} listParms_t;
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClip::ClipModelsTouchingBounds_r( const struct clipSector_s* node, listParms_t& parms ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
while( node->axis != -1 )
|
|
|
|
{
|
|
|
|
if( parms.bounds[0][node->axis] > node->dist )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
node = node->children[0];
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( parms.bounds[1][node->axis] < node->dist )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
node = node->children[1];
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ClipModelsTouchingBounds_r( node->children[0], parms );
|
|
|
|
node = node->children[1];
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( clipLink_t* link = node->clipLinks; link; link = link->nextInSector )
|
|
|
|
{
|
|
|
|
idClipModel* check = link->clipModel;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// if the clip model is enabled
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !check->enabled )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// avoid duplicates in the list
|
2012-11-28 15:47:07 +00:00
|
|
|
if( check->touchCount == touchCount )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// if the clip model does not have any contents we are looking for
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !( check->contents & parms.contentMask ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// if the bounds really do overlap
|
2012-11-28 15:47:07 +00:00
|
|
|
if( check->absBounds[0][0] > parms.bounds[1][0] ||
|
2012-11-26 18:58:24 +00:00
|
|
|
check->absBounds[1][0] < parms.bounds[0][0] ||
|
|
|
|
check->absBounds[0][1] > parms.bounds[1][1] ||
|
|
|
|
check->absBounds[1][1] < parms.bounds[0][1] ||
|
|
|
|
check->absBounds[0][2] > parms.bounds[1][2] ||
|
2012-11-28 15:47:07 +00:00
|
|
|
check->absBounds[1][2] < parms.bounds[0][2] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( parms.count >= parms.maxCount )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Warning( "idClip::ClipModelsTouchingBounds_r: max count" );
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
check->touchCount = touchCount;
|
|
|
|
parms.list[parms.count] = check;
|
|
|
|
parms.count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClip::ClipModelsTouchingBounds
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
int idClip::ClipModelsTouchingBounds( const idBounds& bounds, int contentMask, idClipModel** clipModelList, int maxCount ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
listParms_t parms;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( bounds[0][0] > bounds[1][0] ||
|
2012-11-26 18:58:24 +00:00
|
|
|
bounds[0][1] > bounds[1][1] ||
|
2012-11-28 15:47:07 +00:00
|
|
|
bounds[0][2] > bounds[1][2] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// we should not go through the tree for degenerate or backwards bounds
|
|
|
|
assert( false );
|
|
|
|
return 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
parms.bounds[0] = bounds[0] - vec3_boxEpsilon;
|
|
|
|
parms.bounds[1] = bounds[1] + vec3_boxEpsilon;
|
|
|
|
parms.contentMask = contentMask;
|
|
|
|
parms.list = clipModelList;
|
|
|
|
parms.count = 0;
|
|
|
|
parms.maxCount = maxCount;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
touchCount++;
|
|
|
|
ClipModelsTouchingBounds_r( clipSectors, parms );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return parms.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idClip::EntitiesTouchingBounds
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
int idClip::EntitiesTouchingBounds( const idBounds& bounds, int contentMask, idEntity** entityList, int maxCount ) const
|
|
|
|
{
|
|
|
|
idClipModel* clipModelList[MAX_GENTITIES];
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, j, count, entCount;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
count = idClip::ClipModelsTouchingBounds( bounds, contentMask, clipModelList, MAX_GENTITIES );
|
|
|
|
entCount = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < count; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// entity could already be in the list because an entity can use multiple clip models
|
2012-11-28 15:47:07 +00:00
|
|
|
for( j = 0; j < entCount; j++ )
|
|
|
|
{
|
|
|
|
if( entityList[j] == clipModelList[i]->entity )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( j >= entCount )
|
|
|
|
{
|
|
|
|
if( entCount >= maxCount )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Warning( "idClip::EntitiesTouchingBounds: max count" );
|
|
|
|
return entCount;
|
|
|
|
}
|
|
|
|
entityList[entCount] = clipModelList[i]->entity;
|
|
|
|
entCount++;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return entCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
idClip::GetTraceClipModels
|
|
|
|
|
|
|
|
an ent will be excluded from testing if:
|
|
|
|
cm->entity == passEntity ( don't clip against the pass entity )
|
|
|
|
cm->entity == passOwner ( missiles don't clip with owner )
|
|
|
|
cm->owner == passEntity ( don't interact with your own missiles )
|
|
|
|
cm->owner == passOwner ( don't interact with other missiles from same owner )
|
|
|
|
====================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
int idClip::GetTraceClipModels( const idBounds& bounds, int contentMask, const idEntity* passEntity, idClipModel** clipModelList ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, num;
|
2012-11-28 15:47:07 +00:00
|
|
|
idClipModel* cm;
|
|
|
|
idEntity* passOwner;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
num = ClipModelsTouchingBounds( bounds, contentMask, clipModelList, MAX_GENTITIES );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !passEntity )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return num;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( passEntity->GetPhysics()->GetNumClipModels() > 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
passOwner = passEntity->GetPhysics()->GetClipModel()->GetOwner();
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
passOwner = NULL;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < num; i++ )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
cm = clipModelList[i];
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// check if we should ignore this entity
|
2012-11-28 15:47:07 +00:00
|
|
|
if( cm->entity == passEntity )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
clipModelList[i] = NULL; // don't clip against the pass entity
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( cm->entity == passOwner )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
clipModelList[i] = NULL; // missiles don't clip with their owner
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( cm->owner )
|
|
|
|
{
|
|
|
|
if( cm->owner == passEntity )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
clipModelList[i] = NULL; // don't clip against own missiles
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( cm->owner == passOwner )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
clipModelList[i] = NULL; // don't clip against other missiles from same owner
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idClip::TraceRenderModel
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClip::TraceRenderModel( trace_t& trace, const idVec3& start, const idVec3& end, const float radius, const idMat3& axis, idClipModel* touch ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
trace.fraction = 1.0f;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// if the trace is passing through the bounds
|
2012-11-28 15:47:07 +00:00
|
|
|
if( touch->absBounds.Expand( radius ).LineIntersection( start, end ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
modelTrace_t modelTrace;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// test with exact render model and modify trace_t structure accordingly
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameRenderWorld->ModelTrace( modelTrace, touch->renderModelHandle, start, end, radius ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
trace.fraction = modelTrace.fraction;
|
|
|
|
trace.endAxis = axis;
|
|
|
|
trace.endpos = modelTrace.point;
|
|
|
|
trace.c.normal = modelTrace.normal;
|
|
|
|
trace.c.dist = modelTrace.point * modelTrace.normal;
|
|
|
|
trace.c.point = modelTrace.point;
|
|
|
|
trace.c.type = CONTACT_TRMVERTEX;
|
|
|
|
trace.c.modelFeature = 0;
|
|
|
|
trace.c.trmFeature = 0;
|
|
|
|
trace.c.contents = modelTrace.material->GetContentFlags();
|
|
|
|
trace.c.material = modelTrace.material;
|
|
|
|
// NOTE: trace.c.id will be the joint number
|
|
|
|
touch->id = JOINT_HANDLE_TO_CLIPMODEL_ID( modelTrace.jointNumber );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idClip::TraceModelForClipModel
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
const idTraceModel* idClip::TraceModelForClipModel( const idClipModel* mdl ) const
|
|
|
|
{
|
|
|
|
if( !mdl )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return NULL;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !mdl->IsTraceModel() )
|
|
|
|
{
|
|
|
|
if( mdl->GetEntity() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "TraceModelForClipModel: clip model %d on '%s' is not a trace model\n", mdl->GetId(), mdl->GetEntity()->name.c_str() );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "TraceModelForClipModel: clip model %d is not a trace model\n", mdl->GetId() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return idClipModel::GetCachedTraceModel( mdl->traceModelIndex );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idClip::TestHugeTranslation
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
ID_INLINE bool TestHugeTranslation( trace_t& results, const idClipModel* mdl, const idVec3& start, const idVec3& end, const idMat3& trmAxis )
|
|
|
|
{
|
|
|
|
if( mdl != NULL && ( end - start ).LengthSqr() > Square( CM_MAX_TRACE_DIST ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
#ifndef CTF
|
|
|
|
// May be important: This occurs in CTF when a player connects and spawns
|
|
|
|
// in the PVS of a player that has a flag that is spawning the idMoveableItem
|
|
|
|
// "nuggets". The error seems benign and the assert was getting in the way
|
2012-11-28 15:47:07 +00:00
|
|
|
// of testing.
|
2012-11-26 18:58:24 +00:00
|
|
|
assert( 0 );
|
|
|
|
#endif
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
results.fraction = 0.0f;
|
|
|
|
results.endpos = start;
|
|
|
|
results.endAxis = trmAxis;
|
|
|
|
memset( &results.c, 0, sizeof( results.c ) );
|
|
|
|
results.c.point = start;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( mdl->GetEntity() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Printf( "huge translation for clip model %d on entity %d '%s'\n", mdl->GetId(), mdl->GetEntity()->entityNumber, mdl->GetEntity()->GetName() );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Printf( "huge translation for clip model %d\n", mdl->GetId() );
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idClip::TranslationEntities
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClip::TranslationEntities( trace_t& results, const idVec3& start, const idVec3& end,
|
|
|
|
const idClipModel* mdl, const idMat3& trmAxis, int contentMask, const idEntity* passEntity )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, num;
|
2012-11-28 15:47:07 +00:00
|
|
|
idClipModel* touch, *clipModelList[MAX_GENTITIES];
|
2012-11-26 18:58:24 +00:00
|
|
|
idBounds traceBounds;
|
|
|
|
float radius;
|
|
|
|
trace_t trace;
|
2012-11-28 15:47:07 +00:00
|
|
|
const idTraceModel* trm;
|
|
|
|
|
|
|
|
if( TestHugeTranslation( results, mdl, start, end, trmAxis ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
trm = TraceModelForClipModel( mdl );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
results.fraction = 1.0f;
|
|
|
|
results.endpos = end;
|
|
|
|
results.endAxis = trmAxis;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !trm )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
traceBounds.FromPointTranslation( start, end - start );
|
|
|
|
radius = 0.0f;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
traceBounds.FromBoundsTranslation( trm->bounds, start, trmAxis, end - start );
|
|
|
|
radius = trm->bounds.GetRadius();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
num = GetTraceClipModels( traceBounds, contentMask, passEntity, clipModelList );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < num; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
touch = clipModelList[i];
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !touch )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( touch->renderModelHandle != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idClip::numRenderModelTraces++;
|
|
|
|
TraceRenderModel( trace, start, end, radius, trmAxis, touch );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idClip::numTranslations++;
|
|
|
|
collisionModelManager->Translation( &trace, start, end, trm, trmAxis, contentMask,
|
2012-11-28 15:47:07 +00:00
|
|
|
touch->Handle(), touch->origin, touch->axis );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( trace.fraction < results.fraction )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
results = trace;
|
|
|
|
results.c.entityNum = touch->entity->entityNumber;
|
|
|
|
results.c.id = touch->id;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( results.fraction == 0.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idClip::Translation
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClip::Translation( trace_t& results, const idVec3& start, const idVec3& end,
|
|
|
|
const idClipModel* mdl, const idMat3& trmAxis, int contentMask, const idEntity* passEntity )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, num;
|
2012-11-28 15:47:07 +00:00
|
|
|
idClipModel* touch, *clipModelList[MAX_GENTITIES];
|
2012-11-26 18:58:24 +00:00
|
|
|
idBounds traceBounds;
|
|
|
|
float radius;
|
|
|
|
trace_t trace;
|
2012-11-28 15:47:07 +00:00
|
|
|
const idTraceModel* trm;
|
|
|
|
|
|
|
|
if( TestHugeTranslation( results, mdl, start, end, trmAxis ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
trm = TraceModelForClipModel( mdl );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !passEntity || passEntity->entityNumber != ENTITYNUM_WORLD )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// test world
|
|
|
|
idClip::numTranslations++;
|
|
|
|
collisionModelManager->Translation( &results, start, end, trm, trmAxis, contentMask, 0, vec3_origin, mat3_default );
|
|
|
|
results.c.entityNum = results.fraction != 1.0f ? ENTITYNUM_WORLD : ENTITYNUM_NONE;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( results.fraction == 0.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return true; // blocked immediately by the world
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
memset( &results, 0, sizeof( results ) );
|
|
|
|
results.fraction = 1.0f;
|
|
|
|
results.endpos = end;
|
|
|
|
results.endAxis = trmAxis;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !trm )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
traceBounds.FromPointTranslation( start, results.endpos - start );
|
|
|
|
radius = 0.0f;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
traceBounds.FromBoundsTranslation( trm->bounds, start, trmAxis, results.endpos - start );
|
|
|
|
radius = trm->bounds.GetRadius();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
num = GetTraceClipModels( traceBounds, contentMask, passEntity, clipModelList );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < num; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
touch = clipModelList[i];
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !touch )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( touch->renderModelHandle != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idClip::numRenderModelTraces++;
|
|
|
|
TraceRenderModel( trace, start, end, radius, trmAxis, touch );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idClip::numTranslations++;
|
|
|
|
collisionModelManager->Translation( &trace, start, end, trm, trmAxis, contentMask,
|
2012-11-28 15:47:07 +00:00
|
|
|
touch->Handle(), touch->origin, touch->axis );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( trace.fraction < results.fraction )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
results = trace;
|
|
|
|
results.c.entityNum = touch->entity->entityNumber;
|
|
|
|
results.c.id = touch->id;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( results.fraction == 0.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return ( results.fraction < 1.0f );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idClip::Rotation
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClip::Rotation( trace_t& results, const idVec3& start, const idRotation& rotation,
|
|
|
|
const idClipModel* mdl, const idMat3& trmAxis, int contentMask, const idEntity* passEntity )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, num;
|
2012-11-28 15:47:07 +00:00
|
|
|
idClipModel* touch, *clipModelList[MAX_GENTITIES];
|
2012-11-26 18:58:24 +00:00
|
|
|
idBounds traceBounds;
|
|
|
|
trace_t trace;
|
2012-11-28 15:47:07 +00:00
|
|
|
const idTraceModel* trm;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
trm = TraceModelForClipModel( mdl );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !passEntity || passEntity->entityNumber != ENTITYNUM_WORLD )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// test world
|
|
|
|
idClip::numRotations++;
|
|
|
|
collisionModelManager->Rotation( &results, start, rotation, trm, trmAxis, contentMask, 0, vec3_origin, mat3_default );
|
|
|
|
results.c.entityNum = results.fraction != 1.0f ? ENTITYNUM_WORLD : ENTITYNUM_NONE;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( results.fraction == 0.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return true; // blocked immediately by the world
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
memset( &results, 0, sizeof( results ) );
|
|
|
|
results.fraction = 1.0f;
|
|
|
|
results.endpos = start;
|
|
|
|
results.endAxis = trmAxis * rotation.ToMat3();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !trm )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
traceBounds.FromPointRotation( start, rotation );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
traceBounds.FromBoundsRotation( trm->bounds, start, trmAxis, rotation );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
num = GetTraceClipModels( traceBounds, contentMask, passEntity, clipModelList );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < num; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
touch = clipModelList[i];
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !touch )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// no rotational collision with render models
|
2012-11-28 15:47:07 +00:00
|
|
|
if( touch->renderModelHandle != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idClip::numRotations++;
|
|
|
|
collisionModelManager->Rotation( &trace, start, rotation, trm, trmAxis, contentMask,
|
2012-11-28 15:47:07 +00:00
|
|
|
touch->Handle(), touch->origin, touch->axis );
|
|
|
|
|
|
|
|
if( trace.fraction < results.fraction )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
results = trace;
|
|
|
|
results.c.entityNum = touch->entity->entityNumber;
|
|
|
|
results.c.id = touch->id;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( results.fraction == 0.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return ( results.fraction < 1.0f );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idClip::Motion
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClip::Motion( trace_t& results, const idVec3& start, const idVec3& end, const idRotation& rotation,
|
|
|
|
const idClipModel* mdl, const idMat3& trmAxis, int contentMask, const idEntity* passEntity )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, num;
|
2012-11-28 15:47:07 +00:00
|
|
|
idClipModel* touch, *clipModelList[MAX_GENTITIES];
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec3 dir, endPosition;
|
|
|
|
idBounds traceBounds;
|
|
|
|
float radius;
|
|
|
|
trace_t translationalTrace, rotationalTrace, trace;
|
|
|
|
idRotation endRotation;
|
2012-11-28 15:47:07 +00:00
|
|
|
const idTraceModel* trm;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
assert( rotation.GetOrigin() == start );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( TestHugeTranslation( results, mdl, start, end, trmAxis ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( mdl != NULL && rotation.GetAngle() != 0.0f && rotation.GetVec() != vec3_origin )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// if no translation
|
2012-11-28 15:47:07 +00:00
|
|
|
if( start == end )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// pure rotation
|
|
|
|
return Rotation( results, start, rotation, mdl, trmAxis, contentMask, passEntity );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( start != end )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// pure translation
|
|
|
|
return Translation( results, start, end, mdl, trmAxis, contentMask, passEntity );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// no motion
|
|
|
|
results.fraction = 1.0f;
|
|
|
|
results.endpos = start;
|
|
|
|
results.endAxis = trmAxis;
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
trm = TraceModelForClipModel( mdl );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
radius = trm->bounds.GetRadius();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !passEntity || passEntity->entityNumber != ENTITYNUM_WORLD )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// translational collision with world
|
|
|
|
idClip::numTranslations++;
|
|
|
|
collisionModelManager->Translation( &translationalTrace, start, end, trm, trmAxis, contentMask, 0, vec3_origin, mat3_default );
|
|
|
|
translationalTrace.c.entityNum = translationalTrace.fraction != 1.0f ? ENTITYNUM_WORLD : ENTITYNUM_NONE;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
memset( &translationalTrace, 0, sizeof( translationalTrace ) );
|
|
|
|
translationalTrace.fraction = 1.0f;
|
|
|
|
translationalTrace.endpos = end;
|
|
|
|
translationalTrace.endAxis = trmAxis;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( translationalTrace.fraction != 0.0f )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
traceBounds.FromBoundsRotation( trm->bounds, start, trmAxis, rotation );
|
|
|
|
dir = translationalTrace.endpos - start;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < 3; i++ )
|
|
|
|
{
|
|
|
|
if( dir[i] < 0.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
traceBounds[0][i] += dir[i];
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
traceBounds[1][i] += dir[i];
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
num = GetTraceClipModels( traceBounds, contentMask, passEntity, clipModelList );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < num; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
touch = clipModelList[i];
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !touch )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( touch->renderModelHandle != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idClip::numRenderModelTraces++;
|
|
|
|
TraceRenderModel( trace, start, end, radius, trmAxis, touch );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idClip::numTranslations++;
|
|
|
|
collisionModelManager->Translation( &trace, start, end, trm, trmAxis, contentMask,
|
2012-11-28 15:47:07 +00:00
|
|
|
touch->Handle(), touch->origin, touch->axis );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( trace.fraction < translationalTrace.fraction )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
translationalTrace = trace;
|
|
|
|
translationalTrace.c.entityNum = touch->entity->entityNumber;
|
|
|
|
translationalTrace.c.id = touch->id;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( translationalTrace.fraction == 0.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
num = -1;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
endPosition = translationalTrace.endpos;
|
|
|
|
endRotation = rotation;
|
|
|
|
endRotation.SetOrigin( endPosition );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !passEntity || passEntity->entityNumber != ENTITYNUM_WORLD )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// rotational collision with world
|
|
|
|
idClip::numRotations++;
|
|
|
|
collisionModelManager->Rotation( &rotationalTrace, endPosition, endRotation, trm, trmAxis, contentMask, 0, vec3_origin, mat3_default );
|
|
|
|
rotationalTrace.c.entityNum = rotationalTrace.fraction != 1.0f ? ENTITYNUM_WORLD : ENTITYNUM_NONE;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
memset( &rotationalTrace, 0, sizeof( rotationalTrace ) );
|
|
|
|
rotationalTrace.fraction = 1.0f;
|
|
|
|
rotationalTrace.endpos = endPosition;
|
|
|
|
rotationalTrace.endAxis = trmAxis * rotation.ToMat3();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( rotationalTrace.fraction != 0.0f )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( num == -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
traceBounds.FromBoundsRotation( trm->bounds, endPosition, trmAxis, endRotation );
|
|
|
|
num = GetTraceClipModels( traceBounds, contentMask, passEntity, clipModelList );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < num; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
touch = clipModelList[i];
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !touch )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// no rotational collision detection with render models
|
2012-11-28 15:47:07 +00:00
|
|
|
if( touch->renderModelHandle != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idClip::numRotations++;
|
|
|
|
collisionModelManager->Rotation( &trace, endPosition, endRotation, trm, trmAxis, contentMask,
|
2012-11-28 15:47:07 +00:00
|
|
|
touch->Handle(), touch->origin, touch->axis );
|
|
|
|
|
|
|
|
if( trace.fraction < rotationalTrace.fraction )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
rotationalTrace = trace;
|
|
|
|
rotationalTrace.c.entityNum = touch->entity->entityNumber;
|
|
|
|
rotationalTrace.c.id = touch->id;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( rotationalTrace.fraction == 0.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( rotationalTrace.fraction < 1.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
results = rotationalTrace;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
results = translationalTrace;
|
|
|
|
results.endAxis = rotationalTrace.endAxis;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
results.fraction = Max( translationalTrace.fraction, rotationalTrace.fraction );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return ( translationalTrace.fraction < 1.0f || rotationalTrace.fraction < 1.0f );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idClip::Contacts
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
int idClip::Contacts( contactInfo_t* contacts, const int maxContacts, const idVec3& start, const idVec6& dir, const float depth,
|
|
|
|
const idClipModel* mdl, const idMat3& trmAxis, int contentMask, const idEntity* passEntity )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, j, num, n, numContacts;
|
2012-11-28 15:47:07 +00:00
|
|
|
idClipModel* touch, *clipModelList[MAX_GENTITIES];
|
2012-11-26 18:58:24 +00:00
|
|
|
idBounds traceBounds;
|
2012-11-28 15:47:07 +00:00
|
|
|
const idTraceModel* trm;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
trm = TraceModelForClipModel( mdl );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !passEntity || passEntity->entityNumber != ENTITYNUM_WORLD )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// test world
|
|
|
|
idClip::numContacts++;
|
|
|
|
numContacts = collisionModelManager->Contacts( contacts, maxContacts, start, dir, depth, trm, trmAxis, contentMask, 0, vec3_origin, mat3_default );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
numContacts = 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < numContacts; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
contacts[i].entityNum = ENTITYNUM_WORLD;
|
|
|
|
contacts[i].id = 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( numContacts >= maxContacts )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return numContacts;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !trm )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
traceBounds = idBounds( start ).Expand( depth );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
traceBounds.FromTransformedBounds( trm->bounds, start, trmAxis );
|
|
|
|
traceBounds.ExpandSelf( depth );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
num = GetTraceClipModels( traceBounds, contentMask, passEntity, clipModelList );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < num; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
touch = clipModelList[i];
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !touch )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// no contacts with render models
|
2012-11-28 15:47:07 +00:00
|
|
|
if( touch->renderModelHandle != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idClip::numContacts++;
|
|
|
|
n = collisionModelManager->Contacts( contacts + numContacts, maxContacts - numContacts,
|
2012-11-28 15:47:07 +00:00
|
|
|
start, dir, depth, trm, trmAxis, contentMask,
|
|
|
|
touch->Handle(), touch->origin, touch->axis );
|
|
|
|
|
|
|
|
for( j = 0; j < n; j++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
contacts[numContacts].entityNum = touch->entity->entityNumber;
|
|
|
|
contacts[numContacts].id = touch->id;
|
|
|
|
numContacts++;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( numContacts >= maxContacts )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return numContacts;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idClip::Contents
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
int idClip::Contents( const idVec3& start, const idClipModel* mdl, const idMat3& trmAxis, int contentMask, const idEntity* passEntity )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, num, contents;
|
2012-11-28 15:47:07 +00:00
|
|
|
idClipModel* touch, *clipModelList[MAX_GENTITIES];
|
2012-11-26 18:58:24 +00:00
|
|
|
idBounds traceBounds;
|
2012-11-28 15:47:07 +00:00
|
|
|
const idTraceModel* trm;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
trm = TraceModelForClipModel( mdl );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !passEntity || passEntity->entityNumber != ENTITYNUM_WORLD )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// test world
|
|
|
|
idClip::numContents++;
|
|
|
|
contents = collisionModelManager->Contents( start, trm, trmAxis, contentMask, 0, vec3_origin, mat3_default );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
contents = 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !trm )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
traceBounds[0] = start;
|
|
|
|
traceBounds[1] = start;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( trmAxis.IsRotated() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
traceBounds.FromTransformedBounds( trm->bounds, start, trmAxis );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
traceBounds[0] = trm->bounds[0] + start;
|
|
|
|
traceBounds[1] = trm->bounds[1] + start;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
num = GetTraceClipModels( traceBounds, -1, passEntity, clipModelList );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < num; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
touch = clipModelList[i];
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !touch )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// no contents test with render models
|
2012-11-28 15:47:07 +00:00
|
|
|
if( touch->renderModelHandle != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// if the entity does not have any contents we are looking for
|
2012-11-28 15:47:07 +00:00
|
|
|
if( ( touch->contents & contentMask ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// if the entity has no new contents flags
|
2012-11-28 15:47:07 +00:00
|
|
|
if( ( touch->contents & contents ) == touch->contents )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idClip::numContents++;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( collisionModelManager->Contents( start, trm, trmAxis, contentMask, touch->Handle(), touch->origin, touch->axis ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
contents |= ( touch->contents & contentMask );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return contents;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idClip::TranslationModel
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClip::TranslationModel( trace_t& results, const idVec3& start, const idVec3& end,
|
|
|
|
const idClipModel* mdl, const idMat3& trmAxis, int contentMask,
|
|
|
|
cmHandle_t model, const idVec3& modelOrigin, const idMat3& modelAxis )
|
|
|
|
{
|
|
|
|
const idTraceModel* trm = TraceModelForClipModel( mdl );
|
2012-11-26 18:58:24 +00:00
|
|
|
idClip::numTranslations++;
|
|
|
|
collisionModelManager->Translation( &results, start, end, trm, trmAxis, contentMask, model, modelOrigin, modelAxis );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idClip::RotationModel
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClip::RotationModel( trace_t& results, const idVec3& start, const idRotation& rotation,
|
|
|
|
const idClipModel* mdl, const idMat3& trmAxis, int contentMask,
|
|
|
|
cmHandle_t model, const idVec3& modelOrigin, const idMat3& modelAxis )
|
|
|
|
{
|
|
|
|
const idTraceModel* trm = TraceModelForClipModel( mdl );
|
2012-11-26 18:58:24 +00:00
|
|
|
idClip::numRotations++;
|
|
|
|
collisionModelManager->Rotation( &results, start, rotation, trm, trmAxis, contentMask, model, modelOrigin, modelAxis );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idClip::ContactsModel
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
int idClip::ContactsModel( contactInfo_t* contacts, const int maxContacts, const idVec3& start, const idVec6& dir, const float depth,
|
|
|
|
const idClipModel* mdl, const idMat3& trmAxis, int contentMask,
|
|
|
|
cmHandle_t model, const idVec3& modelOrigin, const idMat3& modelAxis )
|
|
|
|
{
|
|
|
|
const idTraceModel* trm = TraceModelForClipModel( mdl );
|
2012-11-26 18:58:24 +00:00
|
|
|
idClip::numContacts++;
|
|
|
|
return collisionModelManager->Contacts( contacts, maxContacts, start, dir, depth, trm, trmAxis, contentMask, model, modelOrigin, modelAxis );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idClip::ContentsModel
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
int idClip::ContentsModel( const idVec3& start,
|
|
|
|
const idClipModel* mdl, const idMat3& trmAxis, int contentMask,
|
|
|
|
cmHandle_t model, const idVec3& modelOrigin, const idMat3& modelAxis )
|
|
|
|
{
|
|
|
|
const idTraceModel* trm = TraceModelForClipModel( mdl );
|
2012-11-26 18:58:24 +00:00
|
|
|
idClip::numContents++;
|
|
|
|
return collisionModelManager->Contents( start, trm, trmAxis, contentMask, model, modelOrigin, modelAxis );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idClip::GetModelContactFeature
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClip::GetModelContactFeature( const contactInfo_t& contact, const idClipModel* clipModel, idFixedWinding& winding ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
|
|
|
cmHandle_t handle;
|
|
|
|
idVec3 start, end;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
handle = -1;
|
|
|
|
winding.Clear();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( clipModel == NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
handle = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( clipModel->renderModelHandle != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
winding += contact.point;
|
|
|
|
return true;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( clipModel->traceModelIndex != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
handle = collisionModelManager->SetupTrmModel( *idClipModel::GetCachedTraceModel( clipModel->traceModelIndex ), clipModel->material );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
handle = clipModel->collisionModelHandle;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// if contact with a collision model
|
2012-11-28 15:47:07 +00:00
|
|
|
if( handle != -1 )
|
|
|
|
{
|
|
|
|
switch( contact.type )
|
|
|
|
{
|
|
|
|
case CONTACT_EDGE:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// the model contact feature is a collision model edge
|
|
|
|
collisionModelManager->GetModelEdge( handle, contact.modelFeature, start, end );
|
|
|
|
winding += start;
|
|
|
|
winding += end;
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case CONTACT_MODELVERTEX:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// the model contact feature is a collision model vertex
|
|
|
|
collisionModelManager->GetModelVertex( handle, contact.modelFeature, start );
|
|
|
|
winding += start;
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case CONTACT_TRMVERTEX:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// the model contact feature is a collision model polygon
|
|
|
|
collisionModelManager->GetModelPolygon( handle, contact.modelFeature, winding );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// transform the winding to world space
|
2012-11-28 15:47:07 +00:00
|
|
|
if( clipModel )
|
|
|
|
{
|
|
|
|
for( i = 0; i < winding.GetNumPoints(); i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
winding[i].ToVec3() *= clipModel->axis;
|
|
|
|
winding[i].ToVec3() += clipModel->origin;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idClip::PrintStatistics
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClip::PrintStatistics()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Printf( "t = %-3d, r = %-3d, m = %-3d, render = %-3d, contents = %-3d, contacts = %-3d\n",
|
2012-11-28 15:47:07 +00:00
|
|
|
numTranslations, numRotations, numMotions, numRenderModelTraces, numContents, numContacts );
|
2012-11-26 18:58:24 +00:00
|
|
|
numRotations = numTranslations = numMotions = numRenderModelTraces = numContents = numContacts = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idClip::DrawClipModels
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idClip::DrawClipModels( const idVec3& eye, const float radius, const idEntity* passEntity )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, num;
|
|
|
|
idBounds bounds;
|
2012-11-28 15:47:07 +00:00
|
|
|
idClipModel* clipModelList[MAX_GENTITIES];
|
|
|
|
idClipModel* clipModel;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
bounds = idBounds( eye ).Expand( radius );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
num = idClip::ClipModelsTouchingBounds( bounds, -1, clipModelList, MAX_GENTITIES );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < num; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
clipModel = clipModelList[i];
|
2012-11-28 15:47:07 +00:00
|
|
|
if( clipModel->GetEntity() == passEntity )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( clipModel->renderModelHandle != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameRenderWorld->DebugBounds( colorCyan, clipModel->GetAbsBounds() );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
collisionModelManager->DrawModel( clipModel->Handle(), clipModel->GetOrigin(), clipModel->GetAxis(), eye, radius );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idClip::DrawModelContactFeature
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idClip::DrawModelContactFeature( const contactInfo_t& contact, const idClipModel* clipModel, int lifetime ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
|
|
|
idMat3 axis;
|
|
|
|
idFixedWinding winding;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !GetModelContactFeature( contact, clipModel, winding ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
axis = contact.normal.ToMat3();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( winding.GetNumPoints() == 1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameRenderWorld->DebugLine( colorCyan, winding[0].ToVec3(), winding[0].ToVec3() + 2.0f * axis[0], lifetime );
|
|
|
|
gameRenderWorld->DebugLine( colorWhite, winding[0].ToVec3() - 1.0f * axis[1], winding[0].ToVec3() + 1.0f * axis[1], lifetime );
|
|
|
|
gameRenderWorld->DebugLine( colorWhite, winding[0].ToVec3() - 1.0f * axis[2], winding[0].ToVec3() + 1.0f * axis[2], lifetime );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( i = 0; i < winding.GetNumPoints(); i++ )
|
|
|
|
{
|
|
|
|
gameRenderWorld->DebugLine( colorCyan, winding[i].ToVec3(), winding[( i + 1 ) % winding.GetNumPoints()].ToVec3(), lifetime );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
axis[0] = -axis[0];
|
|
|
|
axis[2] = -axis[2];
|
|
|
|
gameRenderWorld->DrawText( contact.material->GetName(), winding.GetCenter() - 4.0f * axis[2], 0.1f, colorWhite, axis, 1, 5000 );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|