ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

stringpullingpath.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "engines/stark/movement/stringpullingpath.h"
00024 
00025 #include "engines/stark/resources/floor.h"
00026 
00027 #include "engines/stark/services/global.h"
00028 #include "engines/stark/services/services.h"
00029 
00030 #include "math/line3d.h"
00031 
00032 namespace Stark {
00033 
00034 StringPullingPath::StringPullingPath() :
00035         _targetStep(1) {
00036 }
00037 
00038 void StringPullingPath::addStep(const Math::Vector3d &position) {
00039     _steps.push_back(position);
00040 }
00041 
00042 void StringPullingPath::reset() {
00043     _steps.clear();
00044     _targetStep = 1;
00045 }
00046 
00047 Math::Vector3d StringPullingPath::computeWalkTarget(const Math::Vector3d &fromPosition) {
00048     Current *current = StarkGlobal->getCurrent();
00049     Resources::Floor *floor = current->getFloor();
00050 
00051     // HACK: Sometimes the character gets stuck because of rounding errors
00052     // If we detect the character is stuck on a step, just make it go to the next one.
00053     // TODO: Improve the string pulling code so that the targets can also be points between two steps.
00054     if (fromPosition.getDistanceTo(_steps[_targetStep]) < 1.0 && _targetStep < _steps.size() - 1) {
00055         _targetStep++;
00056     }
00057 
00058     for (uint i = _targetStep + 1; i < _steps.size(); i++) {
00059         Math::Line3d testSegment = Math::Line3d(fromPosition, _steps[i]);
00060         if (!floor->isSegmentInside(testSegment)) {
00061             break;
00062         }
00063 
00064         _targetStep = i;
00065     }
00066 
00067     return _steps[_targetStep];
00068 }
00069 
00070 bool StringPullingPath::hasSteps() const {
00071     return _steps.size() > 1;
00072 }
00073 
00074 } // End of namespace Stark


Generated on Sat May 18 2019 05:01:21 for ResidualVM by doxygen 1.7.1
curved edge   curved edge