44 #include <OgreVector3.h> 45 #include <OgreQuaternion.h> 47 #include <OgreCamera.h> 48 #include <OgreSceneNode.h> 49 #include <OgreMaterialManager.h> 50 #include <OgreHardwareBufferManager.h> 51 #include <OgreFontManager.h> 58 #define POS_TEX_BINDING 0 59 #define COLOUR_BINDING 1 64 MovableText::MovableText(
const String &caption,
const String &fontName, Real charHeight,
const ColourValue &color)
66 , mType(
"MovableText")
68 , mHorizontalAlignment(H_LEFT)
69 , mVerticalAlignment(V_BELOW)
71 , mCharHeight(charHeight)
76 , mTimeUntilNextToggle(0)
77 , mGlobalTranslation(0.0)
78 , mLocalTranslation(0.0)
85 ss <<
"MovableText" << count++;
99 MaterialManager::getSingletonPtr()->remove(
mpMaterial->getName());
104 if ((Ogre::MaterialManager::getSingletonPtr()->resourceExists(
mName +
"Material")))
106 Ogre::MaterialManager::getSingleton().remove(
mName +
"Material");
113 = (Font *) FontManager::getSingleton().getByName(
mFontName).getPointer();
115 throw Exception(Exception::ERR_ITEM_NOT_FOUND,
"Could not find font " 116 + fontName,
"MovableText::setFontName");
121 MaterialManager::getSingletonPtr()->remove(
mpMaterial->getName());
224 unsigned int vertexCount = 0;
227 std::string::iterator i =
mCaption.begin();
228 std::string::iterator iend =
mCaption.end();
229 for ( ; i != iend; ++i )
231 if ((*i !=
' ') && (*i !=
'\n'))
254 mRenderOp.vertexData->vertexCount = vertexCount;
255 mRenderOp.operationType = RenderOperation::OT_TRIANGLE_LIST;
258 VertexDeclaration *decl =
mRenderOp.vertexData->vertexDeclaration;
259 VertexBufferBinding *bind =
mRenderOp.vertexData->vertexBufferBinding;
263 if (!decl->findElementBySemantic(VES_POSITION))
266 offset += VertexElement::getTypeSize(VET_FLOAT3);
268 if (!decl->findElementBySemantic(VES_TEXTURE_COORDINATES))
270 Ogre::VES_TEXTURE_COORDINATES, 0);
272 HardwareVertexBufferSharedPtr ptbuf =
273 HardwareBufferManager::getSingleton().createVertexBuffer(
276 HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY);
280 if (!decl->findElementBySemantic(VES_DIFFUSE))
283 HardwareVertexBufferSharedPtr cbuf =
284 HardwareBufferManager::getSingleton().createVertexBuffer(
287 HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY);
291 static_cast<float*
> (ptbuf->lock(HardwareBuffer::HBL_DISCARD));
299 float total_width = 0.0f;
300 float current_width = 0.0f;
303 for ( ; i != iend; ++i )
309 if ( current_width > total_width )
311 total_width = current_width;
317 current_width += spaceWidth;
325 if ( current_width > total_width )
327 total_width = current_width;
334 top = total_height * 2;
337 top = 0.5 * total_height * 2;
344 float starting_left = 0.0f;
348 starting_left = 0.0f;
351 starting_left = -total_width / 2.0f;
355 float left = starting_left;
360 Ogre::Vector3
min(9999999.0
f), max(-9999999.0
f), currPos(0.0
f);
361 Ogre::Real maxSquaredRadius = -99999999.0f;
362 float largestWidth = 0.0f;
363 for (i =
mCaption.begin(); i != iend; ++i)
368 for (String::iterator j = i; j != iend && *j !=
'\n'; j++)
380 left = starting_left;
390 currPos = Ogre::Vector3(left, top, 0.0);
391 min.makeFloor(currPos);
392 max.makeCeil(currPos);
393 maxSquaredRadius = std::max(maxSquaredRadius, currPos.squaredLength());
397 Real horiz_height =
mpFont->getGlyphAspectRatio(*i);
399 Ogre::Font::UVRect utmp;
400 utmp =
mpFont->getGlyphTexCoords(*i);
411 currPos = Ogre::Vector3(left, top, 0.0);
413 *pPCBuff++ = currPos.x;
414 *pPCBuff++ = currPos.y;
415 *pPCBuff++ = currPos.z;
422 min.makeFloor(currPos);
423 max.makeCeil(currPos);
424 maxSquaredRadius = std::max(maxSquaredRadius, currPos.squaredLength());
429 currPos = Ogre::Vector3(left, top, 0.0);
430 *pPCBuff++ = currPos.x;
431 *pPCBuff++ = currPos.y;
432 *pPCBuff++ = currPos.z;
437 min.makeFloor(currPos);
438 max.makeCeil(currPos);
439 maxSquaredRadius = std::max(maxSquaredRadius, currPos.squaredLength());
445 currPos = Ogre::Vector3(left, top, 0.0);
446 *pPCBuff++ = currPos.x;
447 *pPCBuff++ = currPos.y;
448 *pPCBuff++ = currPos.z;
454 min.makeFloor(currPos);
455 max.makeCeil(currPos);
456 maxSquaredRadius = std::max(maxSquaredRadius, currPos.squaredLength());
462 currPos = Ogre::Vector3(left, top, 0.0);
463 *pPCBuff++ = currPos.x;
464 *pPCBuff++ = currPos.y;
465 *pPCBuff++ = currPos.z;
469 min.makeFloor(currPos);
470 max.makeCeil(currPos);
471 maxSquaredRadius = std::max(maxSquaredRadius, currPos.squaredLength());
477 currPos = Ogre::Vector3(left, top, 0.0);
478 *pPCBuff++ = currPos.x;
479 *pPCBuff++ = currPos.y;
480 *pPCBuff++ = currPos.z;
484 min.makeFloor(currPos);
485 max.makeCeil(currPos);
486 maxSquaredRadius = std::max(maxSquaredRadius, currPos.squaredLength());
491 currPos = Ogre::Vector3(left, top, 0.0);
492 *pPCBuff++ = currPos.x;
493 *pPCBuff++ = currPos.y;
494 *pPCBuff++ = currPos.z;
498 min.makeFloor(currPos);
499 max.makeCeil(currPos);
500 maxSquaredRadius = std::max(maxSquaredRadius, currPos.squaredLength());
505 float currentWidth = (left + 1) / 2 - 0;
506 if (currentWidth > largestWidth)
507 largestWidth = currentWidth;
513 currPos = Ogre::Vector3(left, top, 0.0);
514 min.makeFloor(currPos);
515 max.makeCeil(currPos);
516 maxSquaredRadius = std::max(maxSquaredRadius, currPos.squaredLength());
522 mAABB = Ogre::AxisAlignedBox(
min, max);
523 mRadius = Ogre::Math::Sqrt(maxSquaredRadius);
538 Root::getSingleton().convertColourValue(
mColor, &color);
539 HardwareVertexBufferSharedPtr vbuf =
541 RGBA *pDest =
static_cast<RGBA*
> (vbuf->lock(HardwareBuffer::HBL_DISCARD));
542 for (
int i = 0; i < (int)
mRenderOp.vertexData->vertexCount; ++i)
551 return const_cast<Quaternion&
> (
mpCam->getDerivedOrientation());
554 #if( (OGRE_VERSION_MAJOR >= 1 && OGRE_VERSION_MINOR >= 6) || OGRE_VERSION_MAJOR >= 2 ) 555 void MovableText::visitRenderables(Ogre::Renderable::Visitor* visitor,
bool debugRenderables)
557 visitor->visit(
this, 0,
false );
564 return mParentNode->_getDerivedPosition();
569 if (this->isVisible() &&
mpCam)
571 Matrix3 rot3x3, scale3x3 = Matrix3::IDENTITY;
574 mpCam->getDerivedOrientation().ToRotationMatrix(rot3x3);
577 Vector3 ppos = mParentNode->_getDerivedPosition() + Vector3::UNIT_Y
582 scale3x3[0][0] = mParentNode->_getDerivedScale().x / 2;
583 scale3x3[1][1] = mParentNode->_getDerivedScale().y / 2;
584 scale3x3[2][2] = mParentNode->_getDerivedScale().z / 2;
587 *xform = (rot3x3 * scale3x3);
588 xform->setTrans(ppos);
594 if (this->isVisible())
611 if (this->isVisible())
618 queue->addRenderable(
this, mRenderQueueID, OGRE_RENDERABLE_DEFAULT_PRIORITY);
void showOnTop(bool show=true)
void setGlobalTranslation(Ogre::Vector3 trans)
void getRenderOperation(Ogre::RenderOperation &op)
Ogre::RenderOperation mRenderOp
Ogre::AxisAlignedBox mAABB
void setCharacterHeight(Ogre::Real height)
void setLocalTranslation(Ogre::Vector3 trans)
const Ogre::Quaternion & getWorldOrientation(void) const
VerticalAlignment mVerticalAlignment
void getWorldTransforms(Ogre::Matrix4 *xform) const
Ogre::Vector3 mGlobalTranslation
HorizontalAlignment mHorizontalAlignment
void _notifyCurrentCamera(Ogre::Camera *cam)
void _updateRenderQueue(Ogre::RenderQueue *queue)
TFSIMD_FORCE_INLINE Vector3()
void setCaption(const Ogre::String &caption)
void setSpaceWidth(Ogre::Real width)
void setTextAlignment(const HorizontalAlignment &horizontalAlignment, const VerticalAlignment &verticalAlignment)
void setLineSpacing(Ogre::Real height)
const Ogre::Vector3 & getWorldPosition(void) const
void setColor(const Ogre::ColourValue &color)
Ogre::Vector3 mLocalTranslation
Ogre::MaterialPtr mpMaterial
void setFontName(const Ogre::String &fontName)