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
|
|
|
|
#include "../idlib/precompiled.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "tr_local.h"
|
|
|
|
#include "Model_local.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
This is a simple dynamic model that just creates a stretched quad between
|
|
|
|
two points that faces the view, like a dynamic deform tube.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
static const char* beam_SnapshotName = "_beam_Snapshot_";
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idRenderModelBeam::IsDynamicModel
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
dynamicModel_t idRenderModelBeam::IsDynamicModel() const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return DM_CONTINUOUS; // regenerate for every view
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idRenderModelBeam::IsLoaded
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idRenderModelBeam::IsLoaded() const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return true; // don't ever need to load
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idRenderModelBeam::InstantiateDynamicModel
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idRenderModel* idRenderModelBeam::InstantiateDynamicModel( const struct renderEntity_s* renderEntity, const viewDef_t* viewDef, idRenderModel* cachedModel )
|
|
|
|
{
|
|
|
|
idRenderModelStatic* staticModel;
|
|
|
|
srfTriangles_t* tri;
|
2012-11-26 18:58:24 +00:00
|
|
|
modelSurface_t surf;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( cachedModel )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
delete cachedModel;
|
|
|
|
cachedModel = NULL;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( renderEntity == NULL || viewDef == NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
delete cachedModel;
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( cachedModel != NULL )
|
|
|
|
{
|
|
|
|
|
|
|
|
assert( dynamic_cast<idRenderModelStatic*>( cachedModel ) != NULL );
|
2012-11-26 18:58:24 +00:00
|
|
|
assert( idStr::Icmp( cachedModel->Name(), beam_SnapshotName ) == 0 );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
staticModel = static_cast<idRenderModelStatic*>( cachedModel );
|
2012-11-26 18:58:24 +00:00
|
|
|
surf = *staticModel->Surface( 0 );
|
|
|
|
tri = surf.geometry;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
staticModel = new( TAG_MODEL ) idRenderModelStatic;
|
2012-11-26 18:58:24 +00:00
|
|
|
staticModel->InitEmpty( beam_SnapshotName );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
tri = R_AllocStaticTriSurf();
|
|
|
|
R_AllocStaticTriSurfVerts( tri, 4 );
|
|
|
|
R_AllocStaticTriSurfIndexes( tri, 6 );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
tri->verts[0].Clear();
|
|
|
|
tri->verts[0].SetTexCoord( 0, 0 );
|
|
|
|
|
|
|
|
tri->verts[1].Clear();
|
|
|
|
tri->verts[1].SetTexCoord( 0, 1 );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
tri->verts[2].Clear();
|
|
|
|
tri->verts[2].SetTexCoord( 1, 0 );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
tri->verts[3].Clear();
|
|
|
|
tri->verts[3].SetTexCoord( 1, 1 );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
tri->indexes[0] = 0;
|
|
|
|
tri->indexes[1] = 2;
|
|
|
|
tri->indexes[2] = 1;
|
|
|
|
tri->indexes[3] = 2;
|
|
|
|
tri->indexes[4] = 3;
|
|
|
|
tri->indexes[5] = 1;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
tri->numVerts = 4;
|
|
|
|
tri->numIndexes = 6;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
surf.geometry = tri;
|
|
|
|
surf.id = 0;
|
|
|
|
surf.shader = tr.defaultMaterial;
|
|
|
|
staticModel->AddSurface( surf );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idVec3 target = *reinterpret_cast<const idVec3*>( &renderEntity->shaderParms[SHADERPARM_BEAM_END_X] );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// we need the view direction to project the minor axis of the tube
|
|
|
|
// as the view changes
|
|
|
|
idVec3 localView, localTarget;
|
|
|
|
float modelMatrix[16];
|
|
|
|
R_AxisToModelMatrix( renderEntity->axis, renderEntity->origin, modelMatrix );
|
2012-11-28 15:47:07 +00:00
|
|
|
R_GlobalPointToLocal( modelMatrix, viewDef->renderView.vieworg, localView );
|
|
|
|
R_GlobalPointToLocal( modelMatrix, target, localTarget );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec3 major = localTarget;
|
|
|
|
idVec3 minor;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec3 mid = 0.5f * localTarget;
|
|
|
|
idVec3 dir = mid - localView;
|
|
|
|
minor.Cross( major, dir );
|
|
|
|
minor.Normalize();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( renderEntity->shaderParms[SHADERPARM_BEAM_WIDTH] != 0.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
minor *= renderEntity->shaderParms[SHADERPARM_BEAM_WIDTH] * 0.5f;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int red = idMath::Ftoi( renderEntity->shaderParms[SHADERPARM_RED] * 255.0f );
|
|
|
|
int green = idMath::Ftoi( renderEntity->shaderParms[SHADERPARM_GREEN] * 255.0f );
|
|
|
|
int blue = idMath::Ftoi( renderEntity->shaderParms[SHADERPARM_BLUE] * 255.0f );
|
|
|
|
int alpha = idMath::Ftoi( renderEntity->shaderParms[SHADERPARM_ALPHA] * 255.0f );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
tri->verts[0].xyz = minor;
|
|
|
|
tri->verts[0].color[0] = red;
|
|
|
|
tri->verts[0].color[1] = green;
|
|
|
|
tri->verts[0].color[2] = blue;
|
|
|
|
tri->verts[0].color[3] = alpha;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
tri->verts[1].xyz = -minor;
|
|
|
|
tri->verts[1].color[0] = red;
|
|
|
|
tri->verts[1].color[1] = green;
|
|
|
|
tri->verts[1].color[2] = blue;
|
|
|
|
tri->verts[1].color[3] = alpha;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
tri->verts[2].xyz = localTarget + minor;
|
|
|
|
tri->verts[2].color[0] = red;
|
|
|
|
tri->verts[2].color[1] = green;
|
|
|
|
tri->verts[2].color[2] = blue;
|
|
|
|
tri->verts[2].color[3] = alpha;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
tri->verts[3].xyz = localTarget - minor;
|
|
|
|
tri->verts[3].color[0] = red;
|
|
|
|
tri->verts[3].color[1] = green;
|
|
|
|
tri->verts[3].color[2] = blue;
|
|
|
|
tri->verts[3].color[3] = alpha;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
R_BoundTriSurf( tri );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
staticModel->bounds = tri->bounds;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return staticModel;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idRenderModelBeam::Bounds
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idBounds idRenderModelBeam::Bounds( const struct renderEntity_s* renderEntity ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idBounds b;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
b.Zero();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !renderEntity )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
b.ExpandSelf( 8.0f );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
idVec3 target = *reinterpret_cast<const idVec3*>( &renderEntity->shaderParms[SHADERPARM_BEAM_END_X] );
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec3 localTarget;
|
|
|
|
float modelMatrix[16];
|
|
|
|
R_AxisToModelMatrix( renderEntity->axis, renderEntity->origin, modelMatrix );
|
2012-11-28 15:47:07 +00:00
|
|
|
R_GlobalPointToLocal( modelMatrix, target, localTarget );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
b.AddPoint( localTarget );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( renderEntity->shaderParms[SHADERPARM_BEAM_WIDTH] != 0.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
b.ExpandSelf( renderEntity->shaderParms[SHADERPARM_BEAM_WIDTH] * 0.5f );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return b;
|
|
|
|
}
|