From 740d57a2c478b6f7923ccddeae361fb06863daf2 Mon Sep 17 00:00:00 2001 From: riso <4726939+risostk@users.noreply.github.com> Date: Sun, 16 Feb 2020 02:31:30 -0600 Subject: [PATCH] Show kart direction by an arrow in soccer (#4230) * Show kart direction by an arrow in soccer * bug fix * bug fix * correct grammar --- data/gui/icons/icons-frame_arrow.png | Bin 0 -> 3615 bytes data/shaders/colortexturedquad.vert | 6 +++++- src/graphics/2dutils.cpp | 12 ++++++------ src/states_screens/race_gui.cpp | 20 +++++++++++++++++++- src/states_screens/race_gui_base.cpp | 9 ++++++++- src/tracks/track.hpp | 3 +++ 6 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 data/gui/icons/icons-frame_arrow.png diff --git a/data/gui/icons/icons-frame_arrow.png b/data/gui/icons/icons-frame_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..d7619b4ab92aa07557c1caf9d3ed006bf0d214d3 GIT binary patch literal 3615 zcmV+)4&d>LP)pF8FWQhbW?9;ba!ELWdL_~cP?peYja~^aAhuUa%Y?FJQ@H14XjB- zK~#90?VWqDUE>wNe=Bd1G%v3N6^|e&>aB`|B8p;K6HJk|+ETB0`CH|qt{H}6%komZJXG3VVtHATXWMGPje38?$Q>CF4KvlZ}M*yb*CjkR$+oBDu0-gmX024)IX^q!rL)|KXs`drO0Owlu~mAP}Ls5xxlqRzZy3uFV+L&fXjeB*fjS&;7b**TMN96 zDaLEjzi)`h`$-#8Qw31fZvnRfU#?|4YRFp55LInI{Fg`>fG0&{Qrrt`q5!J8HP-Pb z*W&q2&P);6JFal<3ZSZ|0(X%A9)3CSF>U7F7NB)L?THP=y@6iXR&!v^?MsVwKz|Wg z8ArHV#*Nv4s(uOhJ+{!vk``bFws2aAb^0P~nDo#W*dlrj#;lI}VP^>SOjpbt{#+d4 zTogc6_W&LxoBjM6;6=u?=brbAJbX1kM`WzcU zCSi-bMnp^6 zl#6XhGzCNlJCBmA^WO)~BXoWtpJLNN+N0qrDtyV4t^w{O*}={%;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UrVEeGDj%*-=^7l7AAB#B#mUC}fOPzqJ;iDFmv%T l>>Ob}FfWRZ4g{Ky{{w?)d!rlAp-lh)002ovPDHLkV1mlBotyvw literal 0 HcmV?d00001 diff --git a/data/shaders/colortexturedquad.vert b/data/shaders/colortexturedquad.vert index b1f84264f..9386ce69a 100644 --- a/data/shaders/colortexturedquad.vert +++ b/data/shaders/colortexturedquad.vert @@ -2,6 +2,7 @@ uniform vec2 center; uniform vec2 size; uniform vec2 texcenter; uniform vec2 texsize; +uniform float rotation; #ifdef Explicit_Attrib_Location_Usable layout(location=0) in vec2 Position; @@ -18,7 +19,10 @@ out vec4 col; void main() { + float s = sin(rotation); + float c = cos(rotation); + mat2 m = mat2(c, -s, s, c); col = Color.zyxw; uv = Texcoord * texsize + texcenter; - gl_Position = vec4(Position * size + center, 0., 1.); + gl_Position = vec4(m * Position * size + center, 0., 1.); } diff --git a/src/graphics/2dutils.cpp b/src/graphics/2dutils.cpp index 293191773..48b3955cb 100644 --- a/src/graphics/2dutils.cpp +++ b/src/graphics/2dutils.cpp @@ -109,7 +109,7 @@ public: class ColoredTextureRectShader : public TextureShader + core::vector2df, core::vector2df, float> { public: GLuint m_color_vbo; @@ -119,7 +119,7 @@ public: { loadProgram(OBJECT, GL_VERTEX_SHADER, "colortexturedquad.vert", GL_FRAGMENT_SHADER, "colortexturedquad.frag"); - assignUniforms("center", "size", "texcenter", "texsize"); + assignUniforms("center", "size", "texcenter", "texsize", "rotation"); assignSamplerNames(0, "tex", ST_BILINEAR_FILTERED); @@ -150,7 +150,7 @@ static void drawTexColoredQuad(const video::ITexture *texture, float height, float center_pos_x, float center_pos_y, float tex_center_pos_x, float tex_center_pos_y, float tex_width, - float tex_height) + float tex_height, float rotation) { glBindVertexArray(ColoredTextureRectShader::getInstance()->m_vao); glBindBuffer(GL_ARRAY_BUFFER, @@ -166,7 +166,7 @@ static void drawTexColoredQuad(const video::ITexture *texture, ->setUniforms(core::vector2df(center_pos_x, center_pos_y), core::vector2df(width, height), core::vector2df(tex_center_pos_x, tex_center_pos_y), - core::vector2df(tex_width, tex_height)); + core::vector2df(tex_width, tex_height), rotation); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glBindBuffer(GL_ARRAY_BUFFER, 0); @@ -524,7 +524,7 @@ void draw2DImage(const video::ITexture* texture, { drawTexColoredQuad(texture, colors, width, height, center_pos_x, center_pos_y, tex_center_pos_x, tex_center_pos_y, - tex_width, tex_height); + tex_width, tex_height, rotation); } else { @@ -656,7 +656,7 @@ void draw2DImage(const video::ITexture* texture, { drawTexColoredQuad(texture, colors, width, height, center_pos_x, center_pos_y, tex_center_pos_x, tex_center_pos_y, - tex_width, tex_height); + tex_width, tex_height, 0.0f/*rotation*/); } else { diff --git a/src/states_screens/race_gui.cpp b/src/states_screens/race_gui.cpp index 43ea7f160..4833b0246 100644 --- a/src/states_screens/race_gui.cpp +++ b/src/states_screens/race_gui.cpp @@ -680,7 +680,25 @@ void RaceGUI::drawGlobalMiniMap() const core::rect rect(core::position2d(0,0), m_icons_frame->getSize()); - draw2DImage(m_icons_frame, position, rect, NULL, colors, true); + // show kart direction in soccer + if (soccer_world) + { + // Find the direction a kart is moving in + btTransform trans = kart->getTrans(); + Vec3 direction(trans.getBasis().getColumn(2)); + // Get the rotation to rotate the icon frame + float rotation = atan2f(direction.getZ(),direction.getX()); + if (track->getMinimapInvert()) + { // correct the direction due to invert minimap for blue + rotation = rotation + M_PI; + } + rotation = -1.0f * rotation + 0.25f * M_PI; // icons-frame_arrow.png was rotated by 45 degrees + draw2DImage(m_icons_frame, position, rect, NULL, colors, true, false, rotation); + } + else + { + draw2DImage(m_icons_frame, position, rect, NULL, colors, true); + } } // if isPlayerController draw2DImage(icon, position, source, NULL, NULL, true); diff --git a/src/states_screens/race_gui_base.cpp b/src/states_screens/race_gui_base.cpp index 3e17b5ae3..e19d8d639 100644 --- a/src/states_screens/race_gui_base.cpp +++ b/src/states_screens/race_gui_base.cpp @@ -94,7 +94,14 @@ RaceGUIBase::RaceGUIBase() } //read frame picture for icons in the mini map. - m_icons_frame = irr_driver->getTexture("icons-frame.png"); + if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_SOCCER) + { // show the kart direction in soccer + m_icons_frame = irr_driver->getTexture("icons-frame_arrow.png"); + } + else + { + m_icons_frame = irr_driver->getTexture("icons-frame.png"); + } if (!m_icons_frame) { Log::error("RaceGuiBase", diff --git a/src/tracks/track.hpp b/src/tracks/track.hpp index 4cb71c107..a47f64aa9 100644 --- a/src/tracks/track.hpp +++ b/src/tracks/track.hpp @@ -509,6 +509,9 @@ public: /** Returns if the track is during day time */ const bool getIsDuringDay () const {return m_is_day; } // ------------------------------------------------------------------------ + /** Returns if invert minimap */ + const bool getMinimapInvert () const {return m_minimap_invert_x_z; } + // ------------------------------------------------------------------------ /** Returns the start coordinates for a kart with a given index. * \param index Index of kart ranging from 0 to kart_num-1. */ const btTransform& getStartTransform (unsigned int index) const