forked from bridgecommand/bc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimulationModel.cpp
More file actions
683 lines (530 loc) · 23.2 KB
/
SimulationModel.cpp
File metadata and controls
683 lines (530 loc) · 23.2 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
/* 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. */
#include "SimulationModel.hpp"
#include "Constants.hpp"
#include "Utilities.hpp"
//#include <ctime>
using namespace irr;
SimulationModel::SimulationModel(IrrlichtDevice* dev, scene::ISceneManager* scene, GUIMain* gui, std::string scenarioName, bool secondary) //constructor, including own ship model
{
//get reference to scene manager
device = dev;
smgr = scene;
driver = scene->getVideoDriver();
guiMain = gui;
//store scenario name
this->scenarioName = scenarioName;
//store if we're running in secondary mode
this->secondary = secondary;
//Set loop number to zero
loopNumber = 0;
//construct path to scenario
std::string scenarioPath = "Scenarios/"; //Fixme: Should be a parameter, and duplicated in ScenarioChoice.cpp
scenarioPath.append(scenarioName);
//Read world file name from scenario:
std::string environmentIniFilename = scenarioPath;
environmentIniFilename.append("/environment.ini");
worldName = IniFile::iniFileToString(environmentIniFilename,"Setting");
irr::f32 startTime = IniFile::iniFileTof32(environmentIniFilename,"StartTime");
irr::u32 startDay=IniFile::iniFileTou32(environmentIniFilename,"StartDay");
irr::u32 startMonth=IniFile::iniFileTou32(environmentIniFilename,"StartMonth");
irr::u32 startYear=IniFile::iniFileTou32(environmentIniFilename,"StartYear");
//load the sun times
irr::f32 sunRise = IniFile::iniFileTof32(environmentIniFilename,"SunRise");
irr::f32 sunSet = IniFile::iniFileTof32(environmentIniFilename,"SunSet" );
if(sunRise==0.0) {sunRise=6;}
if(sunSet==0.0) {sunSet=18;}
//load the weather:
//Fixme: add in wind direction etc
weather = IniFile::iniFileTof32(environmentIniFilename,"Weather");
rainIntensity = IniFile::iniFileTof32(environmentIniFilename,"Rain");
//Fixme: Think about time zone handling
//Fixme: Note that if the time_t isn't long enough, 2038 problem exists
scenarioOffsetTime = Utilities::dmyToTimestamp(startDay,startMonth,startYear);//Time in seconds to start of scenario day (unix timestamp for 0000h on day scenario starts)
//set internal scenario time to start
scenarioTime = startTime * SECONDS_IN_HOUR;
//Start paused initially
device->getTimer()->setSpeed(0.0);
//Set initial tide height to zero
tideHeight = 0;
if (worldName == "") {
//Could not load world name from scenario, so end here
//ToDo: Tell user problem
exit(EXIT_FAILURE);
}
//construct path to world model
std::string worldPath = "World/";
worldPath.append(worldName);
//Add terrain: Needs to happen first, so the terrain parameters are available
terrain.load(worldPath, smgr);
//add water
bool detailedWater;
if (driver->queryFeature(video::EVDF_RENDER_TO_TARGET ) && driver->queryFeature(video::EVDF_ARB_GLSL) ) { //Fixme: check exactly what's needed by shader - currently assumes GL
detailedWater = true;
} else {
detailedWater = false;
}
water.load(smgr,weather,detailedWater);
//sky box/dome
Sky sky (smgr);
//make ambient light
light.load(smgr,sunRise,sunSet);
//Load own ship model.
ownShip.load(scenarioPath, smgr, this, &terrain);
if(secondary) {
ownShip.setSpeed(0); //Don't start moving if in secondary mode
}
//Tell gui to hide the second engine scroll bar if we have a single engine
if (ownShip.isSingleEngine()) {
gui->hideStbdEngineBar();
}
//Tell gui to hide all ship controls if in secondary mode
if (secondary) {
gui->hideEngineAndRudder();
}
//Todo: Set the radar parameters, based on the radar.ini file from the own ship
//std::cout << "Radar file:" << ownShip.getRadarConfigFile() << std::endl;
radarCalculation.load(ownShip.getRadarConfigFile());
//set camera zoom to 1
zoom = 1.0;
//make a camera, setting parent and offset
std::vector<core::vector3df> views = ownShip.getCameraViews(); //Get the initial camera offset from the own ship model
camera.load(smgr,ownShip.getSceneNode(),views,core::PI/2.0);
//Load other ships
otherShips.load(scenarioPath,scenarioTime,secondary,smgr,this);
//Load buoys
buoys.load(worldPath, smgr, this);
//Load land objects
landObjects.load(worldPath, smgr, this, terrain);
//Load land lights
landLights.load(worldPath, smgr, this, terrain);
//Load tidal information
tide.load(worldPath);
//Load rain
rain.load(smgr, camera.getSceneNode());
//make a radar screen, setting parent and offset from own ship
core::vector3df radarOffset = core::vector3df(0,100,0); //FIXME: Temporary - radar 100m above ship - used to render 2d radar, but could also be used in 3d view if required
//core::vector3df radarOffset = core::vector3df(0.45,-0.28,0.75); //Previous offset from camera
radarScreen.load(smgr,ownShip.getSceneNode(),radarOffset);
//make radar image
radarImage = driver->createImage (video::ECF_R8G8B8, core::dimension2d<u32>(256, 256)); //Create image for radar calculation to work on
radarImage->fill(video::SColor(255, 0, 0, 255)); //Fill with background colour
//make radar camera
std::vector<core::vector3df> radarViews; //Get the initial camera offset from the radar screen
radarViews.push_back(core::vector3df(0,0,-0.25));
radarCamera.load(smgr,radarScreen.getSceneNode(),radarViews,core::PI/2.0);
radarCamera.updateViewport(1.0);
radarCamera.setNearValue(0.2);
radarCamera.setFarValue(0.3);
//initialise offset
offsetPosition = core::vector3d<s64>(0,0,0);
//store time
previousTime = device->getTimer()->getTime();
} //end of SimulationModel constructor
SimulationModel::~SimulationModel()
{
radarImage->drop(); //We created this with 'create', so drop it when we're finished
}
irr::f32 SimulationModel::longToX(irr::f32 longitude) const
{
return terrain.longToX(longitude); //Cascade to terrain
}
irr::f32 SimulationModel::latToZ(irr::f32 latitude) const
{
return terrain.latToZ(latitude); //Cascade to terrain
}
void SimulationModel::setSpeed(irr::f32 spd)
{
ownShip.setSpeed(spd);
}
irr::f32 SimulationModel::getSpeed() const
{
return(ownShip.getSpeed());
}
irr::f32 SimulationModel::getLat() const{
return terrain.zToLat(ownShip.getPosition().Z + offsetPosition.Z);
}
irr::f32 SimulationModel::getLong() const{
return terrain.xToLong(ownShip.getPosition().X + offsetPosition.X);
}
irr::f32 SimulationModel::getPosX() const{
return ownShip.getPosition().X + offsetPosition.X;
}
irr::f32 SimulationModel::getPosZ() const{
return ownShip.getPosition().Z + offsetPosition.Z;
}
irr::f32 SimulationModel::getCOG() const{
return getHeading(); //FIXME: Will need to be updated when currents etc included
}
irr::f32 SimulationModel::getSOG() const{
return getSpeed(); //FIXME: Will need to be updated when currents etc included
}
// void SimulationModel::getTime(irr::u8& hour, irr::u8& min, irr::u8& sec) const{
// //FIXME: Complete
// }
//void SimulationModel::getDate(irr::u8& day, irr::u8& month, irr::u16& year) const{
// //FIXME: Complete
//}
uint64_t SimulationModel::getTimestamp() const{
return absoluteTime;
}
uint64_t SimulationModel::getTimeOffset() const { //The timestamp at the start of the first day of the scenario
return scenarioOffsetTime;
}
void SimulationModel::setTimeDelta(irr::f32 scenarioTime) {
this->scenarioTime = scenarioTime;
}
irr::f32 SimulationModel::getTimeDelta() const { //The change in time (s) since the start of the start day of the scenario
return scenarioTime;
}
irr::u32 SimulationModel::getNumberOfOtherShips() const {
return otherShips.getNumber();
}
irr::u32 SimulationModel::getNumberOfBuoys() const {
return buoys.getNumber();
}
std::string SimulationModel::getOtherShipName(int number) const{
return otherShips.getName(number);
}
irr::f32 SimulationModel::getOtherShipPosX(int number) const{
return otherShips.getPosition(number).X + offsetPosition.X;
}
irr::f32 SimulationModel::getOtherShipPosZ(int number) const{
return otherShips.getPosition(number).Z + offsetPosition.Z;
}
irr::f32 SimulationModel::getOtherShipHeading(int number) const{
return otherShips.getHeading(number);
}
irr::f32 SimulationModel::getOtherShipSpeed(int number) const{
return otherShips.getSpeed(number);
}
void SimulationModel::setOtherShipHeading(int number, irr::f32 hdg){
otherShips.setHeading(number, hdg);
}
void SimulationModel::setOtherShipSpeed(int number, irr::f32 speed){
otherShips.setSpeed(number, speed);
}
void SimulationModel::setOtherShipPos(int number, irr::f32 positionX, irr::f32 positionZ){
otherShips.setPos(number, positionX - offsetPosition.X, positionZ - offsetPosition.Z);
}
std::vector<Leg> SimulationModel::getOtherShipLegs(int number) const{
return otherShips.getLegs(number);
}
irr::f32 SimulationModel::getBuoyPosX(int number) const{
return buoys.getPosition(number).X + offsetPosition.X;
}
irr::f32 SimulationModel::getBuoyPosZ(int number) const{
return buoys.getPosition(number).Z + offsetPosition.Z;
}
void SimulationModel::changeOtherShipLeg(int shipNumber, int legNumber, irr::f32 bearing, irr::f32 speed, irr::f32 distance) {
otherShips.changeLeg(shipNumber, legNumber, bearing, speed, distance, scenarioTime);
}
void SimulationModel::addOtherShipLeg(int shipNumber, int afterLegNumber, irr::f32 bearing, irr::f32 speed, irr::f32 distance) {
otherShips.addLeg(shipNumber, afterLegNumber, bearing, speed, distance, scenarioTime);
}
void SimulationModel::deleteOtherShipLeg(int shipNumber, int legNumber) {
otherShips.deleteLeg(shipNumber, legNumber, scenarioTime);
}
void SimulationModel::setHeading(f32 hdg)
{
ownShip.setHeading(hdg);
}
void SimulationModel::setPos(irr::f32 positionX, irr::f32 positionZ)
{
ownShip.setPosition(positionX - offsetPosition.X, positionZ - offsetPosition.Z );
}
irr::f32 SimulationModel::getHeading() const
{
return(ownShip.getHeading());
}
void SimulationModel::setRudder(irr::f32 rudder)
{
//Set the rudder (-ve is port, +ve is stbd)
ownShip.setRudder(rudder);
}
irr::f32 SimulationModel::getRudder() const
{
return ownShip.getRudder();
}
void SimulationModel::setPortEngine(irr::f32 port)
{
//Set the engine, (-ve astern, +ve ahead)
ownShip.setPortEngine(port);
}
void SimulationModel::setStbdEngine(irr::f32 stbd)
{
//Set the engine, (-ve astern, +ve ahead)
ownShip.setStbdEngine(stbd);
}
/*irr::f32 SimulationModel::getPortEngine() const
{
return ownShip.getPortEngine();
}
irr::f32 SimulationModel::getStbdEngine() const
{
return ownShip.getStbdEngine();
}*/
irr::f32 SimulationModel::getPortEngineRPM() const
{
return ownShip.getPortEngineRPM();
}
irr::f32 SimulationModel::getStbdEngineRPM() const
{
return ownShip.getStbdEngineRPM();
}
void SimulationModel::setAccelerator(irr::f32 accelerator)
{
device->getTimer()->setSpeed(accelerator);
}
irr::f32 SimulationModel::getAccelerator() const
{
return device->getTimer()->getSpeed();
}
void SimulationModel::setWeather(irr::f32 weather)
{
this->weather = weather;
}
irr::f32 SimulationModel::getWeather() const
{
return weather;
}
void SimulationModel::setRain(irr::f32 rainIntensity)
{
this->rainIntensity = rainIntensity;
}
irr::f32 SimulationModel::getRain() const
{
return rainIntensity;
}
void SimulationModel::lookUp()
{
camera.lookUp();
}
void SimulationModel::lookDown()
{
camera.lookDown();
}
void SimulationModel::lookLeft()
{
camera.lookLeft();
}
void SimulationModel::lookRight()
{
camera.lookRight();
}
void SimulationModel::lookAhead()
{
camera.lookAhead();
}
void SimulationModel::lookAstern()
{
camera.lookAstern();
}
void SimulationModel::lookPort()
{
camera.lookPort();
}
void SimulationModel::lookStbd()
{
camera.lookStbd();
}
void SimulationModel::changeView()
{
camera.changeView();
}
irr::u32 SimulationModel::getCameraView() const
{
return camera.getView();
}
void SimulationModel::increaseRadarRange()
{
radarCalculation.increaseRange();
}
void SimulationModel::decreaseRadarRange()
{
radarCalculation.decreaseRange();
}
void SimulationModel::setRadarGain(irr::f32 value)
{
radarCalculation.setGain(value);
}
void SimulationModel::setRadarClutter(irr::f32 value)
{
radarCalculation.setClutter(value);
}
void SimulationModel::setRadarRain(irr::f32 value)
{
radarCalculation.setRainClutter(value);
}
void SimulationModel::increaseRadarEBLRange() {radarCalculation.increaseEBLRange();}
void SimulationModel::decreaseRadarEBLRange() {radarCalculation.decreaseEBLRange();}
void SimulationModel::increaseRadarEBLBrg() {radarCalculation.increaseEBLBrg();}
void SimulationModel::decreaseRadarEBLBrg() {radarCalculation.decreaseEBLBrg();}
void SimulationModel::setMainCameraActive()
{
camera.setActive();
}
void SimulationModel::setRadarCameraActive()
{
radarCamera.setActive();
}
void SimulationModel::toggleZoom()
{
if (zoom > 1) {
zoom = 1;
} else {
zoom = 7.0; //Binoculars magnification
}
camera.setHFOV((core::PI/2)/zoom);
}
void SimulationModel::updateViewport(irr::f32 aspect)
{
camera.updateViewport(aspect);
}
irr::u32 SimulationModel::getLoopNumber() const
{
return loopNumber;
}
std::string SimulationModel::getScenarioName() const
{
return scenarioName;
}
std::string SimulationModel::getWorldName() const
{
return worldName;
}
void SimulationModel::update()
{
//get delta time
currentTime = device->getTimer()->getTime();
deltaTime = (currentTime - previousTime)/1000.f;
//deltaTime = (currentTime - previousTime)/1000.f;
previousTime = currentTime;
//add this to the scenario time
scenarioTime += deltaTime;
absoluteTime = Utilities::round(scenarioTime) + scenarioOffsetTime;
//increment loop number
loopNumber++;
//Update tide height here.
tide.update(absoluteTime);
tideHeight = tide.getTideHeight();
//std::cout << tideHeight << std::endl;
//update ambient lighting
light.update(scenarioTime);
driver->setFog(light.getLightSColor(), video::EFT_FOG_EXP , 250, 5*M_IN_NM, .0003f, true, true);
irr::u32 lightLevel = light.getLightLevel();
//update rain
rain.setIntensity(rainIntensity);
rain.update(scenarioTime);
//update other ship positions etc
otherShips.update(deltaTime,scenarioTime,tideHeight,camera.getPosition(),lightLevel); //Update other ship motion (based on leg information), and light visibility.
//update buoys (for lights)
buoys.update(deltaTime,scenarioTime,tideHeight,camera.getPosition(),lightLevel);
//std::cout << tideHeight << std::endl;
//update own ship
ownShip.update(deltaTime, scenarioTime, tideHeight, weather);
//Check for collisions
bool collided = checkOwnShipCollision();
bool sunk = checkOwnShipSunk();
//update water position
water.update(tideHeight,camera.getPosition(),light.getLightLevel(), weather);
//Normalise positions if required (More than 2000 metres from origin)
//FIXME: TEMPORARY MODS WITH REALISTICWATERSCENENODE
if(ownShip.getPosition().getLength() > 1000) {
core::vector3df ownShipPos = ownShip.getPosition();
irr::s32 deltaX = -1*(s32)ownShipPos.X;
irr::s32 deltaZ = -1*(s32)ownShipPos.Z;
//Round to nearest 1000 metres - water tile width, to avoid jumps
deltaX = 500.0*Utilities::round(deltaX/500.0);
deltaZ = 500.0*Utilities::round(deltaZ/500.0);
//Move all objects
ownShip.moveNode(deltaX,0,deltaZ);
terrain.moveNode(deltaX,0,deltaZ);
otherShips.moveNode(deltaX,0,deltaZ);
buoys.moveNode(deltaX,0,deltaZ);
landObjects.moveNode(deltaX,0,deltaZ);
landLights.moveNode(deltaX,0,deltaZ);
//Change stored offset
offsetPosition.X -= deltaX;
offsetPosition.Z -= deltaZ;
std::cout << "Normalised, offset X: " << offsetPosition.X << " Z: " << offsetPosition.Z <<std::endl;
}
//update the camera position
camera.update();
//set radar screen position, and update it with a radar image from the radar calculation
radarCalculation.update(radarImage,terrain,ownShip,buoys,otherShips,weather,tideHeight,deltaTime);
radarScreen.update(radarImage);
radarCamera.update();
//check if paused
bool paused = device->getTimer()->getSpeed()==0.0;
//calculate current angular elevation due to pitch and roll in the view direction
irr::f32 lookRadians = irr::core::degToRad(camera.getLook());
irr::f32 elevAngle = -1*ownShip.getPitch()*cos(lookRadians) + ownShip.getRoll()*sin(lookRadians) + camera.getLookUp();
//send data to gui
guiMain->updateGuiData(getLat(), getLong(), ownShip.getHeading(), camera.getLook(), elevAngle, ownShip.getSpeed(), ownShip.getPortEngine(), ownShip.getStbdEngine(), ownShip.getRudder(), ownShip.getDepth(), weather, rainIntensity, radarCalculation.getRangeNm(), radarCalculation.getGain(), radarCalculation.getClutter(), radarCalculation.getRainClutter(), radarCalculation.getEBLBrg(), radarCalculation.getEBLRangeNm(), Utilities::timestampToString(absoluteTime), paused, collided, sunk); //Set GUI heading in degrees and speed (in m/s)
}
bool SimulationModel::checkOwnShipSunk()
{
if(ownShip.isSunk()){
return true;
}
else{
return false;
}
}
bool SimulationModel::checkOwnShipCollision()
{
irr::u32 numberOfOtherShips = otherShips.getNumber();
irr::u32 numberOfBuoys = buoys.getNumber();
irr::core::vector3df thisShipPosition = ownShip.getPosition();
irr::f32 thisShipLength = ownShip.getLength();
irr::f32 thisShipWidth = ownShip.getWidth();
irr::f32 thisShipHeading = ownShip.getHeading();
for (irr::u32 i = 0; i<numberOfOtherShips; i++) {
irr::core::vector3df otherPosition = otherShips.getPosition(i);
irr::f32 otherShipLength = otherShips.getLength(i);
irr::f32 otherShipWidth = otherShips.getWidth(i);
irr::f32 otherShipHeading = otherShips.getHeading(i);
irr::core::vector3df relPosition = otherPosition - thisShipPosition;
irr::f32 distanceToShip = relPosition.getLength();
irr::f32 bearingToOtherShipDeg = irr::core::radToDeg(atan2(relPosition.X, relPosition.Z));
//Bearings relative to ship's head (from this ship and from other)
irr::f32 relativeBearingOwnShip = bearingToOtherShipDeg - thisShipHeading;
irr::f32 relativeBearingOtherShip = 180 + bearingToOtherShipDeg - otherShipHeading;
//Find the minimum distance before a collision occurs
irr::f32 minDistanceOwn = 0.5*fabs(thisShipWidth*sin(irr::core::degToRad(relativeBearingOwnShip))) + 0.5*fabs(thisShipLength*cos(irr::core::degToRad(relativeBearingOwnShip)));
irr::f32 minDistanceOther = 0.5*fabs(otherShipWidth*sin(irr::core::degToRad(relativeBearingOtherShip))) + 0.5*fabs(otherShipLength*cos(irr::core::degToRad(relativeBearingOtherShip)));
irr::f32 minDistance = minDistanceOther + minDistanceOwn;
if (distanceToShip < minDistance) {
return true;
}
}
for (irr::u32 i = 0; i<numberOfBuoys; i++) { //Collision with buoy
irr::core::vector3df otherPosition = buoys.getPosition(i);
irr::core::vector3df relPosition = otherPosition - thisShipPosition;
irr::f32 distanceToBuoy = relPosition.getLength();
irr::f32 bearingToBuoyDeg = irr::core::radToDeg(atan2(relPosition.X, relPosition.Z));
//Bearings relative to ship's head (from this ship and from other)
irr::f32 relativeBearingOwnShip = bearingToBuoyDeg - thisShipHeading;
//Find the minimum distance before a collision occurs
irr::f32 minDistanceOwn = 0.5*fabs(thisShipWidth*sin(irr::core::degToRad(relativeBearingOwnShip))) + 0.5*fabs(thisShipLength*cos(irr::core::degToRad(relativeBearingOwnShip)));
if (distanceToBuoy < minDistanceOwn) {
return true;
}
}
return false; //If no collision has been found
}
void SimulationModel::sinkOwnShip()
{
ownShip.sink();
}