SuperTuxKart
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | Private Attributes | List of all members
Graph Class Referenceabstract

This class stores a graph of quads. More...

#include <graph.hpp>

Inheritance diagram for Graph:
Inheritance graph
[legend]

Public Member Functions

void createDebugMesh ()
 Creates the debug mesh to display the graph on top of the track model.
 
RenderTargetmakeMiniMap (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.
 
void mapPoint2MiniMap (const Vec3 &xyz, Vec3 *out) const
 Returns the 2d coordinates of a point when drawn on the mini map texture.
 
QuadgetQuad (unsigned int i) const
 
unsigned int getNumNodes () const
 
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.
 
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 the outside of the track than the inside, and for STK's needs the accuracy on top of the track is unacceptable; but if this was a 2D function, the accuracy for out of road sectors would be perfect.
 
const Vec3getBBMin () const
 
const Vec3getBBMax () const
 
const int * getBBNodes () const
 

Static Public Member Functions

static Graphget ()
 Returns the one instance of this object.
 
static void setGraph (Graph *graph)
 Set the graph (either drive or arena graph for now).
 
static void destroy ()
 Cleans up the graph.
 

Static Public Attributes

static const int UNKNOWN_SECTOR = -1
 
static const float MIN_HEIGHT_TESTING = -1.0f
 
static const float MAX_HEIGHT_TESTING = 5.0f
 

Protected Member Functions

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.
 
void loadBoundingBoxNodes ()
 Map 4 bounding box points to 4 closest graph nodes.
 

Protected Attributes

std::vector< Quad * > m_all_nodes
 

Static Protected Attributes

static Graphm_graph = NULL
 

Private Member Functions

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()
 
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()
 
void cleanupDebugMesh ()
 Cleans up the debug mesh.
 
virtual bool hasLapLine () const =0
 
virtual void differentNodeColor (int n, video::SColor *c) const =0
 

Private Attributes

Vec3 m_bb_min
 The 2d bounding box, used for hashing.
 
Vec3 m_bb_max
 
int m_bb_nodes [4]
 The 4 closest graph nodes to the bounding box.
 
scene::ISceneNode * m_node
 The node of the graph mesh.
 
scene::IMesh * m_mesh
 The mesh of the graph mesh.
 
scene::IMeshBuffer * m_mesh_buffer
 The actual mesh buffer storing the graph.
 
float m_scaling
 Scaling for mini map.
 
std::unique_ptr< RenderTargetm_render_target
 The render target used for drawing the minimap.
 

Detailed Description

This class stores a graph of quads.

It uses a 'simplified singleton' design pattern: it has a static create function to create exactly instance, a destroy function, and a get function (that does not have the side effect of the 'normal singleton' design pattern to create an instance). Besides saving on the if statement in get(), this is necessary since certain race modes might not have a quad graph at all (e.g. arena without navmesh). So get() returns NULL in this case, and this is tested where necessary.

Member Function Documentation

◆ destroy()

static void Graph::destroy ( )
inlinestatic

Cleans up the graph.

It is possible that this function is called even if no instance exists (e.g. arena without navmesh). So it is not an error if there is no instance.

◆ findOutOfRoadSector()

int Graph::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 the outside of the track than the inside, and for STK's needs the accuracy on top of the track is unacceptable; but if this was a 2D function, the accuracy for out of road sectors would be perfect.

To find the sector we look for the closest line segment from the right and left drivelines, and the number of that segment will be the sector.

The SIDE argument is used to speed up the function only; if we know that XYZ is on the left or right side of the track, we know that the closest driveline must be the one that matches that condition. In reality, the side used in STK is the one from the previous frame, but in order to move from one side to another a point would go through the middle, that is handled by findRoadSector() which doesn't has speed ups based on the side.

NOTE: This method of finding the sector outside of the road is not perfect: if two line segments have a similar altitude (but enough to let a kart get through) and they are very close on a 2D system, if a kart is on the air it could be closer to the top line segment even if it is supposed to be on the sector of the lower line segment. Probably the best solution would be to construct a quad that reaches until the next higher overlapping line segment, and find the closest one to XYZ.

◆ findRoadSector()

void Graph::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.

If xyz is not on top of the road, it sets UNKNOWN_SECTOR as sector.

Parameters
xyzPosition for which the segment should be determined.
sectorContains the previous sector (as a shortcut, since usually the sector is the same as the last one), and on return the result
all_sectorsIf this is not NULL, it is a list of all sectors to test. This is used by the AI to make sure that it ends up on the selected way in case of a branch, and also to make sure that it doesn't skip e.g. a loop (see explanation below for details).

◆ get()

static Graph * Graph::get ( )
inlinestatic

Returns the one instance of this object.

It is possible that there is no instance created (e.g. arena without navmesh) so we don't assert that an instance exist.

◆ mapPoint2MiniMap()

void Graph::mapPoint2MiniMap ( const Vec3 xyz,
Vec3 draw_at 
) const

Returns the 2d coordinates of a point when drawn on the mini map texture.

Parameters
xyzCoordinates of the point to map.
draw_atThe coordinates in pixel on the mini map of the point, only the first two coordinates will be used.

The documentation for this class was generated from the following files: