mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-06 05:19:43 +00:00
Directly use Geometry instead of Geode; fix for loop; add size_t type-cast.
This commit is contained in:
parent
73949d5bd0
commit
7be891b440
2 changed files with 20 additions and 19 deletions
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
#include <osg/Group>
|
#include <osg/Group>
|
||||||
#include <osg/PositionAttitudeTransform>
|
#include <osg/PositionAttitudeTransform>
|
||||||
#include <osg/Geode>
|
|
||||||
#include <osg/Geometry>
|
#include <osg/Geometry>
|
||||||
#include <osg/PrimitiveSet>
|
#include <osg/PrimitiveSet>
|
||||||
|
|
||||||
|
@ -19,12 +18,12 @@ const int CSVRender::CellBorder::VertexCount = (ESM::Land::LAND_SIZE * 4) - 3;
|
||||||
CSVRender::CellBorder::CellBorder(osg::Group* cellNode, const CSMWorld::CellCoordinates& coords)
|
CSVRender::CellBorder::CellBorder(osg::Group* cellNode, const CSMWorld::CellCoordinates& coords)
|
||||||
: mParentNode(cellNode)
|
: mParentNode(cellNode)
|
||||||
{
|
{
|
||||||
mBorderGeode = new osg::Geode();
|
mBorderGeometry = new osg::Geometry();
|
||||||
|
|
||||||
mBaseNode = new osg::PositionAttitudeTransform();
|
mBaseNode = new osg::PositionAttitudeTransform();
|
||||||
mBaseNode->setNodeMask(Mask_CellBorder);
|
mBaseNode->setNodeMask(Mask_CellBorder);
|
||||||
mBaseNode->setPosition(osg::Vec3f(coords.getX() * CellSize, coords.getY() * CellSize, 10));
|
mBaseNode->setPosition(osg::Vec3f(coords.getX() * CellSize, coords.getY() * CellSize, 10));
|
||||||
mBaseNode->addChild(mBorderGeode);
|
mBaseNode->addChild(mBorderGeometry);
|
||||||
|
|
||||||
mParentNode->addChild(mBaseNode);
|
mParentNode->addChild(mBaseNode);
|
||||||
}
|
}
|
||||||
|
@ -41,54 +40,56 @@ void CSVRender::CellBorder::buildShape(const ESM::Land& esmLand)
|
||||||
if (!landData)
|
if (!landData)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry();
|
mBaseNode->removeChild(mBorderGeometry);
|
||||||
|
mBorderGeometry = new osg::Geometry();
|
||||||
|
|
||||||
// Vertices
|
// Vertices
|
||||||
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array();
|
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array();
|
||||||
|
|
||||||
int x = 0, y = 0;
|
int x = 0;
|
||||||
for (; x < ESM::Land::LAND_SIZE; ++x)
|
int y = 0;
|
||||||
|
|
||||||
|
for (/* */; x < ESM::Land::LAND_SIZE - 1; ++x)
|
||||||
vertices->push_back(osg::Vec3f(scaleToWorld(x), scaleToWorld(y), landData->mHeights[landIndex(x, y)]));
|
vertices->push_back(osg::Vec3f(scaleToWorld(x), scaleToWorld(y), landData->mHeights[landIndex(x, y)]));
|
||||||
|
|
||||||
x = ESM::Land::LAND_SIZE - 1;
|
x = ESM::Land::LAND_SIZE - 1;
|
||||||
for (; y < ESM::Land::LAND_SIZE; ++y)
|
for (/* */; y < ESM::Land::LAND_SIZE - 1; ++y)
|
||||||
vertices->push_back(osg::Vec3f(scaleToWorld(x), scaleToWorld(y), landData->mHeights[landIndex(x, y)]));
|
vertices->push_back(osg::Vec3f(scaleToWorld(x), scaleToWorld(y), landData->mHeights[landIndex(x, y)]));
|
||||||
|
|
||||||
y = ESM::Land::LAND_SIZE - 1;
|
y = ESM::Land::LAND_SIZE - 1;
|
||||||
for (; x >= 0; --x)
|
for (/* */; x > 0; --x)
|
||||||
vertices->push_back(osg::Vec3f(scaleToWorld(x), scaleToWorld(y), landData->mHeights[landIndex(x, y)]));
|
vertices->push_back(osg::Vec3f(scaleToWorld(x), scaleToWorld(y), landData->mHeights[landIndex(x, y)]));
|
||||||
|
|
||||||
x = 0;
|
x = 0;
|
||||||
for (; y >= 0; --y)
|
for (/* */; y >= 0; --y)
|
||||||
vertices->push_back(osg::Vec3f(scaleToWorld(x), scaleToWorld(y), landData->mHeights[landIndex(x, y)]));
|
vertices->push_back(osg::Vec3f(scaleToWorld(x), scaleToWorld(y), landData->mHeights[landIndex(x, y)]));
|
||||||
|
|
||||||
geometry->setVertexArray(vertices);
|
mBorderGeometry->setVertexArray(vertices);
|
||||||
|
|
||||||
// Color
|
// Color
|
||||||
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array();
|
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array();
|
||||||
colors->push_back(osg::Vec4f(0.f, 0.5f, 0.f, 1.f));
|
colors->push_back(osg::Vec4f(0.f, 0.5f, 0.f, 1.f));
|
||||||
|
|
||||||
geometry->setColorArray(colors, osg::Array::BIND_PER_PRIMITIVE_SET);
|
mBorderGeometry->setColorArray(colors, osg::Array::BIND_PER_PRIMITIVE_SET);
|
||||||
|
|
||||||
// Primitive
|
// Primitive
|
||||||
osg::ref_ptr<osg::DrawElementsUShort> primitives =
|
osg::ref_ptr<osg::DrawElementsUShort> primitives =
|
||||||
new osg::DrawElementsUShort(osg::PrimitiveSet::LINE_STRIP, VertexCount+1);
|
new osg::DrawElementsUShort(osg::PrimitiveSet::LINE_STRIP, VertexCount);
|
||||||
|
|
||||||
for (size_t i = 0; i < VertexCount; ++i)
|
for (size_t i = 0; i < VertexCount; ++i)
|
||||||
primitives->setElement(i, i);
|
primitives->setElement(i, i);
|
||||||
|
|
||||||
primitives->setElement(VertexCount, 0);
|
primitives->setElement(VertexCount, 0);
|
||||||
|
|
||||||
geometry->addPrimitiveSet(primitives);
|
mBorderGeometry->addPrimitiveSet(primitives);
|
||||||
geometry->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
|
mBorderGeometry->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
|
||||||
|
|
||||||
mBorderGeode->removeDrawables(0);
|
mBaseNode->addChild(mBorderGeometry);
|
||||||
mBorderGeode->addDrawable(geometry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t CSVRender::CellBorder::landIndex(int x, int y)
|
size_t CSVRender::CellBorder::landIndex(int x, int y)
|
||||||
{
|
{
|
||||||
return y * ESM::Land::LAND_SIZE + x;
|
return static_cast<size_t>(y) * ESM::Land::LAND_SIZE + x;
|
||||||
}
|
}
|
||||||
|
|
||||||
float CSVRender::CellBorder::scaleToWorld(int value)
|
float CSVRender::CellBorder::scaleToWorld(int value)
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
namespace osg
|
namespace osg
|
||||||
{
|
{
|
||||||
class Geode;
|
class Geometry;
|
||||||
class Group;
|
class Group;
|
||||||
class PositionAttitudeTransform;
|
class PositionAttitudeTransform;
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ namespace CSVRender
|
||||||
|
|
||||||
osg::Group* mParentNode;
|
osg::Group* mParentNode;
|
||||||
osg::ref_ptr<osg::PositionAttitudeTransform> mBaseNode;
|
osg::ref_ptr<osg::PositionAttitudeTransform> mBaseNode;
|
||||||
osg::ref_ptr<osg::Geode> mBorderGeode;
|
osg::ref_ptr<osg::Geometry> mBorderGeometry;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue