00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- 00002 00003 this file is part of rcssserver3D 00004 Fri May 9 2003 00005 Copyright (C) 2002,2003 Koblenz University 00006 Copyright (C) 2004 RoboCup Soccer Server 3D Maintenance Group 00007 $Id: ball.cpp,v 1.4 2005/07/13 01:07:34 fruit Exp $ 00008 00009 This program is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation; version 2 of the License. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program; if not, write to the Free Software 00020 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00021 */ 00022 #include <oxygen/agentaspect/agentaspect.h> 00023 #include <oxygen/physicsserver/body.h> 00024 #include <soccer/ballstateaspect/ballstateaspect.h> 00025 #include "ball.h" 00026 00027 using namespace boost; 00028 using namespace oxygen; 00029 00030 Ball::Ball() : Transform(), mForceTTL(0) 00031 { 00032 } 00033 00034 void 00035 Ball::SetAcceleration(int steps, const salt::Vector3f& force, 00036 const salt::Vector3f& torque, 00037 boost::shared_ptr<oxygen::AgentAspect> agent) 00038 { 00039 if (mForceTTL > 0 && mKickedLast == agent) return; 00040 00041 mForceTTL = steps; 00042 00043 mForce = force; 00044 mTorque = torque; 00045 mKickedLast = agent; 00046 00047 if (mBody.get() == 0) 00048 { 00049 mBody = shared_dynamic_cast<Body>(GetChildOfClass("Body")); 00050 } 00051 } 00052 00053 void 00054 Ball::PrePhysicsUpdateInternal(float deltaTime) 00055 { 00056 Transform::PrePhysicsUpdateInternal(deltaTime); 00057 if (mBody.get() == 0 || mForceTTL <= 0) return; 00058 00059 // the BallStateAspect is created after the ball, so we cannot set 00060 // mBallStateAspect during OnLink 00061 if (mBallStateAspect.get() == 0) 00062 { 00063 mBallStateAspect = shared_dynamic_cast<BallStateAspect> 00064 (GetCore()->Get("/sys/server/gamecontrol/BallStateAspect")); 00065 if (mBallStateAspect.get() == 0) return; 00066 } 00067 00068 mBody->AddForce(mForce); 00069 mBody->AddTorque(mTorque); 00070 mBallStateAspect->UpdateLastCollidingAgent(mKickedLast); 00071 00072 --mForceTTL; 00073 }