Show kart direction by an arrow in soccer (#4230)

* Show kart direction by an arrow in soccer

* bug fix

* bug fix

* correct grammar
This commit is contained in:
riso 2020-02-16 02:31:30 -06:00 committed by GitHub
parent 3df7feb654
commit 740d57a2c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 9 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

@ -2,6 +2,7 @@ uniform vec2 center;
uniform vec2 size; uniform vec2 size;
uniform vec2 texcenter; uniform vec2 texcenter;
uniform vec2 texsize; uniform vec2 texsize;
uniform float rotation;
#ifdef Explicit_Attrib_Location_Usable #ifdef Explicit_Attrib_Location_Usable
layout(location=0) in vec2 Position; layout(location=0) in vec2 Position;
@ -18,7 +19,10 @@ out vec4 col;
void main() void main()
{ {
float s = sin(rotation);
float c = cos(rotation);
mat2 m = mat2(c, -s, s, c);
col = Color.zyxw; col = Color.zyxw;
uv = Texcoord * texsize + texcenter; uv = Texcoord * texsize + texcenter;
gl_Position = vec4(Position * size + center, 0., 1.); gl_Position = vec4(m * Position * size + center, 0., 1.);
} }

View File

@ -109,7 +109,7 @@ public:
class ColoredTextureRectShader : public TextureShader<ColoredTextureRectShader, 1, class ColoredTextureRectShader : public TextureShader<ColoredTextureRectShader, 1,
core::vector2df, core::vector2df, core::vector2df, core::vector2df,
core::vector2df, core::vector2df> core::vector2df, core::vector2df, float>
{ {
public: public:
GLuint m_color_vbo; GLuint m_color_vbo;
@ -119,7 +119,7 @@ public:
{ {
loadProgram(OBJECT, GL_VERTEX_SHADER, "colortexturedquad.vert", loadProgram(OBJECT, GL_VERTEX_SHADER, "colortexturedquad.vert",
GL_FRAGMENT_SHADER, "colortexturedquad.frag"); GL_FRAGMENT_SHADER, "colortexturedquad.frag");
assignUniforms("center", "size", "texcenter", "texsize"); assignUniforms("center", "size", "texcenter", "texsize", "rotation");
assignSamplerNames(0, "tex", ST_BILINEAR_FILTERED); assignSamplerNames(0, "tex", ST_BILINEAR_FILTERED);
@ -150,7 +150,7 @@ static void drawTexColoredQuad(const video::ITexture *texture,
float height, float center_pos_x, float height, float center_pos_x,
float center_pos_y, float tex_center_pos_x, float center_pos_y, float tex_center_pos_x,
float tex_center_pos_y, float tex_width, float tex_center_pos_y, float tex_width,
float tex_height) float tex_height, float rotation)
{ {
glBindVertexArray(ColoredTextureRectShader::getInstance()->m_vao); glBindVertexArray(ColoredTextureRectShader::getInstance()->m_vao);
glBindBuffer(GL_ARRAY_BUFFER, glBindBuffer(GL_ARRAY_BUFFER,
@ -166,7 +166,7 @@ static void drawTexColoredQuad(const video::ITexture *texture,
->setUniforms(core::vector2df(center_pos_x, center_pos_y), ->setUniforms(core::vector2df(center_pos_x, center_pos_y),
core::vector2df(width, height), core::vector2df(width, height),
core::vector2df(tex_center_pos_x, tex_center_pos_y), 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); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0);
@ -524,7 +524,7 @@ void draw2DImage(const video::ITexture* texture,
{ {
drawTexColoredQuad(texture, colors, width, height, center_pos_x, drawTexColoredQuad(texture, colors, width, height, center_pos_x,
center_pos_y, tex_center_pos_x, tex_center_pos_y, center_pos_y, tex_center_pos_x, tex_center_pos_y,
tex_width, tex_height); tex_width, tex_height, rotation);
} }
else else
{ {
@ -656,7 +656,7 @@ void draw2DImage(const video::ITexture* texture,
{ {
drawTexColoredQuad(texture, colors, width, height, center_pos_x, drawTexColoredQuad(texture, colors, width, height, center_pos_x,
center_pos_y, tex_center_pos_x, tex_center_pos_y, center_pos_y, tex_center_pos_x, tex_center_pos_y,
tex_width, tex_height); tex_width, tex_height, 0.0f/*rotation*/);
} }
else else
{ {

View File

@ -680,7 +680,25 @@ void RaceGUI::drawGlobalMiniMap()
const core::rect<s32> rect(core::position2d<s32>(0,0), const core::rect<s32> rect(core::position2d<s32>(0,0),
m_icons_frame->getSize()); 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 } // if isPlayerController
draw2DImage(icon, position, source, NULL, NULL, true); draw2DImage(icon, position, source, NULL, NULL, true);

View File

@ -94,7 +94,14 @@ RaceGUIBase::RaceGUIBase()
} }
//read frame picture for icons in the mini map. //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) if (!m_icons_frame)
{ {
Log::error("RaceGuiBase", Log::error("RaceGuiBase",

View File

@ -509,6 +509,9 @@ public:
/** Returns if the track is during day time */ /** Returns if the track is during day time */
const bool getIsDuringDay () const {return m_is_day; } 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. /** Returns the start coordinates for a kart with a given index.
* \param index Index of kart ranging from 0 to kart_num-1. */ * \param index Index of kart ranging from 0 to kart_num-1. */
const btTransform& getStartTransform (unsigned int index) const const btTransform& getStartTransform (unsigned int index) const