CBaseEntity Functions: Difference between revisions
Charlysotelo (talk | contribs) m (→GetAbsAngles()) |
Charlysotelo (talk | contribs) No edit summary |
||
Line 71: | Line 71: | ||
Msg("This Entity's Position is %f %f %f/n",worldPos[0][3],worldPos[1][3],worldPos[2][3]); | Msg("This Entity's Position is %f %f %f/n",worldPos[0][3],worldPos[1][3],worldPos[2][3]); | ||
</source> | |||
== ShouldCollide() == | |||
'''Parameters:''' | |||
:* <code>int collisionGroup</code> The collision group we are testing [[this]] entity against. | |||
:* <code>int contentsMask</code> Similar to <code>UTIL_TraceLine</code>'s MASK_ parameter. It represents the MASK_ types to collide with. | |||
'''Returns:''' | |||
:* <code>bool</code> True if [[this]] entity should collide with the given <code>collisionGroup</code> with the given <code>contentsMask</code>. | |||
Example Usage: | |||
<source lang=cpp> | |||
bool ShouldHitEntity( IHandleEntity *pHandleEntity, int contentsMask ) | |||
{ | |||
CBaseEntity *pEntity = EntityFromEntityHandle( pHandleEntity ); | |||
if ( pEntity ) | |||
{ | |||
if ( !pEntity->ShouldCollide( m_collisionGroup, contentsMask ) ) | |||
return false; | |||
} | |||
Msg("We should hit this guy!\n"); | |||
} | |||
</source> | </source> |
Revision as of 10:38, 6 July 2014
CBaseEntity derives from IServerEntity.
As its name suggests, all entity types derive from it.
NOTE: This article is under-construction. As with any wiki, please feel free to add to it, or edit it. My goal here is to document every single function in the 2013 sdk.
GetAbsOrigin()
GetAbsOrigin()
returns the absolute (i.e. world-relative) origin of an entity as a vector. Its sister function SetAbsOrigin()
changes it.
The origin is actually stored in local space (i.e parent-relative), meaning that the Abs functions perform extra calculations to get their return value. Use the more direct GetLocalOrigin()
and SetLocalOrigin()
if possible; they work directly with the stored value (m_vecOrigin
).

GetAbsOrigin()
seems to recalculate its return value only if it was changed since the last time it was used, otherwise it just returns cached value stored in a member variable.Example Usage:
void CMyEntity::Think()
{
BaseClass::Think(); // Always do this if you override Think()
Msg( "My World Position Is %f %f %f.\n",GetAbsOrigin().x,GetAbsOrigin().y,GetAbsOrigin().z);
}
GetAbsAngles()
GetAbsAngles()
returns the absolute (i.e. world-relative) angles of an entity as a QAngle. Its sister function SetAbsAngles()
changes it.
Similar to GetAbsOrigin()
, the actual orientation information about this entity is stored relative to its parent - and thus, extra calculations are needed to fetch its Absolute Orientation.
Example Usage:
void CMyEntity::Think()
{
BaseClass::Think(); // Always do this if you override Think()
Msg( "My World Angle Is %f %f %f.\n",GetAbsAngles().x,GetAbsAngles().y,GetAbsAngles().z);
}
DecalTrace()
Parameters:
trace_t *pTrace
is the traceline along which the decal will be applied.char const *decalName
is the name of the decal that is to be applied.
Applies a decal to this entity, in the direction of pTrace.
This function is usually not called directly, but through UTIL_DecalTrace()
.
Example Usage:
trace_t tr;
UTIL_TraceLine( GetAbsOrigin(), GetAbsOrigin() - Vector( 0, 0, 128 ), MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &tr );
if(tr.fraction == 1)
{
CBaseEntity *pEntity = tr.m_pEnt;
pEntity->DecalTrace(&tr,"Scorch");
}
EntityToWorldTransform()
Returns:
matrix3x4_t &
is a 3x4 matrix denoting the linear transformation from the entity's coordinate frame to the world coordinate frame. The first three columns of the matrix are the world-relative positions of the x,y,and z-axes respectively. The last column is the position of the entity's origin relative to the world.
Example Usage:
matrix3x4_t worldPos = EntityToWorldTransform();
Msg("This Entity's Position is %f %f %f/n",worldPos[0][3],worldPos[1][3],worldPos[2][3]);
ShouldCollide()
Parameters:
int collisionGroup
The collision group we are testing this entity against.int contentsMask
Similar toUTIL_TraceLine
's MASK_ parameter. It represents the MASK_ types to collide with.
Returns:
bool
True if this entity should collide with the givencollisionGroup
with the givencontentsMask
.
Example Usage:
bool ShouldHitEntity( IHandleEntity *pHandleEntity, int contentsMask )
{
CBaseEntity *pEntity = EntityFromEntityHandle( pHandleEntity );
if ( pEntity )
{
if ( !pEntity->ShouldCollide( m_collisionGroup, contentsMask ) )
return false;
}
Msg("We should hit this guy!\n");
}