本文整理汇总了C++中VectorScale函数的典型用法代码示例。如果您正苦于以下问题:C++ VectorScale函数的具体用法?C++ VectorScale怎么用?C++ VectorScale使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VectorScale函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: turret_breach_think
void turret_breach_think(edict_t * self)
{
edict_t *ent;
vec3_t current_angles;
vec3_t delta;
VectorCopy(self->s.angles, current_angles);
AnglesNormalize(current_angles);
AnglesNormalize(self->move_angles);
if (self->move_angles[PITCH] > 180)
self->move_angles[PITCH] -= 360;
// clamp angles to mins & maxs
if (self->move_angles[PITCH] > self->pos1[PITCH])
self->move_angles[PITCH] = self->pos1[PITCH];
else if (self->move_angles[PITCH] < self->pos2[PITCH])
self->move_angles[PITCH] = self->pos2[PITCH];
if ((self->move_angles[YAW] < self->pos1[YAW])
|| (self->move_angles[YAW] > self->pos2[YAW])) {
float dmin, dmax;
dmin = fabs(self->pos1[YAW] - self->move_angles[YAW]);
if (dmin < -180)
dmin += 360;
else if (dmin > 180)
dmin -= 360;
dmax = fabs(self->pos2[YAW] - self->move_angles[YAW]);
if (dmax < -180)
dmax += 360;
else if (dmax > 180)
dmax -= 360;
if (fabs(dmin) < fabs(dmax))
self->move_angles[YAW] = self->pos1[YAW];
else
self->move_angles[YAW] = self->pos2[YAW];
}
VectorSubtract(self->move_angles, current_angles, delta);
if (delta[0] < -180)
delta[0] += 360;
else if (delta[0] > 180)
delta[0] -= 360;
if (delta[1] < -180)
delta[1] += 360;
else if (delta[1] > 180)
delta[1] -= 360;
delta[2] = 0;
if (delta[0] > self->speed * FRAMETIME)
delta[0] = self->speed * FRAMETIME;
if (delta[0] < -1 * self->speed * FRAMETIME)
delta[0] = -1 * self->speed * FRAMETIME;
if (delta[1] > self->speed * FRAMETIME)
delta[1] = self->speed * FRAMETIME;
if (delta[1] < -1 * self->speed * FRAMETIME)
delta[1] = -1 * self->speed * FRAMETIME;
VectorScale(delta, 1.0 / FRAMETIME, self->avelocity);
self->nextthink = level.time + FRAMETIME;
for (ent = self->teammaster; ent; ent = ent->teamchain)
ent->avelocity[1] = self->avelocity[1];
// if we have adriver, adjust his velocities
if (self->owner) {
float angle;
float target_z;
float diff;
vec3_t target;
vec3_t dir;
// angular is easy, just copy ours
self->owner->avelocity[0] = self->avelocity[0];
self->owner->avelocity[1] = self->avelocity[1];
// x & y
angle = self->s.angles[1] + self->owner->move_origin[1];
angle *= (M_PI * 2 / 360);
target[0] =
SnapToEights(self->s.origin[0] +
cos(angle) * self->owner->move_origin[0]);
target[1] =
SnapToEights(self->s.origin[1] +
sin(angle) * self->owner->move_origin[0]);
target[2] = self->owner->s.origin[2];
VectorSubtract(target, self->owner->s.origin, dir);
self->owner->velocity[0] = dir[0] * 1.0 / FRAMETIME;
self->owner->velocity[1] = dir[1] * 1.0 / FRAMETIME;
// z
angle = self->s.angles[PITCH] * (M_PI * 2 / 360);
target_z =
SnapToEights(self->s.origin[2] +
self->owner->move_origin[0] * tan(angle) +
self->owner->move_origin[2]);
//.........这里部分代码省略.........
示例2: T_Damage
void T_Damage (edict_t *targ, edict_t *inflictor, edict_t *attacker, vec3_t dir, vec3_t point, vec3_t normal, int damage, int knockback, int dflags, int mod)
{
gclient_t *client;
int take;
int save;
int asave;
int psave;
int te_sparks;
if (!targ->takedamage)
return;
if(mod == MOD_CRUSH)
{
//bot's state change
if((targ->svflags & SVF_MONSTER) && targ->client)
{
if((targ->client->zc.waitin_obj == inflictor && targ->client->zc.zcstate)
|| targ->groundentity == inflictor)
{
// gi.bprintf(PRINT_HIGH,"MOOOOOOOOOOOOOOOOOOOO\n");
targ->client->zc.zcstate |= STS_W_DONT;
}
}
}
// friendly fire avoidance
// if enabled you can't hurt teammates (but you can hurt yourself)
// knockback still occurs
if ((targ != attacker) && ((deathmatch->value && ((int)(dmflags->value) & (DF_MODELTEAMS | DF_SKINTEAMS))) || coop->value))
{
if (OnSameTeam (targ, attacker))
{
if ((int)(dmflags->value) & DF_NO_FRIENDLY_FIRE)
damage = 0;
else
mod |= MOD_FRIENDLY_FIRE;
}
else if(targ->client && !(targ->svflags & SVF_MONSTER))
{
if(attacker->client) targ->client->zc.first_target = attacker;
}
}
meansOfDeath = mod;
// easy mode takes half damage
if (skill->value == 0 && deathmatch->value == 0 && targ->client)
{
damage *= 0.5;
if (!damage)
damage = 1;
}
client = targ->client;
if (dflags & DAMAGE_BULLET)
te_sparks = TE_BULLET_SPARKS;
else
te_sparks = TE_SPARKS;
VectorNormalize(dir);
// bonus damage for suprising a monster
if (!(dflags & DAMAGE_RADIUS) && (targ->svflags & SVF_MONSTER) && (attacker->client) && (!targ->enemy) && (targ->health > 0))
damage *= 2;
//ZOID
//strength tech
damage = CTFApplyStrength(attacker, damage);
//ZOID
if (targ->flags & FL_NO_KNOCKBACK)
knockback = 0;
// figure momentum add
if (!(dflags & DAMAGE_NO_KNOCKBACK))
{
if ((knockback) && (targ->movetype != MOVETYPE_NONE) && (targ->movetype != MOVETYPE_BOUNCE) && (targ->movetype != MOVETYPE_PUSH) && (targ->movetype != MOVETYPE_STOP))
{
vec3_t kvel;
float mass;
if (targ->mass < 50)
mass = 50;
else
mass = targ->mass;
if (targ->client && attacker == targ)
VectorScale (dir, 1600.0 * (float)knockback / mass, kvel); // the rocket jump hack...
else
VectorScale (dir, 500.0 * (float)knockback / mass, kvel);
VectorAdd (targ->velocity, kvel, targ->velocity);
}
}
take = damage;
save = 0;
// check for godmode
//.........这里部分代码省略.........
示例3: mass
/*QUAKED func_explosive (0 .5 .8) ? Trigger_Spawn ANIMATED ANIMATED_FAST INACTIVE
Any brush that you want to explode or break apart. If you want an
ex0plosion, set dmg and it will do a radius explosion of that amount
at the center of the bursh.
If targeted it will not be shootable.
INACTIVE - specifies that the entity is not explodable until triggered. If you use this you must
target the entity you want to trigger it. This is the only entity approved to activate it.
health defaults to 100.
mass defaults to 75. This determines how much debris is emitted when
it explodes. You get one large chunk per 100 of mass (up to 8) and
one small chunk per 25 of mass (up to 16). So 800 gives the most.
*/
void func_explosive_explode (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
vec3_t origin;
vec3_t chunkorigin;
vec3_t size;
int count;
int mass;
edict_t *master;
qboolean done = false;
// bmodel origins are (0 0 0), we need to adjust that here
VectorScale (self->size, 0.5, size);
VectorAdd (self->absmin, size, origin);
VectorCopy (origin, self->s.origin);
self->takedamage = DAMAGE_NO;
if (self->dmg)
T_RadiusDamage (self, attacker, self->dmg, NULL, self->dmg+40, MOD_EXPLOSIVE);
VectorSubtract (self->s.origin, inflictor->s.origin, self->velocity);
VectorNormalize (self->velocity);
VectorScale (self->velocity, 150, self->velocity);
// start chunks towards the center
VectorScale (size, 0.5, size);
mass = self->mass;
if (!mass)
mass = 75;
// big chunks
if (mass >= 100)
{
count = mass / 100;
if (count > 8)
count = 8;
while(count--)
{
chunkorigin[0] = origin[0] + crandom() * size[0];
chunkorigin[1] = origin[1] + crandom() * size[1];
chunkorigin[2] = origin[2] + crandom() * size[2];
ThrowDebris (self, "models/objects/debris1/tris.md2", 1, chunkorigin);
}
}
// small chunks
count = mass / 25;
if (count > 16)
count = 16;
while(count--)
{
chunkorigin[0] = origin[0] + crandom() * size[0];
chunkorigin[1] = origin[1] + crandom() * size[1];
chunkorigin[2] = origin[2] + crandom() * size[2];
ThrowDebris (self, "models/objects/debris2/tris.md2", 2, chunkorigin);
}
// PMM - if we're part of a train, clean ourselves out of it
if (self->flags & FL_TEAMSLAVE)
{
if (self->teammaster)
{
master = self->teammaster;
if(master && master->inuse) // because mappers (other than jim (usually)) are stupid....
{
while (!done)
{
if (master->teamchain == self)
{
master->teamchain = self->teamchain;
done = true;
}
master = master->teamchain;
}
}
}
}
G_UseTargets (self, attacker);
if (self->dmg)
BecomeExplosion1 (self);
else
//.........这里部分代码省略.........
示例4: MakeTextureMatrix
static qboolean MakeTextureMatrix(vec4_t texMat[2], vec4_t projection, decalVert_t *a, decalVert_t *b, decalVert_t *c)
{
int i, j;
double bb, s, t, d;
dvec3_t pa, pb, pc;
dvec3_t bary, origin, xyz;
vec3_t vecs[3], axis[3], lengths;
/* project triangle onto plane of projection */
d = DotProduct(a->xyz, projection) - projection[3];
VectorMA(a->xyz, -d, projection, pa);
d = DotProduct(b->xyz, projection) - projection[3];
VectorMA(b->xyz, -d, projection, pb);
d = DotProduct(c->xyz, projection) - projection[3];
VectorMA(c->xyz, -d, projection, pc);
/* calculate barycentric basis for the triangle */
bb = (b->st[0] - a->st[0]) * (c->st[1] - a->st[1]) - (c->st[0] - a->st[0]) * (b->st[1] - a->st[1]);
if (fabs(bb) < 0.00000001f)
{
return qfalse;
}
/* calculate texture origin */
s = 0.0f;
t = 0.0f;
bary[0] = ((b->st[0] - s) * (c->st[1] - t) - (c->st[0] - s) * (b->st[1] - t)) / bb;
bary[1] = ((c->st[0] - s) * (a->st[1] - t) - (a->st[0] - s) * (c->st[1] - t)) / bb;
bary[2] = ((a->st[0] - s) * (b->st[1] - t) - (b->st[0] - s) * (a->st[1] - t)) / bb;
origin[0] = bary[0] * pa[0] + bary[1] * pb[0] + bary[2] * pc[0];
origin[1] = bary[0] * pa[1] + bary[1] * pb[1] + bary[2] * pc[1];
origin[2] = bary[0] * pa[2] + bary[1] * pb[2] + bary[2] * pc[2];
/* calculate s vector */
s = 1.0f;
t = 0.0f;
bary[0] = ((b->st[0] - s) * (c->st[1] - t) - (c->st[0] - s) * (b->st[1] - t)) / bb;
bary[1] = ((c->st[0] - s) * (a->st[1] - t) - (a->st[0] - s) * (c->st[1] - t)) / bb;
bary[2] = ((a->st[0] - s) * (b->st[1] - t) - (b->st[0] - s) * (a->st[1] - t)) / bb;
xyz[0] = bary[0] * pa[0] + bary[1] * pb[0] + bary[2] * pc[0];
xyz[1] = bary[0] * pa[1] + bary[1] * pb[1] + bary[2] * pc[1];
xyz[2] = bary[0] * pa[2] + bary[1] * pb[2] + bary[2] * pc[2];
VectorSubtract(xyz, origin, vecs[0]);
/* calculate t vector */
s = 0.0f;
t = 1.0f;
bary[0] = ((b->st[0] - s) * (c->st[1] - t) - (c->st[0] - s) * (b->st[1] - t)) / bb;
bary[1] = ((c->st[0] - s) * (a->st[1] - t) - (a->st[0] - s) * (c->st[1] - t)) / bb;
bary[2] = ((a->st[0] - s) * (b->st[1] - t) - (b->st[0] - s) * (a->st[1] - t)) / bb;
xyz[0] = bary[0] * pa[0] + bary[1] * pb[0] + bary[2] * pc[0];
xyz[1] = bary[0] * pa[1] + bary[1] * pb[1] + bary[2] * pc[1];
xyz[2] = bary[0] * pa[2] + bary[1] * pb[2] + bary[2] * pc[2];
VectorSubtract(xyz, origin, vecs[1]);
/* calcuate r vector */
VectorScale(projection, -1.0f, vecs[2]);
/* calculate transform axis */
for (i = 0; i < 3; i++)
lengths[i] = VectorNormalize2(vecs[i], axis[i]);
for (i = 0; i < 2; i++)
for (j = 0; j < 3; j++)
texMat[i][j] = lengths[i] > 0.0f ? (axis[i][j] / lengths[i]) : 0.0f;
texMat[0][3] = a->st[0] - DotProduct(pa, texMat[0]);
texMat[1][3] = a->st[1] - DotProduct(pa, texMat[1]);
/* disco */
return qtrue;
}
示例5: PM_SlideMove
//.........这里部分代码省略.........
//
if ( !(pm->ps->pm_flags&PMF_STUCK_TO_WALL) )
{//no sliding if stuck to wall!
for ( i = 0 ; i < numplanes ; i++ ) {
if ( VectorCompare( normal, planes[i] ) ) {//DotProduct( normal, planes[i] ) > 0.99 ) {
VectorAdd( normal, pm->ps->velocity, pm->ps->velocity );
break;
}
}
if ( i < numplanes ) {
continue;
}
}
VectorCopy (normal, planes[numplanes]);
numplanes++;
//
// modify velocity so it parallels all of the clip planes
//
// find a plane that it enters
for ( i = 0 ; i < numplanes ; i++ ) {
into = DotProduct( pm->ps->velocity, planes[i] );
if ( into >= 0.1 ) {
continue; // move doesn't interact with the plane
}
// see how hard we are hitting things
if ( -into > pml.impactSpeed ) {
pml.impactSpeed = -into;
}
// slide along the plane
PM_ClipVelocity (pm->ps->velocity, planes[i], clipVelocity, OVERCLIP );
// slide along the plane
PM_ClipVelocity (endVelocity, planes[i], endClipVelocity, OVERCLIP );
// see if there is a second plane that the new move enters
for ( j = 0 ; j < numplanes ; j++ ) {
if ( j == i ) {
continue;
}
if ( DotProduct( clipVelocity, planes[j] ) >= 0.1 ) {
continue; // move doesn't interact with the plane
}
// try clipping the move to the plane
PM_ClipVelocity( clipVelocity, planes[j], clipVelocity, OVERCLIP );
PM_ClipVelocity( endClipVelocity, planes[j], endClipVelocity, OVERCLIP );
// see if it goes back into the first clip plane
if ( DotProduct( clipVelocity, planes[i] ) >= 0 ) {
continue;
}
// slide the original velocity along the crease
CrossProduct (planes[i], planes[j], dir);
VectorNormalize( dir );
d = DotProduct( dir, pm->ps->velocity );
VectorScale( dir, d, clipVelocity );
CrossProduct (planes[i], planes[j], dir);
VectorNormalize( dir );
d = DotProduct( dir, endVelocity );
VectorScale( dir, d, endClipVelocity );
// see if there is a third plane the the new move enters
for ( k = 0 ; k < numplanes ; k++ ) {
if ( k == i || k == j ) {
continue;
}
if ( DotProduct( clipVelocity, planes[k] ) >= 0.1 ) {
continue; // move doesn't interact with the plane
}
// stop dead at a triple plane interaction
VectorClear( pm->ps->velocity );
return qtrue;
}
}
// if we have fixed all interactions, try another move
VectorCopy( clipVelocity, pm->ps->velocity );
VectorCopy( endClipVelocity, endVelocity );
break;
}
}
if ( gravity ) {
VectorCopy( endVelocity, pm->ps->velocity );
}
// don't change velocity if in a timer (FIXME: is this correct?)
if ( pm->ps->pm_time ) {
VectorCopy( primal_velocity, pm->ps->velocity );
}
return (qboolean)( bumpcount != 0 );
}
示例6: G_RunMissile
void G_RunMissile( gentity_t *ent )
{
vec3_t oldOrg;
trace_t tr;
int trHitLoc=HL_NONE;
if ( (ent->s.eFlags&EF_HELD_BY_SAND_CREATURE) )
{//in a sand creature's mouth
if ( ent->activator )
{
mdxaBone_t boltMatrix;
// Getting the bolt here
//in hand
vec3_t scAngles = {0};
scAngles[YAW] = ent->activator->currentAngles[YAW];
gi.G2API_GetBoltMatrix( ent->activator->ghoul2, ent->activator->playerModel, ent->activator->gutBolt,
&boltMatrix, scAngles, ent->activator->currentOrigin, (cg.time?cg.time:level.time),
NULL, ent->activator->s.modelScale );
// Storing ent position, bolt position, and bolt axis
gi.G2API_GiveMeVectorFromMatrix( boltMatrix, ORIGIN, ent->currentOrigin );
G_SetOrigin( ent, ent->currentOrigin );
}
// check think function
G_RunThink( ent );
return;
}
VectorCopy( ent->currentOrigin, oldOrg );
// get current position
if ( ent->s.pos.trType == TR_INTERPOLATE )
{//rolling missile?
//FIXME: WTF?!! Sticks to stick missiles?
//FIXME: they stick inside the player
G_RollMissile( ent );
if ( ent->s.eType != ET_GENERAL )
{//didn't explode
VectorCopy( ent->currentOrigin, ent->s.pos.trBase );
gi.trace( &tr, oldOrg, ent->mins, ent->maxs, ent->currentOrigin, ent->s.number, ent->clipmask, G2_RETURNONHIT, 10 );
if ( VectorCompare( ent->s.pos.trDelta, vec3_origin ) )
{
//VectorCopy( ent->currentAngles, ent->s.apos.trBase );
VectorClear( ent->s.apos.trDelta );
}
else
{
vec3_t ang, fwdDir, rtDir;
float speed;
ent->s.apos.trType = TR_INTERPOLATE;
VectorSet( ang, 0, ent->s.apos.trBase[1], 0 );
AngleVectors( ang, fwdDir, rtDir, NULL );
speed = VectorLength( ent->s.pos.trDelta )*4;
//HMM, this works along an axis-aligned dir, but not along diagonals
//This is because when roll gets to 90, pitch becomes yaw, and vice-versa
//Maybe need to just set the angles directly?
ent->s.apos.trDelta[0] = DotProduct( fwdDir, ent->s.pos.trDelta );
ent->s.apos.trDelta[1] = 0;//never spin!
ent->s.apos.trDelta[2] = DotProduct( rtDir, ent->s.pos.trDelta );
VectorNormalize( ent->s.apos.trDelta );
VectorScale( ent->s.apos.trDelta, speed, ent->s.apos.trDelta );
ent->s.apos.trTime = level.previousTime;
}
}
}
else
{
vec3_t origin;
EvaluateTrajectory( &ent->s.pos, level.time, origin );
// trace a line from the previous position to the current position,
// ignoring interactions with the missile owner
gi.trace( &tr, ent->currentOrigin, ent->mins, ent->maxs, origin,
ent->owner ? ent->owner->s.number : ent->s.number, ent->clipmask, G2_COLLIDE, 10 );
if ( tr.entityNum != ENTITYNUM_NONE )
{
gentity_t *other = &g_entities[tr.entityNum];
// check for hitting a lightsaber
if ( other->contents & CONTENTS_LIGHTSABER )
{//hit a lightsaber bbox
if ( other->owner
&& other->owner->client
&& !other->owner->client->ps.saberInFlight
&& ( Q_irand( 0, (other->owner->client->ps.forcePowerLevel[FP_SABER_DEFENSE]*other->owner->client->ps.forcePowerLevel[FP_SABER_DEFENSE]) ) == 0
|| !InFront( ent->currentOrigin, other->owner->currentOrigin, other->owner->client->ps.viewangles, SABER_REFLECT_MISSILE_CONE ) ) )//other->owner->s.number == 0 &&
{//Jedi cannot block shots from behind!
//re-trace from here, ignoring the lightsaber
gi.trace( &tr, tr.endpos, ent->mins, ent->maxs, origin, tr.entityNum, ent->clipmask, G2_RETURNONHIT, 10 );
}
}
}
VectorCopy( tr.endpos, ent->currentOrigin );
}
// get current angles
VectorMA( ent->s.apos.trBase, (level.time - ent->s.apos.trTime) * 0.001, ent->s.apos.trDelta, ent->s.apos.trBase );
//.........这里部分代码省略.........
示例7: G_BounceMissile
/*
================
G_BounceMissile
================
*/
void G_BounceMissile( gentity_t *ent, trace_t *trace ) {
vec3_t velocity;
float dot;
int hitTime;
// reflect the velocity on the trace plane
hitTime = level.previousTime + ( level.time - level.previousTime ) * trace->fraction;
EvaluateTrajectoryDelta( &ent->s.pos, hitTime, velocity );
dot = DotProduct( velocity, trace->plane.normal );
VectorMA( velocity, -2*dot, trace->plane.normal, ent->s.pos.trDelta );
if ( ent->s.eFlags & EF_BOUNCE_SHRAPNEL )
{
VectorScale( ent->s.pos.trDelta, 0.25f, ent->s.pos.trDelta );
ent->s.pos.trType = TR_GRAVITY;
// check for stop
if ( trace->plane.normal[2] > 0.7 && ent->s.pos.trDelta[2] < 40 ) //this can happen even on very slightly sloped walls, so changed it from > 0 to > 0.7
{
G_SetOrigin( ent, trace->endpos );
ent->nextthink = level.time + 100;
return;
}
}
else if ( ent->s.eFlags & EF_BOUNCE_HALF )
{
VectorScale( ent->s.pos.trDelta, 0.5, ent->s.pos.trDelta );
// check for stop
if ( trace->plane.normal[2] > 0.7 && ent->s.pos.trDelta[2] < 40 ) //this can happen even on very slightly sloped walls, so changed it from > 0 to > 0.7
{
if ( ent->s.weapon == WP_THERMAL )
{//roll when you "stop"
ent->s.pos.trType = TR_INTERPOLATE;
}
else
{
G_SetOrigin( ent, trace->endpos );
ent->nextthink = level.time + 500;
return;
}
}
if ( ent->s.weapon == WP_THERMAL )
{
ent->has_bounced = qtrue;
}
}
#if 0
// OLD--this looks so wrong. It looked wrong in EF. It just must be wrong.
VectorAdd( ent->currentOrigin, trace->plane.normal, ent->currentOrigin);
ent->s.pos.trTime = level.time - 10;
#else
// NEW--It would seem that we want to set our trBase to the trace endpos
// and set the trTime to the actual time of impact....
VectorAdd( trace->endpos, trace->plane.normal, ent->currentOrigin );
if ( hitTime >= level.time )
{//trace fraction must have been 1
ent->s.pos.trTime = level.time - 10;
}
else
{
ent->s.pos.trTime = hitTime - 10; // this is kinda dumb hacking, but it pushes the missile away from the impact plane a bit
}
#endif
VectorCopy( ent->currentOrigin, ent->s.pos.trBase );
VectorCopy( trace->plane.normal, ent->pos1 );
if ( ent->s.weapon != WP_SABER
&& ent->s.weapon != WP_THERMAL
&& ent->e_clThinkFunc != clThinkF_CG_Limb
&& ent->e_ThinkFunc != thinkF_LimbThink )
{//not a saber, bouncing thermal or limb
//now you can damage the guy you came from
ent->owner = NULL;
}
}
示例8: SV_Physics_Toss
/*
=============
SV_Physics_Toss
Toss, bounce, and fly movement. When onground, do nothing.
=============
*/
void SV_Physics_Toss (edict_t *ent)
{
trace_t trace;
vec3_t move;
float backoff;
edict_t *slave;
qboolean wasinwater;
qboolean isinwater;
vec3_t old_origin;
// regular thinking
SV_RunThink (ent);
// if not a team captain, so movement will be handled elsewhere
if ( ent->flags & FL_TEAMSLAVE)
return;
if (ent->velocity[2] > 0)
ent->groundentity = NULL;
// check for the groundentity going away
if (ent->groundentity)
if (!ent->groundentity->inuse)
ent->groundentity = NULL;
// if onground, return without moving
if ( ent->groundentity )
return;
VectorCopy (ent->s.origin, old_origin);
SV_CheckVelocity (ent);
// add gravity
if (ent->movetype != MOVETYPE_FLY
&& ent->movetype != MOVETYPE_FLYMISSILE
// RAFAEL
// move type for rippergun projectile
&& ent->movetype != MOVETYPE_WALLBOUNCE)
SV_AddGravity (ent);
// move angles
VectorMA (ent->s.angles, FRAMETIME, ent->avelocity, ent->s.angles);
// move origin
VectorScale (ent->velocity, FRAMETIME, move);
trace = SV_PushEntity (ent, move);
if (!ent->inuse)
return;
if (trace.fraction < 1)
{
// RAFAEL
if (ent->movetype == MOVETYPE_WALLBOUNCE)
backoff = 2.0;
// RAFAEL ( else )
else if (ent->movetype == MOVETYPE_BOUNCE)
backoff = 1.5;
else
backoff = 1;
ClipVelocity (ent->velocity, trace.plane.normal, ent->velocity, backoff);
// RAFAEL
if (ent->movetype == MOVETYPE_WALLBOUNCE)
vectoangles (ent->velocity, ent->s.angles);
// stop if on ground
// RAFAEL
if (trace.plane.normal[2] > 0.7 && ent->movetype != MOVETYPE_WALLBOUNCE)
{
if (ent->velocity[2] < 60 || ent->movetype != MOVETYPE_BOUNCE )
{
ent->groundentity = trace.ent;
ent->groundentity_linkcount = trace.ent->linkcount;
VectorCopy (vec3_origin, ent->velocity);
VectorCopy (vec3_origin, ent->avelocity);
}
}
// if (ent->touch)
// ent->touch (ent, trace.ent, &trace.plane, trace.surface);
}
// check for water transition
wasinwater = (ent->watertype & MASK_WATER);
ent->watertype = gi.pointcontents (ent->s.origin);
isinwater = ent->watertype & MASK_WATER;
if (isinwater)
ent->waterlevel = 1;
else
ent->waterlevel = 0;
//.........这里部分代码省略.........
示例9: CanDamage
/*
============
CanDamage
Returns true if the inflictor can directly damage the target. Used for
explosions and melee attacks.
============
*/
qboolean CanDamage(edict_t * targ, edict_t * inflictor)
{
vec3_t dest;
trace_t trace;
// bmodels need special checking because their origin is 0,0,0
if (targ->movetype == MOVETYPE_PUSH) {
VectorAdd(targ->absmin, targ->absmax, dest);
VectorScale(dest, 0.5, dest);
trace =
gi.trace(inflictor->s.origin, vec3_origin, vec3_origin,
dest, inflictor, MASK_SOLID);
if (trace.fraction == 1.0)
return true;
if (trace.ent == targ)
return true;
return false;
}
trace =
gi.trace(inflictor->s.origin, vec3_origin, vec3_origin,
targ->s.origin, inflictor, MASK_SOLID);
if (trace.fraction == 1.0)
return true;
VectorCopy(targ->s.origin, dest);
dest[0] += 15.0;
dest[1] += 15.0;
trace =
gi.trace(inflictor->s.origin, vec3_origin, vec3_origin, dest,
inflictor, MASK_SOLID);
if (trace.fraction == 1.0)
return true;
VectorCopy(targ->s.origin, dest);
dest[0] += 15.0;
dest[1] -= 15.0;
trace =
gi.trace(inflictor->s.origin, vec3_origin, vec3_origin, dest,
inflictor, MASK_SOLID);
if (trace.fraction == 1.0)
return true;
VectorCopy(targ->s.origin, dest);
dest[0] -= 15.0;
dest[1] += 15.0;
trace =
gi.trace(inflictor->s.origin, vec3_origin, vec3_origin, dest,
inflictor, MASK_SOLID);
if (trace.fraction == 1.0)
return true;
VectorCopy(targ->s.origin, dest);
dest[0] -= 15.0;
dest[1] -= 15.0;
trace =
gi.trace(inflictor->s.origin, vec3_origin, vec3_origin, dest,
inflictor, MASK_SOLID);
if (trace.fraction == 1.0)
return true;
return false;
}
示例10: NPC_BSHowler_Default
/*
-------------------------
NPC_BSHowler_Default
-------------------------
*/
void NPC_BSHowler_Default( void )
{
if ( NPC->client->ps.legsAnim != BOTH_GESTURE1 )
{
NPC->count = 0;
}
//FIXME: if in jump, do damage in front and maybe knock them down?
if ( !TIMER_Done( NPC, "attacking" ) )
{
if ( NPC->enemy )
{
//NPC_FaceEnemy( qfalse );
Howler_Attack( Distance( NPC->enemy->currentOrigin, NPC->currentOrigin ) );
}
else
{
//NPC_UpdateAngles( qfalse, qtrue );
Howler_Attack( 0.0f );
}
NPC_UpdateAngles( qfalse, qtrue );
return;
}
if ( NPC->enemy )
{
if ( NPCInfo->stats.aggression > 0 )
{
if ( TIMER_Done( NPC, "aggressionDecay" ) )
{
NPCInfo->stats.aggression--;
TIMER_Set( NPC, "aggressionDecay", 500 );
}
}
if ( !TIMER_Done( NPC, "flee" )
&& NPC_BSFlee() ) //this can clear ENEMY
{//successfully trying to run away
return;
}
if ( NPC->enemy == NULL)
{
NPC_UpdateAngles( qfalse, qtrue );
return;
}
if ( NPCInfo->localState == LSTATE_FLEE )
{//we were fleeing, now done (either timer ran out or we cannot flee anymore
if ( NPC_ClearLOS( NPC->enemy ) )
{//if enemy is still around, go berzerk
NPCInfo->localState = LSTATE_BERZERK;
}
else
{//otherwise, lick our wounds?
NPCInfo->localState = LSTATE_CLEAR;
TIMER_Set( NPC, "standing", Q_irand( 3000, 10000 ) );
}
}
else if ( NPCInfo->localState == LSTATE_BERZERK )
{//go nuts!
}
else if ( NPCInfo->stats.aggression >= Q_irand( 75, 125 ) )
{//that's it, go nuts!
NPCInfo->localState = LSTATE_BERZERK;
}
else if ( !TIMER_Done( NPC, "retreating" ) )
{//trying to back off
NPC_FaceEnemy( qtrue );
if ( NPC->client->ps.speed > NPCInfo->stats.walkSpeed )
{
NPC->client->ps.speed = NPCInfo->stats.walkSpeed;
}
ucmd.buttons |= BUTTON_WALKING;
if ( Distance( NPC->enemy->currentOrigin, NPC->currentOrigin ) < HOWLER_RETREAT_DIST )
{//enemy is close
vec3_t moveDir;
AngleVectors( NPC->currentAngles, moveDir, NULL, NULL );
VectorScale( moveDir, -1, moveDir );
if ( !NAV_DirSafe( NPC, moveDir, 8 ) )
{//enemy is backing me up against a wall or ledge! Start to get really mad!
NPCInfo->stats.aggression += 2;
}
else
{//back off
ucmd.forwardmove = -127;
}
//enemy won't leave me alone, get mad...
NPCInfo->stats.aggression++;
}
return;
}
else if ( TIMER_Done( NPC, "standing" ) )
{//not standing around
if ( !(NPCInfo->last_ucmd.forwardmove)
&& !(NPCInfo->last_ucmd.rightmove) )
{//stood last frame
if ( TIMER_Done( NPC, "walking" )
&& TIMER_Done( NPC, "running" ) )
//.........这里部分代码省略.........
示例11: SV_FlyMove
//.........这里部分代码省略.........
if (trace.allsolid)
{ // entity is trapped in another solid
VectorCopy (vec3_origin, ent->velocity);
return 3;
}
if (trace.fraction > 0)
{ // actually covered some distance
VectorCopy (trace.endpos, ent->s.origin);
VectorCopy (ent->velocity, original_velocity);
numplanes = 0;
}
if (trace.fraction == 1)
break; // moved the entire distance
hit = trace.ent;
if (trace.plane.normal[2] > 0.7)
{
blocked |= 1; // floor
if ( hit->solid == SOLID_BSP)
{
ent->groundentity = hit;
ent->groundentity_linkcount = hit->linkcount;
}
}
if (!trace.plane.normal[2])
{
blocked |= 2; // step
}
//
// run the impact function
//
SV_Impact (ent, &trace);
if (!ent->inuse)
break; // removed by the impact function
time_left -= time_left * trace.fraction;
// cliped to another plane
if (numplanes >= MAX_CLIP_PLANES)
{ // this shouldn't really happen
VectorCopy (vec3_origin, ent->velocity);
return 3;
}
VectorCopy (trace.plane.normal, planes[numplanes]);
numplanes++;
//
// modify original_velocity so it parallels all of the clip planes
//
for (i=0 ; i<numplanes ; i++)
{
ClipVelocity (original_velocity, planes[i], new_velocity, 1);
for (j=0 ; j<numplanes ; j++)
if ((j != i) && !VectorCompare (planes[i], planes[j]))
{
if (DotProduct (new_velocity, planes[j]) < 0)
break; // not ok
}
if (j == numplanes)
break;
}
if (i != numplanes)
{ // go along this plane
VectorCopy (new_velocity, ent->velocity);
}
else
{ // go along the crease
if (numplanes != 2)
{
// gi.dprintf ("clip velocity, numplanes == %i\n",numplanes);
VectorCopy (vec3_origin, ent->velocity);
return 7;
}
CrossProduct (planes[0], planes[1], dir);
d = DotProduct (dir, ent->velocity);
VectorScale (dir, d, ent->velocity);
}
//
// if original velocity is against the original velocity, stop dead
// to avoid tiny occilations in sloping corners
//
if (DotProduct (ent->velocity, primal_velocity) <= 0)
{
VectorCopy (vec3_origin, ent->velocity);
return blocked;
}
}
return blocked;
}
示例12: Howler_Attack
//------------------------------
static void Howler_Attack( float enemyDist, qboolean howl )
{
int dmg = (NPCInfo->localState==LSTATE_BERZERK)?5:2;
if ( !TIMER_Exists( NPC, "attacking" ))
{
int attackAnim = BOTH_GESTURE1;
// Going to do an attack
if ( NPC->enemy && NPC->enemy->client && PM_InKnockDown( &NPC->enemy->client->ps )
&& enemyDist <= MIN_DISTANCE )
{
attackAnim = BOTH_ATTACK2;
}
else if ( !Q_irand( 0, 4 ) || howl )
{//howl attack
//G_SoundOnEnt( NPC, CHAN_VOICE, "sound/chars/howler/howl.mp3" );
}
else if ( enemyDist > MIN_DISTANCE && Q_irand( 0, 1 ) )
{//lunge attack
//jump foward
vec3_t fwd, yawAng = {0, NPC->client->ps.viewangles[YAW], 0};
AngleVectors( yawAng, fwd, NULL, NULL );
VectorScale( fwd, (enemyDist*3.0f), NPC->client->ps.velocity );
NPC->client->ps.velocity[2] = 200;
NPC->client->ps.groundEntityNum = ENTITYNUM_NONE;
attackAnim = BOTH_ATTACK1;
}
else
{//tongue attack
attackAnim = BOTH_ATTACK2;
}
NPC_SetAnim( NPC, SETANIM_BOTH, attackAnim, SETANIM_FLAG_OVERRIDE | SETANIM_FLAG_HOLD | SETANIM_FLAG_RESTART );
if ( NPCInfo->localState == LSTATE_BERZERK )
{//attack again right away
TIMER_Set( NPC, "attacking", NPC->client->ps.legsAnimTimer );
}
else
{
TIMER_Set( NPC, "attacking", NPC->client->ps.legsAnimTimer + Q_irand( 0, 1500 ) );//FIXME: base on skill
TIMER_Set( NPC, "standing", -level.time );
TIMER_Set( NPC, "walking", -level.time );
TIMER_Set( NPC, "running", NPC->client->ps.legsAnimTimer + 5000 );
}
TIMER_Set( NPC, "attack_dmg", 200 ); // level two damage
}
// Need to do delayed damage since the attack animations encapsulate multiple mini-attacks
switch ( NPC->client->ps.legsAnim )
{
case BOTH_ATTACK1:
case BOTH_MELEE1:
if ( NPC->client->ps.legsAnimTimer > 650//more than 13 frames left
&& PM_AnimLength( NPC->client->clientInfo.animFileIndex, (animNumber_t)NPC->client->ps.legsAnim ) - NPC->client->ps.legsAnimTimer >= 800 )//at least 16 frames into anim
{
Howler_TryDamage( dmg, qfalse, qfalse );
}
break;
case BOTH_ATTACK2:
case BOTH_MELEE2:
if ( NPC->client->ps.legsAnimTimer > 350//more than 7 frames left
&& PM_AnimLength( NPC->client->clientInfo.animFileIndex, (animNumber_t)NPC->client->ps.legsAnim ) - NPC->client->ps.legsAnimTimer >= 550 )//at least 11 frames into anim
{
Howler_TryDamage( dmg, qtrue, qfalse );
}
break;
case BOTH_GESTURE1:
{
if ( NPC->client->ps.legsAnimTimer > 1800//more than 36 frames left
&& PM_AnimLength( NPC->client->clientInfo.animFileIndex, (animNumber_t)NPC->client->ps.legsAnim ) - NPC->client->ps.legsAnimTimer >= 950 )//at least 19 frames into anim
{
Howler_Howl();
if ( !NPC->count )
{
G_PlayEffect( G_EffectIndex( "howler/sonic" ), NPC->playerModel, NPC->genericBolt1, NPC->s.number, NPC->currentOrigin, 4750, qtrue );
G_SoundOnEnt( NPC, CHAN_VOICE, "sound/chars/howler/howl.mp3" );
NPC->count = 1;
}
}
}
break;
default:
//anims seem to get reset after a load, so just stop attacking and it will restart as needed.
TIMER_Remove( NPC, "attacking" );
break;
}
// Just using this to remove the attacking flag at the right time
TIMER_Done2( NPC, "attacking", qtrue );
}
示例13: modified
//.........这里部分代码省略.........
// actually covered some distance
VectorCopy( trace.endpos, ent->v.origin );
VectorCopy( ent->v.velocity, original_velocity );
numplanes = 0;
}
if( trace.fraction == 1.0f )
break; // moved the entire distance
if( !trace.ent )
MsgDev( D_ERROR, "SV_FlyMove: trace.ent == NULL\n" );
if( trace.plane.normal[2] > 0.7f )
{
blocked |= 1; // floor
if( trace.ent->v.solid == SOLID_BSP || trace.ent->v.solid == SOLID_SLIDEBOX ||
trace.ent->v.movetype == MOVETYPE_PUSHSTEP || (trace.ent->v.flags & FL_CLIENT))
{
ent->v.flags |= FL_ONGROUND;
ent->v.groundentity = trace.ent;
}
}
if( trace.plane.normal[2] == 0.0f )
{
blocked |= 2; // step
if( steptrace ) *steptrace = trace; // save for player extrafriction
}
// run the impact function
SV_Impact( ent, trace.ent, &trace );
// break if removed by the impact function
if( ent->free ) break;
time_left -= time_left * trace.fraction;
// clipped to another plane
if( numplanes >= MAX_CLIP_PLANES )
{
// this shouldn't really happen
VectorClear( ent->v.velocity );
break;
}
VectorCopy( trace.plane.normal, planes[numplanes] );
numplanes++;
// modify original_velocity so it parallels all of the clip planes
for( i = 0; i < numplanes; i++ )
{
SV_ClipVelocity( original_velocity, planes[i], new_velocity, 1.0f );
for( j = 0; j < numplanes; j++ )
{
if( j != i )
{
if( DotProduct( new_velocity, planes[j] ) < 0.0f )
break; // not ok
}
}
if( j == numplanes )
break;
}
if( i != numplanes )
{
// go along this plane
VectorCopy( new_velocity, ent->v.velocity );
}
else
{
// go along the crease
if( numplanes != 2 )
{
VectorClear( ent->v.velocity );
break;
}
CrossProduct( planes[0], planes[1], dir );
d = DotProduct( dir, ent->v.velocity );
VectorScale( dir, d, ent->v.velocity );
}
// if current velocity is against the original velocity,
// stop dead to avoid tiny occilations in sloping corners
if( DotProduct( ent->v.velocity, primal_velocity ) <= 0.0f )
{
VectorClear( ent->v.velocity );
break;
}
}
if( allFraction == 0.0f )
VectorClear( ent->v.velocity );
return blocked;
}
示例14: SV_Physics_Toss
/*
=============
SV_Physics_Toss
Toss, bounce, and fly movement. When onground, do nothing.
=============
*/
void SV_Physics_Toss( edict_t *ent )
{
trace_t trace;
vec3_t move;
float backoff;
edict_t *ground;
SV_CheckWater( ent );
// regular thinking
if( !SV_RunThink( ent )) return;
ground = ent->v.groundentity;
if( ent->v.velocity[2] > 0.0f || !SV_IsValidEdict( ground ) || ground->v.flags & (FL_MONSTER|FL_CLIENT) || svgame.globals->changelevel )
{
ent->v.flags &= ~FL_ONGROUND;
}
// if on ground and not moving, return.
if( ent->v.flags & FL_ONGROUND && VectorIsNull( ent->v.velocity ))
{
VectorClear( ent->v.avelocity );
if( VectorIsNull( ent->v.basevelocity ))
return; // at rest
}
SV_CheckVelocity( ent );
// add gravity
switch( ent->v.movetype )
{
case MOVETYPE_FLY:
case MOVETYPE_FLYMISSILE:
case MOVETYPE_BOUNCEMISSILE:
break;
default:
SV_AddGravity( ent );
break;
}
// move angles (with friction)
switch( ent->v.movetype )
{
case MOVETYPE_TOSS:
case MOVETYPE_BOUNCE:
SV_AngularMove( ent, host.frametime, ent->v.friction );
break;
default:
SV_AngularMove( ent, host.frametime, 0.0f );
break;
}
// move origin
// Base velocity is not properly accounted for since this entity will move again
// after the bounce without taking it into account
VectorAdd( ent->v.velocity, ent->v.basevelocity, ent->v.velocity );
SV_CheckVelocity( ent );
VectorScale( ent->v.velocity, host.frametime, move );
VectorSubtract( ent->v.velocity, ent->v.basevelocity, ent->v.velocity );
trace = SV_PushEntity( ent, move, vec3_origin, NULL );
if( ent->free ) return;
SV_CheckVelocity( ent );
if( trace.allsolid )
{
// entity is trapped in another solid
VectorClear( ent->v.avelocity );
VectorClear( ent->v.velocity );
return;
}
if( trace.fraction == 1.0f )
{
SV_CheckWaterTransition( ent );
return;
}
if( ent->v.movetype == MOVETYPE_BOUNCE )
backoff = 2.0f - ent->v.friction;
else if( ent->v.movetype == MOVETYPE_BOUNCEMISSILE )
backoff = 2.0f;
else backoff = 1.0f;
SV_ClipVelocity( ent->v.velocity, trace.plane.normal, ent->v.velocity, backoff );
// stop if on ground
if( trace.plane.normal[2] > 0.7f )
//.........这里部分代码省略.........
示例15: fabs
/*
=================
BaseWindingForPlane
=================
*/
winding_t *BaseWindingForPlane (vec3_t normal, vec_t dist)
{
int i, x;
vec_t max, v;
vec3_t org, vright, vup;
winding_t *w;
// find the major axis
max = -BOGUS_RANGE;
x = -1;
for (i=0 ; i<3; i++)
{
v = fabs(normal[i]);
if (v > max)
{
x = i;
max = v;
}
}
if (x==-1)
Error ("BaseWindingForPlane: no axis found");
VectorCopy (vec3_origin, vup);
switch (x)
{
case 0:
case 1:
vup[2] = 1;
break;
case 2:
vup[0] = 1;
break;
}
v = DotProduct (vup, normal);
VectorMA (vup, -v, normal, vup);
VectorNormalize (vup, vup);
VectorScale (normal, dist, org);
CrossProduct (vup, normal, vright);
VectorScale (vup, 8192, vup);
VectorScale (vright, 8192, vright);
// project a really big axis aligned box onto the plane
w = AllocWinding (4);
VectorSubtract (org, vright, w->p[0]);
VectorAdd (w->p[0], vup, w->p[0]);
VectorAdd (org, vright, w->p[1]);
VectorAdd (w->p[1], vup, w->p[1]);
VectorAdd (org, vright, w->p[2]);
VectorSubtract (w->p[2], vup, w->p[2]);
VectorSubtract (org, vright, w->p[3]);
VectorSubtract (w->p[3], vup, w->p[3]);
w->numpoints = 4;
return w;
}