1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
|
#ifndef ADAPTIVEFIELD_H
#define ADAPTIVEFIELD_H
using namespace std;
class AdaptiveFieldCell;
class AdaptiveField
{
friend class AdaptiveFieldCell;
public:
AdaptiveField();
virtual ~AdaptiveField();
bool Generate(double radius, float resolution, bool generateGeometry); // Create
unsigned int GetMaxLod(){return m_MaxLOD;};
double GetFieldSize(){return m_FieldSize;};
protected:
private:
float m_FixedClamp; // fixed clamp - Perlin clamp level
unsigned int m_MaxLOD; // Maximum LOD
double m_FieldSize; // field size - can be number of polys (resolution)
vector<AdaptiveFieldCell *> m_PatchRegion; // Adaptive field;
unsigned int m_Iteration; // Used this passed for interation
};
#endif // ADAPTIVEFIELD_H
// field size is the physical size
// m_field size is the sizw
#include <memory>
#include <vector>
#include <cmath>
#include "../include/AdaptiveField.h"
#include "../include/AdaptiveFieldCell.h"
AdaptiveField::AdaptiveField()
{
m_PatchRegion.resize(8);
}
AdaptiveField::~AdaptiveField()
{
}
// Generate each area field
bool AdaptiveField::Generate(double radius, float resolution, bool generateGeometry)
{
// generate maxLOD;
m_MaxLOD = (unsigned int)log2((float)(2.0f * 3.14 * radius) / 4/.0f);
// override
m_MaxLOD = 2;
// radius is twice -- use for simplex
m_FieldSize = radius*2;
// default interation
m_Iteration=1;
// resize
// Generate - translation would be x,y,z but flat
for(unsigned int x=0; x<2; x++)
{
for(unsigned int y=0; y<2; y++)
{
for(unsigned int z=0; z<2; z++)
{
// Generate Cell
AdaptiveFieldCell * newPatch = new AdaptiveFieldCell();
newPatch->SetField(this);
// Set locatoin
newPatch->SetLocation(x,y,z);
// add a new patch recursively till the final
m_PatchRegion.push_back(newPatch);
// Generate patch
newPatch->Generate(m_Iteration+1);
}
}
}
return false;
}
#ifndef ADAPTIVEFIELDCELL_H
#define ADAPTIVEFIELDCELL_H
using namespace std;
class AdaptiveField;
struct bVector3
{
bool x_;
bool y_;
bool z_;
};
struct uVector3
{
unsigned int x;
unsigned int y;
unsigned int z;
};
// maybe can be similiar to terrainpatch
class AdaptiveFieldCell
{
public:
AdaptiveFieldCell();
virtual ~AdaptiveFieldCell();
// Generate new cell
virtual bool Generate(unsigned int interation);
// Save root location
void SetLocation(unsigned int x, unsigned int y, unsigned int z)
{
m_Location.x = x;
m_Location.y = y;
m_Location.z = z;
};
void SetField(AdaptiveField * passedField)
{
m_ParentField = passedField;
};
protected:
private:
vector <AdaptiveFieldCell *> m_PatchRegion; // not set based on interation can be 8 or 1;
bool m_IsLeaf; // Final
bool m_IsSolid; // Solid
AdaptiveField * m_ParentField; // Parent Field;
unsigned int m_Iteration; // iteration
uVector3 m_Location; // Location
};
#endif // ADAPTIVEFIELDCELL_H
#include <memory>
#include <vector>
#include <iostream>
#include "../include/AdaptiveField.h"
#include "../include/AdaptiveFieldCell.h"
AdaptiveFieldCell::AdaptiveFieldCell()
{
// Create region here
// m_PatchRegion = new vector<AdaptiveFieldCell *>;
m_PatchRegion.resize(8);
}
AdaptiveFieldCell::~AdaptiveFieldCell()
{
}
bool AdaptiveFieldCell::Generate(unsigned int interation=1)
{
// if interaction
if(interation>m_ParentField->GetMaxLod())
{
m_IsLeaf=true;
m_Iteration = m_ParentField->GetMaxLod();
}
else
{
m_IsLeaf=false;
m_Iteration = interation;
}
// if generate patch
if(m_IsLeaf==false)
{
m_PatchRegion.resize(8);for(unsigned int x=0; x<2; x++)
{
for(unsigned int y=0; y<2; y++)
{
for(unsigned int z=0; z<2; z++)
{
// Generate Cell
AdaptiveFieldCell * newPatch = (AdaptiveFieldCell *) new AdaptiveFieldCell;
// Set Location
newPatch->SetLocation(x,y,z);
// set field
newPatch->SetField(m_ParentField);
// add a new patch recursively till the final
m_PatchRegion.push_back(newPatch);
// Generate patch
newPatch->Generate(m_Iteration++);
}
}
}
}
// if generate patch
if(m_IsLeaf==true)
{
// Bit manipulation
float sizecell=m_ParentField->GetFieldSize()/(1<<m_Iteration);
cout << sizecell << endl;
}
return false;
}
|