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

movement.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/movement.h"
00024 
00025 #include "engines/stark/movement/walk.h"
00026 #include "engines/stark/movement/followpath.h"
00027 #include "engines/stark/movement/followpathlight.h"
00028 #include "engines/stark/movement/turn.h"
00029 
00030 #include "engines/stark/resources/item.h"
00031 
00032 #include "common/textconsole.h"
00033 
00034 namespace Stark {
00035 
00036 Movement *Movement::construct(uint32 type, Resources::ItemVisual *item) {
00037     switch (type) {
00038         case kTypeWalk:
00039             return new Walk(Resources::Object::cast<Resources::FloorPositionedItem>(item));
00040         case kTypeFollowPath:
00041             return new FollowPath(item);
00042         case kTypeFollowPathLight:
00043             return new FollowPathLight(item);
00044         case kTypeTurn:
00045             return new Turn(Resources::Object::cast<Resources::FloorPositionedItem>(item));
00046         default:
00047             error("Unexepected movement type '%d'", type);
00048     }
00049 }
00050 
00051 Movement::Movement(Resources::ItemVisual *item) :
00052         _ended(false),
00053         _item(item),
00054         _defaultTurnAngleSpeed(18.0f * 30.0f / 1000.0f) { // 18 degrees per gameloop at 30 fps
00055 }
00056 
00057 Movement::~Movement() {
00058 }
00059 
00060 void Movement::start() {
00061     _ended = false;
00062 }
00063 
00064 void Movement::stop(bool force) {
00065     _ended = true;
00066 }
00067 
00068 bool Movement::hasEnded() const {
00069     return _ended;
00070 }
00071 
00072 float Movement::computeAngleBetweenVectorsXYPlane(const Math::Vector3d &v1, const Math::Vector3d &v2) const {
00073     Math::Vector3d v1XY = v1;
00074     v1XY.z() = 0.0;
00075 
00076     Math::Vector3d v2XY = v2;
00077     v2XY.z() = 0.0;
00078 
00079     Math::Angle angle = Math::Vector3d::angle(v1XY, v2XY);
00080     Math::Vector3d cross = Math::Vector3d::crossProduct(v1XY, v2XY);
00081     if (cross.z() < 0) {
00082         angle = -angle;
00083     }
00084 
00085     return angle.getDegrees();
00086 }
00087 
00088 bool Movement::hasReachedDestination() const {
00089     return true;
00090 }
00091 } // End of namespace Stark


Generated on Sat Feb 16 2019 05:00:58 for ResidualVM by doxygen 1.7.1
curved edge   curved edge