STARK: Change the Movement base class to only keep an ItemVisual pointer

This commit is contained in:
Bastien Bouclet 2015-09-23 19:42:37 +02:00
parent 8678e56301
commit c733a5ab59
6 changed files with 25 additions and 13 deletions

View File

@ -24,7 +24,7 @@
namespace Stark {
Movement::Movement(Resources::FloorPositionedItem *item) :
Movement::Movement(Resources::ItemVisual *item) :
_ended(false),
_item(item) {
}

View File

@ -28,7 +28,7 @@
namespace Stark {
namespace Resources {
class FloorPositionedItem;
class ItemVisual;
}
/**
@ -36,7 +36,7 @@ class FloorPositionedItem;
*/
class Movement {
public:
Movement(Resources::FloorPositionedItem *item);
Movement(Resources::ItemVisual *item);
virtual ~Movement();
/**
@ -71,7 +71,7 @@ protected:
float computeAngleBetweenVectorsXYPlane(const Math::Vector3d &v1, const Math::Vector3d &v2) const;
bool _ended;
Resources::FloorPositionedItem *_item;
Resources::ItemVisual *_item;
};
} // End of namespace Stark

View File

@ -31,6 +31,7 @@ namespace Stark {
Turn::Turn(Resources::FloorPositionedItem *item) :
Movement(item),
_item3D(item),
_turnSpeed(_defaultTurnAngleSpeed) {
}
@ -44,7 +45,7 @@ void Turn::onGameLoop() {
direction.normalize();
// Compute the angle with the current character direction
Math::Vector3d currentDirection = _item->getDirectionVector();
Math::Vector3d currentDirection = _item3D->getDirectionVector();
float directionDeltaAngle = computeAngleBetweenVectorsXYPlane(currentDirection, direction);
// If the angle between the current direction and the new one is too high,
@ -68,7 +69,7 @@ void Turn::onGameLoop() {
}
// Update the item's direction
_item->setDirection(computeAngleBetweenVectorsXYPlane(direction, Math::Vector3d(1.0, 0.0, 0.0)));
_item3D->setDirection(computeAngleBetweenVectorsXYPlane(direction, Math::Vector3d(1.0, 0.0, 0.0)));
// Check if we are close enough to the destination to stop
if (direction == _targetDirection) {

View File

@ -27,6 +27,10 @@
namespace Stark {
namespace Resources {
class FloorPositionedItem;
}
/**
* Make an item turn on itself towards a target direction
*/
@ -42,6 +46,7 @@ public:
void setTargetDirection(const Math::Vector3d &direction);
private:
Resources::FloorPositionedItem *_item3D;
Math::Vector3d _targetDirection;
float _turnSpeed;
};

View File

@ -38,6 +38,7 @@ namespace Stark {
Walk::Walk(Resources::FloorPositionedItem *item) :
Movement(item),
_item3D(item),
_running(false),
_turnDirection(kTurnNone) {
_path = new StringPullingPath();
@ -60,8 +61,8 @@ void Walk::start() {
void Walk::updatePath() const {
Resources::Floor *floor = StarkGlobal->getCurrent()->getFloor();
Math::Vector3d startPosition = _item->getPosition3D();
int32 startFloorFaceIndex = _item->getFloorFaceIndex();
Math::Vector3d startPosition = _item3D->getPosition3D();
int32 startFloorFaceIndex = _item3D->getFloorFaceIndex();
Resources::FloorFace *startFloorFace = floor->getFace(startFloorFaceIndex);
Resources::FloorEdge *startFloorEdge = startFloorFace->findNearestEdge(startPosition);
@ -86,7 +87,7 @@ void Walk::onGameLoop() {
Resources::Floor *floor = StarkGlobal->getCurrent()->getFloor();
// Get the target to walk to
Math::Vector3d currentPosition = _item->getPosition3D();
Math::Vector3d currentPosition = _item3D->getPosition3D();
Math::Vector3d target = _path->computeWalkTarget(currentPosition);
// Compute the direction to walk into
@ -95,7 +96,7 @@ void Walk::onGameLoop() {
direction.normalize();
// Compute the angle with the current character direction
Math::Vector3d currentDirection = _item->getDirectionVector();
Math::Vector3d currentDirection = _item3D->getDirectionVector();
float directionDeltaAngle = computeAngleBetweenVectorsXYPlane(currentDirection, direction);
// If the angle between the current direction and the new one is too high,
@ -140,11 +141,11 @@ void Walk::onGameLoop() {
}
// Update the item's properties
_item->setPosition3D(newPosition);
_item3D->setPosition3D(newPosition);
if (direction.getMagnitude() != 0.0) {
_item->setDirection(computeAngleBetweenVectorsXYPlane(direction, Math::Vector3d(1.0, 0.0, 0.0)));
_item3D->setDirection(computeAngleBetweenVectorsXYPlane(direction, Math::Vector3d(1.0, 0.0, 0.0)));
}
_item->setFloorFaceIndex(newFloorFaceIndex);
_item3D->setFloorFaceIndex(newFloorFaceIndex);
changeItemAnim();
}

View File

@ -29,6 +29,10 @@ namespace Stark {
class StringPullingPath;
namespace Resources {
class FloorPositionedItem;
}
/**
* Make an item walk / run to its destination on the current
* location's floor
@ -54,6 +58,7 @@ private:
void changeItemAnim();
void updatePath() const;
Resources::FloorPositionedItem *_item3D;
StringPullingPath *_path;
Math::Vector3d _destination;