Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add odd grid offset and fix vertical bars #71

Merged
merged 2 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 36 additions & 9 deletions ogre/src/OgreGrid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ void OgreGrid::Create()

this->dataPtr->manualObject->clear();

double extent = (this->cellLength * static_cast<double>(this->cellCount))/2;
double baseExtent = (this->cellLength *
static_cast<double>(this->cellCount - this->cellCount % 2))/2;

this->dataPtr->manualObject->setCastShadows(false);
this->dataPtr->manualObject->estimateVertexCount(
Expand All @@ -91,20 +92,30 @@ void OgreGrid::Create()
for (unsigned int h = 0; h <= this->verticalCellCount; ++h)
{
double hReal = this->heightOffset +
(this->verticalCellCount / 2.0f - static_cast<double>(h))
(this->verticalCellCount / 2 - static_cast<double>(h))
* this->cellLength;

// If there are odd vertical cells, shift cell planes up
if (this->verticalCellCount % 2)
hReal += this->cellLength;

for (unsigned int i = 0; i <= this->cellCount; i++)
{
double inc = extent - (i * this->cellLength);
double extent = baseExtent;

// If there is an odd cell count, extend a row and column along
// the positive x and y axes
if (this->cellCount % 2)
extent += this->cellLength;

Ogre::Vector3 p1(inc, -extent, hReal);
double inc = extent - (i * this->cellLength);
Ogre::Vector3 p1(inc, -baseExtent, hReal);
Ogre::Vector3 p2(inc, extent , hReal);
Ogre::Vector3 p3(-extent, inc, hReal);
Ogre::Vector3 p3(-baseExtent, inc, hReal);
Ogre::Vector3 p4(extent, inc, hReal);

this->dataPtr->manualObject->position(p1);
this->dataPtr->manualObject->position(p2);

this->dataPtr->manualObject->position(p3);
this->dataPtr->manualObject->position(p4);
}
Expand All @@ -116,14 +127,30 @@ void OgreGrid::Create()
{
for (unsigned int y = 0; y <= this->cellCount; ++y)
{
double xReal = extent - x * this->cellLength;
double yReal = extent - y * this->cellLength;
double xReal = baseExtent - x * this->cellLength;
double yReal = baseExtent - y * this->cellLength;

double zTop = (this->verticalCellCount / 2.0f) * this->cellLength;
double zBottom = -zTop;

// If odd vertical cell count, add cell length offset to adjust
// z min and max
if (this->verticalCellCount % 2)
{
zTop += this->cellLength / 2.0f;
zBottom += this->cellLength / 2.0f;
}

// If odd horizontal cell count, shift vertical lines
// towards positive x, y axes
if (this->cellCount % 2)
{
xReal += this->cellLength;
yReal += this->cellLength;
}

this->dataPtr->manualObject->position(xReal, yReal, zBottom);
this->dataPtr->manualObject->position(xReal, yReal, zBottom);
this->dataPtr->manualObject->position(xReal, yReal, zTop);
}
}
}
Expand Down
44 changes: 36 additions & 8 deletions ogre2/src/Ogre2Grid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,31 @@ void Ogre2Grid::Create()
this->dataPtr->grid->Update();

this->dataPtr->grid->SetOperationType(MarkerType::MT_LINE_LIST);
double extent = (this->cellLength * static_cast<double>(this->cellCount))/2;
double baseExtent = (this->cellLength *
static_cast<double>(this->cellCount - this->cellCount % 2))/2;
for (unsigned int h = 0; h <= this->verticalCellCount; ++h)
{
double hReal = this->heightOffset +
(this->verticalCellCount / 2.0f - static_cast<double>(h))
(this->verticalCellCount / 2 - static_cast<double>(h))
* this->cellLength;

// If there are odd vertical cells, shift cell planes up
if (this->verticalCellCount % 2)
hReal += this->cellLength;

for (unsigned int i = 0; i <= this->cellCount; i++)
{
double inc = extent - (i * this->cellLength);
double extent = baseExtent;

// If there is an odd cell count, extend a row and column along
// the positive x and y axes
if (this->cellCount % 2)
extent += this->cellLength;

math::Vector3d p1{inc, -extent, hReal};
double inc = extent - (i * this->cellLength);
math::Vector3d p1{inc, -baseExtent, hReal};
math::Vector3d p2{inc, extent , hReal};
math::Vector3d p3{-extent, inc, hReal};
math::Vector3d p3{-baseExtent, inc, hReal};
math::Vector3d p4{extent, inc, hReal};

this->dataPtr->grid->AddPoint(p1);
Expand All @@ -101,20 +113,36 @@ void Ogre2Grid::Create()
this->dataPtr->grid->AddPoint(p4);
}
}

if (this->verticalCellCount > 0)
{
for (unsigned int x = 0; x <= this->cellCount; ++x)
{
for (unsigned int y = 0; y <= this->cellCount; ++y)
{
double xReal = extent - x * this->cellLength;
double yReal = extent - y * this->cellLength;
double xReal = baseExtent - x * this->cellLength;
double yReal = baseExtent - y * this->cellLength;

double zTop = (this->verticalCellCount / 2.0f) * this->cellLength;
double zBottom = -zTop;

// If odd vertical cell count, add cell length offset to adjust
// z min and max
if (this->verticalCellCount % 2)
{
zTop += this->cellLength / 2.0f;
zBottom += this->cellLength / 2.0f;
}

// If odd horizontal cell count, shift vertical lines
// towards positive x, y axes
if (this->cellCount % 2)
{
xReal += this->cellLength;
yReal += this->cellLength;
}

this->dataPtr->grid->AddPoint(xReal, yReal, zBottom);
this->dataPtr->grid->AddPoint(xReal, yReal, zTop);
}
}
}
Expand Down