comparison engine/core/util/math/angles.h @ 407:f27880d4c08c

Moved getAngleBetween() form Camera to angles.h and updated it to not use the camera angle in it's calculation. Added camera rotation to the angle calculation for selecting the correct image by angles. Added a call to setRotation() to make sure that instance rotation is valid.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 29 Jan 2010 21:03:51 +0000
parents 90005975cdbb
children 356634098bd9
comparison
equal deleted inserted replaced
406:b50dd16543b2 407:f27880d4c08c
29 29
30 // FIFE includes 30 // FIFE includes
31 // These includes are split up in two parts, separated by one empty line 31 // These includes are split up in two parts, separated by one empty line
32 // First block: files included from the FIFE root src directory 32 // First block: files included from the FIFE root src directory
33 // Second block: files included from the same folder 33 // Second block: files included from the same folder
34 #include "model/structures/location.h"
34 35
35 namespace FIFE { 36 namespace FIFE {
36 typedef std::map<unsigned int, int> type_angle2id; 37 typedef std::map<unsigned int, int> type_angle2id;
37 38
38 /** Returns id for given angle from angle2id map 39 /** Returns id for given angle from angle2id map
39 * in case there are no elements in the map, negative value is returned 40 * in case there are no elements in the map, negative value is returned
40 */ 41 */
41 int getIndexByAngle(int angle, const type_angle2id& angle2id, int& closestMatchingAngle); 42 int getIndexByAngle(int angle, const type_angle2id& angle2id, int& closestMatchingAngle);
43
44 /** Gets angle of vector defined by given locations
45 * @return angle in polar coordinates between the line
46 * defined by the two locations and the horizontal axis (East <-> West)
47 */
48 inline int getAngleBetween(const Location& loc1, const Location& loc2) {
49 ExactModelCoordinate c1 = loc1.getMapCoordinates();
50 ExactModelCoordinate c2 = loc2.getMapCoordinates();
51
52 double dy = (c2.y - c1.y);
53 double dx = (c2.x - c1.x);
54
55 int angle = static_cast<int>(atan2(-dy,dx)*(180.0/M_PI));
56
57 return angle;
58 }
42 } 59 }
43 60
44 #endif 61 #endif