Skip to content

Commit

Permalink
Calculate randomTranslate on ResourceParameter
Browse files Browse the repository at this point in the history
  • Loading branch information
latami committed Feb 10, 2017
1 parent abf7e08 commit 1600940
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
7 changes: 1 addition & 6 deletions HeightMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,7 @@ HeightMap::HeightMap(unsigned int size,
minHeight = -maxAmplitude;
maxHeight = +maxAmplitude;

/* Re-create randomTranslate using seed. Avoids passing it as a costructor
* parameter. */
srand(RParam->getSeed());
randomTranslate.x = (float)((rand() % 1000)-500)/100.0f;
randomTranslate.y = (float)((rand() % 1000)-500)/100.0f;
randomTranslate.z = (float)((rand() % 1000)-500)/100.0f;
RParam->getRandomTranslate(randomTranslate.x, randomTranslate.y, randomTranslate.z);
}

HeightMap::~HeightMap()
Expand Down
5 changes: 1 addition & 4 deletions PSphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,7 @@ void PSphere::create(Ogre::uint32 iters, Ogre::uint32 gridSize, ResourceParamete
rotX_90 = Ogre::Matrix3(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f);
rotX_270 = Ogre::Matrix3(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 0.0f);

srand(RParameter.getSeed());
randomTranslate.x = (float)((rand() % 1000)-500)/100.0f;
randomTranslate.y = (float)((rand() % 1000)-500)/100.0f;
randomTranslate.z = (float)((rand() % 1000)-500)/100.0f;
RParameter.getRandomTranslate(randomTranslate.x, randomTranslate.y, randomTranslate.z);

calculateSeaLevel(minimumHeight, maximumHeight, waterFraction);

Expand Down
8 changes: 8 additions & 0 deletions ResourceParameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <algorithm>
#include <vector>
#include <sstream>
#include <stdlib.h>

using namespace std;

Expand Down Expand Up @@ -151,6 +152,13 @@ unsigned int ResourceParameter::getSeed(void)
{
return seed;
}
void ResourceParameter::getRandomTranslate(float &x, float &y, float &z)
{
srand(this->seed);
x = (float)((rand() % 1000)-500)/100.0f;
y = (float)((rand() % 1000)-500)/100.0f;
z = (float)((rand() % 1000)-500)/100.0f;
}
vector <float>& ResourceParameter::getFrequency(void)
{
return frequency;
Expand Down
1 change: 1 addition & 0 deletions ResourceParameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class ResourceParameter
float getWaterFraction(void);
float getRadius(void);
unsigned int getSeed(void);
void getRandomTranslate(float &x, float &y, float &z);
std::vector <float>& getFrequency(void);
std::vector <float>& getAmplitude(void);
std::vector<std::pair <float, float> >& getFrequencyAmplitude(void);
Expand Down

0 comments on commit 1600940

Please sign in to comment.