📄 ballstateaspect.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: ballstateaspect.cpp,v 1.7 2007/06/15 09:47:29 jboedeck 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 "ballstateaspect.h"#include <zeitgeist/logserver/logserver.h>#include <oxygen/sceneserver/sceneserver.h>#include <oxygen/sceneserver/scene.h>#include <oxygen/agentaspect/agentaspect.h>#include <oxygen/physicsserver/recorderhandler.h>#include <soccer/gamestateaspect/gamestateaspect.h>#include <soccer/soccerbase/soccerbase.h>#include <soccer/ball/ball.h>using namespace oxygen;using namespace boost;using namespace std;using namespace salt;BallStateAspect::BallStateAspect() : SoccerControlAspect(){ mBallOnField = false; mLastValidBallPos = Vector3f(0,0,0); mGoalState = TI_NONE; mLastAgentCollisionTime = 0;}BallStateAspect::~BallStateAspect(){}bool BallStateAspect::GetLastCollidingAgent(shared_ptr<AgentAspect>& agent, TTime& time){ agent = mLastCollidingAgent; time = mLastAgentCollisionTime; return (agent.get() != 0);}bool BallStateAspect::GetLastKickingAgent(shared_ptr<AgentAspect>& agent, TTime& time){ agent = mLastKickingAgent; time = mLastAgentKickTime; return (agent.get() != 0);}void BallStateAspect::UpdateLastCollidingAgent(){ // get a list of agents that collided with the ball since the last // update of the recorder and remember the first returned node as // the last agent that collided with the ball. RecorderHandler::TParentList agents; mBallRecorder->FindParentsSupportingClass<AgentAspect>(agents); if (agents.size() > 0) { mLastCollidingAgent = shared_static_cast<AgentAspect> (agents.front().lock()); mLastAgentCollisionTime = mGameState->GetTime(); } // empty the recorder buffer mBallRecorder->Clear();}voidBallStateAspect::UpdateLastCollidingAgent(boost::shared_ptr<AgentAspect> agent){ mLastCollidingAgent = agent; mLastAgentCollisionTime = mGameState->GetTime();}voidBallStateAspect::UpdateLastKickingAgent(boost::shared_ptr<AgentAspect> agent){ mLastKickingAgent = agent; mLastAgentKickTime = mGameState->GetTime();}void BallStateAspect::UpdateBallOnField(){ // get a list of Ball nodes that collided with the field RecorderHandler::TParentList ball; mFieldRecorder->FindParentsSupportingClass<Ball>(ball); // the ball is on or above the playing field iff it collided with // the box collider around the playing field mBallOnField = (ball.size() > 0); // empty the recorder buffer mFieldRecorder->Clear();}void BallStateAspect::UpdateLastValidBallPos(){ if (! mBallOnField) { return; } mLastValidBallPos = mBall->GetWorldTransform().Pos();}void BallStateAspect::UpdateGoalState(){ // check both goal box collider RecorderHandler::TParentList ball; mLeftGoalRecorder->FindParentsSupportingClass<Ball>(ball); if (! ball.empty()) { mGoalState = TI_LEFT; } else { mRightGoalRecorder->FindParentsSupportingClass<Ball>(ball); if (! ball.empty()) { mGoalState = TI_RIGHT; } else { mGoalState = TI_NONE; } } mLeftGoalRecorder->Clear(); mRightGoalRecorder->Clear();}TTeamIndex BallStateAspect::GetGoalState(){ return mGoalState;}void BallStateAspect::Update(float deltaTime){ if ( (mFieldRecorder.get() == 0) || (mBall.get() == 0) || (mBallRecorder.get() == 0) || (mLeftGoalRecorder.get() == 0) || (mRightGoalRecorder.get() == 0) ) { return; } UpdateLastCollidingAgent(); UpdateBallOnField(); UpdateLastValidBallPos(); UpdateGoalState();}void BallStateAspect::OnLink(){ SoccerControlAspect::OnLink(); mFieldRecorder = GetFieldRecorder(); SoccerBase::GetBall(*this,mBall); mBallRecorder = GetBallRecorder(); mLeftGoalRecorder = GetLeftGoalRecorder(); mRightGoalRecorder = GetRightGoalRecorder(); mGameState = shared_dynamic_cast<GameStateAspect> (GetControlAspect("GameStateAspect"));}void BallStateAspect::OnUnlink(){ SoccerControlAspect::OnUnlink(); mBallRecorder.reset(); mFieldRecorder.reset(); mLastCollidingAgent.reset(); mLeftGoalRecorder.reset(); mRightGoalRecorder.reset(); mGameState.reset();}bool BallStateAspect::GetBallOnField(){ return mBallOnField;}salt::Vector3f BallStateAspect::GetLastValidBallPosition(){ return mLastValidBallPos;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -