SuperTuxKart
Loading...
Searching...
No Matches
drive_node.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2009-2015 Joerg Henrichs
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License
7// as published by the Free Software Foundation; either version 3
8// of the License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place - Suite 330, B
18
19#ifndef HEADER_DRIVE_NODE_HPP
20#define HEADER_DRIVE_NODE_HPP
21
22#include <vector>
23
24#include "tracks/quad.hpp"
25
31class DriveNode : public Quad
32{
33public:
37 enum DirectionType {DIR_STRAIGHT, DIR_LEFT, DIR_RIGHT,
38 DIR_UNDEFINED};
39protected:
42
45
48
49private:
52
54 std::vector<int> m_successor_nodes;
55
57 std::vector<int> m_predecessor_nodes;
58
60 std::vector<float> m_distance_to_next;
61
63 std::vector<float> m_angle_to_next;
64
67 float m_width;
68
71
72 typedef std::vector<int> PathToNodeVector;
77 PathToNodeVector m_path_to_node;
78
80 std::vector<DirectionType> m_direction;
81
86 std::vector<unsigned int> m_last_index_same_direction;
87
91
97 std::vector< int > m_checkline_requirements;
98
99
100 // ------------------------------------------------------------------------
101 void markAllSuccessorsToUse(unsigned int n,
102 PathToNodeVector *m_path_to_node);
103
104public:
105 DriveNode(const Vec3 &p0, const Vec3 &p1, const Vec3 &p2,
106 const Vec3 &p3, const Vec3 &normal,
107 unsigned int node_index, bool invisible,
108 bool ai_ignore, bool ignored);
109 // ------------------------------------------------------------------------
110 virtual ~DriveNode() {}
111 // ------------------------------------------------------------------------
112 void addSuccessor (unsigned int to);
113 // ------------------------------------------------------------------------
114 void setupPathsToNode();
115 // ------------------------------------------------------------------------
116 void setChecklineRequirements(int latest_checkline);
117 // ------------------------------------------------------------------------
118 void setDirectionData(unsigned int successor, DirectionType dir,
119 unsigned int last_node_index);
120 // ------------------------------------------------------------------------
122 unsigned int getNumberOfSuccessors() const
123 { return (unsigned int)m_successor_nodes.size(); }
124 // ------------------------------------------------------------------------
126 unsigned int getSuccessor(unsigned int i) const
127 { return m_successor_nodes[i]; }
128 // ------------------------------------------------------------------------
130 unsigned int getNumberOfPredecessors() const
131 { return (unsigned int)m_predecessor_nodes.size(); }
132 // ------------------------------------------------------------------------
136 int getPredecessor(unsigned int i) const { return m_predecessor_nodes[i]; }
137 // ------------------------------------------------------------------------
139 float getDistanceToSuccessor(unsigned int j) const
140 { return m_distance_to_next[j]; }
141 // ------------------------------------------------------------------------
143 float getAngleToSuccessor(unsigned int j) const
144 { return m_angle_to_next[j]; }
145 // ------------------------------------------------------------------------
148 { return m_distance_from_start; }
149 // ------------------------------------------------------------------------
152 // ------------------------------------------------------------------------
154 float getPathWidth() const { return m_width; }
155 // ------------------------------------------------------------------------
157 const Vec3& getLowerCenter() const { return m_lower_center; }
158 // ------------------------------------------------------------------------
160 const Vec3& getUpperCenter() const { return m_upper_center; }
161 // ------------------------------------------------------------------------
163 float getNodeLength() const
164 { return (m_lower_center-m_upper_center).length(); }
165 // ------------------------------------------------------------------------
166 bool ignoreSuccessorForAI(unsigned int i) const;
167 // ------------------------------------------------------------------------
172 int getSuccessorToReach(unsigned int n)
173 {
174 // If we have a path to node vector, use its information, otherwise
175 // (i.e. there is only one successor anyway) use this one successor.
176 return m_path_to_node.size()>0 ? m_path_to_node[n] : 0;
177 } // getSuccesorToReach
178 // ------------------------------------------------------------------------
180 const std::vector<int>& getChecklineRequirements() const
181 { return m_checkline_requirements; }
182 // ------------------------------------------------------------------------
184 void getDirectionData(unsigned int succ, DirectionType *dir,
185 unsigned int *last) const
186 {
187 *dir = m_direction[succ]; *last = m_last_index_same_direction[succ];
188 }
189 // ------------------------------------------------------------------------
191 const Vec3 &getRightUnitVector() const { return m_right_unit_vector; }
192 // ------------------------------------------------------------------------
194 bool letAIIgnore() const { return m_ai_ignore; }
195 // ------------------------------------------------------------------------
196 virtual void getDistances(const Vec3 &xyz, Vec3 *result) const = 0;
197
198}; // DriveNode
199
200#endif
This class stores a node of the drive graph, i.e.
Definition: drive_node.hpp:32
const Vec3 & getUpperCenter() const
Returns the center point of the upper edge of this drive node.
Definition: drive_node.hpp:160
float m_width
Width of the track, which is the average of the width at the beginning and at the end.
Definition: drive_node.hpp:67
float getDistanceToSuccessor(unsigned int j) const
Returns the distance to the j-th.
Definition: drive_node.hpp:139
Vec3 m_lower_center
Lower center point of the drive node.
Definition: drive_node.hpp:41
bool m_ai_ignore
Set to true if this drive node should not be used by the AI.
Definition: drive_node.hpp:51
float m_distance_from_start
Distance from the start to the beginning of the drive node.
Definition: drive_node.hpp:47
const Vec3 & getRightUnitVector() const
Returns a unit vector pointing to the right side of the quad.
Definition: drive_node.hpp:191
unsigned int getSuccessor(unsigned int i) const
Returns the i-th successor node.
Definition: drive_node.hpp:126
PathToNodeVector m_path_to_node
This vector is only used if the drive node has more than one successor.
Definition: drive_node.hpp:77
const std::vector< int > & getChecklineRequirements() const
Returns the checkline requirements of this drive node.
Definition: drive_node.hpp:180
float getAngleToSuccessor(unsigned int j) const
Returns the angle from this node to the j-th.
Definition: drive_node.hpp:143
Vec3 m_center_to_right
A vector from the center of the quad to the right edge.
Definition: drive_node.hpp:70
std::vector< unsigned int > m_last_index_same_direction
Stores for each successor the index of the last drive node that has the same direction (i....
Definition: drive_node.hpp:86
Vec3 m_upper_center
Upper center point of the drive node.
Definition: drive_node.hpp:44
std::vector< int > m_predecessor_nodes
The list of predecessors of a node.
Definition: drive_node.hpp:57
std::vector< DirectionType > m_direction
The direction for each of the successors.
Definition: drive_node.hpp:80
bool letAIIgnore() const
True if this node should be ignored by the AI.
Definition: drive_node.hpp:194
int getPredecessor(unsigned int i) const
Returns a predecessor for this node.
Definition: drive_node.hpp:136
void addSuccessor(unsigned int to)
Adds a successor to a node.
Definition: drive_node.cpp:67
std::vector< int > m_checkline_requirements
Sets of checklines you should have activated when you are driving on this node (there is a possibilit...
Definition: drive_node.hpp:97
bool ignoreSuccessorForAI(unsigned int i) const
Returns true if the index-successor of this node is one that the AI is allowed to use.
Definition: drive_node.cpp:176
float getDistanceFromStart() const
Returns the distance from start.
Definition: drive_node.hpp:147
float getPathWidth() const
Returns the width of the part for this quad.
Definition: drive_node.hpp:154
float getNodeLength() const
Returns the length of the quad of this node.
Definition: drive_node.hpp:163
DirectionType
To indiciate in which direction the track is going: straight, left, right.
Definition: drive_node.hpp:37
std::vector< float > m_angle_to_next
The angle of the line from this node to each neighbour.
Definition: drive_node.hpp:63
unsigned int getNumberOfPredecessors() const
Returns the number of predecessors.
Definition: drive_node.hpp:130
void markAllSuccessorsToUse(unsigned int n, PathToNodeVector *m_path_to_node)
This function marks that the successor n should be used to reach this node.
Definition: drive_node.cpp:138
void getDirectionData(unsigned int succ, DirectionType *dir, unsigned int *last) const
Returns the direction in which the successor n is.
Definition: drive_node.hpp:184
std::vector< int > m_successor_nodes
The list of successor drive nodes.
Definition: drive_node.hpp:54
void setupPathsToNode()
If this node has more than one successor, it will set up a vector that contains the direction to use ...
Definition: drive_node.cpp:92
unsigned int getNumberOfSuccessors() const
Returns the number of successors.
Definition: drive_node.hpp:122
void setDistanceFromStart(float d)
Sets the distance from start for this node.
Definition: drive_node.hpp:151
Vec3 m_right_unit_vector
A unit vector pointing from the center to the right side, orthogonal to the driving direction.
Definition: drive_node.hpp:90
const Vec3 & getLowerCenter() const
Returns the center point of the lower edge of this drive node.
Definition: drive_node.hpp:157
int getSuccessorToReach(unsigned int n)
Returns which successor node to use in order to be able to reach the given node n.
Definition: drive_node.hpp:172
std::vector< float > m_distance_to_next
The distance to each of the successors.
Definition: drive_node.hpp:60
Definition: quad.hpp:38
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:35