void TurretAI::ProcessTurn() { // Check for errors if(myEntity->GetFaction() == RelationshipManager::FACTIONLESS) { FILE_LOG(logWARNING) << "(TurretAI): The entity I'm attached to is FACTIONLESS: " << myEntity->GetName(); } // Make sure we have a valid entity if(myEntity != nullptr) { // Set up initial variables Entity* targettedEnt = nullptr; float targettedRot = 9999; float targettedAngle = 0; float myRotation = fmod (myEntity->GetCurrentRotation(),6.28); // Get our list of entities in this galaxy std::vector<Entity*> listOfEntites = myEntity->GetGame()->GetUniverseManager()->GetCurrentGalaxy()->GetEntityList(); // We only want to target ones within our range. for(auto it = listOfEntites.begin(); it != listOfEntites.end(); ++it) { if((*it) != nullptr) { float dist = GetDistances(myEntity->GetCurrentPosition(), (*it)->GetCurrentPosition()); if(dist < MAX_VISUAL_RANGE) { // If the other entity is an enemy.. if(RelationshipManager::GetRelationship(myEntity, (*it)) == RelationshipManager::ENEMY) { // We want to prioritize the ones that are "easiest" to reach. AKA rotation points in their direction. float rot2 = 0; rot2 = GetAngles(myEntity->GetCurrentPosition(), (*it)->GetCurrentPosition()); float deltaRot = rot2 - myRotation; if(abs(deltaRot) < targettedRot) { /* TODO: Why does this even work? */ targettedEnt = (*it); targettedRot = abs(deltaRot); } } } } } // If we have a target, we'll adjust to it. if(targettedEnt != nullptr) { float targetRotation = GetAngles(myEntity->GetCurrentPosition(), targettedEnt->GetCurrentPosition()); // Fire a missle if we have one. if(myEntity->HasMissile(MISSILE_VEILLON_I)) { myEntity->FireMissile(MISSILE_VEILLON_I); } float deltaRot = targetRotation - myRotation; myEntity->SetDeltaRotation(deltaRot); } } }
void CCeilingTurret::Spawn() { Precache( ); SetModel( "models/combine_turrets/ceiling_turret.mdl" ); BaseClass::Spawn( ); m_iHealth = sk_turret_health.GetFloat(); m_HackedGunPos = Vector( 0, 0, 12.75 ); AngleVectors( GetAngles(), NULL, NULL, &m_vecViewOffset ); m_vecViewOffset = m_vecViewOffset * Vector( 0, 0, -64 ); m_flFieldOfView = VIEW_FIELD_FULL; m_iRetractHeight = 16; m_iDeployHeight = 32; m_iMinPitch = -45; UTIL_SetSize(this, Vector(-32, -32, -m_iRetractHeight), Vector(32, 32, m_iRetractHeight)); SetThink(Initialize); m_pEyeGlow = CSprite::SpriteCreate( TURRET_GLOW_SPRITE, GetOrigin(), FALSE ); m_pEyeGlow->SetTransparency( kRenderGlow, 255, 0, 0, 0, kRenderFxNoDissipation ); m_pEyeGlow->SetAttachment( this, 2 ); m_eyeBrightness = 0; SetNextThink( gpGlobals->curtime + 0.3; );
/** * \brief Interrupt-Service-Routine of the Control_Timer * * \details Central Control Routine for Quadcopter\n * This routine gets the momentary position and the desired position \n * and calculates new output for motors and transmits it via DaisyChain to the \n * Electric Speed Controller * */ void Control_Timer_ISR(void) { float YPR[3]; float powerD = 0.0f;/* throttle value of remote, range: 0 - 100*/ float yawD_dot = 0.0f;/* yaw value of remote, range: -90 - +90*/ float pitchD = 0.0f;/* pitchD value of remote, range: -30 - +30*/ float rollD = 0.0f;/* rollD value of remote, range: -30 - +30*/ static float x_pitch[CONTROL_ORDER]; static float x_roll[CONTROL_ORDER]; float u_yaw_dot = 0.0f;/* output of angle-rate controller for yaw*/ float u_pitch = 0.0f;/* output of angle controller for pitch*/ float u_roll = 0.0f;/* output of angle controller for roll*/ float PWM_percent[4];/* scaled motor power from controller output, range: 0 - 100*/ uint8_t height_control = 0;/* for enabling height-control, activated: 0xff, disabled: 0x00*/ GetAngles(YPR); GetRCData(&powerD, &height_control, &yawD_dot, &pitchD, &rollD); //yaw control AngleRateController(&yawD_dot, &YPR[0], ¶meter.P_yaw, &u_yaw_dot); //pitch control AngleController(&pitchD, &YPR[1], CONTROL_ORDER, polynoms.a_pitch, polynoms.b_pitch, x_pitch, &u_pitch); //roll control AngleController(&rollD, &YPR[2], CONTROL_ORDER, polynoms.a_roll, polynoms.b_roll, x_roll, &u_roll); //generate actuator values CreatePulseWidth(&u_roll, &u_pitch, &u_yaw_dot, &powerD, PWM_percent); if (powerD > 5.0f) SendDaisyPWMPercentages(PWM_percent); else SendDaisyStopCommand(); }
String ADXL335::AnglesString(){ AngleData data = GetAngles(); // // Read the analog values from the accelerometer // AnalogData data = GetAnalog(); // //convert read values to degrees -90 to 90 - Needed for atan2 // int xmap = map(data.x, _minVal, _maxVal, -90, 90); // int ymap = map(data.y, _minVal, _maxVal, -90, 90); // int zmap = map(data.z, _minVal, _maxVal, -90, 90); // //Caculate 360deg values like so: atan2(-ymap, -zmap) // //atan2 outputs the value of -π to π (radians) // //We are then converting the radians to degrees // xAng = RAD_TO_DEG * (atan2(-ymap, -zmap) + PI); // yAng = RAD_TO_DEG * (atan2(-xmap, -zmap) + PI); // zAng = RAD_TO_DEG * (atan2(-ymap, -xmap) + PI); //Return the caculations as a string String temp; char dtostrfbuffer[15]; temp.concat("x: "); temp.concat(dtostrf(data.xAng, 8, 2, dtostrfbuffer)); temp.concat(" | y: "); temp.concat(dtostrf(data.yAng, 8, 2, dtostrfbuffer)); temp.concat(" | z: "); temp.concat(dtostrf(data.zAng, 8, 2, dtostrfbuffer)); return temp; };
LUAMTA_FUNCTION(camera, GetAngles) { auto self = my->ToCameraPtr(1); my->Push(self->GetAngles()); return 1; }
int KChainOrientationBodySchema::InverseKinematics(const cart_vec_t& pos,joint_vec_t& angles){ // int config[MAX_LINKS]; maybe later to try more sophistaicated search int done =ik_trials; joint_vec_t a; while(TryInverseKinematics(pos)>tol && done){ // update config and done // set angles SetRandomAngle(a); done--; } GetAngles(angles); return done; }
void CBaseTurret::Retire(void) { // make the turret level m_vecGoalAngles = GetAngles( ); SetNextThink( gpGlobals->curtime + 0.1f ); StudioFrameAdvance( ); EyeOff( ); if ( m_Activity != ACT_TURRET_CLOSE ) { SetActivity( (Activity)ACT_TURRET_OPEN_IDLE ); if (!MoveTurret()) { SetActivity( (Activity)ACT_TURRET_CLOSE ); EmitSound( "NPC_Turret.Retire" ); m_OnRetire.FireOutput(NULL, this); } } else if (m_fSequenceFinished) { m_iOn = 0; m_flLastSight = 0; SetActivity( (Activity)ACT_TURRET_CLOSED_IDLE ); Vector curmins, curmaxs; curmins = WorldAlignMins(); curmaxs = WorldAlignMaxs(); curmaxs.z = m_iRetractHeight; curmins.z = -m_iRetractHeight; SetCollisionBounds( curmins, curmaxs ); Relink(); if (m_iAutoStart) { SetThink(AutoSearchThink); SetNextThink( gpGlobals->curtime + .1 ); } else { SetThink(SUB_DoNothing); } } }
SimpleString WBEvent::SParameter::CoerceString() const { switch( m_Type ) { case EWBEPT_None: return "None"; case EWBEPT_Bool: return GetBool() ? "True" : "False"; case EWBEPT_Int: return SimpleString::PrintF( "%d", GetInt() ); case EWBEPT_Float: return SimpleString::PrintF( "%f", GetFloat() ); case EWBEPT_Hash: return SimpleString::PrintF( "%s", ReverseHash::ReversedHash( GetHash() ).CStr() ); case EWBEPT_Vector: return GetVector().GetString(); case EWBEPT_Angles: return GetAngles().GetString(); case EWBEPT_Entity: { WBEntity* const pEntity = GetEntity().Get(); return pEntity ? pEntity->GetUniqueName() : "NULL"; } case EWBEPT_Pointer: return SimpleString::PrintF( "Ptr: 0x%08X", GetPointer() ); default: return "Unknown"; } }
void AttControl_TIMER_ISR(void) { GetAngles(YPR,&yoffset); GetRCData(&powerD, &yawD_dot, &pitchD, &rollD); uint32_t Now = millis(); float dt = ((Now - timePrev)/1000.0f); timePrev = Now; // filter float delta_yaw = YPR[0]-yaw; if (delta_yaw >= 180.0) delta_yaw-=360; if (delta_yaw <= -180.0) delta_yaw+=360; yaw+=0.3*delta_yaw; if (yaw >= 180.0) yaw-=360; if (yaw <= -180.0) yaw+=360; //derive delta_yaw=yaw-yaw_old; if (delta_yaw >= 180.0) delta_yaw-=360; if (delta_yaw <= -180.0) delta_yaw+=360; yaw_dot=delta_yaw/dt; yaw_old=yaw; //yaw control AngleRateController(&yawD_dot, &yaw_dot, &P_yaw, &u_yaw_dot); //AngleController(&yawD_dot, &yaw_dot, CONTROL_ORDER, a_yaw, b_yaw, x_yaw, &u_yaw_dot); //pitch control AngleController(&pitchD, &YPR[1], CONTROL_ORDER, a_pitch, b_pitch, x_pitch, &u_pitch); //roll control AngleController(&rollD, &YPR[2], CONTROL_ORDER, a_roll, b_roll, x_roll, &u_roll); counter_main++; newvalue=1; }
END_CLASS void idEntity_Leaf::Spawn() { liveTime = spawnArgs.GetFloat( "leaf_liveTime" ); // in seconds. Keep this low to prevent too many leaves in the map at a time. each leaf is an entity! Try to make each leaf live at least until it touches the ground. Some leaves will slide along the ground if they live long enough. default: 8 moveSpeed = spawnArgs.GetFloat( "leaf_moveSpeed" ); // from 1-10. How fast the leaves move regardless of wind. Keep this high. default: 10 spread = spawnArgs.GetFloat( "leaf_spread" ); // from 1-10. Affects how far apart leafs speread apart when falling. default: 10 windPower = spawnArgs.GetFloat( "leaf_windPower" ); // from 1-10. How strong the wind is on the leaves. default: 1 windDir = spawnArgs.GetVector( "leaf_windDir" ); // Wind direction. default: '0 1 0' gravity = spawnArgs.GetVector( "leaf_gravity" ); // Gravity of the leaf. Keep this pretty low, or accept the default. default: '0 0 -20' origin = spawnArgs.GetVector( "leaf_origin" ); ang = GetAngles(); dieTime = gameLocal.time + liveTime * 1000; if( moveSpeed == 0 ) { moveSpeed = 1; } if( origin != idVec3( 0, 0, 0 ) ) { SetOrigin( origin ); } spread = spread / 20; //max spread is 0.5 dir = gameLocal.random.RandomInt( 3 ); if( dir < 1 ) { spreadX = spread; } else if( dir < 2 && dir > 1 ) { spreadX = 0; } else { spreadX = -spread; } dir = gameLocal.random.RandomInt( 3 ); if( dir < 1 ) { spreadY = spread; } else if( dir < 2 && dir > 1 ) { spreadY = 0; } else { spreadY = -spread; } SetAngles( idAngles( gameLocal.random.CRandomFloat() * 360, gameLocal.random.CRandomFloat() * 360, gameLocal.random.CRandomFloat() * 360 ) ); GetPhysics()->SetLinearVelocity( idVec3( 0, 0, 0 ) ); GetPhysics()->SetGravity( idVec3( 0, 0, 0 ) ); //gravity - if we set zero gravity, the leaves stop when they hit the ground. dont know why, but it's cool! curVel = GetPhysics()->GetLinearVelocity(); nextAngles = 0; }
/////////////////// // Initialize the sky bool CSky::Initialize(void) { // Allocate the stars m_psStars = new star_t[MAX_STARS]; if(m_psStars == NULL) return false; // Set the star details float radius = 90; CVec f; for(int i=0; i<MAX_STARS; i++) { GetAngles(-fabs(GetRandomNum()*45), 0, fabs(GetRandomNum()*360), &f, NULL, NULL); m_psStars[i].pos = f*radius; m_psStars[i].size = fabs(GetRandomNum()); m_psStars[i].flicker = fabs(GetRandomNum()); // Calculate the rotation CVec p = m_psStars[i].pos; VectorNormalize( &p ); m_psStars[i].yaw = (float)(-atan2(p.GetX(),p.GetY()) * (180/PI)); float dist = (float)sqrt((float)(p.GetX() * p.GetX() + p.GetY() * p.GetY())); m_psStars[i].pitch = (float)(-atan2(dist,p.GetZ()) * (180/PI)+270); } // Load the moon texture m_psMoonTexture = Cache_LoadTexture("data/textures/sky/moonlg.png"); if(m_psMoonTexture == NULL) return false; Tex_Upload(m_psMoonTexture); // Load the star texture m_psStarTexture = Cache_LoadTexture("data/textures/sky/star.png"); if(m_psStarTexture == NULL) return false; Tex_Upload(m_psStarTexture); return true; }
/** * \brief Interrupt-Service-Routine of the Control_Timer * * \details Central Control Routine for Quadcopter\n * This routine gets the momentary position and the desired position \n * and calculates new output for motors and transmits it via DaisyChain to the \n * Electric Speed Controller * */ void Control_Timer_ISR(void) { static float x_pitch[CONTROL_ORDER]; static float x_roll[CONTROL_ORDER]; GetAngles(YPR); GetRCData(&powerD, &height_control, &yawD_dot, &pitchD, &rollD); //yaw control AngleRateController(&yawD_dot, &YPR[0], ¶meter.P_yaw, &u_yaw_dot); //pitch control AngleController(&pitchD, &YPR[1], CONTROL_ORDER, polynoms.a_pitch, polynoms.b_pitch, x_pitch, &u_pitch); //roll control AngleController(&rollD, &YPR[2], CONTROL_ORDER, polynoms.a_roll, polynoms.b_roll, x_roll, &u_roll); //generate actuator values CreatePulseWidth(&u_roll, &u_pitch, &u_yaw_dot, &powerD, PWM_percent); if (powerD > 5.0f) SendDaisyPWMPercentages(PWM_percent); else SendDaisyStopCommand(); }
void CBaseTurret::Initialize(void) { m_iOn = 0; m_fBeserk = 0; SetPoseParameter( TURRET_BC_YAW, 0 ); SetPoseParameter( TURRET_BC_PITCH, 0 ); if (m_iBaseTurnRate == 0) m_iBaseTurnRate = TURRET_TURNRATE; if (m_flMaxWait == 0) m_flMaxWait = TURRET_MAXWAIT; m_vecGoalAngles = GetAngles(); if (m_iAutoStart) { m_flLastSight = gpGlobals->curtime + m_flMaxWait; SetThink(AutoSearchThink); SetNextThink( gpGlobals->curtime + .1 ); } else SetThink(SUB_DoNothing); }
Angles WBEvent::SParameter::CoerceAngles() const { return m_Type == EWBEPT_Angles ? GetAngles() : Angles(); }
void Launcher::GetAngles(const cure::ContextObject* target, float& pitch, float& guide_pitch, float& yaw, float& guide_yaw) const { GetAngles(target->GetPosition(), target->GetVelocity(), pitch, guide_pitch, yaw, guide_yaw); }