forked from bridgecommand/bc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShip.cpp
More file actions
118 lines (96 loc) · 2.83 KB
/
Ship.cpp
File metadata and controls
118 lines (96 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* Bridge Command 5.0 Ship Simulator
Copyright (C) 2014 James Packer
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY Or FITNESS For A PARTICULAR PURPOSE. See the
GNU General Public License For more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
//Parent class for own and other ships - not used un-extended
#include "Ship.hpp"
#include "Constants.hpp"
#include "SimulationModel.hpp"
#include "IniFile.hpp"
using namespace irr;
Ship::Ship()
{
//Default to run on defined spd and hdg
controlMode = MODE_AUTO;
positionManuallyUpdated = false; //Used to track if position has been manually updated, and shouldn't have position update applied this loop
this->sunk = false; // We start off not sunk
}
Ship::~Ship()
{
//dtor
}
irr::scene::IMeshSceneNode* Ship::getSceneNode() const
{
return ship;
}
irr::core::vector3df Ship::getRotation() const
{
return ship->getRotation();
}
irr::core::vector3df Ship::getPosition() const
{
ship->updateAbsolutePosition();//ToDo: This may be needed, but seems odd that it's required
return ship->getAbsolutePosition();
}
irr::f32 Ship::getLength() const
{
return length;
}
irr::f32 Ship::getWidth() const
{
return width;
}
void Ship::setPosition(irr::f32 xPos, irr::f32 zPos)
{
//Update the position used, ready for next update. Doesn't actually move the mesh at this point
this->xPos = xPos;
this->zPos = zPos;
positionManuallyUpdated = true;
}
void Ship::setHeading(irr::f32 hdg)
{
this->hdg = hdg;
controlMode = MODE_AUTO; //Switch to auto mode
}
void Ship::setSpeed(irr::f32 spd)
{
this->spd = spd;
controlMode = MODE_AUTO; //Switch to auto mode
}
irr::f32 Ship::getHeading() const
{
return hdg;
}
irr::f32 Ship::getSpeed() const
{
return spd;
}
void Ship::moveNode(irr::f32 deltaX, irr::f32 deltaY, irr::f32 deltaZ)
{
if(!this->sunk){ // Don't move if we're sunk
xPos += deltaX;
yPos += deltaY;
zPos += deltaZ;
ship->setPosition(core::vector3df(xPos,yPos,zPos));
}
else{ // Sink down
zPos -= 0.1;
ship->setPosition(core::vector3df(xPos,yPos,zPos));
}
}
bool Ship::isSunk()
{
return this->sunk;
}
void Ship::sink()
{
this->sunk = true; // Sink the Ship - Oh no...
}