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:
parent
3df7feb654
commit
740d57a2c4
BIN
data/gui/icons/icons-frame_arrow.png
Normal file
BIN
data/gui/icons/icons-frame_arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
@ -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.);
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ public:
|
||||
|
||||
class ColoredTextureRectShader : public TextureShader<ColoredTextureRectShader, 1,
|
||||
core::vector2df, core::vector2df,
|
||||
core::vector2df, core::vector2df>
|
||||
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
|
||||
{
|
||||
|
@ -680,7 +680,25 @@ void RaceGUI::drawGlobalMiniMap()
|
||||
const core::rect<s32> rect(core::position2d<s32>(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);
|
||||
|
@ -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",
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user