From: Oliver O. <fr...@us...> - 2007-03-07 10:39:24
|
Update of /cvsroot/simspark/simspark/simulations/soccer/plugin/ball In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv24718/ball Added Files: Tag: projectx ball.cpp ball.h ball_c.cpp Log Message: soccer plugins from rcssserver3D --- NEW FILE: ball_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: ball_c.cpp,v 1.1.2.1 2007/03/07 10:39:20 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 "ball.h" using namespace oxygen; void CLASS(Ball)::DefineClass() { DEFINE_BASECLASS(oxygen/Transform); } --- NEW FILE: ball.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) 2004 RoboCup Soccer Server 3D Maintenance Group $Id: ball.cpp,v 1.1.2.1 2007/03/07 10:39:19 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 <oxygen/agentaspect/agentaspect.h> #include <oxygen/physicsserver/body.h> #include <soccer/ballstateaspect/ballstateaspect.h> #include "ball.h" using namespace boost; using namespace oxygen; Ball::Ball() : Transform(), mForceTTL(0) { } void Ball::SetAcceleration(int steps, const salt::Vector3f& force, const salt::Vector3f& torque, boost::shared_ptr<oxygen::AgentAspect> agent) { if (mForceTTL > 0 && mKickedLast == agent) return; mForceTTL = steps; mForce = force; mTorque = torque; mKickedLast = agent; if (mBody.get() == 0) { mBody = shared_dynamic_cast<Body>(GetChildOfClass("Body")); } } void Ball::PrePhysicsUpdateInternal(float deltaTime) { Transform::PrePhysicsUpdateInternal(deltaTime); if (mBody.get() == 0 || mForceTTL <= 0) return; // the BallStateAspect is created after the ball, so we cannot set // mBallStateAspect during OnLink if (mBallStateAspect.get() == 0) { mBallStateAspect = shared_dynamic_cast<BallStateAspect> (GetCore()->Get("/sys/server/gamecontrol/BallStateAspect")); if (mBallStateAspect.get() == 0) return; } mBody->AddForce(mForce); mBody->AddTorque(mTorque); mBallStateAspect->UpdateLastCollidingAgent(mKickedLast); --mForceTTL; } --- NEW FILE: ball.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: ball.h,v 1.1.2.1 2007/03/07 10:39:19 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 BALL_H #define BALL_H #include <oxygen/sceneserver/transform.h> #include <oxygen/physicsserver/body.h> #include <salt/vector.h> class BallStateAspect; namespace oxygen { class AgentAspect; } /** \class Ball represents the ball on the soccer field ;) */ class Ball : public oxygen::Transform { public: Ball(); virtual ~Ball() {}; /** Set the acceleration of the ball. * * This method can be used to accelerate the ball over a number * of simulation steps. The ball acceleration will be applied over the number * of steps using a constant force and torque. * * \param steps number of steps the acceleration should be applied. * \param force the maximum force to add to the ball * \param torque the maximum torque to add to the ball * \param agent the agent kicking the ball */ void SetAcceleration(int steps, const salt::Vector3f& force, const salt::Vector3f& torque, boost::shared_ptr<oxygen::AgentAspect> agent); /** This method is used to add forces and torques to the ball before each simulation * step, if necessary. */ virtual void PrePhysicsUpdateInternal(float deltaTime); private: int mForceTTL; salt::Vector3f mForce; salt::Vector3f mTorque; boost::shared_ptr<oxygen::Body> mBody; boost::shared_ptr<oxygen::AgentAspect> mKickedLast; boost::shared_ptr<BallStateAspect> mBallStateAspect; }; DECLARE_CLASS(Ball); #endif // BALL_H |