File: coord.cpp

package info (click to toggle)
openssn 1.4-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 7,340 kB
  • sloc: cpp: 10,973; makefile: 80
file content (129 lines) | stat: -rw-r--r-- 4,321 bytes parent folder | download | duplicates (3)
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
/***************************************************************************
                          coord.cpp  -  description
                             -------------------
    begin                : Sat Mar 16 2002
    copyright            : (C) 2002 by Michael Bridak
    email                : michael.bridak@verizon.net
$Id: coord.cpp,v 1.7 2003/05/20 17:36:04 mbridak Exp $
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License.     *
 *    .                                   *
 *                                                                         *
 ***************************************************************************/

#include "coord.h"

Coord::Coord(){
}
Coord::~Coord(){
}

void Coord::UpdateLatLon()
{
	//procedure to update the latitude and longitude of a moving object.
	//This is what actually moves an object.

	float amountofchange = 0;
	float LongitudePercent = 0;
	float LatitudePercent = 0;
	LatLonPercent(Heading, LongitudePercent, LatitudePercent);
	amountofchange = (Speed * 0.555) * LongitudePercent;
	if ((Heading > 270) || (Heading < 90)){
		Lon_TotalYards = Lon_TotalYards + amountofchange;
	}
	if ((Heading < 270) && (Heading > 90)){
		Lon_TotalYards = Lon_TotalYards - amountofchange;
		// if (Lon_TotalYards < 0){
		//	Lon_TotalYards = 0;
		// }
	}
	amountofchange = (Speed * 0.555) * LatitudePercent;
	if ((Heading <= 359) && (Heading > 180)){
		Lat_TotalYards = Lat_TotalYards + amountofchange;
	}
	if ((Heading > 0) && (Heading < 180)){
		Lat_TotalYards = Lat_TotalYards - amountofchange;
		// if (Lat_TotalYards < 0){
		//	Lat_TotalYards = 0;
		// }
	}

        // Important, we need to keep the ships on the map.
        // The map is in the upp-erleft corner of the quad so
        // higher numbers are up and to the left.
        if (Lon_TotalYards < MAP_MIN)
        {
            Lon_TotalYards = MAP_MIN;
            Heading = 0;
        }
        else if (Lon_TotalYards > MAP_MAX)
        {
             Lon_TotalYards = MAP_MAX;
             Heading = 180;
        }
        if (Lat_TotalYards < MAP_MIN)
        {
            Lat_TotalYards = MAP_MIN;
            Heading = 270;
        }
        else if (Lat_TotalYards > MAP_MAX)
        {
            Lat_TotalYards = MAP_MAX;
            Heading = 90;
        }
 
        
/*
	Lon_Degrees = (int)Lon_TotalYards / 120000;
	Lon_Minutes = ((int)Lon_TotalYards - (Lon_Degrees *120000)) / 2000;
	Lon_Seconds = Lon_TotalYards - (Lon_Degrees * 120000) - (Lon_Minutes * 2000) / 33.33;
	Lon_SubSeconds = Lon_TotalYards - (Lon_Degrees * 120000) - (Lon_Minutes * 2000) - (Lon_Seconds * 33.33) / 0.555;

	Lat_Degrees = (int)Lat_TotalYards / 120000;
	Lat_Minutes = ((int)Lat_TotalYards - (Lat_Degrees *120000)) / 2000;
	Lat_Seconds = Lat_TotalYards - (Lat_Degrees * 120000) - (Lat_Minutes * 2000) / 33.33;
	Lat_SubSeconds = Lat_TotalYards - (Lat_Degrees * 120000) - (Lat_Minutes * 2000) - (Lat_Seconds * 33.33) / 0.555;
*/

}

void Coord::LatLonPercent(float heading, float &lonpercent, float &latpercent)
{
	//Calculate the % of change of Latitude VS Longitude based on heading"
	float llb=0;
	if ((heading < 90) &&  (heading > 0)){
		latpercent = (1.1111111111 * heading);
		lonpercent = (100.0 - latpercent);
	}
	if ((heading > 90) && (heading < 180)){
		llb = (heading - 90.0);
		lonpercent = (1.1111111111 * llb);
		latpercent = (100.0 - lonpercent);
	}
	if ((heading > 180) && (heading < 270)){
		llb = (heading - 180.0);
		latpercent = (1.1111111111 * llb);
		lonpercent = (100.0 - latpercent);
	}
	if ((heading > 270) && (heading < 360)){
		llb = (heading - 270.0);
		lonpercent = (1.1111111111 * llb);
		latpercent = (100.0 - lonpercent);
	}
	if ((heading == 0) || (heading == 360) || (heading == 180)){
		lonpercent = 100.0;
		latpercent = 0.0;
	}
	if ((heading == 270) || (heading == 90)){
		latpercent = 100.0;
		lonpercent = 0.0;
	}

	lonpercent = lonpercent / 100.0;
	latpercent = latpercent / 100.0;
}