Skip to content

Commit 4872276

Browse files
committed
Invert x-z of position for soccer blue team player
1 parent f124bd9 commit 4872276

File tree

4 files changed

+68
-12
lines changed

4 files changed

+68
-12
lines changed

src/tracks/graph.cpp

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void Graph::cleanupDebugMesh()
120120
/** Creates the actual mesh that is used by createDebugMesh() or makeMiniMap()
121121
*/
122122
void Graph::createMesh(bool show_invisible, bool enable_transparency,
123-
const video::SColor *track_color)
123+
const video::SColor *track_color, bool invert_x_z)
124124
{
125125
#ifndef SERVER_ONLY
126126
// The debug track will not be lighted or culled.
@@ -172,6 +172,18 @@ void Graph::createMesh(bool show_invisible, bool enable_transparency,
172172
differentNodeColor(count, &this_color);
173173
// Transfer the 4 points of the current quad to the list of vertices
174174
m_all_nodes[count]->getVertices(new_v+4*i, this_color);
175+
if (invert_x_z)
176+
{
177+
auto* vptr = new_v + 4 * i;
178+
vptr[0].Pos.X = -vptr[0].Pos.X;
179+
vptr[0].Pos.Z = -vptr[0].Pos.Z;
180+
vptr[1].Pos.X = -vptr[1].Pos.X;
181+
vptr[1].Pos.Z = -vptr[1].Pos.Z;
182+
vptr[2].Pos.X = -vptr[2].Pos.X;
183+
vptr[2].Pos.Z = -vptr[2].Pos.Z;
184+
vptr[3].Pos.X = -vptr[3].Pos.X;
185+
vptr[3].Pos.Z = -vptr[3].Pos.Z;
186+
}
175187

176188
// Set up the indices for the triangles
177189
// (note, afaik with opengl we could use quads directly, but the code
@@ -244,7 +256,7 @@ void Graph::createMesh(bool show_invisible, bool enable_transparency,
244256
/** Creates the actual mesh that is used by createDebugMesh() or makeMiniMap()
245257
*/
246258
void Graph::createMeshSP(bool show_invisible, bool enable_transparency,
247-
const video::SColor *track_color)
259+
const video::SColor *track_color, bool invert_x_z)
248260
{
249261
#ifndef SERVER_ONLY
250262

@@ -294,6 +306,18 @@ void Graph::createMeshSP(bool show_invisible, bool enable_transparency,
294306
differentNodeColor(count, &this_color);
295307
// Transfer the 4 points of the current quad to the list of vertices
296308
m_all_nodes[count]->getSPMVertices(vertices.data() + (4 * i), this_color);
309+
if (invert_x_z)
310+
{
311+
auto* vptr = vertices.data() + (4 * i);
312+
vptr[0].m_position.X = -vptr[0].m_position.X;
313+
vptr[0].m_position.Z = -vptr[0].m_position.Z;
314+
vptr[1].m_position.X = -vptr[1].m_position.X;
315+
vptr[1].m_position.Z = -vptr[1].m_position.Z;
316+
vptr[2].m_position.X = -vptr[2].m_position.X;
317+
vptr[2].m_position.Z = -vptr[2].m_position.Z;
318+
vptr[3].m_position.X = -vptr[3].m_position.X;
319+
vptr[3].m_position.Z = -vptr[3].m_position.Z;
320+
}
297321

298322
// Set up the indices for the triangles
299323
indices[6 * i] = 4 * i + 2; // First triangle: vertex 0, 1, 2
@@ -366,7 +390,8 @@ void Graph::createMeshSP(bool show_invisible, bool enable_transparency,
366390
*/
367391
RenderTarget* Graph::makeMiniMap(const core::dimension2du &dimension,
368392
const std::string &name,
369-
const video::SColor &fill_color)
393+
const video::SColor &fill_color,
394+
bool invert_x_z)
370395
{
371396
// Skip minimap when profiling
372397
if (ProfileWorld::isNoGraphics()) return NULL;
@@ -384,14 +409,14 @@ RenderTarget* Graph::makeMiniMap(const core::dimension2du &dimension,
384409
if (CVS->isGLSL())
385410
{
386411
createMeshSP(/*show_invisible part of the track*/ false,
387-
/*enable_transparency*/ false,
388-
/*track_color*/ &fill_color);
412+
/*enable_transparency*/ false, /*track_color*/&fill_color,
413+
invert_x_z);
389414
}
390415
else
391416
{
392417
createMesh(/*show_invisible part of the track*/ false,
393-
/*enable_transparency*/ false,
394-
/*track_color*/ &fill_color);
418+
/*enable_transparency*/ false, /*track_color*/&fill_color,
419+
invert_x_z);
395420
}
396421
#endif
397422

src/tracks/graph.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,13 @@ class Graph : public NoCopy
9393
// ------------------------------------------------------------------------
9494
void createMesh(bool show_invisible=true,
9595
bool enable_transparency=false,
96-
const video::SColor *track_color=NULL);
96+
const video::SColor *track_color=NULL,
97+
bool invert_x_z = false);
9798
// ------------------------------------------------------------------------
9899
void createMeshSP(bool show_invisible=true,
99100
bool enable_transparency=false,
100-
const video::SColor *track_color=NULL);
101+
const video::SColor *track_color=NULL,
102+
bool invert_x_z = false);
101103
// ------------------------------------------------------------------------
102104
void cleanupDebugMesh();
103105
// ------------------------------------------------------------------------
@@ -143,7 +145,8 @@ class Graph : public NoCopy
143145
// ------------------------------------------------------------------------
144146
RenderTarget* makeMiniMap(const core::dimension2du &dimension,
145147
const std::string &name,
146-
const video::SColor &fill_color);
148+
const video::SColor &fill_color,
149+
bool invert_x_z);
147150
// ------------------------------------------------------------------------
148151
void mapPoint2MiniMap(const Vec3 &xyz, Vec3 *out) const;
149152
// ------------------------------------------------------------------------

src/tracks/track.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ Track::Track(const std::string &filename)
105105
m_magic_number = 0x17AC3802;
106106
#endif
107107

108+
m_minimap_invert_x_z = false;
108109
m_materials_loaded = false;
109110
m_filename = filename;
110111
m_root =
@@ -709,6 +710,21 @@ void Track::startMusic() const
709710
*/
710711
void Track::loadArenaGraph(const XMLNode &node)
711712
{
713+
// Determine if rotate minimap is needed for soccer mode (for blue team)
714+
// Only need to test local player
715+
if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_SOCCER)
716+
{
717+
for (unsigned i = 0; i < race_manager->getNumberOfKarts(); i++)
718+
{
719+
if (race_manager->getKartType(i) != RaceManager::KT_PLAYER)
720+
continue;
721+
if (race_manager->getKartInfo(i).getSoccerTeam() ==
722+
SOCCER_TEAM_BLUE)
723+
m_minimap_invert_x_z = true;
724+
break;
725+
}
726+
}
727+
712728
ArenaGraph* graph = new ArenaGraph(m_root+"navmesh.xml", &node);
713729
Graph::setGraph(graph);
714730

@@ -786,7 +802,15 @@ void Track::loadDriveGraph(unsigned int mode_id, const bool reverse)
786802

787803
void Track::mapPoint2MiniMap(const Vec3 &xyz, Vec3 *draw_at) const
788804
{
789-
Graph::get()->mapPoint2MiniMap(xyz, draw_at);
805+
if (m_minimap_invert_x_z)
806+
{
807+
Vec3 invert = xyz;
808+
invert.setX(-xyz.x());
809+
invert.setZ(-xyz.z());
810+
Graph::get()->mapPoint2MiniMap(invert, draw_at);
811+
}
812+
else
813+
Graph::get()->mapPoint2MiniMap(xyz, draw_at);
790814
draw_at->setX(draw_at->getX() * m_minimap_x_scale);
791815
draw_at->setY(draw_at->getY() * m_minimap_y_scale);
792816
}
@@ -1115,7 +1139,9 @@ void Track::loadMinimap()
11151139
m_mini_map_size = World::getWorld()->getRaceGUI()->getMiniMapSize();
11161140

11171141
//Use twice the size of the rendered minimap to reduce significantly aliasing
1118-
m_render_target = Graph::get()->makeMiniMap(m_mini_map_size*2, "minimap::" + m_ident, video::SColor(127, 255, 255, 255));
1142+
m_render_target = Graph::get()->makeMiniMap(m_mini_map_size * 2,
1143+
"minimap::" + m_ident, video::SColor(127, 255, 255, 255),
1144+
m_minimap_invert_x_z);
11191145
if (!m_render_target) return;
11201146

11211147
core::dimension2du mini_map_texture_size = m_render_target->getTextureSize();

src/tracks/track.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,8 @@ class Track
365365
float m_displacement_speed;
366366
int m_physical_object_uid;
367367

368+
bool m_minimap_invert_x_z;
369+
368370
/** The levels for color correction
369371
* m_color_inlevel(black, gamma, white)
370372
* m_color_outlevel(black, white)*/

0 commit comments

Comments
 (0)