//---------------------------------------------- TshMiniMultipleShot::TshMiniMultipleShot( TsceneGame *game, const Vector2D &pos, const Vector2D &velocity) :TobjShot( game, Vector2D(pos.x,pos.y-2), // position 1.5, // radius velocity, // velocity 30, // max_speed Vec2DNormalize(velocity), // heading 1., // mass Vector2D(2.0, 2.0), // scale 10, // turn_rate 10, // max_force 1 // vitality ), FdRadian(0), FdTheta(0), FiImageWidth(TRIMMING__IMAGE_RBX - TRIMMING__IMAGE_LTX), FiImageHeight(TRIMMING__IMAGE_RBY - TRIMMING__IMAGE_LTY), FiFlyingTime(0) { // オブジェクト向いている方向を受け取り描画するための計算 FdRadian = atan2(FvVelocity.y ,FvVelocity.x); FdRadian /= D3DX_PI; FdRadian += 0.5; FdTheta = FdRadian * 180 ; }
//---------------------------------------------- TbulAiming::TbulAiming( TsceneGame *game, const Vector2D &pos, const Vector2D &velocity) :TobjBullet( game, pos, // position 0.3, // radius velocity, // velocity 30, // max_speed Vec2DNormalize(velocity), // heading 0., // mass Vector2D(2., 2.), // scale 0, // turn_rate 1, // max_force 1 // vitality ), FdRadian(0), FdTheta(0), FiImageWidth(TRIMMING__IMAGE_RBX - TRIMMING__IMAGE_LTX), FiImageHeight(TRIMMING__IMAGE_RBY - TRIMMING__IMAGE_LTY) { const TobjPlayer *pPlayer = FpGame->pPlayer; if(pPlayer) FvVelocity = pPlayer->vPosition - FvPosition; else FvVelocity = Vector2D(0,1.0); FvVelocity.Normalize(); FvHeading = FvVelocity; FvSide = FvHeading.Perp(); }
//---------------------------------------------- TeffFinalBigExplosion::TeffFinalBigExplosion( TsceneGame *game, const Vector2D &pos, const Vector2D &velocity) :TobjEffect( game, pos, // position 0.5, // radius velocity, // velocity 0.5, // max_speed Vec2DNormalize(velocity), // heading 0., // mass Vector2D(5.0, 5.0), // scale 0, // turn_rate 1, // max_force 1 // vitality ), FiTimer(0), FiAlpha(1.0), FiFrame(0) { iImageWidth=TRIMMING__IMAGE_RBX - TRIMMING__IMAGE_LTX; iImageHeight=TRIMMING__IMAGE_RBY - TRIMMING__IMAGE_LTY; // ボス独自の爆発音を発生 int ch = PlayDxSound( SND_SE_BOSS_DEATH ); int bgm_vol = GetVolume(ch); SetVolume(ch, -300); }
//---------------------------------------------- TeffHit::TeffHit( TsceneGame *game, const Vector2D &pos, const Vector2D &velocity) :TobjEffect( game, pos, // position 0.5, // radius velocity, // velocity 0.5, // max_speed Vec2DNormalize(velocity), // heading 0., // mass Vector2D(0.08, 0.08), // scale 0, // turn_rate 1, // max_force 1 // vitality ), FiTimer(0), FiAlpha(1.0) { iImageWidth=TRIMMING__IMAGE_RBX - TRIMMING__IMAGE_LTX; iImageHeight=TRIMMING__IMAGE_RBY - TRIMMING__IMAGE_LTY; // ヒット時の効果音 int ch = PlayDxSound( SND_SE_SHOT ); int bgm_vol = GetVolume(ch); SetVolume(ch, -200); }
//------------------------------- Seek ----------------------------------- // // Given a target, this behavior returns a steering force which will // direct the agent towards the target //------------------------------------------------------------------------ Vector2D SteeringBehavior::Seek(Vector2D TargetPos) { Vector2D DesiredVelocity = Vec2DNormalize(TargetPos - m_pMovingEntity->Pos()) * m_pMovingEntity->MaxSpeed(); return (DesiredVelocity - m_pMovingEntity->Velocity()); }
void PutBallBackInPlay::Execute(GoalKeeper* keeper) { PlayerBase* receiver = NULL; Vector2D BallTarget; //test if there are players further forward on the field we might //be able to pass to. If so, make a pass. if (keeper->Team()->FindPass(keeper, receiver, BallTarget, Prm.MaxPassingForce, Prm.GoalkeeperMinPassDist)) { //make the pass keeper->Ball()->Kick(Vec2DNormalize(BallTarget - keeper->Ball()->Pos()), Prm.MaxPassingForce); //goalkeeper no longer has ball keeper->Pitch()->SetGoalKeeperHasBall(false); //let the receiving player know the ball's comin' at him Dispatcher->DispatchMsg(SEND_MSG_IMMEDIATELY, keeper->ID(), receiver->ID(), Msg_ReceiveBall, &BallTarget); //go back to tending the goal keeper->GetFSM()->ChangeState(TendGoal::Instance()); return; } keeper->SetVelocity(Vector2D()); }
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); }
//-------------------------------Update()-------------------------------- // // First we take sensor readings and feed these into the sweepers brain. // // The inputs are: // // A vector to the closest mine (x, y) // The sweepers 'look at' vector (x, y) // // We receive two outputs from the brain.. lTrack & rTrack. // So given a force for each track we calculate the resultant rotation // and acceleration and apply to current velocity vector. // //----------------------------------------------------------------------- bool CMinesweeper::Update(vector<SVector2D> &mines) { //this will store all the inputs for the NN vector<double> inputs; //get vector to closest mine SVector2D vClosestMine = GetClosestMine(mines); //normalise it Vec2DNormalize(vClosestMine); //add in vector to closest mine inputs.push_back(vClosestMine.x); inputs.push_back(vClosestMine.y); //add in sweepers look at vector inputs.push_back(m_vLookAt.x); inputs.push_back(m_vLookAt.y); //update the brain and get feedback vector<double> output = m_ItsBrain.Update(inputs); //make sure there were no errors in calculating the //output if (output.size() < CParams::iNumOutputs) { return false; } //assign the outputs to the sweepers left & right tracks m_lTrack = output[0]; m_rTrack = output[1]; //calculate steering forces double RotForce = m_lTrack - m_rTrack; //clamp rotation Clamp(RotForce, -CParams::dMaxTurnRate, CParams::dMaxTurnRate); m_dRotation += RotForce; m_dSpeed = (m_lTrack + m_rTrack); //update Look At m_vLookAt.x = -sin(m_dRotation); m_vLookAt.y = cos(m_dRotation); //update position m_vPosition += (m_vLookAt * m_dSpeed); //wrap around window limits if (m_vPosition.x > CParams::WindowWidth) m_vPosition.x = 0; if (m_vPosition.x < 0) m_vPosition.x = CParams::WindowWidth; if (m_vPosition.y > CParams::WindowHeight) m_vPosition.y = 0; if (m_vPosition.y < 0) m_vPosition.y = CParams::WindowHeight; return true; }
Vector2D SteeringBehavior::Cohesion(const std::vector<Vehicle*> &neighbors) { //first find the center of mass of all the agents Vector2D CenterOfMass, SteeringForce; int NeighborCount = 0; //iterate through the neighbors and sum up all the position vectors for (unsigned int a = 0; a<neighbors.size(); ++a) { //make sure *this* agent isn't included in the calculations and that //the agent being examined is close enough ***also make sure it doesn't //include the evade target *** if ((neighbors[a] != vehicle_) && neighbors[a]->IsTagged() && (neighbors[a] != target_agent_)) { CenterOfMass += neighbors[a]->Position(); ++NeighborCount; } } if (NeighborCount > 0) { //the center of mass is the average of the sum of positions CenterOfMass /= (double)NeighborCount; //now seek towards that position SteeringForce = Seek(CenterOfMass); } //the magnitude of cohesion is usually much larger than separation or //allignment so it usually helps to normalize it. return Vec2DNormalize(SteeringForce); }
void Pellet::Update() { if (!HasImpacted()) { //calculate the steering force Vector2D DesiredVelocity = Vec2DNormalize(m_vTarget - Pos()) * MaxSpeed(); Vector2D sf = DesiredVelocity - Velocity(); //update the position Vector2D accel = sf / m_dMass; m_vVelocity += accel; //make sure vehicle does not exceed maximum velocity m_vVelocity.Truncate(m_dMaxSpeed); //update the position m_vPosition += m_vVelocity; TestForImpact(); } else if (!isVisibleToPlayer()) { m_bDead = true; } }
// This function calculates how much of its max steering force the // vehicle has left to apply and then applies that amount of the // force to add. bool SteeringBehavior::AccumulateForce(Vector2D &running_total, Vector2D force_to_add) { // Calculate how much steering force the vehicle has used so far double magnitude_so_far = running_total.Length(); // Calculate how much steering force remains to be used by this vehicle double magnitude_remaining = vehicle_->MaxForce() - magnitude_so_far; // Return false if there is no more force left to use if (magnitude_remaining <= 0.0) return false; // Calculate the magnitude of the force we want to add double magnitude_to_add = force_to_add.Length(); // If the magnitude of the sum of force_to_add and the running total // does not exceed the maximum force available to this vehicle, just // add together. Otherwise add as much of the force_to_add vector is // possible without going over the max. if (magnitude_to_add < magnitude_remaining) { running_total += force_to_add; } else { // Add it to the steering force running_total += (Vec2DNormalize(force_to_add) * magnitude_remaining); } return true; }
bool S013010C_Aaron_Smith_Steering::AccumulateForce(Vector2D& totalForce, Vector2D newForce) { //calculate how much steering force the vehicle has used so far double MagnitudeSoFar = totalForce.Length(); //calculate how much steering force remains to be used by this vehicle double MagnitudeRemaining = mTank->GetMaxSpeed() - MagnitudeSoFar; //return false if there is no more force left to use if (MagnitudeRemaining <= 0.0) return false; //calculate the magnitude of the force we want to add double MagnitudeToAdd = newForce.Length(); //if the magnitude of the sum of ForceToAdd and the running total //does not exceed the maximum force available to this vehicle, just //add together. Otherwise add as much of the ForceToAdd vector is //possible without going over the max. if (MagnitudeToAdd < MagnitudeRemaining) { totalForce += newForce; } else { //add it to the steering force totalForce += (Vec2DNormalize(newForce) * MagnitudeRemaining); } return true; }
//------------------------- UpdateMovement ------------------------------------ // // this method is called from the update method. It calculates and applies // the steering force for this time-step. //----------------------------------------------------------------------------- void Raven_Bot::UpdateMovement() { //calculate the combined steering force Vector2D force = m_pSteering->Calculate(); //if no steering force is produced decelerate the player by applying a //braking force if (m_pSteering->Force().isZero()) { const double BrakingRate = 0.8; m_vVelocity = m_vVelocity * BrakingRate; } //calculate the acceleration Vector2D accel = force / m_dMass; //update the velocity m_vVelocity += accel; //make sure vehicle does not exceed maximum velocity m_vVelocity.Truncate(m_dMaxSpeed); //update the position m_vPosition += m_vVelocity; //if the vehicle has a non zero velocity the heading and side vectors must //be updated if (!m_vVelocity.isZero()) { m_vHeading = Vec2DNormalize(m_vVelocity); m_vSide = m_vHeading.Perp(); } }
bool B020612E_Steering::AccumulateForce(Vector2D &RunningTot, Vector2D ForceToAdd) { //calculate how much steering force the vehicle has used so far double MagnitudeSoFar = RunningTot.Length(); //calculate how much steering force remains to be used by this vehicle double MagnitudeRemaining = _pTank->GetMaxForce() - MagnitudeSoFar; //return false if there is no more force left to use if (MagnitudeRemaining <= 0.0) return false; //calculate the magnitude of the force we want to add double MagnitudeToAdd = ForceToAdd.Length(); //if the magnitude of the sum of ForceToAdd and the running total //does not exceed the maximum force available to this vehicle, just //add together. Otherwise add as much of the ForceToAdd vector is //possible without going over the max. if (MagnitudeToAdd < MagnitudeRemaining) { RunningTot += ForceToAdd; } else { //add it to the steering force RunningTot += (Vec2DNormalize(ForceToAdd) * MagnitudeRemaining); } return true; }
void TestTank::Render() { //Call parent render. BaseTank::Render(); //Draw the left cannon. if (mDrawTarget) mTargetSprite->Render(Vector2D(mTargetPos.x + mTargetSprite->GetWidth() / 2, mTargetPos.y + mTargetSprite->GetHeight() / 2)); //+ 16 //DrawDebugCircle(Vector2D(GetCentrePosition().x - mHeading.x * 20, GetCentrePosition().y - mHeading.y* 20), 10); Vector2D normVel = Vec2DNormalize(mVelocity); DrawDebugCircle(Vector2D(GetCentrePosition().x + normVel.x * 20, GetCentrePosition().y + normVel.y * 20), 10); if (mShowingDebug) { for (int i = 50; i > 44; i--) { DrawDebugCircle(Vector2D(mMouseX, mMouseY), i); } // drawing the heading vector line //Start position will be the front of the tank //the End position will be the tanks heading vector SDL_SetRenderDrawColor(mRenderer, 255, 0, 0, 255); //heading end = centreposition - mHeading * by some length SDL_RenderDrawLine(mRenderer, GetCentrePosition().x, GetCentrePosition().y, GetCentrePosition().x - mHeading.x * 50, GetCentrePosition().y - mHeading.y * 50); //Render the Steering Force SDL_SetRenderDrawColor(mRenderer, 0, 255, 0, 255); SDL_RenderDrawLine(mRenderer, GetCentrePosition().x, GetCentrePosition().y, GetCentrePosition().x + mSteeringForce.x * 5, GetCentrePosition().y + mSteeringForce.y * 5); } Vector2D ahead = Vec2DNormalize(mVelocity); if (ahead.Length() == 0) ahead = mHeading; Vector2D cenPos = GetCentralPosition(); Vector2D aheadDistance = cenPos + ahead * 30; DrawDebugCircle(Vector2D(aheadDistance.x, aheadDistance.y), 5); }
Vector2D S013010C_Aaron_Smith_Steering::Seek( Vector2D targetPos) { //cout << "SEEKING" << endl; Vector2D reqVelocity = Vec2DNormalize(targetPos - mTank->GetCentrePosition() ) * mTank->GetMaxSpeed(); reqVelocity -= mTank->GetVelocity(); /*mSteeringForces.push_back(reqVelocity);*/ return reqVelocity; }
Vector2D S013010C_Aaron_Smith_Steering::Wander(float deltaTime) { float wanderCircleRadius = 11; Vector2D normVel = Vec2DNormalize( mTank->GetVelocity()); Vector2D circleInFront = Vector2D(mTank->GetCentrePosition().x + normVel.x * wanderCircleRadius, mTank->GetCentrePosition().y + normVel.y * wanderCircleRadius); Vector2D randPos = Vector2D((RandFloat() - RandFloat()) , (RandFloat() - RandFloat()) ); mWanderTarget += randPos; mWanderTarget = Vec2DNormalize(mWanderTarget); mWanderTarget *= wanderCircleRadius; Vector2D newForce = circleInFront + mWanderTarget; Vector2D reqVelocity = Vec2DNormalize(newForce - mTank->GetCentrePosition()) * mTank->GetMaxSpeed(); return reqVelocity -= mTank->GetVelocity(); }
void GoalKeeper::Update() { //run the logic for the current state m_pStateMachine->Update(); //calculate the combined force from each steering behavior Vector2D SteeringForce = m_pSteering->Calculate(); //Acceleration = Force/Mass Vector2D Acceleration = SteeringForce / m_dMass; //update velocity m_vVelocity += Acceleration; //make sure player does not exceed maximum velocity m_vVelocity.Truncate(m_dMaxSpeed); //update the position m_vPosition += m_vVelocity; //enforce a non-penetration constraint if desired if(Prm.bNonPenetrationConstraint) { EnforceNonPenetrationContraint(this, AutoList<PlayerBase>::GetAllMembers()); } //update the heading if the player has a non zero velocity if ( !m_vVelocity.isZero()) { m_vHeading = Vec2DNormalize(m_vVelocity); m_vSide = m_vHeading.Perp(); } //look-at vector always points toward the ball if (!Pitch()->GoalKeeperHasBall()) { m_vLookAt = Vec2DNormalize(Ball()->Pos() - Pos()); } }
//----------------------------- Flee ------------------------------------- // // Does the opposite of Seek //------------------------------------------------------------------------ Vector2D SteeringBehavior::Flee(Vector2D TargetPos) { //only flee if the target is within 'panic distance'. Work in distance //squared space. /* const double PanicDistanceSq = 100.0f * 100.0; if (Vec2DDistanceSq(m_pMovingEntity->Pos(), target) > PanicDistanceSq) { return Vector2D(0,0); } */ Vector2D DesiredVelocity = Vec2DNormalize(m_pMovingEntity->Pos() - TargetPos) * m_pMovingEntity->MaxSpeed(); return (DesiredVelocity - m_pMovingEntity->Velocity()); }
//------------------------- GetHidingPosition ---------------------------- // // Given the position of a hunter, and the position and radius of // an obstacle, this method calculates a position DistanceFromBoundary // away from its bounding radius and directly opposite the hunter //------------------------------------------------------------------------ Vector2D SteeringBehavior::GetHidingPosition(const Vector2D& posOb, const double radiusOb, const Vector2D& posHunter) { //calculate how far away the agent is to be from the chosen obstacle's //bounding radius const double DistanceFromBoundary = 30.0; double DistAway = radiusOb + DistanceFromBoundary; //calculate the heading toward the object from the hunter Vector2D ToOb = Vec2DNormalize(posOb - posHunter); //scale it to size and add to the obstacles position to get //the hiding spot. return (ToOb * DistAway) + posOb; }
Vector2D SteeringBehavior::Flee(const std::vector<Vehicle*> &neighbors) { for (unsigned int a = 0; a<neighbors.size(); ++a) { // Make sure this agent isn't included in the calculations and that // the agent being examined is close enough. Also check if it's // within the panic distance. if ((neighbors[a] != vehicle_) && neighbors[a]->IsTagged()) { Vector2D DesiredVelocity = Vec2DNormalize(vehicle_->Position() - neighbors[a]->Position()) * vehicle_->MaxSpeed(); return (DesiredVelocity - vehicle_->Velocity()); } } return Vector2D(0, 0); }
void StateCowFleeGetWeapon::seek2( SVector2D target){ //entity->setVelocityX(velocityX); //entity->setVelocityX(velocityY); SVector2D vectorCow; vectorCow.x = entity->GetX() + entity->getVelocityX(); vectorCow.y = entity->GetY() + entity->getVelocityX(); SVector2D vectorPill = target; SVector2D desired_velocity = vectorPill - vectorCow; Vec2DNormalize(desired_velocity); //desired_velocity = Vec2DNormalize2(desired_velocity); desired_velocity = desired_velocity * entity->getMaxSpeed(); //* max speed of cow //toroid(entity, entityOther); entity->SetOffset(entity->GetX() + desired_velocity.x, entity->GetY() + desired_velocity.y); // Seek }
//---------------------------- ctor ------------------------------------------- //----------------------------------------------------------------------------- Raven_Door::Raven_Door(Raven_Map* pMap, std::ifstream& is): BaseGameEntity(GetValueFromStream<int>(is)), m_Status(closed), m_iNumTicksStayOpen(60) //MGC! { Read(is); m_vtoP2Norm = Vec2DNormalize(m_vP2 - m_vP1); m_dCurrentSize = m_dSize = Vec2DDistance(m_vP2, m_vP1); Vector2D perp = m_vtoP2Norm.Perp(); //create the walls that make up the door's geometry m_pWall1 = pMap->AddWall(m_vP1+perp, m_vP2+perp); m_pWall2 = pMap->AddWall(m_vP2-perp, m_vP1-perp); }
//---------------------------------------------- TbulHoming::TbulHoming( TsceneGame *game, const Vector2D &pos , const Vector2D &velocity) :TobjBullet( game, pos, // position 1.0, // radius velocity, // velocity 20, // max_speed Vec2DNormalize(velocity), // heading 0., // mass Vector2D(2. , 2.), // scale 1.0, // turn_rate 1, // max_force 1 // vitality ), FdTimer(0), FiImageWidth(TRIMMING__IMAGE_RBX - TRIMMING__IMAGE_LTX), FiImageHeight(TRIMMING__IMAGE_RBY - TRIMMING__IMAGE_LTY) { }
void S013010C_Aaron_Smith_Tank::CreateStraightFeelers(vector<Vector2D> &feelers) { feelers.clear(); Vector2D ahead = Vec2DNormalize(mVelocity); if (ahead.Length() == 0) ahead = mHeading; double dynamicLength = mVelocity.Length() / GetMaxSpeed(); double angle = 70; int ahead2Amount = 50; int ahead1Amount = ahead2Amount / 2; mAhead1Distance = GetCentrePosition() + (ahead * dynamicLength * ahead1Amount); mAhead2Distance = GetCentrePosition() + (ahead * dynamicLength * (ahead2Amount + 50)); feelers.push_back(mAhead1Distance); feelers.push_back(mAhead2Distance); }
// Calculates a force repelling from the other neighbors Vector2D SteeringBehavior::Separation(const std::vector<Vehicle*> &neighbors) { Vector2D SteeringForce; for (unsigned int a = 0; a<neighbors.size(); ++a) { //make sure this agent isn't included in the calculations and that //the agent being examined is close enough. ***also make sure it doesn't //include the evade target *** if ((neighbors[a] != vehicle_) && neighbors[a]->IsTagged() && (neighbors[a] != target_agent_)) { Vector2D ToAgent = vehicle_->Position() - neighbors[a]->Position(); //scale the force inversely proportional to the agents distance //from its neighbor. SteeringForce += Vec2DNormalize(ToAgent) / ToAgent.Length(); } } return SteeringForce; }
//---------------------------------------------- TuiBtnStg3::TuiBtnStg3( TsceneStageSelect *select, const Vector2D &pos, const Vector2D &velocity) :TobjUi( select, pos, // position 0, // radius velocity, // velocity 0, // max_speed Vec2DNormalize(velocity), // heading 0., // mass Vector2D(1.0, 1.0), // scale 0, // turn_rate 1, // max_force 1 // vitality ), FiTimer(0), FiAlpha(1.0) { iImageWidth=TRIMMING__IMAGE_RBX - TRIMMING__IMAGE_LTX; iImageHeight=TRIMMING__IMAGE_RBY - TRIMMING__IMAGE_LTY; FStgId= STAGE_3; }
bool Level::isPathObstructed(Vector2D A, Vector2D B, double BoundingRadius)const { Vector2D ToB = Vec2DNormalize(B - A); Vector2D curPos = A; while (Vec2DDistanceSq(curPos, B) > BoundingRadius*BoundingRadius) { //advance curPos one step curPos += ToB * 0.5 * BoundingRadius; //test all walls against the new position //if (doWallsIntersectCircle(m_pMap->GetWalls(), curPos, BoundingRadius)) { return true; } } return false; }
//------------------ RotateFacingTowardPosition ------------------------------- // // given a target position, this method rotates the bot's facing vector // by an amount not greater than m_dMaxTurnRate until it // directly faces the target. // // returns true when the heading is facing in the desired direction //---------------------------------------------------------------------------- bool Raven_Bot::RotateFacingTowardPosition(Vector2D target) { Vector2D toTarget = Vec2DNormalize(target - m_vPosition); double dot = m_vFacing.Dot(toTarget); //clamp to rectify any rounding errors Clamp(dot, -1, 1); //determine the angle between the heading vector and the target double angle = acos(dot); //return true if the bot's facing is within WeaponAimTolerance degs of //facing the target const double WeaponAimTolerance = 0.01; //2 degs approx if (angle < WeaponAimTolerance) { m_vFacing = toTarget; return true; } //clamp the amount to turn to the max turn rate if (angle > m_dMaxTurnRate) angle = m_dMaxTurnRate; //The next few lines use a rotation matrix to rotate the player's facing //vector accordingly C2DMatrix RotationMatrix; //notice how the direction of rotation has to be determined when creating //the rotation matrix RotationMatrix.Rotate(angle * m_vFacing.Sign(toTarget)); RotationMatrix.TransformVector2Ds(m_vFacing); return false; }