예제 #1
0
int LuaPerlinNoiseMap::l_get3dMap_flat(lua_State *L)
{
    NO_MAP_LOCK_REQUIRED;

    LuaPerlinNoiseMap *o = checkobject(L, 1);
    v3f p                = check_v3f(L, 2);
    bool use_buffer      = lua_istable(L, 3);

    if (!o->m_is3d)
        return 0;

    Noise *n = o->noise;
    n->perlinMap3D(p.X, p.Y, p.Z);

    size_t maplen = n->sx * n->sy * n->sz;

    if (use_buffer)
        lua_pushvalue(L, 3);
    else
        lua_newtable(L);

    for (size_t i = 0; i != maplen; i++) {
        lua_pushnumber(L, n->result[i]);
        lua_rawseti(L, -2, i + 1);
    }
    return 1;
}
예제 #2
0
파일: l_noise.cpp 프로젝트: 0151n/minetest
int LuaPerlinNoiseMap::l_get3dMap(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	int i = 0;

	LuaPerlinNoiseMap *o = checkobject(L, 1);
	v3f p = read_v3f(L, 2);

	Noise *n = o->noise;
	n->perlinMap3D(p.X, p.Y, p.Z);

	lua_newtable(L);
	for (int z = 0; z != n->sz; z++) {
		lua_newtable(L);
		for (int y = 0; y != n->sy; y++) {
			lua_newtable(L);
			for (int x = 0; x != n->sx; x++) {
				lua_pushnumber(L, n->np->offset + n->np->scale * n->result[i++]);
				lua_rawseti(L, -2, x + 1);
			}
			lua_rawseti(L, -2, y + 1);
		}
		lua_rawseti(L, -2, z + 1);
	}
	return 1;
}
예제 #3
0
Particle Predictor::genNoise(float sigma, Particle pConstraint, unsigned int type){
	if(sigma == 0.0f)
                ROS_DEBUG("[Predictor::genNoise] Warning standard deviation sigma is 0.0");
	
	Particle epsilon;
	Noise N;
	
	//epsilon.r.x = noise(sigma, type) * pConstraint.r.x;
	//epsilon.r.y = noise(sigma, type) * pConstraint.r.y;
	//epsilon.r.z = noise(sigma, type) * pConstraint.r.z;
	//epsilon.t.x = noise(sigma, type) * pConstraint.t.x;
	//epsilon.t.y = noise(sigma, type) * pConstraint.t.y;
	//epsilon.t.z = noise(sigma, type) * pConstraint.t.z;
	//
	//epsilon.z   = noise(sigma, type) * pConstraint.z;
	
	epsilon.r.x = N.randn_notrig(0.0f, sigma * pConstraint.r.x);
	epsilon.r.y = N.randn_notrig(0.0f, sigma * pConstraint.r.y);
	epsilon.r.z = N.randn_notrig(0.0f, sigma * pConstraint.r.z);
	epsilon.t.x = N.randn_notrig(0.0f, sigma * pConstraint.t.x);
	epsilon.t.y = N.randn_notrig(0.0f, sigma * pConstraint.t.y);
	epsilon.t.z = N.randn_notrig(0.0f, sigma * pConstraint.t.z);
	
	epsilon.z = N.randn_notrig(0.0f, sigma * pConstraint.z);
		
	return epsilon;
}
예제 #4
0
int LuaPerlinNoiseMap::l_get3dMap(lua_State *L)
{
    NO_MAP_LOCK_REQUIRED;
    size_t i = 0;

    LuaPerlinNoiseMap *o = checkobject(L, 1);
    v3f p = check_v3f(L, 2);

    if (!o->m_is3d)
        return 0;

    Noise *n = o->noise;
    n->perlinMap3D(p.X, p.Y, p.Z);

    lua_newtable(L);
    for (u32 z = 0; z != n->sz; z++) {
        lua_newtable(L);
        for (u32 y = 0; y != n->sy; y++) {
            lua_newtable(L);
            for (u32 x = 0; x != n->sx; x++) {
                lua_pushnumber(L, n->result[i++]);
                lua_rawseti(L, -2, x + 1);
            }
            lua_rawseti(L, -2, y + 1);
        }
        lua_rawseti(L, -2, z + 1);
    }
    return 1;
}
예제 #5
0
MStatus mDbl3dNoise::doIt( const MArgList& args )
{
	if (args.length() == 1)
	{
    	// vector array
		// get the arguments
    	MDoubleArray dblA;
	    unsigned int count;
		MStatus stat = getArgVec(args, dblA, count);
		ERROR_FAIL(stat);
    
		// do the job
		MDoubleArray result = MDoubleArray(count);		

        Noise noiseGen;
        for(int i=0;i<count;i++)
        {
        	int id = ELEMENTS_VEC *i;
	    	result[i] = noiseGen.improvedPerlin3dS(float(dblA[id]), float(dblA[id+1]),float(dblA[id+2]));
        }
            
        setResult(result);
        
	}
	else if (args.length() == 3)
	{
		// get the arguments
	    MDoubleArray dblA, dblB, dblC;
    	unsigned int incA, incB, incC, count;
		MStatus stat = getArgDblDblDbl(args, dblA, dblB, dblC, incA, incB, incC, count);
		ERROR_FAIL(stat);
	
		// do the actual job
		unsigned int iterA, iterB, iterC;
		iterA = iterB = iterC = 0;

		MDoubleArray result(count);
		Noise noiseGen;

		for (unsigned int i=0;i<count;i++)
		{
        	result[i] = noiseGen.improvedPerlin3dS(float(dblA[iterA]), float(dblB[iterB]),  float(dblC[iterC]));

			iterA += incA;
			iterB += incB;
			iterC += incC;            
		}
		
        setResult(result);
	}
	else
	{
		USER_ERROR_CHECK(MS::kFailure,("mDbl3dNoise: wrong number of arguments, should be 1 vecArray or 3 dblArrays!"));
	}
    
	return MS::kSuccess;

}
예제 #6
0
파일: Random.hpp 프로젝트: rayfill/cpplib
	Random():
		noise(),
		twister(
			(noise.getRandom() << 24) +
			(noise.getRandom() << 16) +
			(noise.getRandom() <<  8) +
			noise.getRandom())
	{
	}
예제 #7
0
void PeakFinder_SNR::findPeaks(const OrderedPairContainerRef& pairs,
                               vector<size_t>& resultIndices) const
{
    vector<OrderedPair> preprocessedData;
    if (config_.preprocessWithLogarithm)
        transform(pairs.begin(), pairs.end(), back_inserter(preprocessedData), ComputeLogarithm());  

    const OrderedPairContainerRef& data = config_.preprocessWithLogarithm ? preprocessedData : pairs;

    Noise noise = noiseCalculator_->calculateNoise(data); // TODO: investigate calculating noise on unprocessed data

    vector<double> pvalues;
    transform(data.begin(), data.end(), back_inserter(pvalues), CalculatePValue(noise));
    
    vector<double> rollingProducts = calculateRollingProducts(pvalues, config_.windowRadius);
    if (rollingProducts.size() != data.size()) 
        throw runtime_error("[PeakFinder_SNR::findPeaks()] This isn't happening"); 

    double thresholdValue = noise.mean + config_.zValueThreshold * noise.standardDeviation;
    double thresholdPValue = noise.pvalue(thresholdValue);
    double threshold = ((double(*)(double,int))std::pow)(thresholdPValue, 1+2*config_.windowRadius);

    // report local minima above the threshold
    for (size_t i=0; i<rollingProducts.size(); i++)
    {
        if ((i==0 || rollingProducts[i]<rollingProducts[i-1]) &&
            (i+1==rollingProducts.size() || rollingProducts[i]<rollingProducts[i+1]) &&
            rollingProducts[i] < threshold)
        { 
            resultIndices.push_back(i);
        }
    }

    if (config_.log) 
    {
        ostream& log = *config_.log;

        log << "[PeakFinder_SNR::findPeaks()]\n";

        log << "# noise: " << noise.mean << " " << noise.standardDeviation << endl;
        log << "# thresholdValue: " << thresholdValue << endl;
        log << "# thresholdPValue: " << thresholdPValue << endl;
        log << "# threshold: " << threshold << endl;
        log << "#\n";

        log << "# found data pvalue rollingProduct\n";
        for (size_t i=0; i<data.size(); ++i)
        {
            bool found = (find(resultIndices.begin(), resultIndices.end(), i) != resultIndices.end());
            log << (found?"* ":"  ") << fixed << setprecision(6) << data[i] << scientific << setw(15) << pvalues[i] << setw(15) << rollingProducts[i] << endl;
        }
        log << endl;

        log << "[PeakFinder_SNR::findPeaks()] end\n";
    }
}
예제 #8
0
MStatus mDbl2dNoise::doIt( const MArgList& args )
{
	if (args.length() == 1)
	{
		// get the arguments
    	MDoubleArray dblA;
	    unsigned int count;
		MStatus stat = getArgUV(args, dblA, count);
		ERROR_FAIL(stat);
    
		// do the job
		MDoubleArray result = MDoubleArray(count);		

        Noise noiseGen;
        for(int i=0;i<count;i++)
	    	result[i] = noiseGen.improvedPerlin2dS(float(dblA[i*ELEMENTS_UV]), float(dblA[i*ELEMENTS_UV+1]));
            
        setResult(result);
        
	}
	else if (args.length() == 2)
	{
		// get the arguments
	    MDoubleArray dblA, dblB;
    	unsigned int incA, incB, count;
		MStatus stat = getArgDblDbl(args, dblA, dblB, incA, incB, count);
		ERROR_FAIL(stat);
	
		// do the actual job
		unsigned int iterA, iterB;
		iterA = iterB = 0;

		MDoubleArray result(count);
		Noise noiseGen;

		for (unsigned int i=0;i<count;i++)
		{
        	result[i] = noiseGen.improvedPerlin2dS(float(dblA[iterA]), float(dblB[iterB]));

			iterA += incA;
			iterB += incB;
		}
		
        setResult(result);
	}
	else
	{
		USER_ERROR_CHECK(MS::kFailure,("mDbl2dNoise: wrong number of arguments, should be 1 uvArray or 2 dblArrays!"));
	}
    
	return MS::kSuccess;

}
예제 #9
0
int LuaPerlinNoiseMap::l_calc2dMap(lua_State *L)
{
    NO_MAP_LOCK_REQUIRED;

    LuaPerlinNoiseMap *o = checkobject(L, 1);
    v2f p                = check_v2f(L, 2);

    Noise *n = o->noise;
    n->perlinMap2D(p.X, p.Y);

    return 0;
}
예제 #10
0
파일: Guitar.cpp 프로젝트: Ahbee/stk
void Guitar :: setBodyFile( std::string bodyfile )
{
  bool fileLoaded = false;
  if ( bodyfile != "" ) {
    try {
      FileWvIn file( bodyfile );
  
      // Fill the StkFrames variable with the (possibly interpolated)
      // file data.
      excitation_.resize( (unsigned long) ( 0.5 + ( file.getSize() * Stk::sampleRate() / file.getFileRate() ) ) );
      file.tick( excitation_ );
      fileLoaded = true;
    }
    catch ( StkError &error ) {
      oStream_ << "Guitar::setBodyFile: file error (" << error.getMessage() << ") ... using noise excitation.";
      handleError( StkError::WARNING );
    }
  }

  if ( !fileLoaded ) {
    unsigned int M = 200;  // arbitrary value
    excitation_.resize( M );
    Noise noise;
    noise.tick( excitation_ );
    // Smooth the start and end of the noise.
    unsigned int N = (unsigned int) M * 0.2; // arbitrary value
    for ( unsigned int n=0; n<N; n++ ) {
      StkFloat weight = 0.5 * ( 1.0 - cos( n * PI / (N-1) ) );
      excitation_[n] *= weight;
      excitation_[M-n-1] *= weight;
    }
  }

  // Filter the excitation to simulate pick hardness
  pickFilter_.tick( excitation_ );

  // Compute file mean and remove (to avoid DC bias).
  StkFloat mean = 0.0;
  for ( unsigned int i=0; i<excitation_.frames(); i++ )
    mean += excitation_[i];
  mean /= excitation_.frames();

  for ( unsigned int i=0; i<excitation_.frames(); i++ )
    excitation_[i] -= mean;

  // Reset all the file pointers.
  for ( unsigned int i=0; i<strings_.size(); i++ )
    filePointer_[i] = 0;
}
예제 #11
0
int LuaPerlinNoiseMap::l_calc3dMap(lua_State *L)
{
    NO_MAP_LOCK_REQUIRED;

    LuaPerlinNoiseMap *o = checkobject(L, 1);
    v3f p                = check_v3f(L, 2);

    if (!o->m_is3d)
        return 0;

    Noise *n = o->noise;
    n->perlinMap3D(p.X, p.Y, p.Z);

    return 0;
}
예제 #12
0
void ParticleSystem::setFogModel(const Color4& color, int materialIndex) {
    const Color4unorm8 c(Color4(color.r, color.g, color.b, pow(color.a, 1.0f / SmokeVolumeSet::PARTICLE_GAMMA)));
    Random rnd;
    Noise noise;

    m_particle.resize(5000);
    m_physicsData.resize(m_particle.size());
    for (int i = 0; i < m_particle.size(); ++i) {
        SmokeVolumeSet::Particle& particle = m_particle[i];
        PhysicsData& physicsData = m_physicsData[i];

        // Fill sponza 
        particle.position = Point3(rnd.uniform(-16, 14), pow(rnd.uniform(0, 1), 4.0f) * 4 + 0.5f, rnd.uniform(-6.5, 6.5));

        /*
        if (rnd.uniform() < 0.3f) {
            // Arena bridge
            particle.position = Point3(rnd.uniform(-14, 14) - 2.0f, pow(rnd.uniform(0, 1), 5.0f) * 16.0f + 7.2f, rnd.uniform(-8, 8) - 28.0f);
        } else {
            // Arena everywhere
            particle.position = Point3(rnd.uniform(-20, 20), pow(rnd.uniform(0, 1), 5.0f) * 12.0f + 7.2f, rnd.uniform(-20, 20));
        }
        */

        particle.angle = rnd.uniform(0.0f, 2.0f) * pif(); 
        particle.materialIndex = materialIndex;
        particle.radius = 1.0f;
        particle.emissive = 0.0f;
        particle.color = c;
        int r = rnd.integer(0, 15);
        particle.color.r = unorm8::fromBits(r + particle.color.r.bits());
        particle.color.g = unorm8::fromBits(r + particle.color.g.bits());
        particle.color.b  = unorm8::fromBits(r + particle.color.b.bits());
        physicsData.angularVelocity = 0;//rnd.uniform(-1.0f, 1.0f) * (360.0f * units::degrees()) / (5.0f * units::seconds());

        // Unique values every 5m for the lowest frequencies
        const Vector3int32 intPos(particle.position * ((1 << 16) / (5 * units::meters())));
        const float acceptProbability = pow(max(0.0f, noise.sampleFloat(intPos.x, intPos.y, intPos.z, 5)), 2.0f);

        if (rnd.uniform() > acceptProbability) {
            // Reject this puff
            --i;
        }
    }

    // Ensure that this matches
    m_physicsData.resize(m_particle.size());
}
예제 #13
0
    void predict_obsrv(Tuple& models_tuple,
                       double delta_time,
                       const State& state,
                       const Noise& noise,
                       Obsrv& prediction,
                       const int obsrv_offset = 0,
                       const int state_offset = 0,
                       const int noise_offset = 0)
    {
        auto&& model = std::get<k>(models_tuple);

        const auto obsrv_dim = model->obsrv_dimension();
        const auto state_dim = model->state_dimension();
        const auto noise_dim = model->noise_dimension();

        prediction.middleRows(obsrv_offset, obsrv_dim) =
            model->predict_obsrv(
                state.middleRows(state_offset, state_dim),
                noise.middleRows(noise_offset, noise_dim),
                delta_time
            );

        if (Size == k + 1) return;

        predict_obsrv<Size, k + (k + 1 < Size ? 1 : 0)>(
                    models_tuple,
                    delta_time,
                    state,
                    noise,
                    prediction,
                    obsrv_offset + obsrv_dim,
                    state_offset + state_dim,
                    noise_offset + noise_dim);
    }
예제 #14
0
파일: apu_test.cpp 프로젝트: crust/nes
int main(int argc, char* argv[]) {

  uint16_t length = 2048;

  Noise noise;
  noise.reg0 = 0;
  noise.reg1 = 0;
  noise.reg2 = 0;

  for (int i = 0; i < length; ++i) {
    noise.update();
    std::cout << (int)noise.sample();
  }
  std::cout << "\n";

}
예제 #15
0
returnValue Sensor::setOutputNoise(	const Noise& _noise,
									double _noiseSamplingTime
									)
{
	if ( _noise.getDim( ) != getNY( ) )
		return ACADOERROR( RET_INVALID_ARGUMENTS );

	for( uint i=0; i<getNY( ); ++i )
	{
		if ( additiveNoise[i] != 0 )
			delete additiveNoise[i];

		additiveNoise[i] = _noise.clone( i );
	}

	noiseSamplingTimes.setAll( _noiseSamplingTime );

	return SUCCESSFUL_RETURN;
}
예제 #16
0
int LuaPerlinNoiseMap::l_get2dMap_flat(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;

	LuaPerlinNoiseMap *o = checkobject(L, 1);
	v2f p = check_v2f(L, 2);

	Noise *n = o->noise;
	n->perlinMap2D(p.X, p.Y);

	size_t maplen = n->sx * n->sy;

	lua_newtable(L);
	for (size_t i = 0; i != maplen; i++) {
		lua_pushnumber(L, n->result[i]);
		lua_rawseti(L, -2, i + 1);
	}
	return 1;
}
예제 #17
0
MStatus mDbl1dNoise::doIt( const MArgList& args )
{
	// get the arguments
    MDoubleArray dblA;
    unsigned int count;
	MStatus stat = getArgDbl(args, dblA, count);
	ERROR_FAIL(stat);
    
	// do the actual job
	Noise noiseGen;
    
	for (unsigned int i=0;i<dblA.length();i++)
	{
        dblA[i] = noiseGen.improvedPerlin1dS(float(dblA[i]));
	}

	setResult(dblA);
	return MS::kSuccess;
}
예제 #18
0
파일: main.cpp 프로젝트: NCCA/RandomTests
OIIO_NAMESPACE_USING

int main()
{
  constexpr int xres = 1024, yres = 720;
  constexpr int channels = 1; // RGB
  int frame=0;

  std::unique_ptr<float []>pixels(new float[xres*yres*channels]);
  std::unique_ptr <ImageOutput> out( ImageOutput::create ("test.png"));
  ImageSpec spec (xres, yres, channels, TypeDesc::FLOAT);

  Noise<uint_fast8_t> n;

 // for(float no=0.001; no<1.0; no+=0.005)
  for(int f=0; f<200; ++f)
  {
    std::cout<<"frame "<<frame<<" "<<f<<"\n";
  int i=-1;
  n.setSeed(f);
  for(int y=0; y<yres; ++y)
  {
    for(int x=0; x<xres; ++x)
    {
//      pixels[++i]=n.complex(12,5.02,0.1,Point(x,y,0.0f));
      pixels[++i]=n.complex(13,3.02,0.1,Point(x,y,0.0f));
     // pixels[++i]=n.complex(8,8.02,no,Point(x,y,0.0f));
     //pixels[++i]=n.noise(0.55,Point(x,y,0.0f));
//     pixels[++i]=n.noise(0.2,Point(x,y,0.0f));
//     pixels[++i]=n.noise(0.3,Point(x,y,0.0f));
//    pixels[++i]=n.turbulance(0.9,Point(x,y,0.0f));
//    pixels[++i]=n.turbulance(1.09,Point(x,y,0.0f));
   // pixels[++i]=n.turbulance(no,Point(x,y,0.0f));
    }
  }
  char str[40];
  sprintf(str,"noiseSeed%03d.png",frame++);
  out->open (str, spec);
  out->write_image (TypeDesc::FLOAT, pixels.get());
  out->close();
  }
  return EXIT_SUCCESS;
}
예제 #19
0
파일: main.cpp 프로젝트: PelinV/Elman
bool DeleteNoise(char* src){
	Noise N;
	
	ofstream FS("pattern_elman.txt");

	int pattern_s = N.delete_noise(src);
	FS << pattern_s << " ";
	for (int i = pattern_s; i > 0; --i)
	{
		FS << i << ".bmp ";
		for (int j = pattern_s; j > 0; --j)
		{
			FS << (j == i)?"1":"0";
			FS << " ";
		}
	}
	
	FS.close();
	return 1;
}
예제 #20
0
파일: l_noise.cpp 프로젝트: 0151n/minetest
int LuaPerlinNoiseMap::l_get2dMap_flat(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;

	LuaPerlinNoiseMap *o = checkobject(L, 1);
	v2f p = read_v2f(L, 2);

	Noise *n = o->noise;
	n->perlinMap2D(p.X, p.Y);

	int maplen = n->sx * n->sy;
	
	lua_newtable(L);
	for (int i = 0; i != maplen; i++) {
		float noiseval = n->np->offset + n->np->scale * n->result[i];
		lua_pushnumber(L, noiseval);
		lua_rawseti(L, -2, i + 1);
	}
	return 1;
}
예제 #21
0
returnValue Sensor::setOutputNoise(	uint idx,
									const Noise& _noise,
									double _noiseSamplingTime
									)
{
	if ( ( idx >= getNY( ) ) || ( _noise.getDim( ) != 1 ) )
		return ACADOERROR( RET_INVALID_ARGUMENTS );

	if ( additiveNoise[idx] != 0 )
		delete additiveNoise[idx];

	additiveNoise[idx] = _noise.clone( );

	if ( ( idx > 0 ) && ( acadoIsEqual( _noiseSamplingTime, noiseSamplingTimes(0) ) == BT_FALSE ) )
		ACADOWARNING( RET_NO_DIFFERENT_NOISE_SAMPLING_FOR_DISCRETE );

	noiseSamplingTimes.setAll( _noiseSamplingTime ); // should be changed later

	return SUCCESSFUL_RETURN;
}
예제 #22
0
파일: noise.cpp 프로젝트: artemeliy/inf4715
	void Set(PB2Value& v, ReferenceMaker* owner, ParamID id, int tabIndex, TimeValue t)    // set from v
	{
		Noise* p = (Noise*)owner;
		if (p!=NULL)
			{
			switch (id)
				{
				case noise_lowthresh:
					{
					float high = p->GetHiThresh();
					float low = v.f;
					if (low > high) p->SetHiThresh(low+0.001f);
					break;
					}
				case noise_hithresh:
					{
					float low = p->GetLowThresh();
					float high = v.f;
					if (low > high) p->SetLowThresh(high-0.001f);
					break;
					}
				}
			p->EnableStuff();
			}

	}
예제 #23
0
파일: noise.cpp 프로젝트: artemeliy/inf4715
RefTargetHandle Noise::Clone(RemapDir &remap) {
	Noise *mnew = new Noise();
	*((MtlBase*)mnew) = *((MtlBase*)this);  // copy superclass stuff
	mnew->ReplaceReference(XYZGEN_REF,remap.CloneRef(xyzGen));
	mnew->ReplaceReference(TEXOUT_REF,remap.CloneRef(texout));
	mnew->ReplaceReference(PBLOCK_REF,remap.CloneRef(pblock));
	mnew->col[0] = col[0];
	mnew->col[1] = col[1];
	mnew->noiseType = noiseType;
	mnew->size = size;
	mnew->avgValue = avgValue;
	mnew->ivalid.SetEmpty();	
	mnew->cacheValid.SetEmpty();
	for (int i = 0; i<NSUBTEX; i++) {
		mnew->subTex[i] = NULL;
		if (subTex[i])
			mnew->ReplaceReference(i+2,remap.CloneRef(subTex[i]));
		mnew->mapOn[i] = mapOn[i];
		}
	BaseClone(this, mnew, remap);
	return (RefTargetHandle)mnew;
	}
예제 #24
0
int LuaPerlinNoiseMap::l_get2dMap(lua_State *L)
{
	int i = 0;

	LuaPerlinNoiseMap *o = checkobject(L, 1);
	v2f p = read_v2f(L, 2);

	Noise *n = o->noise;
	n->perlinMap2D(p.X, p.Y);

	lua_newtable(L);
	for (int y = 0; y != n->sy; y++) {
		lua_newtable(L);
		for (int x = 0; x != n->sx; x++) {
			float noiseval = n->np->offset + n->np->scale * n->result[i++];
			lua_pushnumber(L, noiseval);
			lua_rawseti(L, -2, x + 1);
		}
		lua_rawseti(L, -2, y + 1);
	}
	return 1;
}
예제 #25
0
int LuaPerlinNoiseMap::l_get2dMap(lua_State *L)
{
    NO_MAP_LOCK_REQUIRED;
    size_t i = 0;

    LuaPerlinNoiseMap *o = checkobject(L, 1);
    v2f p = check_v2f(L, 2);

    Noise *n = o->noise;
    n->perlinMap2D(p.X, p.Y);

    lua_newtable(L);
    for (u32 y = 0; y != n->sy; y++) {
        lua_newtable(L);
        for (u32 x = 0; x != n->sx; x++) {
            lua_pushnumber(L, n->result[i++]);
            lua_rawseti(L, -2, x + 1);
        }
        lua_rawseti(L, -2, y + 1);
    }
    return 1;
}
예제 #26
0
파일: noise.cpp 프로젝트: artemeliy/inf4715
		void proc(ILoad *iload) {  
			if (n->FixLevel0())
				iload->SetObsolete();

			if (n->loadOnChecks)
				{
				macroRecorder->Disable();  
					n->pblock->SetValue( noise_map1_on, 0, n->mapOn[0]);
					n->pblock->SetValue( noise_map2_on, 0, n->mapOn[1]);
					n->pblock->SetValue( noise_type, 0, n->noiseType);
				macroRecorder->Enable(); 
				}
			delete this; 


			} 
예제 #27
0
파일: noise.cpp 프로젝트: artemeliy/inf4715
INT_PTR NoiseDlgProc::DlgProc(
		TimeValue t,IParamMap2 *map,HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
	{
	switch (msg) {
		case WM_COMMAND:
			switch (LOWORD(wParam)) 
				{
				case IDC_NOISE_SWAP:
					{
					noise->SwapInputs();
					}
				break;
				}
			break;
		}
	return FALSE;
	}
예제 #28
0
    void predict_state(Tuple& models_tuple,
                       double delta_time,
                       const State& state,
                       const Noise& noise,
                       const Input& input,
                       State& prediction,
                       const int state_offset = 0,
                       const int noise_offset = 0,
                       const int input_offset = 0)
    {
        auto&& model = std::get<k>(models_tuple);

        const auto state_dim = model.state_dimension();
        const auto noise_dim = model.noise_dimension();
        const auto input_dim = model.input_dimension();

        prediction.middleRows(state_offset, state_dim) =
            model.predict_state(
                delta_time,
                state.middleRows(state_offset, state_dim),
                noise.middleRows(noise_offset, noise_dim),
                input.middleRows(input_offset, input_dim)
            );

        if (Size == k + 1) return;

        predict_state<Size, k + (k + 1 < Size ? 1 : 0)>(
                    models_tuple,
                    delta_time,
                    state,
                    noise,
                    input,
                    prediction,
                    state_offset + state_dim,
                    noise_offset + noise_dim,
                    input_offset + input_dim);
    }
예제 #29
0
Map::Map(const int width, const int height, char* mapData)
{
	Map::map = this;
	unsigned int start = clock();

	this->Width = width;
	this->Height = height;
	Noise* noiser = new Noise((unsigned int)time(NULL));

	heightMap = new int[width];
	for (int i = 0; i < Width; i++) {
		heightMap[i] = (int) (noiser->eval(i / 20.0f) * Height);
	}

	walls = new Wall*[Width];
	for (int i = 0; i < Width; i++) {
		walls[i] = new Wall[Height];
		for (int j = 0; j < Height; j++) {
			walls[i][j].Id = 0;
		}
	}
	blocks = new Tile*[Width];
	for (int i = 0; i < Width; i++) {
		blocks[i] = new Tile[Height];
	}

	if (!Settings::Multiplayer)
	{

		for (int i = 0; i < Width; i++) {
			int top = heightMap[i];
			for (int j = 0; j < Height; j++) {
				walls[i][j].Id = Block::Dirt->Id;
				if (rand() % 101 > 50 || true || j > top && j < top + 3)
					blocks[i][j].Id = Block::Dirt->Id;
			}
		}
		for (int i = 0; i < Width; i++) {
			int top = heightMap[i];
			for (int j = 0; j <= top; j++) {
				walls[i][j].Id = 0;
				blocks[i][j].Id = 0;
			}
		}
		printf("World tiles fill: %d ms. \n", clock() - start);
		start = clock();

		/*for (int i = 0; i < 0; i++)
			CelluarAuto(Height, i);*/

		printf("Celluar Auto: %d ms. \n", clock() - start);
		start = clock();

		int k = 0;
		while (k < 100)
		{
			int i = rand() % Width;
			int j = rand() % height;
			if (GetBlock(i, j) == 0)
				continue;
			k += GenerateVein(i, j, Block::Stone->Id, 5);
		}

		printf("Veins generation: %d ms. \n", (clock() - start));
	}
	else
	{
		for (int i = 0; i < Width; i++) {
			for (int j = 0; j < Height; j++) {
				blocks[i][j].Id = mapData[i + j * width];
			}
		}
	}


	start = clock();
	
	for (int i = 0; i < Width; i++) {
		for (int j = 0; j < Height; j++) {
			if (blocks[i][j].Id != 0)
				blocks[i][j].connectionIndex = GetConnectionIndex(i, j);
		}
	}
	for (int i = 0; i < Width; i++) {
		for (int j = 0; j < Height; j++) {
			if (walls[i][j].Id != 0)
				walls[i][j].connectionIndex = GetConnectionIndex(i, j, true);
		}
	}
	printf("Tiles connections: %d ms. \n", clock() - start);
	start = clock();

	for (int i = 0; i < Width; i++) {
		for (int j = 0; j < Height; j++) {
			if (blocks[i][j].Id == 0 && walls[i][j].Id == 0)
			{
				blocks[i][j].lightSource = MAX_LIGHT;
				if (NearLive(i, j, 1) == 0)
					blocks[i][j].lightValue = MAX_LIGHT;
			}
		}
	}

	minX = 0;
	minY = 0;
	maxX = width;
	maxY = height;
	CalculateLights(true);

	printf("Lights calculations: %d ms. \n", clock() - start);
	start = clock();

	player = new Player();
	Respawn();
	entities.push_back(player);

	int water_count = 3;
	int water_x = (int)player->GetPosition().x;
	int water_y = GetTop(water_x);
	for (int i = water_x - 2; i < water_x + 2; i++)
	{
		for (int j = water_y; j < water_y + 2; j++)
		{
			SetBlock(i, j, 0);
			SetWall(i, j, 0);
			for (int k = 0; k < water_count; k++)
			{
				for (int l = 0; l < water_count; l++)
				{
					Water* water = new Water();
					water->SetPosition(glm::vec2(i + k * (1 / (float)water_count), j + l * (1 / (float)water_count)));
					waters.push_back(water);
					entities.push_back(water);
				}
			}
		}
	}
	



	skyManager = new SkyManager(this->Width);
}
예제 #30
0
파일: T08.cpp 프로젝트: saggita/r5ge
void TestApp::Run()
{
	if (*mCore << "Config/T08.txt")
	{
		mCore->Lock();

		// First we need to create a heightmap we'll use to create the terrain. R5 has a fairly flexible
		// noise library with a variety of simple filters that we can use for just that purpose.

		Noise noise;

		// We want to generate a 256x256 heightmap
		noise.SetSize(256, 256);

		// You can combine a variety of filters to create the terrain's "final" look, but for the sake
		// of simplicity, let's only use one -- a perlin noise. The numbers that follow are optional
		// parameters. In this case '8' means generate an 8-octave noise, and 0.65 means that the noise
		// with values above 0.65 will be mirrored, turning high peaks into volcano-like crevices.
		// This type of noise is also known as ridged multifractal due to the ridges it tends to produce.

		noise.ApplyFilter("Perlin").Set(8.0f, 0.65f);

		// Now that we have our heightmap, we should create our terrain.
		mTerrain = mCore->GetRoot()->AddObject<Terrain>("First Terrain");

		// We want to partition our terrain into an 8 by 8 grid. This will create 64 subdivisions
		// that the terrain will use together with frustum culling to automatically discard portions
		// of the terrain that are not visible. We can actually see what percentage of the terrain
		// is being rendered by using the Terrain::GetVisibility() function after the scene has been
		// culled... but more on that later.

		mTerrain->PartitionInto(8, 8);

		// In order to fill the terrain's partitions with geometry we need to provide additional
		// information about the heightmap that will be used and how it will be used to begin with.
		// Terrain::Heightmap struct exists for just this purpose.

		// Provide the heightmap itself
		Terrain::Heightmap hm (noise.GetBuffer(), noise.GetWidth(), noise.GetHeight());

		// We want each subdivided mesh to be 32 by 32 quads. As you might recall there are 64 subdivisions
		// in total, and now each of those 64 will contain (32 x 32) = 1024 quads, or 2048 triangles.
		// When the terrain is generated the provided heightmap will be sampled using bicubic filtering,
		// so you can make the mesh much more tessellated than the heightmap, if you wish.

		hm.mMeshSize.Set(32, 32);

		// By default the terrain will be generated with dimensions of (0, 0, 0) to (1, 1, 1). Of course
		// that's not what we want. Let's apply a different scaling property here, stretching the terrain
		// along the horizontal plane (and a little bit along the vertical as well).
		hm.mTerrainScale.Set(20.0f, 20.0f, 4.0f);

		// By default the terrain starts at (0, 0, 0). Let's somwhat-center it instead.
		hm.mTerrainOffset.Set(-10.0f, -10.0f, -3.0f);

		// Time to fill the actual geometry. One last important thing to note is the optional bounding
		// box padding parameter that QuadTree::Fill function accepts. This parameter is used to extrude
		// the height of the bounding box vertically in both directions so that child objects can
		// fit easier. Objects that "fit" into the bounding box of the terrain's subdivisioned
		// nodes will get culled faster, speeding up your game. I recommend setting this property to
		// the height of the tallest building or tree you expect to place on your map. In this
		// example we don't have any objects placed as children of the terrain, but it's worth
		// noting nonetheless.

		mTerrain->FillGeometry(&hm, 0.0f);

		// And now... we need to be able to see the terrain we've just created.
		// The best way to visualize a terrain without any textures on it is to display it in wireframe.
		// You can easily do that in R5 by using a material that has a "Wireframe" technique as one of
		// its draw methods. As long as you won't forget to use that technique in the OnDraw function,
		// your wireframe object will show up in your scene. In this case it will be used for our terrain.

		// Wireframe is an R5-recognized technique so we don't need to set up any states.
		ITechnique* wireframe = mGraphics->GetTechnique("Wireframe");

		// Save it for our Draw function
		//mTechniques.Expand() = wireframe;

		// We'll be using a custom material to draw our terrain. Let's just give it the same name.
		IMaterial* mat = mGraphics->GetMaterial("Terrain");

		// Se need to change the material's color as all newly created materials start invisible (alpha of 0)
		mat->SetDiffuse( Color4ub(255, 255, 255, 255) );

		// Add this technique to the material
		mat->GetDrawMethod(wireframe, true);

		// Tell the terrain to use this material
		mTerrain->SetMaterial(mat);

		// Last thing we should do is find the label I've added to the "T08.txt" configuration file.
		// The reason it's not created via code is to simplify this tutorial. If you're curious,
		// have a look at that resource file and see how it was created inside. Since the label is
		// part of the configuration file that we've loaded at the top of this function, it's already
		// in memory and all we have to do is find it using this handy template:

		mLabel = mUI->FindWidget<UILabel>("Status");

		// Add a custom draw function that will update the label showing us how much of the terrain is
		// actually visible at any given time. Look below to see exactly what it does.
		mCore->AddOnDraw( bind(&TestApp::OnDraw, this) );

		// Enter the message processing loop
		mCore->Unlock();
		while (mCore->Update());

		//*mCore >> "Config/T08.txt";
	}
}