Giving some help?
I want the other way round
But inverting the signs doesn't work
x3 y:1 z:3
x2 y:1 z:2
x0 y:0 z:0
x-1 y:-1 z:-1
#include <iostream>
#include <memory>
#include <vector>
#include <d3dx9.h>
#include <boost/functional/hash.hpp>
#include <unordered_map>
#include <sstream>
class Indexable {
public:
int Index;
};
class Octant : public Indexable
{
public:
enum Status
{
FREE = 0,
OBSTRUCTED = 1
};
Octant(const D3DXVECTOR3& pivot, D3DXVECTOR3& size) { m_vPivot = pivot; m_vSize = size; }
D3DXVECTOR3 getPivot() const { return m_vPivot; }
D3DXVECTOR3 getSize() const { return m_vSize; }
private:
D3DXVECTOR3 m_vPivot;
D3DXVECTOR3 m_vSize;
public:
Status status;
};
class NodeExtent
{
public:
NodeExtent() : NodeExtent(D3DXVECTOR3(-1, -1, -1), D3DXVECTOR3(-1, -1, -1))
{
}
NodeExtent(D3DXVECTOR3 pivot, D3DXVECTOR3 size) {
//m_pivot = D3DXVECTOR3(round_num(pivot.x, 0.001f), round_num(pivot.y, 0.001f), round_num(pivot.z, 0.001f));
m_pivot = pivot;
m_size = size;
//m_boundingBox[0].x = m_pivot.x - (m_size.x / 2);
//m_boundingBox[0].y = m_pivot.y - (m_size.y / 2);
//m_boundingBox[0].z = m_pivot.z - (m_size.z / 2);
//m_boundingBox[1].x = m_pivot.x + (m_size.x / 2);
//m_boundingBox[1].y = m_pivot.y + (m_size.y / 2);
//m_boundingBox[1].z = m_pivot.z + (m_size.z / 2);
}
bool operator==(const NodeExtent& other) const
{
//return m_boundingBox[0].x == other.m_boundingBox[0].x
// && m_boundingBox[0].y == other.m_boundingBox[0].y
// && m_boundingBox[0].z == other.m_boundingBox[0].z
// && m_boundingBox[1].x == other.m_boundingBox[1].x
// && m_boundingBox[1].y == other.m_boundingBox[1].y
// && m_boundingBox[1].z == other.m_boundingBox[1].z;
return m_pivot.x == other.m_pivot.x
&& m_pivot.y == other.m_pivot.y
&& m_pivot.z == other.m_pivot.z;
}
// for sorting on the fly
bool operator<(const NodeExtent& other) const
{
//return std::tie(m_pivot.x, m_pivot.y, m_pivot.z)
// < std::tie(other.m_pivot.x, other.m_pivot.y, other.m_pivot.z);
//return std::tie(m_boundingBox[0].z, m_boundingBox[0].y, m_boundingBox[0].x)
// < std::tie(m_boundingBox[1].z, m_boundingBox[1].y, m_boundingBox[1].x);
//return (m_pivot.x < other.m_pivot.x &&
// m_pivot.y < other.m_pivot.y &&
// m_pivot.z < other.m_pivot.z);
if (m_pivot.y < other.m_pivot.y)
{
return true;
}
else if (m_pivot.y > other.m_pivot.y)
{
return false;
}
else
{
if (m_pivot.x < other.m_pivot.x)
{
return true;
}
else if (m_pivot.x > other.m_pivot.x)
{
return false;
}
else
{
if (m_pivot.z < other.m_pivot.z)
{
return true;
}
else if (m_pivot.z > other.m_pivot.z)
{
return false;
}
}
}
return false;
}
D3DXVECTOR3 m_pivot;
D3DXVECTOR3 m_size;
};
struct NodeExtentHasher
{
std::size_t operator()(const NodeExtent& k) const
{
using boost::hash_value;
using boost::hash_combine;
std::size_t seed = 0;
hash_combine(seed, hash_value(k.m_pivot.x));
hash_combine(seed, hash_value(k.m_pivot.y));
hash_combine(seed, hash_value(k.m_pivot.z));
return seed;
}
};
int main()
{
D3DXVECTOR3 pivots[4]
{
D3DXVECTOR3(-1, -1, -1),
D3DXVECTOR3(0, 0, 0),
D3DXVECTOR3(2, 1, 2),
D3DXVECTOR3(3, 1, 3)
};
D3DXVECTOR3 s[4]
{
D3DXVECTOR3(1, 1, 1),
D3DXVECTOR3(1, 1, 1),
D3DXVECTOR3(1, 1, 1),
D3DXVECTOR3(1, 1, 1)
};
std::unordered_map<NodeExtent, Octant, NodeExtentHasher> m_physical_nodes;
for (int i = 0; i < 4; i++)
{
std::shared_ptr<Octant> newOctant(new Octant(pivots[i], s[i]));
newOctant->status = Octant::FREE;
NodeExtent newExtent(newOctant->getPivot(), newOctant->getSize());
m_physical_nodes.insert(std::make_pair(newExtent, *newOctant));
}
for (const auto& n : m_physical_nodes)
{
std::stringstream oss;
oss << " x" << n.first.m_pivot.x << " y:" << n.first.m_pivot.y << " z:" << n.first.m_pivot.z << std::endl;
OutputDebugStringA(oss.str().c_str());
}
}