basic cell arrow rendering (shape is a placeholder)

openmw-37
Marc Zinnschlag 9 years ago
parent 3b39572274
commit 0d35938794

@ -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 lightingbright object cell terrainstorage tagbase cellarrow
) )
opencs_hdrs_noqt (view/render opencs_hdrs_noqt (view/render

@ -9,6 +9,7 @@
#include "../../model/world/columns.hpp" #include "../../model/world/columns.hpp"
#include "../../model/world/data.hpp" #include "../../model/world/data.hpp"
#include "../../model/world/refcollection.hpp" #include "../../model/world/refcollection.hpp"
#include "../../model/world/cellcoordinates.hpp"
#include "elements.hpp" #include "elements.hpp"
#include "terrainstorage.hpp" #include "terrainstorage.hpp"
@ -232,3 +233,26 @@ void CSVRender::Cell::setSelection (int elementMask, Selection mode)
} }
} }
} }
void CSVRender::Cell::setCellArrows (int mask)
{
for (int i=0; i<4; ++i)
{
CellArrow::Direction direction = static_cast<CellArrow::Direction> (1<<i);
bool enable = mask & direction;
if (enable!=(mCellArrows[i].get()!=0))
{
if (enable)
mCellArrows[i].reset (new CellArrow (mCellNode, direction, mX, mY));
else
mCellArrows[i].reset (0);
}
}
}
CSMWorld::CellCoordinates CSVRender::Cell::getCoordinates() const
{
return CSMWorld::CellCoordinates (mX, mY);
}

@ -14,6 +14,7 @@
#endif #endif
#include "object.hpp" #include "object.hpp"
#include "cellarrow.hpp"
class QModelIndex; class QModelIndex;
@ -25,6 +26,7 @@ namespace osg
namespace CSMWorld namespace CSMWorld
{ {
class Data; class Data;
class CellCoordinates;
} }
namespace CSVRender namespace CSVRender
@ -38,6 +40,7 @@ namespace CSVRender
std::auto_ptr<Terrain::TerrainGrid> mTerrain; std::auto_ptr<Terrain::TerrainGrid> mTerrain;
int mX; int mX;
int mY; int mY;
std::auto_ptr<CellArrow> mCellArrows[4];
/// Ignored if cell does not have an object with the given ID. /// Ignored if cell does not have an object with the given ID.
/// ///
@ -86,6 +89,11 @@ namespace CSVRender
bool referenceAdded (const QModelIndex& parent, int start, int end); bool referenceAdded (const QModelIndex& parent, int start, int end);
void setSelection (int elementMask, Selection mode); void setSelection (int elementMask, Selection mode);
void setCellArrows (int mask);
/// Returns 0, 0 in case of an unpaged cell.
CSMWorld::CellCoordinates getCoordinates() const;
}; };
} }

@ -0,0 +1,93 @@
#include "cellarrow.hpp"
#include <osg/Group>
#include <osg/PositionAttitudeTransform>
#include <osg/ShapeDrawable>
#include <osg/Shape>
#include <osg/Geode>
#include "elements.hpp"
CSVRender::CellArrowTag::CellArrowTag (CellArrow *arrow)
: TagBase (Element_CellArrow), mArrow (arrow)
{}
CSVRender::CellArrow *CSVRender::CellArrowTag::getCellArrow() const
{
return mArrow;
}
void CSVRender::CellArrow::adjustTransform()
{
// position
const int cellSize = 8192;
const int offset = cellSize / 2 + 400;
int x = mXIndex*cellSize + cellSize/2;
int y = mYIndex*cellSize + cellSize/2;
switch (mDirection)
{
case Direction_North: y += offset; break;
case Direction_West: x -= offset; break;
case Direction_South: y -= offset; break;
case Direction_East: x += offset; break;
};
mBaseNode->setPosition (osg::Vec3f (x, y, 0));
// orientation
osg::Quat xr (0, osg::Vec3f (1,0,0));
osg::Quat yr (0, osg::Vec3f (0,1,0));
osg::Quat zr (0, osg::Vec3f (0,0,1));
mBaseNode->setAttitude (zr*yr*xr);
}
void CSVRender::CellArrow::buildShape()
{
/// \todo placeholder shape -> replace
osg::ref_ptr<osg::Box> shape(new osg::Box(osg::Vec3f(0,0,0), 200));
osg::ref_ptr<osg::ShapeDrawable> shapedrawable(new osg::ShapeDrawable);
shapedrawable->setShape(shape);
osg::ref_ptr<osg::Geode> geode (new osg::Geode);
geode->addDrawable(shapedrawable);
mBaseNode->addChild (geode);
}
CSVRender::CellArrow::CellArrow (osg::Group *cellNode, Direction direction,
int xIndex, int yIndex)
: mDirection (direction), mParentNode (cellNode), mXIndex (xIndex), mYIndex (yIndex)
{
mBaseNode = new osg::PositionAttitudeTransform;
mBaseNode->setUserData (new CellArrowTag (this));
mParentNode->addChild (mBaseNode);
// 0x1 reserved for separating cull and update visitors
mBaseNode->setNodeMask (Element_CellArrow<<1);
adjustTransform();
buildShape();
}
CSVRender::CellArrow::~CellArrow()
{
mParentNode->removeChild (mBaseNode);
}
int CSVRender::CellArrow::getXIndex() const
{
return mXIndex;
}
int CSVRender::CellArrow::getYIndex() const
{
return mYIndex;
}

@ -0,0 +1,70 @@
#ifndef OPENCS_VIEW_CELLARROW_H
#define OPENCS_VIEW_CELLARROW_H
#include "tagbase.hpp"
#include <osg/ref_ptr>
namespace osg
{
class PositionAttitudeTransform;
class Group;
}
namespace CSVRender
{
class CellArrow;
class CellArrowTag : public TagBase
{
CellArrow *mArrow;
public:
CellArrowTag (CellArrow *arrow);
CellArrow *getCellArrow() const;
};
class CellArrow
{
public:
enum Direction
{
Direction_North = 1,
Direction_West = 2,
Direction_South = 4,
Direction_East = 8
};
private:
// not implemented
CellArrow (const CellArrow&);
CellArrow& operator= (const CellArrow&);
Direction mDirection;
osg::Group* mParentNode;
osg::ref_ptr<osg::PositionAttitudeTransform> mBaseNode;
int mXIndex;
int mYIndex;
void adjustTransform();
void buildShape();
public:
CellArrow (osg::Group *cellNode, Direction direction, int xIndex, int yIndex);
~CellArrow();
int getXIndex() const;
int getYIndex() const;
};
}
#endif

@ -21,6 +21,7 @@
bool CSVRender::PagedWorldspaceWidget::adjustCells() bool CSVRender::PagedWorldspaceWidget::adjustCells()
{ {
bool modified = false; bool modified = false;
bool wasEmpty = mCells.empty();
const CSMWorld::IdCollection<CSMWorld::Cell>& cells = mDocument.getData().getCells(); const CSMWorld::IdCollection<CSMWorld::Cell>& cells = mDocument.getData().getCells();
@ -32,6 +33,7 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells()
{ {
int index = cells.searchId (iter->first.getId (mWorldspace)); int index = cells.searchId (iter->first.getId (mWorldspace));
/// \todo handle cells that don't exist
if (!mSelection.has (iter->first) || index==-1 || if (!mSelection.has (iter->first) || index==-1 ||
cells.getRecord (index).mState==CSMWorld::RecordBase::State_Deleted) cells.getRecord (index).mState==CSMWorld::RecordBase::State_Deleted)
{ {
@ -60,6 +62,7 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells()
{ {
int index = cells.searchId (iter->getId (mWorldspace)); int index = cells.searchId (iter->getId (mWorldspace));
/// \todo handle cells that don't exist
if (index > 0 && cells.getRecord (index).mState!=CSMWorld::RecordBase::State_Deleted && if (index > 0 && cells.getRecord (index).mState!=CSMWorld::RecordBase::State_Deleted &&
mCells.find (*iter)==mCells.end()) mCells.find (*iter)==mCells.end())
{ {
@ -72,6 +75,35 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells()
} }
if (modified) if (modified)
{
for (std::map<CSMWorld::CellCoordinates, Cell *>::const_iterator iter (mCells.begin());
iter!=mCells.end(); ++iter)
{
int mask = 0;
for (int i=CellArrow::Direction_North; i<=CellArrow::Direction_East; i *= 2)
{
CSMWorld::CellCoordinates coordinates (iter->second->getCoordinates());
switch (i)
{
case CellArrow::Direction_North: coordinates = coordinates.move (0, 1); break;
case CellArrow::Direction_West: coordinates = coordinates.move (-1, 0); break;
case CellArrow::Direction_South: coordinates = coordinates.move (0, -1); break;
case CellArrow::Direction_East: coordinates = coordinates.move (1, 0); break;
}
if (!mSelection.has (coordinates))
mask |= i;
}
iter->second->setCellArrows (mask);
}
}
/// \todo do not overwrite manipulator object
/// \todo move code to useViewHint function
if (modified && wasEmpty)
mView->setCameraManipulator(new osgGA::TrackballManipulator); mView->setCameraManipulator(new osgGA::TrackballManipulator);
return modified; return modified;

Loading…
Cancel
Save