qboolean canShoot(edict_t *self, edict_t *e) { vec3_t delta; vec3_t dangles; VectorSubtract(e->s.origin, self->s.origin, delta); vectoangles(delta, dangles); dangles[PITCH] = mod180(dangles[PITCH]); if ((!self->onFloor && dangles[PITCH] < 0) || (self->onFloor && dangles[PITCH] > 0)) // facing up or down return false; if (self->monsterinfo.linkcount > 0) { float ideal_yaw = self->monsterinfo.attack_state; float max_yaw = anglemod(ideal_yaw + self->monsterinfo.linkcount); float min_yaw = anglemod(ideal_yaw - self->monsterinfo.linkcount); if (!angleBetween(&dangles[YAW], &min_yaw, &max_yaw)) return false; } return true; }
static float adjustang (float current, float ideal, float speed) { float move; current = anglemod (current); ideal = anglemod (ideal); if (current == ideal) return current; move = ideal - current; if (ideal > current) { if (move >= 180) move = move - 360; } else { if (move <= -180) move = move + 360; } if (move > 0) { if (move > speed) move = speed; } else { if (move < -speed) move = -speed; } return anglemod (current + move); }
/* =============== M_ChangeYaw =============== */ void M_ChangeYaw(edict_t *ent) { float ideal; float current; float move; float speed; current = anglemod(ent->s.angles[YAW]); ideal = ent->ideal_yaw; if (current == ideal) return; move = ideal - current; speed = ent->yaw_speed; if (ideal > current) { if (move >= 180) move = move - 360; } else { if (move <= -180) move = move + 360; } if (move > 0) { if (move > speed) move = speed; } else { if (move < -speed) move = -speed; } ent->s.angles[YAW] = anglemod(current + move); }
void Engineer_RotateSG( ) { int angle; char value[1024]; if( !tg_data.tg_enabled && (self->playerclass != PC_ENGINEER )) return; if( self->current_menu != MENU_ENGINEER_FIX_SENTRYGUN ) return; if( trap_CmdArgc() != 2) return; trap_CmdArgv( 1, value, sizeof( value ) ); if( !strcmp( value,"point") ) { self->building->waitmin = anglemod( ( int ) ( self->s.v.angles[1] - 50 ) ); self->building->waitmax = anglemod( ( int ) ( self->s.v.angles[1] + 50 ) ); return; } angle = atoi(value); self->building->waitmin = anglemod( self->building->waitmin + angle ); self->building->waitmax = anglemod( self->building->waitmax + angle ); }
static float adjustang(float current, float ideal, float speed) { float move; current = anglemod(current); ideal = anglemod(ideal); if (current == ideal) return current; move = ideal - current; if (ideal > current) { if (move >= 180) move = move - 360; } else { if (move <= -180) move = move + 360; } if (move > 0) { if (move > speed) move = speed; } else { if (move < -speed) move = -speed; } //Con_Printf("c/i: %4.2f/%4.2f move: %4.2f\n", current, ideal, move); return anglemod (current + move); }
/* =============== R_ShadowPassSetupFrame =============== */ static void R_ShadowPassSetupFrame( const plight_t *pl ) { // build the transformation matrix for the given view angles RI.refdef.viewangles[0] = anglemod( pl->angles[0] ); RI.refdef.viewangles[1] = anglemod( pl->angles[1] ); RI.refdef.viewangles[2] = anglemod( pl->angles[2] ); AngleVectors( RI.refdef.viewangles, RI.vforward, RI.vright, RI.vup ); RI.vieworg = RI.refdef.vieworg = pl->origin; // setup the screen FOV RI.refdef.fov_x = pl->fov; if( pl->flags & CF_ASPECT3X4 ) RI.refdef.fov_y = pl->fov * (5.0f / 4.0f); else if( pl->flags & CF_ASPECT4X3 ) RI.refdef.fov_y = pl->fov * (4.0f / 5.0f); else RI.refdef.fov_y = pl->fov; // setup frustum memcpy( RI.frustum, pl->frustum, sizeof( RI.frustum )); RI.clipFlags = pl->clipflags; if(!( RI.params & RP_OLDVIEWLEAF )) R_FindViewLeaf(); RI.currentlight = pl; }
void SendProxy_QAngles( const SendProp *pProp, const void *pStruct, const void *pData, DVariant *pOut, int iElement, int objectID ) { QAngle *v = (QAngle*)pData; pOut->m_Vector[0] = anglemod( v->x ); pOut->m_Vector[1] = anglemod( v->y ); pOut->m_Vector[2] = anglemod( v->z ); }
/* extern void SendProxy_Angles( const SendProp *pProp, const void *pStruct, const void *pData, DVariant *pOut, int iElement, int objectID ); void SendProxy_FuncRotatingAngles( const SendProp *pProp, const void *pStruct, const void *pData, DVariant *pOut, int iElement, int objectID ) { CFuncRotating *entity = (CFuncRotating*)pStruct; Assert( entity ); if ( entity->HasSpawnFlags(SF_BRUSH_ROTATE_CLIENTSIDE) ) { const QAngle *a = &entity->m_vecClientAngles; pOut->m_Vector[ 0 ] = anglemod( a->x ); pOut->m_Vector[ 1 ] = anglemod( a->y ); pOut->m_Vector[ 2 ] = anglemod( a->z ); return; } SendProxy_Angles( pProp, pStruct, pData, pOut, iElement, objectID ); } */ void SendProxy_FuncRotatingAngle( const SendProp *pProp, const void *pStruct, const void *pData, DVariant *pOut, int iElement, int objectID) { CFuncRotating *entity = (CFuncRotating*)pStruct; Assert( entity ); vec_t const *qa = (vec_t *)pData; vec_t const *ea = entity->GetLocalAngles().Base(); NOTE_UNUSED(ea); // Assert its actually an index into m_angRotation if not this won't work Assert( (uintp)qa >= (uintp)ea && (uintp)qa < (uintp)ea + sizeof( QAngle )); #ifdef TF_DLL if ( entity->HasSpawnFlags(SF_BRUSH_ROTATE_CLIENTSIDE) ) { const QAngle *a = &entity->m_vecClientAngles; pOut->m_Float = anglemod( (*a)[ qa - ea ] ); return; } #endif pOut->m_Float = anglemod( *qa ); Assert( IsFinite( pOut->m_Float ) ); }
/* * CG_SkyPortal */ int CG_SkyPortal( void ) { float fov = 0; float scale = 0; int noents = 0; float pitchspeed = 0, yawspeed = 0, rollspeed = 0; skyportal_t *sp = &cg.view.refdef.skyportal; if( cgs.configStrings[CS_SKYBOX][0] == '\0' ) return 0; if( sscanf( cgs.configStrings[CS_SKYBOX], "%f %f %f %f %f %i %f %f %f", &sp->vieworg[0], &sp->vieworg[1], &sp->vieworg[2], &fov, &scale, &noents, &pitchspeed, &yawspeed, &rollspeed ) >= 3 ) { float off = cg.view.refdef.time * 0.001f; sp->fov = fov; sp->noEnts = (noents ? true : false); sp->scale = scale ? 1.0f / scale : 0; VectorSet( sp->viewanglesOffset, anglemod( off * pitchspeed ), anglemod( off * yawspeed ), anglemod( off * rollspeed ) ); return RDF_SKYPORTALINVIEW; } return 0; }
/* =============== M_ChangeYaw =============== */ void M_ChangeYaw (edict_t *ent) { float ideal; float current; float move; float speed; current = anglemod(ent->s.angles[YAW]); ideal = ent->ideal_yaw; if (current == ideal) return; move = ideal - current; speed = ent->yaw_speed; // Ridah, turn faster if we have an enemy if (ent->enemy) { speed *= 4; if (speed > 80) speed = 80; } else if (ent->cast_info.currentmove && (ent->cast_info.currentmove->frame->dist)) { // dependant on speed speed *= (fabs(ent->cast_info.currentmove->frame->dist) / 16.0); if (speed > 60) speed = 60; if (speed < 20) speed = 20; //if (ent->name) //gi.dprintf( "%s yaw = %2.1f\n", ent->name, speed ); } if (ideal > current) { if (move >= 180) move = move - 360; } else { if (move <= -180) move = move + 360; } if (move > 0) { if (move > speed) move = speed; } else { if (move < -speed) move = -speed; } ent->s.angles[YAW] = anglemod (current + move); }
void CSimple3DEmitter::SimulateParticles( CParticleSimulateIterator *pIterator ) { Particle3D *pParticle = (Particle3D*)pIterator->GetFirst(); while ( pParticle ) { const float timeDelta = pIterator->GetTimeDelta(); //Should this particle die? pParticle->m_flLifeRemaining -= timeDelta; if ( pParticle->IsDead() ) { pIterator->RemoveParticle( pParticle ); } else { // Angular rotation pParticle->m_vAngles.x += pParticle->m_flAngSpeed * timeDelta; pParticle->m_vAngles.y += pParticle->m_flAngSpeed * timeDelta; pParticle->m_vAngles.z += pParticle->m_flAngSpeed * timeDelta; //Simulate the movement with collision trace_t trace; m_ParticleCollision.MoveParticle( pParticle->m_Pos, pParticle->m_vecVelocity, &pParticle->m_flAngSpeed, timeDelta, &trace ); // --------------------------------------- // Decay towards flat // --------------------------------------- if (pParticle->m_flAngSpeed == 0 || trace.fraction != 1.0) { pParticle->m_vAngles.x = anglemod(pParticle->m_vAngles.x); if (pParticle->m_vAngles.x < 180) { if (fabs(pParticle->m_vAngles.x - 90) > 0.5) { pParticle->m_vAngles.x = 0.5*pParticle->m_vAngles.x + 46; } } else { if (fabs(pParticle->m_vAngles.x - 270) > 0.5) { pParticle->m_vAngles.x = 0.5*pParticle->m_vAngles.x + 135; } } pParticle->m_vAngles.y = anglemod(pParticle->m_vAngles.y); if (fabs(pParticle->m_vAngles.y) > 0.5) { pParticle->m_vAngles.y = 0.5*pParticle->m_vAngles.z; } } } pParticle = (Particle3D*)pIterator->GetNext(); } }
/* ============= zFindRoamYaw Check direction moving in does not hit a wall... if it does change direction. ============== */ int zFindRoamYaw(edict_t *self, float distcheck) { vec3_t forward, end, angles; trace_t tr; float current = anglemod(self->s.angles[YAW]); if(current <= self->ideal_yaw - 1 || current > self->ideal_yaw + 1) { if(fabs(current - self->ideal_yaw) <= 359.0) { return 0; } } AngleVectors (self->s.angles, forward, NULL, NULL); VectorMA (self->s.origin, distcheck, forward, end); tr = gi.trace (self->s.origin, self->mins, self->maxs, end, self, MASK_SOLID); if (tr.fraction < 1.0) { if(random() > 0.75) { self->ideal_yaw = vectoyaw(forward); self->ideal_yaw = self->ideal_yaw + 180; } else { float dir = random() > 0.5 ? -45 : 45; float maxtrys = 100; VectorCopy(self->s.angles, angles); while(tr.fraction < 1.0 && maxtrys) { // blocked, change ideal yaw... self->ideal_yaw = vectoyaw(forward); self->ideal_yaw = self->ideal_yaw + (random() * dir); angles[YAW] = anglemod (self->ideal_yaw); AngleVectors (angles, forward, NULL, NULL); VectorMA (self->s.origin, distcheck, forward, end); tr = gi.trace (self->s.origin, self->mins, self->maxs, end, self, MASK_SOLID); maxtrys--; } } return 1; } return 0; };
void SendProxy_FuncRotatingAngles( const SendProp *pProp, const void *pStruct, const void *pData, DVariant *pOut, int iElement, int objectID ) { CFuncRotating *entity = (CFuncRotating*)pStruct; Assert( entity ); if ( entity->HasSpawnFlags(SF_BRUSH_ROTATE_CLIENTSIDE) ) { const QAngle *a = &entity->m_vecClientAngles; pOut->m_Vector[ 0 ] = anglemod( a->x ); pOut->m_Vector[ 1 ] = anglemod( a->y ); pOut->m_Vector[ 2 ] = anglemod( a->z ); return; } SendProxy_Angles( pProp, pStruct, pData, pOut, iElement, objectID ); }
//----------------------------------------------------------------------------- // Purpose: Think function. Called while rotating at a constant angular velocity. //----------------------------------------------------------------------------- void CFuncRotating::RotateMove( void ) { SetMoveDoneTime( 10 ); if ( m_bStopAtStartPos ) { SetMoveDoneTime( GetNextMoveInterval() ); int checkAxis = 2; // See if we got close to the starting orientation if ( m_vecMoveAng[0] != 0 ) { checkAxis = 0; } else if ( m_vecMoveAng[1] != 0 ) { checkAxis = 1; } float angDelta = anglemod( GetLocalAngles()[ checkAxis ] - m_angStart[ checkAxis ] ); if ( angDelta > 180.0f ) angDelta -= 360.0f; QAngle avel = GetLocalAngularVelocity(); // Delta per tick QAngle avelpertick = avel * TICK_INTERVAL; if ( fabs( angDelta ) < fabs( avelpertick[ checkAxis ] ) ) { SetTargetSpeed( 0 ); SetLocalAngles( m_angStart ); m_bStopAtStartPos = false; } } }
void Simulator::UpdateRobot(SimRobot &r, double dt) { if(r.conf==0.0) { return; } /* do an acceleration check */ AccelerationLimit(r, maxRobotAccel * dt); /* Speed Limit */ SpeedLimit(r, maxRobotSpeed); /* store off old velocities and positions */ r.oldpos = r.pos; /* transform to world coords */ r.vel.v = r.vcmd.v; r.vel.v = r.vel.v.rotate(r.pos.dir); r.pos.p += r.vel.v * dt; r.pos.dir = anglemod(r.pos.dir + r.vcmd.va * dt); /* look for wall collisions */ r.collision = CheckWallCollision(r, field_minX, field_maxX, field_minY, field_maxY); }
void CObjectTeleporter::ShowDirectionArrow( bool bShow ) { if ( bShow != m_bShowDirectionArrow ) { if ( m_iDirectionBodygroup >= 0 ) { SetBodygroup( m_iDirectionBodygroup, bShow ? 1 : 0 ); } m_bShowDirectionArrow = bShow; if ( bShow ) { CObjectTeleporter *pMatch = GetMatchingTeleporter(); Assert( pMatch ); Vector vecToOwner = pMatch->GetAbsOrigin() - GetAbsOrigin(); QAngle angleToExit; VectorAngles( vecToOwner, Vector(0,0,1), angleToExit ); angleToExit -= GetAbsAngles(); // pose param is flipped and backwards, adjust. m_flYawToExit = anglemod( -angleToExit.y + 180 ); } } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void UnitVehicleNavigator::CalcMove( UnitBaseMoveCommand &MoveCommand, QAngle angles, float speed ) { if( GetPath()->m_iGoalType != GOALTYPE_NONE ) { // Check if we need to back the vehicle to make a turn (estimated) UnitBaseWaypoint *pCurWaypoint = GetPath()->m_pWaypointHead; if( pCurWaypoint ) { Vector vDir; float waypointDist = UnitComputePathDirection( GetAbsOrigin(), pCurWaypoint->GetPos(), vDir ); QAngle turnAngles; VectorAngles( vDir, turnAngles ); float angle = anglemod( MoveCommand.viewangles[YAW] - turnAngles[YAW] ); if( angle > 180.0f ) angle = fabs( angle - 360 ); float distNeeded = CalcNeededDistanceForTurn( MoveCommand, angle ); if( angle > unit_vehicle_angle_tolerance.GetFloat() && waypointDist > unit_vehicle_waypoint_tolerance.GetFloat() && distNeeded * unit_vehicle_min_dist_turnmod.GetFloat() > waypointDist ) { MoveCommand.forwardmove = -Min( distNeeded, MoveCommand.maxspeed ); MoveCommand.sidemove = 0; return; } } } BaseClass::CalcMove( MoveCommand, angles, speed ); }
void carrier_ready_spawn(edict_t *self) { float current_yaw; vec3_t offset, f, r, startpoint, spawnpoint; if (!self) { return; } CarrierCoopCheck(self); CarrierMachineGun(self); current_yaw = anglemod(self->s.angles[YAW]); if (fabs(current_yaw - self->ideal_yaw) > 0.1) { self->monsterinfo.aiflags |= AI_HOLD_FRAME; self->timestamp += FRAMETIME; return; } self->monsterinfo.aiflags &= ~AI_HOLD_FRAME; VectorSet(offset, 105, 0, -58); AngleVectors(self->s.angles, f, r, NULL); G_ProjectSource(self->s.origin, offset, f, r, startpoint); if (FindSpawnPoint(startpoint, flyer_mins, flyer_maxs, spawnpoint, 32)) { SpawnGrow_Spawn(spawnpoint, 0); } }
void Bot_CL_KeyMove( ) { int forwardmove = 0, sidemove = 0, upmove = 0; int buttons = 0; buttons = ( ( self->s.v.button0 ) ? 1 : 0 ) + ( ( self->s.v.button2 ) ? 2 : 0 ); sidemove += self->maxstrafespeed * CL_KeyState( KEY_MOVERIGHT ); sidemove -= self->maxstrafespeed * CL_KeyState( KEY_MOVELEFT ); upmove += 200 * CL_KeyState( KEY_MOVEUP ); upmove -= 200 * CL_KeyState( KEY_MOVEDOWN ); forwardmove += self->maxfbspeed * CL_KeyState( KEY_MOVEFORWARD ); forwardmove -= self->maxfbspeed * CL_KeyState( KEY_MOVEBACK ); if ( self->s.v.v_angle[0] > 80 ) self->s.v.v_angle[0] = 80; else { if ( self->s.v.v_angle[0] < -70 ) self->s.v.v_angle[0] = -70; } //self->s.v.v_angle[2] = 0; self->s.v.v_angle[1] = anglemod( self->s.v.v_angle[1] ); trap_SetBotCMD( NUM_FOR_EDICT( self ), bot_frametime * 1000, PASSVEC3(self->s.v.v_angle), forwardmove, sidemove, upmove, buttons, self->s.v.impulse ); }
static void KeyCursorDrawFunc( menuframework_s *menu ) { if (bind_grab) SCR_DrawChar (menu->x, menu->y + menu->cursor * MENU_LINE_SIZE, ALIGN_CENTER, '=', 255,255,255,255, false, true); // R_DrawChar ( SCR_ScaledVideo(menu->x), SCR_ScaledVideo(menu->y + menu->cursor * MENU_LINE_SIZE), // '=', SCR_VideoScale(), 255,255,255,255, false, true); else { /* SCR_DrawChar (menu->x, menu->y + menu->cursor * MENU_LINE_SIZE, ALIGN_CENTER, 12+((int)(Sys_Milliseconds()/250)&1), 255,255,255,255, false, true); */ SCR_DrawChar (menu->x+ (5*sin(anglemod(cl.time*0.01))), menu->y + menu->cursor * MENU_LINE_SIZE, ALIGN_CENTER, 13, 255,255,255, 255, false, true); } /* R_DrawChar ( SCR_ScaledVideo(menu->x), SCR_ScaledVideo(menu->y + menu->cursor * MENU_LINE_SIZE), 12 + ( ( int ) ( Sys_Milliseconds() / 250 ) & 1 ), SCR_VideoScale(), 255,255,255,255, false, true);*/ }
void body_think(edict_t *self) { float r; if (fabsf(self->ideal_yaw - anglemod(self->s.angles[YAW])) < 2) { if (self->timestamp < level.time) { r = random(); if (r < 0.10) { self->ideal_yaw = random() * 350.0; self->timestamp = level.time + 1; } } } else { M_ChangeYaw(self); } self->s.frame++; if (self->s.frame > FRAME_stand40) { self->s.frame = FRAME_stand01; } self->nextthink = level.time + 0.1; }
float angledelta (float a) { a = anglemod(a); if (a > 180) a -= 360; return a; }
void carrier_start_spawn(edict_t *self) { int mytime; float enemy_yaw; vec3_t temp; if (!self) { return; } CarrierCoopCheck(self); if (!orig_yaw_speed) { orig_yaw_speed = self->yaw_speed; } if (!self->enemy) { return; } mytime = (int)((level.time - self->timestamp) / 0.5); VectorSubtract(self->enemy->s.origin, self->s.origin, temp); enemy_yaw = vectoyaw2(temp); /* note that the offsets are based on a forward of 105 from the end angle */ if (mytime == 0) { self->ideal_yaw = anglemod(enemy_yaw - 30); } else if (mytime == 1) { self->ideal_yaw = anglemod(enemy_yaw); } else if (mytime == 2) { self->ideal_yaw = anglemod(enemy_yaw + 30); } CarrierMachineGun(self); }
void ai_face( ) { vec3_t vtemp; VectorSubtract( PROG_TO_EDICT( self->s.v.enemy )->s.v.origin, self->s.v.origin, vtemp ); self->s.v.ideal_yaw = vectoyaw( vtemp ); self->s.v.ideal_yaw = anglemod( self->s.v.ideal_yaw ); changeyaw( self ); }
// ---------------------------------------------------------------------- // // Proxies. // ---------------------------------------------------------------------- // void SendProxy_AngleToFloat( const SendProp *pProp, const void *pStruct, const void *pData, DVariant *pOut, int iElement, int objectID) { float angle; angle = *((float*)pData); pOut->m_Float = anglemod( angle ); Assert( IsFinite( pOut->m_Float ) ); }
/* ============ FacingIdeal ============ */ bool FacingIdeal(edict_t *self) { float delta; delta = anglemod(self->s.angles[YAW] - self->ideal_yaw); if (delta > 5 && delta < 355) return false; return true; }
void CSpriteOriented::Spawn( void ) { // save a copy of the angles, CSprite swaps the yaw and roll QAngle angles = GetAbsAngles(); BaseClass::Spawn(); // ORIENTED sprites "forward" vector points in the players "view" direction, not the direction "out" from the sprite (gah) angles.y = anglemod( angles.y + 180 ); SetAbsAngles( angles ); }
void CRotationSlider::OnSliderMoved( int position ) { C_BaseObject *pObj = m_hObject.Get(); if (pObj && pObj->IsPreviewingYaw()) { m_flYaw = anglemod(position); pObj->PreviewYaw( m_flInitialYaw - m_flYaw ); } }
void CVehicleMortar::UpdateElevation( const Vector &vecTargetVel ) { QAngle angles; VectorAngles( vecTargetVel, angles ); m_flMortarPitch = anglemod( -angles[PITCH] ); SetBoneController( 0, m_flMortarYaw ); SetBoneController( 1, m_flMortarPitch ); }
//----------------------------------------------------------------------------- // Clamps the view angles while manning the gun //----------------------------------------------------------------------------- void C_ObjectBaseMannedGun::UpdateViewAngles( C_BasePlayer *pLocalPlayer, CUserCmd *pCmd ) { #if 0 // Confine the view to the appropriate yaw range... float flAngleDiff = AngleDiff( pCmd->viewangles[YAW], flCenterYaw ); // Here, we must clamp to the cone... if (flAngleDiff < m_Movement.GetMinYaw()) pCmd->viewangles[YAW] = anglemod(flCenterYaw + m_Movement.GetMinYaw()); else if (flAngleDiff > m_Movement.GetMaxYaw()) pCmd->viewangles[YAW] = anglemod(flCenterYaw + m_Movement.GetMaxYaw()); #endif // Prevent too much downward looking if ( pCmd->viewangles[PITCH] > m_Movement.GetMaxPitch()) { pCmd->viewangles[PITCH] = m_Movement.GetMaxPitch(); } }