New billboard text scene node is almost complete now
This commit is contained in:
parent
2ee9a29e11
commit
fd1bde9eeb
@ -10,18 +10,22 @@
|
|||||||
#include <SMesh.h>
|
#include <SMesh.h>
|
||||||
#include <SMeshBuffer.h>
|
#include <SMeshBuffer.h>
|
||||||
#include <ISceneManager.h>
|
#include <ISceneManager.h>
|
||||||
|
#include <ICameraSceneNode.h>
|
||||||
|
|
||||||
using namespace irr;
|
using namespace irr;
|
||||||
|
|
||||||
STKTextBillboard::STKTextBillboard(core::stringw text, gui::ScalableFont* font,
|
STKTextBillboard::STKTextBillboard(core::stringw text, gui::ScalableFont* font,
|
||||||
const video::SColor& color, irr::scene::ISceneNode* parent,
|
const video::SColor& color_top, const video::SColor& color_bottom,
|
||||||
|
irr::scene::ISceneNode* parent,
|
||||||
irr::scene::ISceneManager* mgr, irr::s32 id,
|
irr::scene::ISceneManager* mgr, irr::s32 id,
|
||||||
const irr::core::vector3df& position, const irr::core::vector3df& size) :
|
const irr::core::vector3df& position, const irr::core::vector3df& size) :
|
||||||
STKMeshSceneNode(new scene::SMesh(),
|
STKMeshSceneNode(new scene::SMesh(),
|
||||||
parent, irr_driver->getSceneManager(), -1,
|
parent, irr_driver->getSceneManager(), -1,
|
||||||
position, core::vector3df(0.0f, 0.0f, 0.0f), size, false)
|
position, core::vector3df(0.0f, 0.0f, 0.0f), size, false)
|
||||||
{
|
{
|
||||||
getTextMesh(text, font, color);
|
m_color_top = color_top;
|
||||||
|
m_color_bottom = color_bottom;
|
||||||
|
getTextMesh(text, font);
|
||||||
createGLMeshes();
|
createGLMeshes();
|
||||||
Mesh->drop();
|
Mesh->drop();
|
||||||
//setAutomaticCulling(0);
|
//setAutomaticCulling(0);
|
||||||
@ -29,12 +33,12 @@ STKTextBillboard::STKTextBillboard(core::stringw text, gui::ScalableFont* font,
|
|||||||
updateAbsolutePosition();
|
updateAbsolutePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
scene::IMesh* STKTextBillboard::getTextMesh(core::stringw text, gui::ScalableFont* font,
|
scene::IMesh* STKTextBillboard::getTextMesh(core::stringw text, gui::ScalableFont* font)
|
||||||
const video::SColor& color)
|
|
||||||
{
|
{
|
||||||
font->doDraw(text, core::rect<s32>(0, 0, 1000, 1000), color, false, false, NULL, this);
|
font->doDraw(text, core::rect<s32>(0, 0, 1000, 1000), video::SColor(255,255,255,255),
|
||||||
|
false, false, NULL, this);
|
||||||
|
|
||||||
const float scale = 0.025f;
|
const float scale = 0.018f;
|
||||||
|
|
||||||
//scene::SMesh* mesh = new scene::SMesh();
|
//scene::SMesh* mesh = new scene::SMesh();
|
||||||
std::map<video::ITexture*, scene::SMeshBuffer*> buffers;
|
std::map<video::ITexture*, scene::SMeshBuffer*> buffers;
|
||||||
@ -56,7 +60,7 @@ scene::IMesh* STKTextBillboard::getTextMesh(core::stringw text, gui::ScalableFon
|
|||||||
max_y = char_max_y;
|
max_y = char_max_y;
|
||||||
}
|
}
|
||||||
float scaled_center_x = (max_x / 2.0f) * scale;
|
float scaled_center_x = (max_x / 2.0f) * scale;
|
||||||
float scaled_y = -max_y * scale;
|
float scaled_y = (max_y / 2.0f) * scale; // -max_y * scale;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < m_chars.size(); i++)
|
for (unsigned int i = 0; i < m_chars.size(); i++)
|
||||||
{
|
{
|
||||||
@ -93,25 +97,25 @@ scene::IMesh* STKTextBillboard::getTextMesh(core::stringw text, gui::ScalableFon
|
|||||||
{
|
{
|
||||||
video::S3DVertex(char_pos.X - scaled_center_x, char_pos.Y - scaled_y, 0.0f,
|
video::S3DVertex(char_pos.X - scaled_center_x, char_pos.Y - scaled_y, 0.0f,
|
||||||
0.0f, 0.0f, 1.0f,
|
0.0f, 0.0f, 1.0f,
|
||||||
m_chars[i].m_colors[0],
|
m_color_bottom,
|
||||||
m_chars[i].m_sourceRect.UpperLeftCorner.X / tex_width,
|
m_chars[i].m_sourceRect.UpperLeftCorner.X / tex_width,
|
||||||
m_chars[i].m_sourceRect.LowerRightCorner.Y / tex_height),
|
m_chars[i].m_sourceRect.LowerRightCorner.Y / tex_height),
|
||||||
|
|
||||||
video::S3DVertex(char_pos2.X - scaled_center_x, char_pos.Y - scaled_y, 0.0f,
|
video::S3DVertex(char_pos2.X - scaled_center_x, char_pos.Y - scaled_y, 0.0f,
|
||||||
0.0f, 0.0f, 1.0f,
|
0.0f, 0.0f, 1.0f,
|
||||||
m_chars[i].m_colors[1],
|
m_color_bottom,
|
||||||
m_chars[i].m_sourceRect.LowerRightCorner.X / tex_width,
|
m_chars[i].m_sourceRect.LowerRightCorner.X / tex_width,
|
||||||
m_chars[i].m_sourceRect.LowerRightCorner.Y / tex_height),
|
m_chars[i].m_sourceRect.LowerRightCorner.Y / tex_height),
|
||||||
|
|
||||||
video::S3DVertex(char_pos2.X - scaled_center_x, char_pos2.Y - scaled_y, 0.0f,
|
video::S3DVertex(char_pos2.X - scaled_center_x, char_pos2.Y - scaled_y, 0.0f,
|
||||||
0.0f, 0.0f, 1.0f,
|
0.0f, 0.0f, 1.0f,
|
||||||
m_chars[i].m_colors[2],
|
m_color_top,
|
||||||
m_chars[i].m_sourceRect.LowerRightCorner.X / tex_width,
|
m_chars[i].m_sourceRect.LowerRightCorner.X / tex_width,
|
||||||
m_chars[i].m_sourceRect.UpperLeftCorner.Y / tex_height),
|
m_chars[i].m_sourceRect.UpperLeftCorner.Y / tex_height),
|
||||||
|
|
||||||
video::S3DVertex(char_pos.X - scaled_center_x, char_pos2.Y - scaled_y, 0.0f,
|
video::S3DVertex(char_pos.X - scaled_center_x, char_pos2.Y - scaled_y, 0.0f,
|
||||||
0.0f, 0.0f, 1.0f,
|
0.0f, 0.0f, 1.0f,
|
||||||
m_chars[i].m_colors[3],
|
m_color_top,
|
||||||
m_chars[i].m_sourceRect.UpperLeftCorner.X / tex_width,
|
m_chars[i].m_sourceRect.UpperLeftCorner.X / tex_width,
|
||||||
m_chars[i].m_sourceRect.UpperLeftCorner.Y / tex_height)
|
m_chars[i].m_sourceRect.UpperLeftCorner.Y / tex_height)
|
||||||
};
|
};
|
||||||
@ -142,6 +146,12 @@ void STKTextBillboard::OnRegisterSceneNode()
|
|||||||
if (IsVisible)
|
if (IsVisible)
|
||||||
{
|
{
|
||||||
SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT);
|
SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT);
|
||||||
|
|
||||||
|
scene::ICameraSceneNode* curr_cam = irr_driver->getSceneManager()->getActiveCamera();
|
||||||
|
core::vector3df cam_pos = curr_cam->getPosition();
|
||||||
|
core::vector3df text_pos = this->getAbsolutePosition();
|
||||||
|
float angle = atan2(text_pos.X - cam_pos.X, text_pos.Z - cam_pos.Z);
|
||||||
|
this->setRotation(core::vector3df(0.0f, angle * 180.0f / M_PI, 0.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
ISceneNode::OnRegisterSceneNode();
|
ISceneNode::OnRegisterSceneNode();
|
||||||
|
@ -15,7 +15,7 @@ public:
|
|||||||
irr::video::ITexture* m_texture;
|
irr::video::ITexture* m_texture;
|
||||||
irr::core::rect<irr::s32> m_destRect;
|
irr::core::rect<irr::s32> m_destRect;
|
||||||
irr::core::rect<irr::s32> m_sourceRect;
|
irr::core::rect<irr::s32> m_sourceRect;
|
||||||
irr::video::SColor m_colors[4];
|
//irr::video::SColor m_colors[4];
|
||||||
|
|
||||||
STKTextBillboardChar(irr::video::ITexture* texture,
|
STKTextBillboardChar(irr::video::ITexture* texture,
|
||||||
const irr::core::rect<irr::s32>& destRect,
|
const irr::core::rect<irr::s32>& destRect,
|
||||||
@ -25,30 +25,33 @@ public:
|
|||||||
m_texture = texture;
|
m_texture = texture;
|
||||||
m_destRect = destRect;
|
m_destRect = destRect;
|
||||||
m_sourceRect = sourceRect;
|
m_sourceRect = sourceRect;
|
||||||
if (colors == NULL)
|
//if (colors == NULL)
|
||||||
{
|
//{
|
||||||
m_colors[0] = m_colors[1] = m_colors[2] = m_colors[3] = NULL;
|
// m_colors[0] = m_colors[1] = m_colors[2] = m_colors[3] = NULL;
|
||||||
}
|
//}
|
||||||
else
|
//else
|
||||||
{
|
//{
|
||||||
m_colors[0] = colors[0];
|
// m_colors[0] = colors[0];
|
||||||
m_colors[1] = colors[1];
|
// m_colors[1] = colors[1];
|
||||||
m_colors[2] = colors[2];
|
// m_colors[2] = colors[2];
|
||||||
m_colors[3] = colors[3];
|
// m_colors[3] = colors[3];
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class STKTextBillboard : public STKMeshSceneNode, irr::gui::FontCharCollector
|
class STKTextBillboard : public STKMeshSceneNode, irr::gui::FontCharCollector
|
||||||
{
|
{
|
||||||
std::vector<STKTextBillboardChar> m_chars;
|
std::vector<STKTextBillboardChar> m_chars;
|
||||||
|
irr::video::SColor m_color_top;
|
||||||
|
irr::video::SColor m_color_bottom;
|
||||||
|
|
||||||
irr::scene::IMesh* getTextMesh(irr::core::stringw text, gui::ScalableFont* font,
|
irr::scene::IMesh* getTextMesh(irr::core::stringw text, gui::ScalableFont* font);
|
||||||
const irr::video::SColor& color);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
STKTextBillboard(irr::core::stringw text, irr::gui::ScalableFont* font,
|
STKTextBillboard(irr::core::stringw text, irr::gui::ScalableFont* font,
|
||||||
const irr::video::SColor& color, irr::scene::ISceneNode* parent,
|
const irr::video::SColor& color_top,
|
||||||
|
const irr::video::SColor& color_bottom,
|
||||||
|
irr::scene::ISceneNode* parent,
|
||||||
irr::scene::ISceneManager* mgr, irr::s32 id,
|
irr::scene::ISceneManager* mgr, irr::s32 id,
|
||||||
const irr::core::vector3df& position,
|
const irr::core::vector3df& position,
|
||||||
const irr::core::vector3df& size);
|
const irr::core::vector3df& size);
|
||||||
|
@ -2604,12 +2604,30 @@ void Kart::setOnScreenText(const wchar_t *text)
|
|||||||
// is started without splash screen (since "Loading" is shown even in this
|
// is started without splash screen (since "Loading" is shown even in this
|
||||||
// case). A smaller font would be better
|
// case). A smaller font would be better
|
||||||
|
|
||||||
// TODO: memory management?
|
if (irr_driver->isGLSL())
|
||||||
|
{
|
||||||
gui::ScalableFont* font = GUIEngine::getFont() ? GUIEngine::getFont() : GUIEngine::getTitleFont();
|
gui::ScalableFont* font = GUIEngine::getFont() ? GUIEngine::getFont() : GUIEngine::getTitleFont();
|
||||||
STKTextBillboard* tb = new STKTextBillboard(text, font, video::SColor(255, 255, 225, 255),
|
STKTextBillboard* tb = new STKTextBillboard(text, font,
|
||||||
|
video::SColor(255, 255, 225, 0),
|
||||||
|
video::SColor(255, 255, 89, 0),
|
||||||
getNode(), irr_driver->getSceneManager(), -1,
|
getNode(), irr_driver->getSceneManager(), -1,
|
||||||
core::vector3df(0.f, 0.0f, 0.0f),
|
core::vector3df(0.0f, 1.5f, 0.0f),
|
||||||
core::vector3df(1.0f, 1.0f, 1.0f));
|
core::vector3df(1.0f, 1.0f, 1.0f));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scene::ISceneManager* sm = irr_driver->getSceneManager();
|
||||||
|
sm->addBillboardTextSceneNode(GUIEngine::getFont() ? GUIEngine::getFont()
|
||||||
|
: GUIEngine::getTitleFont(),
|
||||||
|
text,
|
||||||
|
getNode(),
|
||||||
|
core::dimension2df(textsize.Width/55.0f,
|
||||||
|
textsize.Height/55.0f),
|
||||||
|
core::vector3df(0.0f, 1.5f, 0.0f),
|
||||||
|
-1, // id
|
||||||
|
video::SColor(255, 255, 225, 0),
|
||||||
|
video::SColor(255, 255, 89, 0));
|
||||||
|
}
|
||||||
|
|
||||||
// No need to store the reference to the billboard scene node:
|
// No need to store the reference to the billboard scene node:
|
||||||
// It has one reference to the parent, and will get deleted
|
// It has one reference to the parent, and will get deleted
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
#include "graphics/particle_emitter.hpp"
|
#include "graphics/particle_emitter.hpp"
|
||||||
#include "graphics/particle_kind.hpp"
|
#include "graphics/particle_kind.hpp"
|
||||||
#include "graphics/particle_kind_manager.hpp"
|
#include "graphics/particle_kind_manager.hpp"
|
||||||
|
#include "graphics/stk_text_billboard.hpp"
|
||||||
#include "guiengine/scalable_font.hpp"
|
#include "guiengine/scalable_font.hpp"
|
||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
#include "io/xml_node.hpp"
|
#include "io/xml_node.hpp"
|
||||||
@ -1102,19 +1103,33 @@ bool Track::loadMainTrack(const XMLNode &root)
|
|||||||
|
|
||||||
assert(GUIEngine::getHighresDigitFont() != NULL);
|
assert(GUIEngine::getHighresDigitFont() != NULL);
|
||||||
|
|
||||||
// TODO: Add support in the engine for BillboardText or find a replacement
|
if (irr_driver->isGLSL())
|
||||||
/* scene::ISceneManager* sm = irr_driver->getSceneManager();
|
{
|
||||||
|
gui::ScalableFont* font = GUIEngine::getHighresDigitFont();
|
||||||
|
STKTextBillboard* tb = new STKTextBillboard(msg.c_str(), font,
|
||||||
|
video::SColor(255, 255, 225, 0),
|
||||||
|
video::SColor(255, 255, 89, 0),
|
||||||
|
irr_driver->getSceneManager()->getRootSceneNode(),
|
||||||
|
irr_driver->getSceneManager(), -1, xyz,
|
||||||
|
core::vector3df(1.5f, 1.5f, 1.5f));
|
||||||
|
m_all_nodes.push_back(tb);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scene::ISceneManager* sm = irr_driver->getSceneManager();
|
||||||
scene::ISceneNode* sn =
|
scene::ISceneNode* sn =
|
||||||
sm->addBillboardTextSceneNode(GUIEngine::getHighresDigitFont(),
|
sm->addBillboardTextSceneNode(GUIEngine::getHighresDigitFont(),
|
||||||
msg.c_str(),
|
msg.c_str(),
|
||||||
NULL,
|
NULL,
|
||||||
core::dimension2df(textsize.Width/45.0f,
|
core::dimension2df(textsize.Width / 35.0f,
|
||||||
textsize.Height/45.0f),
|
textsize.Height / 35.0f),
|
||||||
xyz,
|
xyz,
|
||||||
-1, // id
|
-1, // id
|
||||||
video::SColor(255, 255, 225, 0),
|
video::SColor(255, 255, 225, 0),
|
||||||
video::SColor(255, 255, 89, 0));
|
video::SColor(255, 255, 89, 0));
|
||||||
m_all_nodes.push_back(sn);*/
|
m_all_nodes.push_back(sn);
|
||||||
|
}
|
||||||
|
|
||||||
if (!shown) continue;
|
if (!shown) continue;
|
||||||
}
|
}
|
||||||
else if (condition == "allchallenges")
|
else if (condition == "allchallenges")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user