void S013010C_Aaron_Smith_Tank::CreateLeftFeelers(vector<Vector2D> &feelers) { feelers.clear(); Vector2D ahead = Vec2DNormalize(mVelocity); if (ahead.Length() == 0) ahead = mHeading; double dynamicLength = mVelocity.Length() / GetMaxSpeed(); double angle = 40; int side2Amount = 30; int side1Amount = side2Amount / 2; Vector2D fannedLeftAhead; fannedLeftAhead.x = ahead.x * cos(DegsToRads(-angle)) - ahead.y * sin(DegsToRads(-angle)); fannedLeftAhead.y = ahead.x * sin(DegsToRads(-angle)) + ahead.y * cos(DegsToRads(-angle)); mLeftAhead2Distance = (mTopLeftCorner)+(fannedLeftAhead * dynamicLength * side2Amount); mLeftAhead1Distance = (mTopLeftCorner)+(fannedLeftAhead * dynamicLength * side1Amount); feelers.push_back(mLeftAhead1Distance); feelers.push_back(mLeftAhead2Distance); }
void S013010C_Aaron_Smith_Tank::CreateFeelers(vector<Vector2D> &feelers, double angle, int distance,Vector2D startPos) { feelers.clear(); Vector2D ahead = Vec2DNormalize(mVelocity); if (ahead.Length() == 0) ahead = mHeading; double dynamicLength = mVelocity.Length() / GetMaxSpeed(); if (dynamicLength < 0.6) dynamicLength = 0.6; cout << dynamicLength << endl; int dist2Amount = distance; int dist1Amount = dist2Amount / 2; Vector2D feelerVect1; Vector2D feelerVect2; if (angle != 0) { Vector2D fannedAhead; fannedAhead.x = ahead.x * cos(DegsToRads(angle)) - ahead.y * sin(DegsToRads(angle)); fannedAhead.y = ahead.x * sin(DegsToRads(angle)) + ahead.y * cos(DegsToRads(angle)); feelerVect2 = (startPos)+(fannedAhead * dynamicLength * dist2Amount); feelerVect1 = (startPos)+(fannedAhead * dynamicLength * dist1Amount); } else { feelerVect1 = GetCentrePosition() + (ahead * dynamicLength * dist1Amount); feelerVect2 = GetCentrePosition() + (ahead * dynamicLength * (dist2Amount + 50)); } feelers.push_back(feelerVect1); feelers.push_back(feelerVect2); }
void TestTank::DrawDebugCircle(Vector2D centrePoint, float radius) { Vector2D polarVec; polarVec.x = 0.0f; polarVec.y = radius; float stepSize = 0.05f; float _360DegAsRads = DegsToRads(360.0); while (polarVec.x < _360DegAsRads) { Vector2D polarAsCart; polarAsCart.x = polarVec.y * cosf(polarVec.x); polarAsCart.y = polarVec.y * sinf(polarVec.x); Vector2D drawPoint; drawPoint.x = centrePoint.x + polarAsCart.x; drawPoint.y = centrePoint.y + polarAsCart.y; SDL_SetRenderDrawColor(mRenderer, 0, 0, 0, 255); SDL_RenderDrawPoint(mRenderer, drawPoint.x, drawPoint.y); polarVec.x += stepSize; } }
//-------------------------- ctor --------------------------------------------- Raven_Bot::Raven_Bot(Team* team, Raven_Game* world,Vector2D pos): MovingEntity(pos, script->GetDouble("Bot_Scale"), Vector2D(0,0), script->GetDouble("Bot_MaxSpeed"), Vector2D(1,0), script->GetDouble("Bot_Mass"), Vector2D(script->GetDouble("Bot_Scale"),script->GetDouble("Bot_Scale")), script->GetDouble("Bot_MaxHeadTurnRate"), script->GetDouble("Bot_MaxForce")), m_pTeam(team), m_iMaxHealth(script->GetInt("Bot_MaxHealth")), m_iHealth(script->GetInt("Bot_MaxHealth")), m_pPathPlanner(NULL), m_pSteering(NULL), m_pWorld(world), m_pBrain(NULL), m_iNumUpdatesHitPersistant((int)(FrameRate * script->GetDouble("HitFlashTime"))), m_bHit(false), m_iScore(0), m_Status(spawning), m_bPossessed(false), m_dFieldOfView(DegsToRads(script->GetDouble("Bot_FOV"))) { SetEntityType(type_bot); SetUpVertexBuffer(); //a bot starts off facing in the direction it is heading m_vFacing = m_vHeading; //create the navigation module m_pPathPlanner = new Raven_PathPlanner(this); //create the steering behavior class m_pSteering = new Raven_Steering(world, this); //create the regulators m_pWeaponSelectionRegulator = new Regulator(script->GetDouble("Bot_WeaponSelectionFrequency")); m_pGoalArbitrationRegulator = new Regulator(script->GetDouble("Bot_GoalAppraisalUpdateFreq")); m_pTargetSelectionRegulator = new Regulator(script->GetDouble("Bot_TargetingUpdateFreq")); m_pTriggerTestRegulator = new Regulator(script->GetDouble("Bot_TriggerUpdateFreq")); m_pVisionUpdateRegulator = new Regulator(script->GetDouble("Bot_VisionUpdateFreq")); //create the goal queue m_pBrain = new Goal_Think(this); //create the targeting system m_pTargSys = new Raven_TargetingSystem(this); m_pWeaponSys = new Raven_WeaponSystem(this, script->GetDouble("Bot_ReactionTime"), script->GetDouble("Bot_AimAccuracy"), script->GetDouble("Bot_AimPersistance")); m_pSensoryMem = new Raven_SensoryMemory(this, script->GetDouble("Bot_MemorySpan")); }
/* * given a particular time (expressed in seconds since the unix * epoch), compute position on the earth (lat, lon) such that the * moon is directly overhead. * * Based on duffett-smith **2nd ed** section 61; combines some steps * into single expressions to reduce the number of extra variables. */ void moon_position(time_t ssue, double *lat, double *lon) /* time_t ssue; seconds since unix epoch */ /* double *lat; (return) latitude in ra */ /* double *lon; (return) longitude in ra */ { double lambda, beta; double D, L, Ms, Mm, N, Ev, Ae, Ec, alpha, delta; D = DaysSinceEpoch(ssue); lambda = sun_ecliptic_longitude(ssue); Ms = mean_sun(D); L = fmod(D / SideralMonth, 1.0) * TWOPI + MoonMeanLongitude; Normalize(L); Mm = L - DegsToRads(0.1114041 * D) - MoonMeanLongitudePerigee; Normalize(Mm); N = MoonMeanLongitudeNode - DegsToRads(0.0529539 * D); Normalize(N); Ev = DegsToRads(1.2739) * sin(2.0 * (L - lambda) - Mm); Ae = DegsToRads(0.1858) * sin(Ms); Mm += Ev - Ae - DegsToRads(0.37) * sin(Ms); Ec = DegsToRads(6.2886) * sin(Mm); L += Ev + Ec - Ae + DegsToRads(0.214) * sin(2.0 * Mm); L += DegsToRads(0.6583) * sin(2.0 * (L - lambda)); N -= DegsToRads(0.16) * sin(Ms); L -= N; lambda = (fabs(cos(L)) < 1e-12) ? (N + sin(L) * cos(MoonInclination) * PI / 2) : (N + atan2(sin(L) * cos(MoonInclination), cos(L))); Normalize(lambda); beta = asin(sin(L) * sin(MoonInclination)); ecliptic_to_equatorial(lambda, beta, &alpha, &delta); alpha -= (TWOPI / 24) * GST(ssue); Normalize(alpha); *lon = alpha; *lat = delta; }