mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 23:53:52 +00:00
Render cell markers
Adds rendering of cell markers. Markers are displayed at center of cell and contain cell's coordinates.
This commit is contained in:
parent
40f4a9811e
commit
a34a08c212
5 changed files with 125 additions and 2 deletions
|
@ -90,7 +90,7 @@ opencs_units (view/render
|
||||||
|
|
||||||
opencs_units_noqt (view/render
|
opencs_units_noqt (view/render
|
||||||
lighting lightingday lightingnight
|
lighting lightingday lightingnight
|
||||||
lightingbright object cell terrainstorage tagbase cellarrow
|
lightingbright object cell terrainstorage tagbase cellarrow cellmarker
|
||||||
)
|
)
|
||||||
|
|
||||||
opencs_hdrs_noqt (view/render
|
opencs_hdrs_noqt (view/render
|
||||||
|
@ -192,6 +192,7 @@ endif(APPLE)
|
||||||
target_link_libraries(openmw-cs
|
target_link_libraries(openmw-cs
|
||||||
${OSG_LIBRARIES}
|
${OSG_LIBRARIES}
|
||||||
${OPENTHREADS_LIBRARIES}
|
${OPENTHREADS_LIBRARIES}
|
||||||
|
${OSGTEXT_LIBRARIES}
|
||||||
${OSGUTIL_LIBRARIES}
|
${OSGUTIL_LIBRARIES}
|
||||||
${OSGVIEWER_LIBRARIES}
|
${OSGVIEWER_LIBRARIES}
|
||||||
${OSGGA_LIBRARIES}
|
${OSGGA_LIBRARIES}
|
||||||
|
|
|
@ -70,6 +70,8 @@ CSVRender::Cell::Cell (CSMWorld::Data& data, osg::Group* rootNode, const std::st
|
||||||
mCellNode = new osg::Group;
|
mCellNode = new osg::Group;
|
||||||
rootNode->addChild(mCellNode);
|
rootNode->addChild(mCellNode);
|
||||||
|
|
||||||
|
setCellMarker();
|
||||||
|
|
||||||
if (!mDeleted)
|
if (!mDeleted)
|
||||||
{
|
{
|
||||||
CSMWorld::IdTable& references = dynamic_cast<CSMWorld::IdTable&> (
|
CSMWorld::IdTable& references = dynamic_cast<CSMWorld::IdTable&> (
|
||||||
|
@ -303,6 +305,11 @@ void CSVRender::Cell::setCellArrows (int mask)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSVRender::Cell::setCellMarker()
|
||||||
|
{
|
||||||
|
mCellMarker.reset(new CellMarker(mCellNode, mCoordinates));
|
||||||
|
}
|
||||||
|
|
||||||
CSMWorld::CellCoordinates CSVRender::Cell::getCoordinates() const
|
CSMWorld::CellCoordinates CSVRender::Cell::getCoordinates() const
|
||||||
{
|
{
|
||||||
return mCoordinates;
|
return mCoordinates;
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#include "object.hpp"
|
#include "object.hpp"
|
||||||
#include "cellarrow.hpp"
|
#include "cellarrow.hpp"
|
||||||
|
#include "cellmarker.hpp"
|
||||||
|
|
||||||
class QModelIndex;
|
class QModelIndex;
|
||||||
|
|
||||||
|
@ -42,6 +43,7 @@ namespace CSVRender
|
||||||
std::auto_ptr<Terrain::TerrainGrid> mTerrain;
|
std::auto_ptr<Terrain::TerrainGrid> mTerrain;
|
||||||
CSMWorld::CellCoordinates mCoordinates;
|
CSMWorld::CellCoordinates mCoordinates;
|
||||||
std::auto_ptr<CellArrow> mCellArrows[4];
|
std::auto_ptr<CellArrow> mCellArrows[4];
|
||||||
|
std::auto_ptr<CellMarker> mCellMarker;
|
||||||
bool mDeleted;
|
bool mDeleted;
|
||||||
|
|
||||||
/// Ignored if cell does not have an object with the given ID.
|
/// Ignored if cell does not have an object with the given ID.
|
||||||
|
@ -105,6 +107,9 @@ namespace CSVRender
|
||||||
|
|
||||||
void setCellArrows (int mask);
|
void setCellArrows (int mask);
|
||||||
|
|
||||||
|
/// \brief Set marker for this cell.
|
||||||
|
void setCellMarker();
|
||||||
|
|
||||||
/// Returns 0, 0 in case of an unpaged cell.
|
/// Returns 0, 0 in case of an unpaged cell.
|
||||||
CSMWorld::CellCoordinates getCoordinates() const;
|
CSMWorld::CellCoordinates getCoordinates() const;
|
||||||
|
|
||||||
|
|
62
apps/opencs/view/render/cellmarker.cpp
Normal file
62
apps/opencs/view/render/cellmarker.cpp
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
#include "cellmarker.hpp"
|
||||||
|
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
|
||||||
|
#include <osg/AutoTransform>
|
||||||
|
#include <osg/Geode>
|
||||||
|
#include <osg/Group>
|
||||||
|
#include <osgText/Text>
|
||||||
|
|
||||||
|
void CSVRender::CellMarker::buildMarker()
|
||||||
|
{
|
||||||
|
const int characterSize = 20;
|
||||||
|
|
||||||
|
// Set up marker text containing cell's coordinates.
|
||||||
|
osg::ref_ptr<osgText::Text> markerText (new osgText::Text);
|
||||||
|
markerText->setBackdropType(osgText::Text::OUTLINE);
|
||||||
|
markerText->setLayout(osgText::Text::LEFT_TO_RIGHT);
|
||||||
|
markerText->setCharacterSize(characterSize);
|
||||||
|
std::string coordinatesText =
|
||||||
|
"#" + boost::lexical_cast<std::string>(mCoordinates.getX()) +
|
||||||
|
" " + boost::lexical_cast<std::string>(mCoordinates.getY());
|
||||||
|
markerText->setText(coordinatesText);
|
||||||
|
|
||||||
|
// Add text to marker node.
|
||||||
|
osg::ref_ptr<osg::Geode> geode (new osg::Geode);
|
||||||
|
geode->addDrawable(markerText);
|
||||||
|
mMarkerNode->addChild(geode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVRender::CellMarker::positionMarker()
|
||||||
|
{
|
||||||
|
const int cellSize = 8192;
|
||||||
|
const int markerHeight = 0;
|
||||||
|
|
||||||
|
// Move marker to center of cell.
|
||||||
|
int x = (mCoordinates.getX() * cellSize) + (cellSize / 2);
|
||||||
|
int y = (mCoordinates.getY() * cellSize) + (cellSize / 2);
|
||||||
|
mMarkerNode->setPosition(osg::Vec3f(x, y, markerHeight));
|
||||||
|
}
|
||||||
|
|
||||||
|
CSVRender::CellMarker::CellMarker(
|
||||||
|
osg::Group *cellNode,
|
||||||
|
const CSMWorld::CellCoordinates& coordinates
|
||||||
|
) : mCellNode(cellNode),
|
||||||
|
mCoordinates(coordinates)
|
||||||
|
{
|
||||||
|
// Set up node for cell marker.
|
||||||
|
mMarkerNode = new osg::AutoTransform();
|
||||||
|
mMarkerNode->setAutoRotateMode(osg::AutoTransform::ROTATE_TO_SCREEN);
|
||||||
|
mMarkerNode->setAutoScaleToScreen(true);
|
||||||
|
mMarkerNode->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
|
||||||
|
|
||||||
|
mCellNode->addChild(mMarkerNode);
|
||||||
|
|
||||||
|
buildMarker();
|
||||||
|
positionMarker();
|
||||||
|
}
|
||||||
|
|
||||||
|
CSVRender::CellMarker::~CellMarker()
|
||||||
|
{
|
||||||
|
mCellNode->removeChild(mMarkerNode);
|
||||||
|
}
|
48
apps/opencs/view/render/cellmarker.hpp
Normal file
48
apps/opencs/view/render/cellmarker.hpp
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
#ifndef OPENCS_VIEW_CELLMARKER_H
|
||||||
|
#define OPENCS_VIEW_CELLMARKER_H
|
||||||
|
|
||||||
|
#include <osg/ref_ptr>
|
||||||
|
|
||||||
|
#include "../../model/world/cellcoordinates.hpp"
|
||||||
|
|
||||||
|
namespace osg
|
||||||
|
{
|
||||||
|
class AutoTransform;
|
||||||
|
class Group;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace CSVRender
|
||||||
|
{
|
||||||
|
/// \brief Marker to display cell coordinates.
|
||||||
|
class CellMarker
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
osg::Group* mCellNode;
|
||||||
|
osg::ref_ptr<osg::AutoTransform> mMarkerNode;
|
||||||
|
CSMWorld::CellCoordinates mCoordinates;
|
||||||
|
|
||||||
|
// Not implemented.
|
||||||
|
CellMarker(const CellMarker&);
|
||||||
|
CellMarker& operator=(const CellMarker&);
|
||||||
|
|
||||||
|
/// \brief Build marker containing cell's coordinates.
|
||||||
|
void buildMarker();
|
||||||
|
|
||||||
|
/// \brief Position marker above center of cell.
|
||||||
|
void positionMarker();
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/// \brief Constructor.
|
||||||
|
/// \param cellNode Cell to create marker for.
|
||||||
|
/// \param coordinates Coordinates of cell.
|
||||||
|
CellMarker(
|
||||||
|
osg::Group *cellNode,
|
||||||
|
const CSMWorld::CellCoordinates& coordinates);
|
||||||
|
|
||||||
|
~CellMarker();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue