📄 entity.cpp
字号:
)
{
if ( text )
{
target = text;
}
else
{
target = "";
}
}
EXPORT_FROM_DLL void Entity::SetTargetName
(
const char *text
)
{
if ( targetname.length() && world )
{
world->RemoveTargetEntity( targetname, this );
}
if ( text )
{
if ( text[ 0 ] == '$' )
text++;
targetname = text;
}
else
{
targetname = "";
}
if ( targetname.length() && world )
{
world->AddTargetEntity( targetname, this );
}
}
EXPORT_FROM_DLL void Entity::SetKillTarget
(
const char *text
)
{
if ( text )
{
killtarget = text;
}
else
{
killtarget = "";
}
}
EXPORT_FROM_DLL int Entity::modelIndex
(
const char *mdl
)
{
str name;
assert( mdl );
if ( !mdl )
{
return 0;
}
// Prepend 'models/' to make things easier
if ( !strchr( mdl, '*' ) && !strchr( mdl, '\\' ) && !strchr( mdl, '/' ) )
{
name = "models/";
}
name += mdl;
return gi.modelindex( name.c_str() );
}
EXPORT_FROM_DLL void Entity::setModel
(
const char *mdl
)
{
str temp;
if ( !mdl )
{
mdl = "";
}
// Prepend 'models/' to make things easier
temp = "";
if ( !strchr( mdl, '*' ) && !strchr( mdl, '\\' ) && !strchr( mdl, '/' ) )
{
temp = "models/";
}
temp += mdl;
// we use a temp string so that if model was passed into here, we don't
// accidentally free up the string that we're using in the process.
model = temp;
gi.setmodel( edict, model.c_str() );
if ( gi.IsModel( edict->s.modelindex ) )
{
Event *ev;
edict->s.numgroups = gi.NumGroups( edict->s.modelindex );
if ( !LoadingSavegame )
{
CancelEventsOfType( EV_ProcessInitCommands );
ev = new Event( EV_ProcessInitCommands );
ev->AddInteger( edict->s.modelindex );
PostEvent( ev, 0 );
}
}
// Sanity check to see if we're expecting a B-Model
assert( !( ( edict->solid == SOLID_BSP ) && !edict->s.modelindex ) );
if ( ( edict->solid == SOLID_BSP ) && !edict->s.modelindex )
{
const char *name;
name = getClassID();
if ( !name )
{
name = getClassname();
}
gi.dprintf( "%s with SOLID_BSP and no model - '%s'(%d)\n", name, targetname.c_str(), entnum );
// Make it non-solid so that the collision code doesn't kick us out.
setSolidType( SOLID_NOT );
}
mins = edict->mins;
maxs = edict->maxs;
size = edict->size;
}
EXPORT_FROM_DLL void Entity::ProcessInitCommands
(
int index
)
{
sinmdl_cmd_t *cmds;
if ( LoadingSavegame )
{
// Don't process init commands when loading a savegame since
// it will cause items to be added to inventories unnecessarily.
// All variables affected by the init commands will be set
// by the unarchive functions.
return;
}
cmds = gi.InitCommands( index );
if (cmds)
{
int i, j;
Event *event;
for (i=0;i<cmds->num_cmds;i++)
{
event = new Event( cmds->cmds[i].args[0] );
for(j=1;j<cmds->cmds[i].num_args;j++)
{
event->AddToken( cmds->cmds[i].args[j] );
}
ProcessEvent( event );
}
}
}
EXPORT_FROM_DLL void Entity::ProcessInitCommandsEvent
(
Event *ev
)
{
int index;
index = ev->GetInteger( 1 );
ProcessInitCommands( index );
}
EXPORT_FROM_DLL void Entity::EventHideModel
(
Event *ev
)
{
hideModel();
}
EXPORT_FROM_DLL void Entity::EventShowModel
(
Event *ev
)
{
showModel();
}
EXPORT_FROM_DLL void Entity::setAlpha
(
float alpha
)
{
if ( alpha > 1.0f )
{
alpha = 1.0f;
}
if ( alpha < 0 )
{
alpha = 0;
}
translucence = 1.0f - alpha;
edict->s.alpha = alpha;
edict->s.renderfx &= ~RF_TRANSLUCENT;
if ( ( translucence > 0 ) && ( translucence <= 1.0 ) )
{
edict->s.renderfx |= RF_TRANSLUCENT;
}
}
EXPORT_FROM_DLL void Entity::setScale
(
float scale
)
{
if ( scale > 255.0f )
{
scale = 255.0f;
}
if ( scale < 0.004f )
{
scale = 0.004f;
}
edict->s.scale = scale;
}
EXPORT_FROM_DLL void Entity::setSolidType
(
solid_t type
)
{
if (
( !LoadingSavegame ) &&
( type == SOLID_BSP ) &&
( this != world ) &&
(
!model.length() ||
(
( model[ 0 ] != '*' ) &&
( !strstr( model.c_str(), ".bsp" ) )
)
)
)
{
error( "setSolidType", "SOLID_BSP entity at x%.2f y%.2f z%.2f with no BSP model", worldorigin[ 0 ], worldorigin[ 1 ], worldorigin[ 2 ] );
}
edict->solid = type;
link();
edict->svflags &= ~SVF_NOCLIENT;
if ( hidden() )
{
edict->svflags |= SVF_NOCLIENT;
}
}
EXPORT_FROM_DLL void Entity::setSize
(
Vector min,
Vector max
)
{
Vector delta;
if ( flags & FL_ROTATEDBOUNDS )
{
vec3_t tempmins, tempmaxs;
float mat[3][3];
//
// rotate the mins and maxs for the model
//
min.copyTo( tempmins );
max.copyTo( tempmaxs );
VectorCopy( orientation[ 0 ], mat[ 0 ] );
VectorNegate( orientation[ 1 ], mat[ 1 ] );
VectorCopy( orientation[ 2 ], mat[ 2 ] );
CalculateRotatedBounds2( mat, tempmins, tempmaxs );
mins = Vector( tempmins );
maxs = Vector( tempmaxs );
size = max - min;
mins.copyTo( edict->mins );
maxs.copyTo( edict->maxs );
size.copyTo( edict->size );
mins.copyTo( edict->fullmins );
maxs.copyTo( edict->fullmaxs );
edict->fullradius = size.length() * 0.5;
}
else
{
if ( ( min == edict->mins ) && ( max == edict->maxs ) )
{
return;
}
mins = min;
maxs = max;
size = max - min;
mins.copyTo( edict->mins );
maxs.copyTo( edict->maxs );
size.copyTo( edict->size );
//
// get the full mins and maxs for this model
//
if ( gi.IsModel( edict->s.modelindex ) )
{
Vector delta;
vec3_t fmins;
vec3_t fmaxs;
const gravityaxis_t &grav = gravity_axis[ gravaxis ];
gi.CalculateBounds( edict->s.modelindex, edict->s.scale, fmins, fmaxs );
edict->fullmins[ 0 ] = fmins[ grav.x ];
edict->fullmaxs[ 0 ] = fmaxs[ grav.x ];
if ( grav.sign > 0 )
{
edict->fullmins[ 1 ] = fmins[ grav.y ];
edict->fullmins[ 2 ] = fmins[ grav.z ];
edict->fullmaxs[ 1 ] = fmaxs[ grav.y ];
edict->fullmaxs[ 2 ] = fmaxs[ grav.z ];
}
else
{
edict->fullmins[ 1 ] = -fmaxs[ grav.y ];
edict->fullmins[ 2 ] = -fmaxs[ grav.z ];
edict->fullmaxs[ 1 ] = -fmins[ grav.y ];
edict->fullmaxs[ 2 ] = -fmins[ grav.z ];
}
delta = Vector( edict->fullmaxs ) - Vector( edict->fullmins );
edict->fullradius = delta.length() * 0.5f;
}
else
{
mins.copyTo( edict->fullmins );
maxs.copyTo( edict->fullmaxs );
edict->fullradius = size.length() * 0.5;
}
}
link();
}
EXPORT_FROM_DLL Vector Entity::getLocalVector
(
Vector vec
)
{
Vector pos;
pos[ 0 ] = vec * orientation[ 0 ];
pos[ 1 ] = vec * orientation[ 1 ];
pos[ 2 ] = vec * orientation[ 2 ];
return pos;
}
EXPORT_FROM_DLL Vector Entity::getParentVector
(
Vector vec
)
{
Vector pos;
if ( !bindmaster )
{
return vec;
}
pos[ 0 ] = vec * bindmaster->orientation[ 0 ];
pos[ 1 ] = vec * bindmaster->orientation[ 1 ];
pos[ 2 ] = vec * bindmaster->orientation[ 2 ];
return pos;
}
EXPORT_FROM_DLL void Entity::link
(
void
)
{
gi.linkentity( edict );
absmin = edict->absmin;
absmax = edict->absmax;
centroid = ( absmin + absmax ) * 0.5;
centroid.copyTo( edict->centroid );
// If this has a parent, then set the areanum the same
// as the parent's
if ( edict->s.parent )
{
edict->areanum = g_edicts[ edict->s.parent ].areanum;
}
}
EXPORT_FROM_DLL void Entity::setOrigin
(
Vector org
)
{
Entity * ent;
int i, num;
origin = org;
if ( bindmaster )
{
MatrixTransformVector( origin.vec3(), bindmaster->orientation, worldorigin.vec3() );
worldorigin += bindmaster->worldorigin;
worldorigin.copyTo( edict->s.vieworigin );
}
else if ( edict->s.parent )
{
org.copyTo( edict->s.vieworigin );
ent = ( Entity * )G_GetEntity( edict->s.parent );
worldorigin = ent->centroid;
}
else
{
worldorigin = origin;
worldorigin.copyTo( edict->s.vieworigin );
}
worldorigin.copyTo( edict->s.origin );
link();
//
// go through and set our children
//
num = numchildren;
for( i = 0; ( i < MAX_MODEL_CHILDREN ) && num; i++ )
{
if ( !children[ i ] )
{
continue;
}
ent = ( Entity * )G_GetEntity( children[ i ] );
ent->setOrigin( ent->origin );
num--;
}
}
EXPORT_FROM_DLL qboolean Entity::GetBone
(
const char *name,
Vector *pos,
Vector *forward,
Vector *right,
Vector *up
)
{
vec3_t trans[ 3 ];
vec3_t p1, p2;
vec3_t orient;
int groupindex;
int tri_num;
// get the bone information
if ( !gi.GetBoneInfo( edict->s.modelindex, name, &groupindex, &tri_num, orient) )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -