SuperTuxKart
Loading...
Searching...
No Matches
graph.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2016 SuperTuxKart Team
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, Boston, MA 02111-1307, USA.
18
19#ifndef HEADER_GRAPH_HPP
20#define HEADER_GRAPH_HPP
21
22#include "utils/no_copy.hpp"
23#include "utils/vec3.hpp"
24
25#include <dimension2d.h>
26
27#include <memory>
28#include <string>
29#include <vector>
30
31namespace irr
32{
33 namespace scene { class ISceneNode; class IMesh; class IMeshBuffer; }
34 namespace video { class ITexture; struct S3DVertex; class SColor; }
35}
36
37using namespace irr;
38
39class Quad;
40class RenderTarget;
41
52class Graph : public NoCopy
53{
54protected:
55 static Graph* m_graph;
56
57 std::vector<Quad*> m_all_nodes;
58
59 // ------------------------------------------------------------------------
62 void createQuad(const Vec3 &p0, const Vec3 &p1, const Vec3 &p2,
63 const Vec3 &p3, unsigned int node_index,
64 bool invisible, bool ai_ignore, bool is_arena,
65 bool ignore);
66 // ------------------------------------------------------------------------
69
70private:
73 Vec3 m_bb_max;
74
76 int m_bb_nodes[4];
77
79 scene::ISceneNode *m_node;
80
82 scene::IMesh *m_mesh;
83
85 scene::IMeshBuffer *m_mesh_buffer;
86
88 float m_scaling;
89
91 std::unique_ptr<RenderTarget> m_render_target;
92
93 // ------------------------------------------------------------------------
94 void createMesh(bool show_invisible=true,
95 bool enable_transparency=false,
96 const video::SColor *track_color=NULL,
97 bool invert_x_z = false, bool flatten = false);
98 // ------------------------------------------------------------------------
99 void createMeshSP(bool show_invisible=true,
100 bool enable_transparency=false,
101 const video::SColor *track_color=NULL,
102 bool invert_x_z = false);
103 // ------------------------------------------------------------------------
104 void cleanupDebugMesh();
105 // ------------------------------------------------------------------------
106 virtual bool hasLapLine() const = 0;
107 // ------------------------------------------------------------------------
108 virtual void differentNodeColor(int n, video::SColor* c) const = 0;
109
110public:
111 static const int UNKNOWN_SECTOR;
112 // For 2d Quad
113 static const float MIN_HEIGHT_TESTING;
114 static const float MAX_HEIGHT_TESTING;
115 // ------------------------------------------------------------------------
119 static Graph* get() { return m_graph; }
120 // ------------------------------------------------------------------------
122 static void setGraph(Graph* graph)
123 {
124 assert(m_graph == NULL);
125 m_graph = graph;
126 } // setGraph
127 // ------------------------------------------------------------------------
131 static void destroy()
132 {
133 if (m_graph)
134 {
135 delete m_graph;
136 m_graph = NULL;
137 }
138 } // destroy
139 // ------------------------------------------------------------------------
140 Graph();
141 // ------------------------------------------------------------------------
142 virtual ~Graph();
143 // ------------------------------------------------------------------------
144 void createDebugMesh();
145 // ------------------------------------------------------------------------
146 RenderTarget* makeMiniMap(const core::dimension2du &dimension,
147 const std::string &name,
148 const video::SColor &fill_color,
149 bool invert_x_z);
150 // ------------------------------------------------------------------------
151 void mapPoint2MiniMap(const Vec3 &xyz, Vec3 *out) const;
152 // ------------------------------------------------------------------------
153 Quad* getQuad(unsigned int i) const
154 {
155 assert(i < m_all_nodes.size());
156 return m_all_nodes[i];
157 }
158 // ------------------------------------------------------------------------
159 unsigned int getNumNodes() const { return (unsigned int)m_all_nodes.size(); }
160 // ------------------------------------------------------------------------
161 void findRoadSector(const Vec3& XYZ, int *sector,
162 std::vector<int> *all_sectors = NULL,
163 bool ignore_vertical = false) const;
164 // ------------------------------------------------------------------------
165 int findOutOfRoadSector(const Vec3& xyz,
166 const int curr_sector = UNKNOWN_SECTOR,
167 std::vector<int> *all_sectors = NULL,
168 bool ignore_vertical = false) const;
169 // ------------------------------------------------------------------------
170 const Vec3& getBBMin() const { return m_bb_min; }
171 // ------------------------------------------------------------------------
172 const Vec3& getBBMax() const { return m_bb_max; }
173 // ------------------------------------------------------------------------
174 const int* getBBNodes() const { return m_bb_nodes; }
175
176}; // Graph
177
178#endif
This class stores a graph of quads.
Definition: graph.hpp:53
void createMeshSP(bool show_invisible=true, bool enable_transparency=false, const video::SColor *track_color=NULL, bool invert_x_z=false)
Creates the actual mesh that is used by createDebugMesh() or makeMiniMap()
Definition: graph.cpp:292
void createQuad(const Vec3 &p0, const Vec3 &p1, const Vec3 &p2, const Vec3 &p3, unsigned int node_index, bool invisible, bool ai_ignore, bool is_arena, bool ignore)
Factory method to dynamic create 2d / 3d quad for drive and arena graph.
Definition: graph.cpp:598
void findRoadSector(const Vec3 &XYZ, int *sector, std::vector< int > *all_sectors=NULL, bool ignore_vertical=false) const
findRoadSector returns in which sector on the road the position xyz is.
Definition: graph.cpp:667
scene::ISceneNode * m_node
The node of the graph mesh.
Definition: graph.hpp:79
scene::IMeshBuffer * m_mesh_buffer
The actual mesh buffer storing the graph.
Definition: graph.hpp:85
void loadBoundingBoxNodes()
Map 4 bounding box points to 4 closest graph nodes.
Definition: graph.cpp:825
static void destroy()
Cleans up the graph.
Definition: graph.hpp:131
int findOutOfRoadSector(const Vec3 &xyz, const int curr_sector=UNKNOWN_SECTOR, std::vector< int > *all_sectors=NULL, bool ignore_vertical=false) const
findOutOfRoadSector finds the sector where XYZ is, but as it name implies, it is more accurate for th...
Definition: graph.cpp:741
float m_scaling
Scaling for mini map.
Definition: graph.hpp:88
static void setGraph(Graph *graph)
Set the graph (either drive or arena graph for now).
Definition: graph.hpp:122
void createMesh(bool show_invisible=true, bool enable_transparency=false, const video::SColor *track_color=NULL, bool invert_x_z=false, bool flatten=false)
Creates the actual mesh that is used by createDebugMesh() or makeMiniMap()
Definition: graph.cpp:140
void createDebugMesh()
Creates the debug mesh to display the graph on top of the track model.
Definition: graph.cpp:76
scene::IMesh * m_mesh
The mesh of the graph mesh.
Definition: graph.hpp:82
std::unique_ptr< RenderTarget > m_render_target
The render target used for drawing the minimap.
Definition: graph.hpp:91
void mapPoint2MiniMap(const Vec3 &xyz, Vec3 *out) const
Returns the 2d coordinates of a point when drawn on the mini map texture.
Definition: graph.cpp:590
void cleanupDebugMesh()
Cleans up the debug mesh.
Definition: graph.cpp:125
RenderTarget * makeMiniMap(const core::dimension2du &dimension, const std::string &name, const video::SColor &fill_color, bool invert_x_z)
Takes a snapshot of the graph so they can be used as minimap.
Definition: graph.cpp:425
int m_bb_nodes[4]
The 4 closest graph nodes to the bounding box.
Definition: graph.hpp:76
static Graph * get()
Returns the one instance of this object.
Definition: graph.hpp:119
Vec3 m_bb_min
The 2d bounding box, used for hashing.
Definition: graph.hpp:72
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26
Definition: quad.hpp:38
Definition: render_target.hpp:42
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:35