Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

forceeffector.cpp

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-indent: 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) 2003 RoboCup Soccer Server 3D Maintenance Group
00007    $Id: forceeffector.cpp,v 1.6 2004/03/23 09:28:57 rollmark 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 
00023 #include "forceeffector.h"
00024 #include "forceaction.h"
00025 #include <zeitgeist/logserver/logserver.h>
00026 #include <oxygen/gamecontrolserver/actionobject.h>
00027 
00028 using namespace boost;
00029 using namespace oxygen;
00030 using namespace salt;
00031 
00032 ForceEffector::ForceEffector() : oxygen::Effector()
00033 {
00034 }
00035 
00036 ForceEffector::~ForceEffector()
00037 {
00038 }
00039 
00040 bool ForceEffector::Realize(boost::shared_ptr<ActionObject> action)
00041 {
00042   if (mBody.get() == 0)
00043     {
00044       return false;
00045     }
00046 
00047   shared_ptr<ForceAction> forceAction =
00048     shared_dynamic_cast<ForceAction>(action);
00049 
00050   if (forceAction.get() == 0)
00051     {
00052       GetLog()->Error()
00053         << "ERROR: (ForceEffector) cannot realize an unknown ActionObject\n";
00054       return false;
00055     }
00056 
00057   const Vector3f& force = forceAction->GetForce();
00058   mBody->AddForce(Vector3f(force[0],force[1],force[2]));
00059 
00060   return true;
00061 }
00062 
00063 shared_ptr<ActionObject>
00064 ForceEffector::GetActionObject(const Predicate& predicate)
00065 {
00066   if (predicate.name != GetPredicate())
00067     {
00068       GetLog()->Error() << "ERROR: (ForceEffector) invalid predicate"
00069                         << predicate.name << "\n";
00070       return shared_ptr<ActionObject>();
00071     }
00072 
00073   Vector3f force;
00074   if (! predicate.GetValue(predicate.begin(), force))
00075   {
00076       GetLog()->Error()
00077         << "ERROR: (ForceEffector) Vector3f parameter expected\n";
00078       return shared_ptr<ActionObject>();
00079   };
00080 
00081   return shared_ptr<ActionObject>(new ForceAction(GetPredicate(),force));
00082 }
00083 
00084 void ForceEffector::OnLink()
00085 {
00086   shared_ptr<BaseNode> parent =
00087     shared_dynamic_cast<BaseNode>(make_shared(GetParent()));
00088 
00089   if (parent.get() == 0)
00090     {
00091       GetLog()->Error()
00092         << "ERROR: (ForceEffector) parent node is not derived from BaseNode\n";
00093       return;
00094     }
00095 
00096   // parent should be a transform, or some other node, which has a
00097   // Body-child
00098   mBody = shared_dynamic_cast<Body>(parent->GetChildOfClass("Body"));
00099 
00100   if (mBody.get() == 0)
00101     {
00102       GetLog()->Error()
00103         << "ERROR: (ForceEffector) parent node has no Body child;"
00104           "cannot apply force\n";
00105       return;
00106     }
00107 }
00108 
00109 void ForceEffector::OnUnlink()
00110 {
00111     mBody.reset();
00112 }
00113 
00114 

Generated on Thu Apr 6 15:25:38 2006 for rcssserver3d by  doxygen 1.4.4