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

velocitycontroller.cpp

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
00002    this file is part of rcssserver3D
00003    Fri May 9 2003
00004    Copyright (C) 2003 Koblenz University
00005    $Id: velocitycontroller.cpp,v 1.1 2004/04/10 07:23:48 rollmark Exp $
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; version 2 of the License.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software
00018    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 */
00020 #include "velocitycontroller.h"
00021 #include "body.h"
00022 
00023 using namespace oxygen;
00024 using namespace salt;
00025 
00026 VelocityController::VelocityController()
00027     : BodyController(), mMaxVel(0)
00028 {
00029 }
00030 
00031 VelocityController::~VelocityController()
00032 {
00033 }
00034 
00035 float VelocityController::GetMaxVelocity()
00036 {
00037     return mMaxVel;
00038 }
00039 
00040 void VelocityController::SetMaxVelocity(float vel)
00041 {
00042     mMaxVel = vel;
00043 }
00044 
00045 void VelocityController::PrePhysicsUpdateInternal(float /*deltaTime*/)
00046 {
00047     // enforce maximum speed
00048     if (
00049         (mMaxVel <= 0) ||
00050         (mBody.get() == 0)
00051         )
00052         {
00053             return;
00054         }
00055 
00056     Vector3f vel = mBody->GetVelocity();
00057     if (vel.SquareLength() < (mMaxVel * mMaxVel))
00058         {
00059             return;
00060         }
00061 
00062     vel.Normalize();
00063     vel *= mMaxVel;
00064 
00065     mBody->SetVelocity(vel);
00066 }

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