forked from teamnwah/openmw-tes3coop
Start cell border debug drawing
parent
36f4f0ef85
commit
db8aaa74d6
@ -0,0 +1,91 @@
|
||||
#include "cellborder.hpp"
|
||||
|
||||
#include <osg/PolygonMode>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Geode>
|
||||
|
||||
#include "world.hpp"
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
|
||||
CellBorder::CellBorder(Terrain::World *world, osg::Group *root):
|
||||
mWorld(world),
|
||||
mRoot(root),
|
||||
mBorderRoot(0)
|
||||
{
|
||||
}
|
||||
|
||||
void CellBorder::createCellBorderGeometry(int x, int y)
|
||||
{
|
||||
const int cellSize = 8192;
|
||||
const int borderSegments = 40;
|
||||
const float offset = 10.0;
|
||||
|
||||
osg::Vec3 cellCorner = osg::Vec3(x * cellSize,y * cellSize,0);
|
||||
|
||||
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
|
||||
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
|
||||
osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
|
||||
|
||||
normals->push_back(osg::Vec3(0.0f,-1.0f, 0.0f));
|
||||
|
||||
float borderStep = cellSize / ((float) borderSegments);
|
||||
|
||||
for (int i = 0; i <= 2 * borderSegments; ++i)
|
||||
{
|
||||
osg::Vec3f pos = i < borderSegments ?
|
||||
osg::Vec3(i * borderStep,0.0f,0.0f) :
|
||||
osg::Vec3(cellSize,(i - borderSegments) * borderStep,0.0f);
|
||||
|
||||
pos += cellCorner;
|
||||
pos += osg::Vec3f(0,0,mWorld->getHeightAt(pos) + offset);
|
||||
|
||||
vertices->push_back(pos);
|
||||
|
||||
osg::Vec4f col = i % 2 == 0 ?
|
||||
osg::Vec4f(0,0,0,1) :
|
||||
osg::Vec4f(1,1,0,1);
|
||||
|
||||
colors->push_back(col);
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Geometry> border = new osg::Geometry;
|
||||
border->setVertexArray(vertices.get());
|
||||
border->setNormalArray(normals.get());
|
||||
border->setNormalBinding(osg::Geometry::BIND_OVERALL);
|
||||
border->setColorArray(colors.get());
|
||||
border->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
|
||||
|
||||
border->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP,0,vertices->size()));
|
||||
|
||||
osg::ref_ptr<osg::Geode> borderGeode = new osg::Geode;
|
||||
borderGeode->addDrawable(border.get());
|
||||
|
||||
osg::StateSet *stateSet = borderGeode->getOrCreateStateSet();
|
||||
|
||||
osg::PolygonMode* polygonmode = new osg::PolygonMode;
|
||||
polygonmode->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE);
|
||||
stateSet->setAttributeAndModes(polygonmode,osg::StateAttribute::ON);
|
||||
|
||||
mRoot->addChild(borderGeode);
|
||||
|
||||
mBorderRoot = borderGeode;
|
||||
|
||||
mCellBorderNodes[std::make_pair(x,y)] = borderGeode;
|
||||
}
|
||||
|
||||
void CellBorder::destroyCellBorderGeometry(int x, int y)
|
||||
{
|
||||
CellGrid::iterator it = mCellBorderNodes.find(std::make_pair(x,y));
|
||||
|
||||
if (it == mCellBorderNodes.end())
|
||||
return;
|
||||
|
||||
osg::ref_ptr<osg::Node> borderNode = it->second;
|
||||
mBorderRoot->removeChild(borderNode);
|
||||
|
||||
mCellBorderNodes.erase(it);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
#ifndef GAME_RENDER_CELLBORDER
|
||||
#define GAME_RENDER_CELLBORDER
|
||||
|
||||
#include <map>
|
||||
#include <osg/Group>
|
||||
|
||||
namespace Terrain
|
||||
{
|
||||
class World;
|
||||
}
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
/**
|
||||
* @Brief Handles the debug cell borders.
|
||||
*/
|
||||
class CellBorder
|
||||
{
|
||||
public:
|
||||
typedef std::map<std::pair<int, int>, osg::ref_ptr<osg::Node> > CellGrid;
|
||||
|
||||
CellBorder(Terrain::World *world, osg::Group *root);
|
||||
|
||||
void createCellBorderGeometry(int x, int y);
|
||||
void destroyCellBorderGeometry(int x, int y);
|
||||
|
||||
protected:
|
||||
Terrain::World *mWorld;
|
||||
osg::Group *mRoot;
|
||||
osg::Group *mBorderRoot;
|
||||
|
||||
CellGrid mCellBorderNodes;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue