From: Oliver O. <fr...@us...> - 2007-03-07 10:39:32
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/beameffector In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/beameffector Added Files: Tag: projectx beamaction.h beameffector.cpp beameffector.h beameffector_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: beameffector.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.1.2.1 2007/03/07 10:39:22 fruit 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> using namespace boost; using namespace oxygen; using namespace salt; using namespace std; BeamEffector::BeamEffector() : oxygen::Effector() { } BeamEffector::~BeamEffector() { } #ifdef __APPLE_CC__ bool isfinite( float f ) { return f == f && f != f * 0.5f; } #endif bool BeamEffector::Realize(boost::shared_ptr<ActionObject> action) { if ( (mBody.get() == 0) || (mGameState.get() == 0) || (mAgentState.get() == 0) ) { return false; } shared_ptr<BeamAction> beamAction = shared_dynamic_cast<BeamAction>(action); if (beamAction.get() == 0) { GetLog()->Error() << "ERROR: (BeamEffector) cannot realize an unknown ActionObject\n"; return false; } // the beam effector only has an effect in PM_BeforeKickOff if (mGameState->GetPlayMode() == PM_BeforeKickOff) { Vector3f pos = beamAction->GetPosition(); // reject nan or infinite numbers in the beam position if ( (! isfinite(pos[0])) || (! isfinite(pos[1])) || (! isfinite(pos[2])) ) { return false; } // an agent can only beam within it's own field half float minX = -mFieldLength/2 + mAgentRadius; pos[0] = std::max<float>(pos[0],minX); pos[0] = std::min<float>(pos[0],0.0f); float minY = -mFieldWidth/2 + mAgentRadius; float maxY = mFieldWidth/2 - mAgentRadius; pos[1] = std::max<float>(minY,pos[1]); pos[1] = std::min<float>(maxY,pos[1]); 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() ); mBody->SetPosition(pos); mBody->SetVelocity(Vector3f(0,0,0)); mBody->SetAngularVelocity(Vector3f(0,0,0)); } return true; } 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>(); } Vector3f pos; if (! predicate.GetValue(predicate.begin(), pos)) { GetLog()->Error() << "ERROR: (BeamEffector) Vector3f parameter expected\n"; return shared_ptr<ActionObject>(new ActionObject(GetPredicate())); } return shared_ptr<ActionObject>(new BeamAction(GetPredicate(),pos)); } void BeamEffector::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); } void BeamEffector::OnUnlink() { mBody.reset(); mGameState.reset(); mAgentState.reset(); } --- NEW FILE: beameffector_c.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_c.cpp,v 1.1.2.1 2007/03/07 10:39:22 fruit 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 "beameffector.h" using namespace oxygen; void CLASS(BeamEffector)::DefineClass() { DEFINE_BASECLASS(oxygen/Effector); } --- NEW FILE: beameffector.h --- /* -*- 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.h,v 1.1.2.1 2007/03/07 10:39:22 fruit 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. */ #ifndef BEAMEFFECTOR_H #define BEAMEFFECTOR_H #include <oxygen/agentaspect/effector.h> #include <oxygen/physicsserver/body.h> #include <soccer/gamestateaspect/gamestateaspect.h> class BeamEffector : public oxygen::Effector { public: BeamEffector(); virtual ~BeamEffector(); /** realizes the action described by the ActionObject */ virtual bool Realize(boost::shared_ptr<oxygen::ActionObject> action); /** returns the name of the predicate this effector implements. */ virtual std::string GetPredicate() { return "beam"; } /** constructs an Actionobject, describing a predicate */ virtual boost::shared_ptr<oxygen::ActionObject> GetActionObject(const oxygen::Predicate& predicate); protected: /** setup the reference to the agents body node */ virtual void OnLink(); /** remove the reference to the agents body node */ virtual void OnUnlink(); protected: /** the reference to the parents body node */ boost::shared_ptr<oxygen::Body> mBody; /** the reference to the GameState */ boost::shared_ptr<GameStateAspect> mGameState; /** a reference to the agent state */ boost::shared_ptr<AgentState> mAgentState; /** the cached field length */ float mFieldLength; /** the cached field width */ float mFieldWidth; /** thec cached agent radius */ float mAgentRadius; }; DECLARE_CLASS(BeamEffector); #endif // BEAMEFFECTOR_H --- NEW FILE: beamaction.h --- /* -*- 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: beamaction.h,v 1.1.2.1 2007/03/07 10:39:21 fruit 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. */ #ifndef BEAMACTION_H #define BEAMACTION_H #include <oxygen/gamecontrolserver/actionobject.h> #include <salt/vector.h> class BeamAction : public oxygen::ActionObject { public: BeamAction(const std::string& predicate, salt::Vector3f pos) : ActionObject(predicate), mPos(pos) {} virtual ~BeamAction() {} /** returns the stored positin */ const salt::Vector3f& GetPosition() { return mPos; } protected: /** the position to beam the agent to */ salt::Vector3f mPos; }; #endif // BEAMACTION_H |