⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 beameffector.cpp

📁 robocup rcssserver 运行防真机器人足球比赛所用的服务器端
💻 CPP
字号:
/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-   this file is part of rcssserver3D   Fri May 9 2003   Copyright (C) 2002,2003 Koblenz University   Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group   $Id: beameffector.cpp,v 1.18 2008/02/20 11:17:20 hedayat Exp $   This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; version 2 of the License.   This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.   You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/#include "beamaction.h"#include "beameffector.h"#include <soccer/soccerbase/soccerbase.h>#include <soccer/agentstate/agentstate.h>#include <cmath>#include <oxygen/agentaspect/agentaspect.h>using namespace boost;using namespace oxygen;using namespace salt;using namespace std;BeamEffector::BeamEffector() : oxygen::Effector(){}BeamEffector::~BeamEffector(){}#ifdef __APPLE_CC__boolisfinite( float f ){    return f == f && f != f * 0.5f;}#endifvoidBeamEffector::PrePhysicsUpdateInternal(float /*deltaTime*/){    if (        (mAction.get() == 0) ||        (mBody.get() == 0) ||        (mGameState.get() == 0) ||        (mAgentState.get() == 0)        )    {        return;    }    shared_ptr<BeamAction> beamAction =        shared_dynamic_cast<BeamAction>(mAction);   mAction.reset();    if (beamAction.get() == 0)    {        GetLog()->Error()            << "ERROR: (BeamEffector) cannot realize an unknown ActionObject\n";        return;    }    // the beam effector only has an effect in PM_BeforeKickOff    if (mGameState->GetPlayMode() == PM_BeforeKickOff        || mGameState->GetPlayMode() == PM_Goal_Left        || mGameState->GetPlayMode() == PM_Goal_Right)    {        Vector3f pos;        pos[0] = beamAction->GetPosX();        pos[1] = beamAction->GetPosY();        float angle = beamAction->GetXYAngle();        // reject nan or infinite numbers in the beam position        if (            (! isfinite(pos[0])) ||            (! isfinite(pos[1]))            )            {                return;            }        // an agent can only beam within it's own field half        float minX = -mFieldLength/2;        pos[0] = std::max<float>(pos[0],minX);        pos[0] = std::min<float>(pos[0],0.0f);        float minY = -mFieldWidth/2;        float maxY = mFieldWidth/2;        pos[1] = std::max<float>(minY,pos[1]);        pos[1] = std::min<float>(maxY,pos[1]);        // fix z coordinate        pos[2] = mAgentRadius;        // swap x and y coordinates accordingly for the current        // team; after the flip pos is global and not independent        // on the team        pos = SoccerBase::FlipView(pos, mAgentState->GetTeamIndex());             shared_ptr<Transform> agentAspect;        SoccerBase::GetTransformParent(*this, agentAspect);        if (agentAspect.get() == 0)        {            GetLog()->Error()            << "ERROR: (BeamEffector) cannot get AgentAspect\n";            return;        }                TTeamIndex team = mAgentState->GetTeamIndex();        angle += mGameState->RequestInitOrientation(team);        if (!SoccerBase::MoveAndRotateAgent(agentAspect, pos, angle))            return;    }}shared_ptr<ActionObject>BeamEffector::GetActionObject(const Predicate& predicate){  if (predicate.name != GetPredicate())    {      GetLog()->Error() << "ERROR: (BeamEffector) invalid predicate"                        << predicate.name << "\n";      return shared_ptr<ActionObject>();    }  Predicate::Iterator iter = predicate.begin();  float posX;  if (! predicate.AdvanceValue(iter, posX))  {      GetLog()->Error()          << "ERROR: (BeamEffector) float expected for parameter1\n";      return shared_ptr<ActionObject>(new ActionObject(GetPredicate()));  }  float posY;  if (! predicate.AdvanceValue(iter, posY))  {      GetLog()->Error()          << "ERROR: (BeamEffector) float expected for parameter2\n";      return shared_ptr<ActionObject>(new ActionObject(GetPredicate()));  }  float angle;  if (! predicate.AdvanceValue(iter, angle))  {      GetLog()->Error()          << "ERROR: (BeamEffector) float expected for parameter3\n";      return shared_ptr<ActionObject>(new ActionObject(GetPredicate()));  }  return shared_ptr<ActionObject>(new BeamAction(GetPredicate(), posX, posY, angle));}voidBeamEffector::OnLink(){    SoccerBase::GetBody(*this,mBody);    SoccerBase::GetGameState(*this, mGameState);    SoccerBase::GetAgentState(*this,mAgentState);    mFieldWidth = 64.0;    SoccerBase::GetSoccerVar(*this,"FieldWidth",mFieldWidth);    mFieldLength = 100.0;    SoccerBase::GetSoccerVar(*this,"FieldLength",mFieldLength);    mAgentRadius = 0.22;    SoccerBase::GetSoccerVar(*this,"AgentRadius",mAgentRadius);}voidBeamEffector::OnUnlink(){    mBody.reset();    mGameState.reset();    mAgentState.reset();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -